Пример #1
0
        private void CreatePeriodicConsumptionItem(InventoryItem inventoryItem,
                                                   WarehouseConsumption previousWhc,
                                                   IEnumerable <InventoryTransaction> transactionItems)
        {
            var pci = PeriodicConsumptionItem.Create(inventoryItem);

            PeriodicConsumptionItems.Add(pci);
            var previousCost = 0m;

            if (previousWhc != null)
            {
                var previousPci = previousWhc.PeriodicConsumptionItems.SingleOrDefault(x => x.InventoryItemId == inventoryItem.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 == inventoryItem.Id).ToList();

            pci.Added   = tim.Where(x => x.TargetWarehouseId == WarehouseId).Sum(x => x.Quantity * x.Multiplier) / pci.UnitMultiplier;
            pci.Removed = tim.Where(x => x.SourceWarehouseId == WarehouseId).Sum(x => x.Quantity * x.Multiplier) / pci.UnitMultiplier;
            var totalPrice = tim.Where(x => x.TargetWarehouseId == WarehouseId).Sum(x => x.Price * x.Quantity);

            if (pci.InStock + pci.Purchase > 0)
            {
                pci.Cost = decimal.Round((totalPrice + previousCost) / (pci.InStock + pci.Added), 2);
            }
        }
Пример #2
0
 private void CreateWarehouseConsumptions(IEnumerable <int> warehouseIds)
 {
     foreach (var warehouseId in warehouseIds)
     {
         var whc = new WarehouseConsumption()
         {
             WarehouseId = warehouseId
         };
         WarehouseConsumptions.Add(whc);
     }
 }
Пример #3
0
 public void CreatePeriodicConsumptionItems(IEnumerable <InventoryItem> inventoryItems, WarehouseConsumption previousPc, List <InventoryTransaction> transactionItems)
 {
     foreach (var inventoryItem in inventoryItems)
     {
         CreatePeriodicConsumptionItem(inventoryItem, previousPc, transactionItems);
     }
 }