Exemple #1
0
        public void TestCost()
        {
            var workspace = PrepareMenu("sd1.txt");
            var testContext = new WarehouseTestContext();
            CreateWarehouseTestContext(testContext, workspace);

            var transaction = new InventoryTransactionDocument();
            workspace.Add(transaction);

            transaction.Add(testContext.PurchaseTransactionType, testContext.DonerEti, 16, 10, "KG", 1000);
            transaction.Add(testContext.PurchaseTransactionType, testContext.Pide, 1, 50, "Adet", 2);
            transaction.Add(testContext.PurchaseTransactionType, testContext.Yogurt, 4, 30, "KG", 1000);
            transaction.Add(testContext.PurchaseTransactionType, testContext.ZeytinYagi, 5, 5, "Litre", 100);
            transaction.TransactionItems.ToList().ForEach(workspace.Add);

            var ticket = TicketBuilder.Create(TicketType.Default, testContext.Department).Build();
            workspace.Add(ticket);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);

            var pc = InventoryService.GetCurrentPeriodicConsumption();
            workspace.Add(pc);

            var whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);

            var iskenderCostItem = whc.CostItems.Single(x => x.MenuItemId == testContext.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 = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.DonerEti.Id);
            var pidepc = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.Pide.Id);
            var yogurtpc = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.Yogurt.Id);
            var zeytinYagipc = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.ZeytinYagi.Id);

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

            InventoryService.CalculateCost(pc, ApplicationState.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));
        }
        public void CanReadInventory()
        {
            var workspace = PrepareMenu("sd4.txt");
            var testContext = new WarehouseTestContext();
            CreateWarehouseTestContext(testContext, workspace);
            var inventoryTransaction1 = new InventoryTransactionDocument();
            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.DonerEti, 16, 10, "KG", 1000);
            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.Pide, 1, 50, "Adet", 2);
            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.Yogurt, 4, 30, "KG", 1000);
            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.ZeytinYagi, 5, 5, "Litre", 100);
            workspace.Add(inventoryTransaction1);
            inventoryTransaction1.TransactionItems.ToList().ForEach(workspace.Add);

            Assert.AreEqual(4, inventoryTransaction1.TransactionItems.Count);
            Assert.AreEqual(10, InventoryService.GetInventory(testContext.DonerEti, testContext.LocalWarehouse));
            Assert.AreEqual(50, InventoryService.GetInventory(testContext.Pide, testContext.LocalWarehouse));
            Assert.AreEqual(30, InventoryService.GetInventory(testContext.Yogurt, testContext.LocalWarehouse));
            Assert.AreEqual(5, InventoryService.GetInventory(testContext.ZeytinYagi, testContext.LocalWarehouse));

            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.DonerEti, 16, 15, "KG", 1000);
            inventoryTransaction1.TransactionItems.ToList().ForEach(workspace.Add);
            Assert.AreEqual(25, InventoryService.GetInventory(testContext.DonerEti, testContext.LocalWarehouse));

            var ticket = Ticket.Create(testContext.Department, TicketType.Default, 1, null);
            workspace.Add(ticket);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);

            Assert.AreEqual(25 - ((120m * 3) / 1000m), InventoryService.GetInventory(testContext.DonerEti, testContext.LocalWarehouse));

            RestartWorkperiod(workspace);

            ticket = Ticket.Create(testContext.Department, TicketType.Default, 1, null);
            workspace.Add(ticket);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            Assert.AreEqual(25 - ((120m * 6) / 1000m), InventoryService.GetInventory(testContext.DonerEti, testContext.LocalWarehouse));
            Assert.AreEqual(50 - (2 * 6) / 2, InventoryService.GetInventory(testContext.Pide, testContext.LocalWarehouse));
        }
        public void CanAssignWarehouse()
        {
            var workspace = PrepareMenu("sd5.txt");
            var testContext = new WarehouseTestContext();
            CreateWarehouseTestContext(testContext, workspace);
            var inventoryTransaction1 = new InventoryTransactionDocument();
            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.DonerEti, 16, 10, "KG", 1000);
            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.Pide, 1, 50, "Adet", 2);
            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.Yogurt, 4, 30, "KG", 1000);
            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.ZeytinYagi, 5, 5, "Litre", 100);
            workspace.Add(inventoryTransaction1);
            inventoryTransaction1.TransactionItems.ToList().ForEach(workspace.Add);

            Assert.AreEqual(10, InventoryService.GetInventory(testContext.DonerEti, testContext.LocalWarehouse));

            var inventoryTransaction2 = new InventoryTransactionDocument();
            inventoryTransaction2.Add(testContext.BarTransferTransactionType, testContext.DonerEti, 16, 5, "KG", 1000);
            workspace.Add(inventoryTransaction2);
            inventoryTransaction2.TransactionItems.ToList().ForEach(workspace.Add);
            Assert.AreEqual(5, InventoryService.GetInventory(testContext.DonerEti, testContext.BarWarehouse));
            Assert.AreEqual(5, InventoryService.GetInventory(testContext.DonerEti, testContext.LocalWarehouse));
        }
        public void TestPurchase()
        {
            var workspace = PrepareMenu("sd2.txt");

            var testContext = new WarehouseTestContext();
            CreateWarehouseTestContext(testContext, workspace);

            var transaction = new InventoryTransactionDocument();
            workspace.Add(transaction);

            transaction.Add(testContext.PurchaseTransactionType, testContext.DonerEti, 16, 10, "KG", 1000);
            transaction.Add(testContext.PurchaseTransactionType, testContext.Pide, 1, 50, "Adet", 2);
            transaction.Add(testContext.PurchaseTransactionType, testContext.Yogurt, 4, 30, "KG", 1000);
            transaction.TransactionItems.ToList().ForEach(workspace.Add);
            var transactionTotal = transaction.TransactionItems.Sum(x => x.Price * x.Quantity);
            Assert.AreEqual(transactionTotal, (16 * 10) + (50 * 1) + (30 * 4));

            var ticket = Ticket.Create(testContext.Department, TicketType.Default, 1, null);
            workspace.Add(ticket);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);

            var transaction2 = new InventoryTransactionDocument();
            workspace.Add(transaction2);
            transaction2.Add(testContext.PurchaseTransactionType, testContext.DonerEti, 15, 10, "KG", 1000);
            transaction2.TransactionItems.ToList().ForEach(workspace.Add);
            var pc = InventoryService.GetCurrentPeriodicConsumption();
            workspace.Add(pc);
            var whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);

            var etpc = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.DonerEti.Id);
            Assert.IsNotNull(etpc);
            Assert.AreEqual(0, etpc.InStock);
            Assert.AreEqual(20, etpc.Purchase);
            Assert.AreEqual(0.24m, etpc.Consumption);
            Assert.AreEqual(15.5m, etpc.Cost);

            var yogurtpc = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.Yogurt.Id);
            Assert.IsNotNull(yogurtpc);
            Assert.AreEqual(0, yogurtpc.InStock);
            Assert.AreEqual(30, yogurtpc.Purchase);
            Assert.AreEqual(0.1m, yogurtpc.Consumption);

            var pidepc = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.Pide.Id);
            Assert.IsNotNull(pidepc);
            Assert.AreEqual(0, pidepc.InStock);
            Assert.AreEqual(50, pidepc.Purchase);
            Assert.AreEqual(2, pidepc.Consumption);

            RestartWorkperiod(workspace);

            pc = InventoryService.GetCurrentPeriodicConsumption();
            whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);
            etpc = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.DonerEti.Id);
            Assert.AreEqual(20 - 0.24m, etpc.InStock);
            Assert.AreEqual(0, etpc.Purchase);
            Assert.AreEqual(0, etpc.Consumption);

            transaction = new InventoryTransactionDocument();
            workspace.Add(transaction);
            const int etAlimMiktari = 50;

            var ti = transaction.Add(testContext.PurchaseTransactionType, testContext.DonerEti, 12, etAlimMiktari, "KG", 1000);
            transaction.TransactionItems.ToList().ForEach(workspace.Add);
            ticket = Ticket.Create(testContext.Department, TicketType.Default, 1, null);
            workspace.Add(ticket);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);

            pc = InventoryService.GetCurrentPeriodicConsumption();
            workspace.Add(pc);
            whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);

            var etpc2 = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.DonerEti.Id);
            Assert.IsNotNull(etpc2);
            Assert.AreEqual(etpc2.InStock, etpc.GetInventoryPrediction());
            Assert.AreEqual(etpc2.Purchase, etAlimMiktari);
            Assert.AreEqual(etpc2.GetInventoryPrediction(), etpc.GetInventoryPrediction() + etAlimMiktari - 0.24m);
            var cost = ((etpc.Cost * etpc.GetInventoryPrediction()) + (ti.Price * ti.Quantity)) / (etpc2.InStock + etpc2.Purchase);
            cost = decimal.Round(cost, 2);
            Assert.AreEqual(etpc2.Cost, cost);

            RestartWorkperiod(workspace);

            transaction = new InventoryTransactionDocument();
            workspace.Add(transaction);
            ti = transaction.Add(testContext.PurchaseTransactionType, testContext.DonerEti, 10, etAlimMiktari, "KG", 1000);
            transaction.TransactionItems.ToList().ForEach(workspace.Add);
            ticket = Ticket.Create(testContext.Department, TicketType.Default, 1, null);
            workspace.Add(ticket);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);

            pc = InventoryService.GetCurrentPeriodicConsumption();
            workspace.Add(pc);
            whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);

            var etpc3 = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.DonerEti.Id);
            Assert.IsNotNull(etpc3);
            Assert.AreEqual(etpc3.InStock, etpc2.GetInventoryPrediction());
            Assert.AreEqual(etpc3.Purchase, etAlimMiktari);
            Assert.AreEqual(etpc3.GetInventoryPrediction(), etpc2.GetInventoryPrediction() + etAlimMiktari - 0.24m);
            cost = ((etpc2.Cost * etpc2.GetInventoryPrediction()) + (ti.Price * ti.Quantity)) / (etpc3.InStock + etpc3.Purchase);
            cost = decimal.Round(cost, 2);
            Assert.AreEqual(etpc3.Cost, cost);
        }
