Example #1
0
        public virtual List <StoreLocatorItemRemoval> FindStoreLocatorItemRemovals(
            long?storeId,
            long?storeLocatorId,
            long?itemId,
            decimal?quantityRemoved,
            out decimal?totalCost
            )
        {
            if (quantityRemoved < 0)
            {
                throw new BaseEamException("quantityRemoved cannot be less than 0");
            }

            totalCost = 0;
            int costingType = _inventorySettings.CostingType.Value;

            List <StoreLocatorItem>        items    = FindStoreLocatorItems(costingType, storeLocatorId, itemId);
            List <StoreLocatorItemRemoval> removals = new List <StoreLocatorItemRemoval>();

            while (quantityRemoved > 0)
            {
                if (items.Count > 0)
                {
                    StoreLocatorItem item             = items[0];
                    decimal?         quantityToRemove = 0;
                    decimal?         priceToRemove    = 0;

                    if ((item.Quantity ?? 0) > quantityRemoved)
                    {
                        // There is more items in the batch
                        quantityToRemove = quantityRemoved;
                        priceToRemove    = quantityToRemove * (item.UnitPrice ?? 0);
                    }
                    else
                    {
                        // There is less items in the batch
                        quantityToRemove = item.Quantity ?? 0;
                        priceToRemove    = item.Cost ?? 0;
                    }

                    removals.Add(new StoreLocatorItemRemoval {
                        UnitPrice = item.UnitPrice ?? 0,
                        Quantity  = quantityToRemove,
                        Cost      = priceToRemove
                    });

                    totalCost       += priceToRemove;
                    quantityRemoved -= quantityToRemove;
                }
                else
                {
                    break;
                }
                items.RemoveAt(0);
            }

            return(removals);
        }
Example #2
0
        public virtual void PostToInventory(List <StoreLocatorItemLog> logs)
        {
            foreach (var log in logs)
            {
                StoreLocatorItem item = null;
                if (log.StoreLocatorItemId == 0)
                {
                    item = new StoreLocatorItem
                    {
                        BatchDate      = log.BatchDate,
                        StoreId        = log.StoreId,
                        StoreLocatorId = log.StoreLocatorId,
                        ItemId         = log.ItemId,
                        UnitPrice      = 0,
                        Quantity       = 0,
                        Cost           = 0,
                        //IsNew = false
                    };
                }
                else
                {
                    item = _storeLocatorItemRepository.GetById(log.StoreLocatorItemId);
                }

                log.StoreLocatorItem = item;
                _storeLocatorItemLogRepository.Update(log);

                decimal?oldUnitPrice = item.UnitPrice ?? 0;
                decimal?oldQuantity  = item.Quantity ?? 0;
                decimal?newUnitPrice = log.UnitPrice ?? 0;
                decimal?newQuantity  = log.QuantityChanged ?? 0;

                item.Quantity += newQuantity;
                item.Cost     += (log.CostChanged ?? 0);

                //For average costing
                if (_inventorySettings.CostingType == (int)ItemCostingType.AverageCosting)
                {
                    if (item.Quantity != 0)
                    {
                        item.UnitPrice = item.Cost / item.Quantity;
                    }
                    else
                    {
                        item.UnitPrice = 0;
                    }
                }
                //For LIFO/FIFO/Standard costing
                else
                {
                    item.UnitPrice = newUnitPrice;
                    item.Cost      = (item.Quantity ?? 0) * item.UnitPrice;
                }

                //If the item's quantity fall to 0, delete it from inventory
                if (item.Quantity == 0)
                {
                    _storeLocatorItemRepository.Deactivate(item);
                    //don't delete the associated logs
                    //var itemLogs = _storeLocatorItemLogRepository.GetAll().Where(s => s.StoreLocatorItemId == item.Id).ToList();
                    //foreach (var itemLog in itemLogs)
                    //    _storeLocatorItemLogRepository.Deactivate(itemLog);
                }
                else
                {
                    _storeLocatorItemRepository.Save(item);
                }
            }
        }
Example #3
0
        public virtual List <StoreLocatorItemRemoval> RemoveStoreLocatorItem(
            long?storeId,
            long?storeLocatorId,
            long?itemId,
            decimal?quantityRemoved,
            string transactionType,
            long?transactionId,
            string transactionNumber,
            DateTime?transactionDate,
            long?transactionItemId,
            out decimal?totalCost
            )
        {
            if (quantityRemoved < 0)
            {
                throw new BaseEamException("quantityRemoved cannot be less than 0");
            }

            totalCost = 0;
            int costingType = _inventorySettings.CostingType.Value;

            List <StoreLocatorItem>        items    = FindStoreLocatorItems(costingType, storeLocatorId, itemId);
            List <StoreLocatorItemRemoval> removals = new List <StoreLocatorItemRemoval>();
            var logs = new List <StoreLocatorItemLog>();

            while (quantityRemoved > 0)
            {
                if (items.Count > 0)
                {
                    StoreLocatorItem item             = items[0];
                    decimal?         quantityToRemove = 0;
                    decimal?         priceToRemove    = 0;

                    if ((item.Quantity ?? 0) > quantityRemoved)
                    {
                        // There is more items in the batch
                        quantityToRemove = quantityRemoved;
                        priceToRemove    = quantityToRemove * (item.UnitPrice ?? 0);
                    }
                    else
                    {
                        // There is less items in the batch
                        quantityToRemove = item.Quantity ?? 0;
                        priceToRemove    = item.Cost ?? 0;
                    }

                    removals.Add(new StoreLocatorItemRemoval
                    {
                        UnitPrice = item.UnitPrice ?? 0,
                        Quantity  = quantityToRemove,
                        Cost      = priceToRemove
                    });

                    var log = this.AddStoreLocatorItemLog(
                        item.Id,
                        item.BatchDate,
                        item.StoreId,
                        item.StoreLocatorId,
                        item.ItemId,
                        item.UnitPrice ?? 0,
                        -quantityToRemove,
                        -priceToRemove,
                        transactionType,
                        transactionId,
                        transactionNumber,
                        transactionDate,
                        transactionItemId
                        );
                    logs.Add(log);

                    totalCost       += priceToRemove;
                    quantityRemoved -= quantityToRemove;
                }
                else
                {
                    break;
                }
                items.RemoveAt(0);
            }

            this.PostToInventory(logs);

            return(removals);
        }