Example #1
0
 private static void OnWorkperiodStatusChanged(EventParameters <WorkPeriod> obj)
 {
     if (obj.Topic == EventTopicNames.WorkPeriodStatusChanged)
     {
         using (var ws = WorkspaceFactory.Create())
         {
             if (ws.Count <Recipe>() > 0)
             {
                 if (!AppServices.MainDataContext.IsCurrentWorkPeriodOpen)
                 {
                     var pc = InventoryService.GetCurrentPeriodicConsumption(ws);
                     if (pc.Id == 0)
                     {
                         ws.Add(pc);
                     }
                     ws.CommitChanges();
                 }
                 else
                 {
                     if (AppServices.MainDataContext.PreviousWorkPeriod != null)
                     {
                         var pc = InventoryService.GetPreviousPeriodicConsumption(ws);
                         if (pc != null)
                         {
                             InventoryService.CalculateCost(pc, AppServices.MainDataContext.PreviousWorkPeriod);
                             ws.CommitChanges();
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
 protected override void OnSave(string value)
 {
     InventoryService.CalculateCost(Model, AppServices.MainDataContext.CurrentWorkPeriod);
     base.OnSave(value);
 }
Example #3
0
 public void UpdateCost()
 {
     InventoryService.CalculateCost(Model, AppServices.MainDataContext.CurrentWorkPeriod);
     _costItems = null;
     RaisePropertyChanged("CostItems");
 }
Example #4
0
        public void TestCost()
        {
            var workspace = PrepareMenu("c:\\sd1.txt");

            var iskender = workspace.Single <MenuItem>(x => x.Name.ToLower().Contains("iskender"));

            iskender.Portions[0].MenuItemId = iskender.Id;

            Assert.IsTrue(workspace.All <MenuItem>().Count() > 0);
            Assert.IsNotNull(iskender);
            Assert.IsTrue(iskender.Portions.Count == 1);

            var donerEti = new InventoryItem {
                Name = "Döner Eti", BaseUnit = "GR", GroupCode = "", TransactionUnit = "KG", TransactionUnitMultiplier = 1000
            };
            var yogurt = new InventoryItem {
                Name = "Yoğurt", BaseUnit = "GR", GroupCode = "", TransactionUnit = "KG", TransactionUnitMultiplier = 1000
            };
            var pide = new InventoryItem {
                Name = "Pide", BaseUnit = "Yarım", GroupCode = "", TransactionUnit = "Adet", TransactionUnitMultiplier = 2
            };
            var zeytinYagi = new InventoryItem {
                Name = "Zeytin Yağı", BaseUnit = "Ölçü", GroupCode = "", TransactionUnit = "Litre", TransactionUnitMultiplier = 100
            };

            workspace.Add(donerEti);
            workspace.Add(yogurt);
            workspace.Add(pide);
            workspace.Add(zeytinYagi);

            var rp = new Recipe {
                Name = "İskender Reçetesi", Portion = iskender.Portions[0]
            };

            workspace.Add(rp);

            rp.RecipeItems.Add(new RecipeItem {
                InventoryItem = donerEti, Quantity = 120
            });
            rp.RecipeItems.Add(new RecipeItem {
                InventoryItem = yogurt, Quantity = 50
            });
            rp.RecipeItems.Add(new RecipeItem {
                InventoryItem = pide, Quantity = 2
            });
            rp.RecipeItems.Add(new RecipeItem {
                InventoryItem = zeytinYagi, Quantity = 1
            });

            AppServices.MainDataContext.StartWorkPeriod("", 0, 0, 0);

            var transaction = new Transaction {
                Date = DateTime.Now, Name = "1"
            };

            workspace.Add(transaction);

            transaction.TransactionItems.Add(new TransactionItem {
                InventoryItem = donerEti, Multiplier = 1000, Price = 16, Quantity = 10, Unit = "KG"
            });
            transaction.TransactionItems.Add(new TransactionItem {
                InventoryItem = pide, Multiplier = 2, Price = 1, Quantity = 50, Unit = "Adet"
            });
            transaction.TransactionItems.Add(new TransactionItem {
                InventoryItem = yogurt, Multiplier = 1000, Price = 4, Quantity = 30, Unit = "KG"
            });
            transaction.TransactionItems.Add(new TransactionItem {
                InventoryItem = zeytinYagi, Multiplier = 100, Price = 5, Quantity = 5, Unit = "Litre"
            });

            var ticket = new Ticket();

            workspace.Add(ticket);
            ticket.AddTicketItem(0, iskender, iskender.Portions[0].Name);
            ticket.AddTicketItem(0, iskender, iskender.Portions[0].Name);
            ticket.AddTicketItem(0, iskender, iskender.Portions[0].Name);

            var pc = InventoryService.GetCurrentPeriodicConsumption(workspace);

            workspace.Add(pc);

            var iskenderCostItem = pc.CostItems.Single(x => x.Portion.MenuItemId == iskender.Id);

            Assert.AreEqual(iskenderCostItem.Quantity, 3);

            var etCost         = ((16m / 1000m) * 120m);
            var pideCost       = ((1m / 2m) * 2m);
            var yogurtCost     = ((4m / 1000m) * 50m);
            var zeytinYagiCost = ((5m / 100m) * 1m);
            var iskenderCost   = decimal.Round(etCost + pideCost + yogurtCost + zeytinYagiCost, 2);

            Assert.AreEqual(iskenderCost, iskenderCostItem.CostPrediction);
            var etpc         = pc.PeriodicConsumptionItems.Single(x => x.InventoryItem.Id == donerEti.Id);
            var pidepc       = pc.PeriodicConsumptionItems.Single(x => x.InventoryItem.Id == pide.Id);
            var yogurtpc     = pc.PeriodicConsumptionItems.Single(x => x.InventoryItem.Id == yogurt.Id);
            var zeytinYagipc = pc.PeriodicConsumptionItems.Single(x => x.InventoryItem.Id == zeytinYagi.Id);

            etpc.PhysicalInventory         = 9.5m;
            yogurtpc.PhysicalInventory     = 28;
            zeytinYagipc.PhysicalInventory = 4.5m;

            InventoryService.CalculateCost(pc, AppServices.MainDataContext.CurrentWorkPeriod);

            etCost         = (etpc.GetConsumption() * etCost) / etpc.GetPredictedConsumption();
            pideCost       = (pidepc.GetConsumption() * pideCost) / pidepc.GetPredictedConsumption();
            yogurtCost     = (yogurtpc.GetConsumption() * yogurtCost) / yogurtpc.GetPredictedConsumption();
            zeytinYagiCost = (zeytinYagipc.GetConsumption() * zeytinYagiCost) / zeytinYagipc.GetPredictedConsumption();

            Assert.AreEqual(iskenderCostItem.Cost, decimal.Round(etCost + pideCost + yogurtCost + zeytinYagiCost, 2));
        }