//changes private async Task <IList <ItemCost> > GetCostOfPlan(ProductionPlanHeader plan, int itemId) { var availableRawMaterials = await _context.RawItems.Where(a => a.CurrentPlace == plan.BusinessPlace && a.AvailableQuantity > 0).ToListAsync(); // calculate Total cost of eacch raw item used IList <ItemCost> rawItemCostList = new List <ItemCost>(); IList <ItemCost> prodItemCostList = new List <ItemCost>(); foreach (var recipeitem in plan.ProductionPlanRecipes) { var currentItemList = availableRawMaterials.Where(a => a.ItemId == recipeitem.ItemId); decimal accumulatedCost = 0; decimal accumulatedQty = 0; foreach (var rawItem in currentItemList) { accumulatedCost = accumulatedCost + (rawItem.AvailableQuantity * rawItem.CostPrice); accumulatedQty = accumulatedQty + rawItem.AvailableQuantity; } var costPerUnit = accumulatedCost / accumulatedQty; rawItemCostList.Add(new ItemCost { ItemID = recipeitem.ItemId, CostPerUnit = costPerUnit }); } foreach (var item in plan.ProductionPlanDetails) { var planQuantity = item.Quantity; var recipe = await _context.IngredientHeaders.Include(a => a.IngredientsDetail).FirstOrDefaultAsync(a => a.ItemId == item.ItemId); decimal accumulatedCost = 0; foreach (var rawItem in recipe.IngredientsDetail) { var costPerUnitItem = rawItemCostList.FirstOrDefault(a => a.ItemID == rawItem.ItemId).CostPerUnit; accumulatedCost = accumulatedCost + (costPerUnitItem * rawItem.Quantity); } var costForOne = accumulatedCost / recipe.ServingSize; prodItemCostList.Add(new ItemCost { ItemID = item.ItemId, CostPerUnit = costForOne }); } //cost of labour and other misc return(prodItemCostList); }
public async Task CreateProductionPlan(ProductionPlanHeader productionPlanHeader) { var prodPlan = await _context.AddAsync(productionPlanHeader); }