public void AddMissingItems()
 {
     _inventoryService.AddMissingItems(Model);
     Refresh();
 }
        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));
        }