Ejemplo n.º 1
0
 public static void CalculateCost(PeriodicConsumption pc, WorkPeriod workPeriod)
 {
     var sales = GetSales(workPeriod);
     foreach (var sale in sales)
     {
         var lSale = sale;
         var recipe = Dao.Single<Recipe>(x => x.Portion.Name == lSale.PortionName && x.Portion.MenuItemId == lSale.MenuItemId, x => x.Portion, x => x.RecipeItems, x => x.RecipeItems.Select(y => y.InventoryItem));
         if (recipe != null)
         {
             var totalcost = recipe.FixedCost;
             foreach (var recipeItem in recipe.RecipeItems.Where(x => x.InventoryItem != null && x.Quantity > 0))
             {
                 var item = recipeItem;
                 var pci = pc.PeriodicConsumptionItems.SingleOrDefault(x => x.InventoryItem.Id == item.InventoryItem.Id);
                 if (pci != null && pci.GetPredictedConsumption() > 0)
                 {
                     var cost = recipeItem.Quantity * (pci.Cost / pci.UnitMultiplier);
                     cost = (pci.GetConsumption() * cost) / pci.GetPredictedConsumption();
                     totalcost += cost;
                 }
             }
             var ci = pc.CostItems.SingleOrDefault(x => x.Portion.Id == recipe.Portion.Id);
             if (ci != null) ci.Cost = decimal.Round(totalcost, 2);
         }
     }
 }
Ejemplo n.º 2
0
        private static void CreatePeriodicConsumptionItems(PeriodicConsumption pc, IWorkspace workspace)
        {
            var previousPc = GetPreviousPeriodicConsumption(workspace);
            var transactionItems = GetTransactionItems();
            foreach (var inventoryItem in workspace.All<InventoryItem>())
            {
                var iItem = inventoryItem;
                var pci = new PeriodicConsumptionItem { InventoryItem = inventoryItem };
                pci.UnitMultiplier = pci.InventoryItem.TransactionUnitMultiplier > 0 ? pci.InventoryItem.TransactionUnitMultiplier : 1;
                pc.PeriodicConsumptionItems.Add(pci);
                var previousCost = 0m;
                if (previousPc != null)
                {
                    var previousPci = previousPc.PeriodicConsumptionItems.SingleOrDefault(x => x.InventoryItem.Id == iItem.Id);
                    if (previousPci != null) pci.InStock =
                        previousPci.PhysicalInventory != null
                        ? previousPci.PhysicalInventory.GetValueOrDefault(0)
                        : previousPci.GetInventoryPrediction();
                    if (previousPci != null)
                        previousCost = previousPci.Cost * pci.InStock;
                }
                var tim = transactionItems.Where(x => x.InventoryItem.Id == iItem.Id);
                pci.Purchase = tim.Sum(x => x.Quantity * x.Multiplier) / pci.UnitMultiplier;
                var totalPrice = tim.Sum(x => x.Price * x.Quantity);
                if (pci.InStock > 0 || pci.Purchase > 0)
                {
                    pci.Cost = pci.InStock > 0
                                   ? decimal.Round((totalPrice + previousCost)/(pci.InStock + pci.Purchase), 2)
                                   : decimal.Round(totalPrice/pci.Purchase, 2);
                }

            }
        }
Ejemplo n.º 3
0
 public void CreatePeriodicConsumptionItems(int warehouseId, IList<InventoryItem> inventoryItems, PeriodicConsumption previousPc, List<InventoryTransaction> transactionItems)
 {
     var warehouseConsumption = WarehouseConsumptions.Single(x => x.WarehouseId == warehouseId);
     var previousWhc = previousPc != null
                           ? previousPc.WarehouseConsumptions.Single(x => x.WarehouseId == warehouseConsumption.WarehouseId)
                           : null;
     warehouseConsumption.CreatePeriodicConsumptionItems(inventoryItems, previousWhc, transactionItems);
 }
Ejemplo n.º 4
0
 public void CalculateCost(PeriodicConsumption pc, WorkPeriod workPeriod)
 {
     foreach (var warehouseConsumption in pc.WarehouseConsumptions)
     {
         var recipes = GetSales(workPeriod, warehouseConsumption.WarehouseId).Select(sale => _inventoryDao.GetRecipe(sale.PortionName, sale.MenuItemId));
         pc.UpdateFinalCost(recipes.ToList(), warehouseConsumption.WarehouseId);
     }
 }
Ejemplo n.º 5
0
 public static PeriodicConsumption Create(WorkPeriod currentWorkPeriod, IEnumerable<int> warehouseIds)
 {
     var result = new PeriodicConsumption
     {
         WorkPeriodId = currentWorkPeriod.Id,
         Name = currentWorkPeriod.StartDate + " - " +
                currentWorkPeriod.EndDate,
         StartDate = currentWorkPeriod.StartDate,
         EndDate = currentWorkPeriod.EndDate
     };
     result.CreateWarehouseConsumptions(warehouseIds);
     return result;
 }
