Beispiel #1
0
 public void updatePrice(PriceChangeData pice_change, bool for_all)
 {
 }
Beispiel #2
0
        public void ChangePrice(PriceChangeData new_price)
        {
            //get the current running stock for the specified product whose price is to be changed
            var current_running_stock = _context.stockTracks
                                        .Where(x => x.IsRunningStock == true & x.ProductId == new_price.product_id)
                                        .FirstOrDefault();

            //get all the stocks that are after the current stock [those are the available stocks] please not this is using FIFO
            var stocks_on_standby = _context.stockTracks
                                    .Where(x => x.ProductId == new_price.product_id & x.EditedOn <= current_running_stock.EditedOn)
                                    .OrderBy(x => x.EditedOn).ToArray();

            //sold products for today
            int products_already_sold = _context.sales.Where(x => x.ProductId == new_price.product_id &
                                                             DbFunctions.TruncateTime(x.DateOfSale) == DateTime.Now.Date & x.state == 1).Select(x => x.Quantity).Sum();

            //stock adjustment
            for (int i = 0; i < stocks_on_standby.Length; i++)
            {
                var stock = stocks_on_standby[i];
                if (stock.running_quantity >= products_already_sold)
                {
                    stock.running_quantity -= products_already_sold;
                    stock.quantity_sold    += products_already_sold;
                    stock.adjusted          = true;
                    stock.EditedOn          = DateTime.Now;

                    StockTrack st = new StockTrack();
                    st.EditedBy           = new_price.edited_by;
                    st.EditedOn           = DateTime.Now;
                    st.BranchId           = new_price.branch_id;
                    st.ProductId          = new_price.product_id;
                    st.NewMarkup          = new_price.new_markup;
                    st.PriceChange        = new_price.new_price - stock.NewPrice;
                    st.NewQuantity        = stock.running_quantity;
                    st.running_quantity   = stock.running_quantity;
                    st.IsPriceChanged     = true;
                    st.IsQuantintyChanged = products_already_sold == 0 ? false : true;
                    st.IsRunningStock     = true;
                    st.NewValue           = new_price.new_price * stock.NewQuantity;
                    st.NewPrice           = new_price.new_price;
                    st.QuantityChange     = stock.running_quantity;
                    st.quantity_sold      = 0;

                    _stockTrack.updateStockTrack(stock);
                    _stockTrack.AddStockTrack(st);
                    break;
                }
                else
                {
                    products_already_sold -= stock.running_quantity;
                    stock.quantity_sold   += stock.running_quantity;
                    stock.running_quantity = 0;
                    stock.adjusted         = true;
                    stock.EditedOn         = DateTime.Now;

                    _stockTrack.updateStockTrack(stock);
                }
            }

            //adjust unreached stocks
            var unadjusteed_stock = stocks_on_standby.Where(x => x.adjusted == false);

            foreach (var stock in unadjusteed_stock)
            {
                stock.NewMarkup      = new_price.new_markup;
                stock.PriceChange    = new_price.new_price - stock.NewPrice;
                stock.NewPrice       = new_price.new_price;
                stock.IsPriceChanged = true;
                stock.EditedOn       = DateTime.Now;

                _stockTrack.updateStockTrack(stock);
            }
        }