Beispiel #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);
            }
        }
Beispiel #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);
                }

            }
        }
 public PeriodicConsumptionItemViewModel(PeriodicConsumptionItem model)
 {
     Model = model;
 }
Beispiel #4
0
 private bool ShouldKeep(PeriodicConsumptionItem periodicConsumptionItem, IEnumerable<InventoryItem> inventoryItems, Warehouse warehouse)
 {
     var wname = warehouse.Name;
     var inventoryItem = inventoryItems.Single(y => y.Id == periodicConsumptionItem.InventoryItemId);
     return inventoryItem.IsMappedToWarehouse(wname);
 }