Ejemplo n.º 6
0
        public static PeriodicConsumption Create(WorkPeriod currentWorkPeriod, IEnumerable <int> warehouseIds)
        {
            var result = new PeriodicConsumption
            {
                WorkPeriodId = currentWorkPeriod.Id,
                Name         = currentWorkPeriod.StartDate + " - " +
                               currentWorkPeriod.EndDate,
                StartDate = currentWorkPeriod.StartDate,
                EndDate   = currentWorkPeriod.EndDate
            };

            result.CreateWarehouseConsumptions(warehouseIds);
            return(result);
        }
Ejemplo n.º 7
0
        private static PeriodicConsumption CreateNewPeriodicConsumption(IWorkspace workspace)
        {
            var pc = new PeriodicConsumption
            {
                WorkPeriodId = AppServices.MainDataContext.CurrentWorkPeriod.Id,
                Name = AppServices.MainDataContext.CurrentWorkPeriod.StartDate + " - " +
                       AppServices.MainDataContext.CurrentWorkPeriod.EndDate,
                StartDate = AppServices.MainDataContext.CurrentWorkPeriod.StartDate,
                EndDate = AppServices.MainDataContext.CurrentWorkPeriod.EndDate
            };

            CreatePeriodicConsumptionItems(pc, workspace);
            UpdateConsumption(pc, workspace);
            CalculateCost(pc, AppServices.MainDataContext.CurrentWorkPeriod);
            return pc;
        }
Ejemplo n.º 8
0
        private static void UpdateConsumption(PeriodicConsumption pc, IWorkspace workspace)
        {
            var sales = GetSales(AppServices.MainDataContext.CurrentWorkPeriod);

            foreach (var sale in sales)
            {
                var lSale = sale;
                var recipe = workspace.Single<Recipe>(x => x.Portion.Name == lSale.PortionName && x.Portion.MenuItemId == lSale.MenuItemId);
                if (recipe != null)
                {
                    var cost = 0m;
                    foreach (var recipeItem in recipe.RecipeItems.Where(x => x.InventoryItem != null && x.Quantity > 0))
                    {
                        var item = recipeItem;
                        var pci = pc.PeriodicConsumptionItems.Single(x => x.InventoryItem.Id == item.InventoryItem.Id);
                        pci.Consumption += (item.Quantity * sale.Total) / pci.UnitMultiplier;
                        Debug.Assert(pci.Consumption > 0);
                        cost += recipeItem.Quantity * (pci.Cost / pci.UnitMultiplier);
                    }
                    pc.CostItems.Add(new CostItem { Name = sale.MenuItemName, Portion = recipe.Portion, CostPrediction = cost, Quantity = sale.Total });
                }
            }
        }
Ejemplo n.º 9
0
        public void CreatePeriodicConsumptionItems(int warehouseId, IList <InventoryItem> inventoryItems, PeriodicConsumption previousPc, List <InventoryTransaction> transactionItems)
        {
            var warehouseConsumption = WarehouseConsumptions.Single(x => x.WarehouseId == warehouseId);
            var previousWhc          = previousPc != null
                                  ? previousPc.WarehouseConsumptions.Single(x => x.WarehouseId == warehouseConsumption.WarehouseId)
                                  : null;

            warehouseConsumption.CreatePeriodicConsumptionItems(inventoryItems, previousWhc, transactionItems);
        }
Ejemplo n.º 10
0
 private void UpdateConsumption(PeriodicConsumption pc, int warehouseId)
 {
     var sales = GetSales(_applicationState.CurrentWorkPeriod, warehouseId);
     foreach (var sale in sales)
     {
         var portionName = sale.PortionName;
         var menuItemId = sale.MenuItemId;
         var recipe = _inventoryDao.GetRecipe(portionName, menuItemId);
         pc.UpdateConsumption(recipe, sale.Total, warehouseId);
         pc.CreateCostItem(recipe, sale.MenuItemName, sale.Total, warehouseId);
     }
 }
Ejemplo n.º 11
0
 public void SavePeriodicConsumption(PeriodicConsumption pc)
 {
     Dao.Save(pc);
 }
Ejemplo n.º 12
0
 private void Filter(PeriodicConsumption pc, IEnumerable<InventoryItem> inventoryItems, bool keepMappedItems)
 {
     foreach (var warehouseConsumption in pc.WarehouseConsumptions)
     {
         var warehouse = _cacheService.GetWarehouses().Single(x => x.Id == warehouseConsumption.WarehouseId);
         var items =
             warehouseConsumption.PeriodicConsumptionItems.Where(
                 x => x.InStock == 0 && x.Consumption == 0 && x.Added == 0 && x.Removed == 0 && x.PhysicalInventory == null);
         var removingItems = keepMappedItems ? items.Where(x => !ShouldKeep(x, inventoryItems, warehouse)).ToList() : items.ToList();
         if (removingItems.Any())
         {
             removingItems.ForEach(x => warehouseConsumption.PeriodicConsumptionItems.Remove(x));
         }
     }
 }
Ejemplo n.º 13
0
 public void FilterUnneededItems(PeriodicConsumption pc)
 {
     var inventoryItems = _inventoryDao.GetInventoryItems();
     Filter(pc, inventoryItems, false);
 }