Exemple #5
0
        public void CanFilterUnneededConsumptionItems()
        {
            var workspace = PrepareMenu("sd6.txt");
            var testContext = new WarehouseTestContext();
            CreateWarehouseTestContext(testContext, workspace);
            testContext.Yogurt.Warehouse = "No Warehouse";

            var inventoryTransaction1 = new InventoryTransactionDocument();
            inventoryTransaction1.Add(testContext.PurchaseTransactionType, testContext.Yogurt, 4, 30, "KG", 1000);
            workspace.Add(inventoryTransaction1);
            inventoryTransaction1.TransactionItems.ToList().ForEach(workspace.Add);

            var pc = InventoryService.GetCurrentPeriodicConsumption();
            var whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);
            Assert.True(whc.PeriodicConsumptionItems.Any(x => x.InventoryItemId == testContext.Yogurt.Id));
            Assert.AreEqual(30, InventoryService.GetInventory(testContext.Yogurt, testContext.LocalWarehouse));

            var ticket = TicketBuilder.Create(TicketType.Default, testContext.Department).Build();

            workspace.Add(ticket);
            var order = ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            order.Quantity = 600;

            Assert.AreEqual(0, InventoryService.GetInventory(testContext.Yogurt, testContext.LocalWarehouse));

            RestartWorkperiod(workspace);

            pc = InventoryService.GetCurrentPeriodicConsumption();
            whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);
            Assert.True(whc.PeriodicConsumptionItems.All(x => x.InventoryItemId != testContext.Yogurt.Id));

            RestartWorkperiod(workspace);
            RestartWorkperiod(workspace);

            pc = InventoryService.GetCurrentPeriodicConsumption();
            whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);

            Assert.True(whc.PeriodicConsumptionItems.All(x => x.InventoryItemId != testContext.Yogurt.Id));

            RestartWorkperiod(workspace);

            ticket = TicketBuilder.Create(TicketType.Default, testContext.Department).Build();

            workspace.Add(ticket);
            order = ticket.AddOrder(AccountTransactionType.Default, testContext.Department, "Emre", testContext.Iskender, null, testContext.Iskender.Portions[0], "", null);
            order.Quantity = 600;

            Assert.AreEqual(-30, InventoryService.GetInventory(testContext.Yogurt, testContext.LocalWarehouse));

            RestartWorkperiod(workspace);

            Assert.AreEqual(-30, InventoryService.GetInventory(testContext.Yogurt, testContext.LocalWarehouse));

            var inventoryTransaction2 = new InventoryTransactionDocument();
            inventoryTransaction2.Add(testContext.PurchaseTransactionType, testContext.Yogurt, 4, 30, "KG", 1000);
            workspace.Add(inventoryTransaction2);
            inventoryTransaction2.TransactionItems.ToList().ForEach(workspace.Add);

            Assert.AreEqual(0, InventoryService.GetInventory(testContext.Yogurt, testContext.LocalWarehouse));

            RestartWorkperiod(workspace);

            pc = InventoryService.GetCurrentPeriodicConsumption();
            whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);

            Assert.True(whc.PeriodicConsumptionItems.All(x => x.InventoryItemId != testContext.Yogurt.Id));
            Assert.AreEqual(0, InventoryService.GetInventory(testContext.Yogurt, testContext.LocalWarehouse));

            testContext.Yogurt.Warehouse = testContext.BarWarehouse.Name;

            RestartWorkperiod(workspace);

            pc = InventoryService.GetCurrentPeriodicConsumption();
            var bwhc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.BarWarehouse.Id);

            Assert.True(bwhc.PeriodicConsumptionItems.Any(x => x.InventoryItemId == testContext.Yogurt.Id));
            Assert.AreEqual(0, InventoryService.GetInventory(testContext.Yogurt, testContext.LocalWarehouse));
            Assert.AreEqual(0, InventoryService.GetInventory(testContext.Yogurt, testContext.BarWarehouse));

            whc = pc.WarehouseConsumptions.Single(x => x.WarehouseId == testContext.LocalWarehouse.Id);

            Assert.True(whc.PeriodicConsumptionItems.All(x => x.InventoryItemId != testContext.Yogurt.Id));
            InventoryService.AddMissingItems(whc);
            Assert.True(whc.PeriodicConsumptionItems.Any(x => x.InventoryItemId == testContext.Yogurt.Id));
            InventoryService.FilterUnneededItems(pc);
            Assert.True(whc.PeriodicConsumptionItems.All(x => x.InventoryItemId != testContext.Yogurt.Id));
            InventoryService.AddMissingItems(whc);
            Assert.True(whc.PeriodicConsumptionItems.Any(x => x.InventoryItemId == testContext.Yogurt.Id));
            var pci = whc.PeriodicConsumptionItems.Single(x => x.InventoryItemId == testContext.Yogurt.Id);
            pci.PhysicalInventory = 10;
            workspace.Add(pci);
            InventoryService.FilterUnneededItems(pc);
            Assert.True(whc.PeriodicConsumptionItems.Any(x => x.InventoryItemId == testContext.Yogurt.Id));
            Assert.AreEqual(10, InventoryService.GetInventory(testContext.Yogurt, testContext.LocalWarehouse));
        }