Exemplo n.º 1
0
        /// <summary>
        /// Executes code that will insert Invoiced Items into Movement.
        /// </summary>
        /// <param name="invoice"></param>
        public void Discount_Items_Origin(item_transfer_detail item_transfer_detail, int ID_BranchOrigin, int ID_BranchDestination, bool movebytruck)
        {
            entity.Brillo.Logic.Stock stock = new Brillo.Logic.Stock();

            if (item_transfer_detail.item_product != null)
            {
                if (movebytruck)
                {
                    app_currencyfx app_currencyfx = base.app_currencyfx.Where(x => x.app_currency.is_active).FirstOrDefault();
                    app_location   app_location   = base.app_location.Where(x => x.id_branch == ID_BranchOrigin && x.is_default).FirstOrDefault();
                    List <entity.Brillo.StockList> Items_InStockLIST;
                    if (item_transfer_detail.movement_id != null)
                    {
                        entity.Brillo.Stock stockBrillo = new Brillo.Stock();
                        Items_InStockLIST = stockBrillo.ScalarMovement(base.item_movement.Where(x => x.id_movement == item_transfer_detail.movement_id).FirstOrDefault());
                    }
                    else
                    {
                        entity.Brillo.Stock stockBrillo = new Brillo.Stock();
                        Items_InStockLIST = stockBrillo.List(app_location.app_branch, app_location, item_transfer_detail.item_product);
                    }

                    List <item_movement> item_movement_originList;
                    item_movement_originList = stock.DebitOnly_MovementLIST(this, Items_InStockLIST, Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfx, item_transfer_detail.item_product, app_location,
                                                                            item_transfer_detail.quantity_origin, item_transfer_detail.item_transfer.trans_date, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""));

                    base.item_movement.AddRange(item_movement_originList);

                    item_movement  item_movement_Dest;
                    app_currencyfx app_currencyfxdest = base.app_currencyfx.Where(x => x.app_currency.is_active).FirstOrDefault();
                    app_location   app_locationdest   = base.app_location.Where(x => x.id_branch == ID_BranchDestination && x.is_default).FirstOrDefault();

                    item_movement_Dest = stock.CreditOnly_Movement(
                        Status.Stock.InStock,
                        App.Names.Transfer,
                        item_transfer_detail.id_transfer,
                        item_transfer_detail.id_transfer_detail,
                        app_currencyfxdest,
                        item_transfer_detail.item_product,
                        app_locationdest,
                        item_transfer_detail.quantity_origin,
                        item_transfer_detail.item_transfer.trans_date,
                        0,
                        stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""),
                        null);

                    base.item_movement.Add(item_movement_Dest);
                }
                else
                {
                    app_currencyfx app_currencyfx = base.app_currencyfx.Where(x => x.app_currency.is_active).FirstOrDefault();
                    app_location   app_location   = base.app_location.Where(x => x.id_branch == ID_BranchOrigin && x.is_default).FirstOrDefault();
                    List <entity.Brillo.StockList> Items_InStockLIST;
                    if (item_transfer_detail.movement_id != null)
                    {
                        entity.Brillo.Stock stockBrillo = new Brillo.Stock();
                        Items_InStockLIST = stockBrillo.ScalarMovement(base.item_movement.Where(x => x.id_movement == item_transfer_detail.movement_id).FirstOrDefault());
                    }
                    else
                    {
                        entity.Brillo.Stock stockBrillo = new Brillo.Stock();
                        Items_InStockLIST = stockBrillo.List(app_location.app_branch, app_location, item_transfer_detail.item_product);
                    }



                    ///Debit Movement from Origin.
                    List <item_movement> item_movement_originList;
                    item_movement_originList = stock.DebitOnly_MovementLIST(this, Items_InStockLIST, Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfx, item_transfer_detail.item_product, app_location,
                                                                            item_transfer_detail.quantity_origin, item_transfer_detail.item_transfer.trans_date, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""));

                    base.item_movement.AddRange(item_movement_originList);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes code that will insert Invoiced Items into Movement.
        /// </summary>
        /// <param name="invoice"></param>
        public void Credit_Items_Destination(item_transfer_detail item_transfer_detail, int ID_BranchOrigin, int ID_BranchDestination, bool MoveByTruck)
        {
            entity.Brillo.Logic.Stock stock          = new Brillo.Logic.Stock();
            app_currencyfx            app_currencyfx = base.app_currencyfx.Where(x => x.app_currency.is_priority && x.is_active).FirstOrDefault();
            app_location app_location_dest           = base.app_location.Where(x => x.id_branch == ID_BranchDestination && x.is_default).FirstOrDefault();

            if (MoveByTruck)
            {
                List <entity.Brillo.StockList> Items_InStockLIST;
                entity.Brillo.Stock            stockBrillo = new Brillo.Stock();
                Items_InStockLIST = stockBrillo.MovementForTransfer(item_transfer_detail.id_transfer_detail, item_transfer_detail.id_item_product);

                List <item_movement> item_movement_LIST = new List <entity.item_movement>();
                ///Discount From Destination. Because merchendice is returned to Origin, so it must be discounted from Destintation.
                item_movement_LIST =
                    stock.DebitOnly_MovementLIST(this, Items_InStockLIST, Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail,
                                                 app_currencyfx, item_transfer_detail.item_product, app_location_dest, item_transfer_detail.quantity_destination,
                                                 item_transfer_detail.item_transfer.trans_date, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""));

                base.item_movement.AddRange(item_movement_LIST);

                app_location app_location_origin = base.app_location.Where(x => x.id_branch == ID_BranchOrigin && x.is_default).FirstOrDefault();

                //Credit in Origin only if it is MoveByTruck.
                item_movement item_movement_origin;
                item_movement_origin =
                    stock.CreditOnly_Movement(
                        Status.Stock.InStock,
                        App.Names.Transfer,
                        item_transfer_detail.id_transfer,
                        item_transfer_detail.id_transfer_detail,
                        app_currencyfx,
                        item_transfer_detail.item_product,
                        app_location_origin,
                        item_transfer_detail.quantity_destination,
                        item_transfer_detail.item_transfer.trans_date,
                        0,
                        stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""),
                        null
                        );

                base.item_movement.Add(item_movement_origin);
            }
            else
            {
                //Credit Destination.
                item_movement        item_movement_dest;
                List <item_movement> Items_InStockLIST = base.item_movement.Where(x => x.id_transfer_detail == item_transfer_detail.id_transfer_detail &&
                                                                                  x.id_item_product == item_transfer_detail.id_item_product && x.debit > 0).ToList();
                int count = 1;
                if (Items_InStockLIST.Count() > 0)
                {
                    count = Items_InStockLIST.Count();
                }

                item_movement parent_item_movement = Items_InStockLIST.FirstOrDefault();

                item_movement_dest =
                    stock.CreditOnly_Movement(
                        Status.Stock.InStock,
                        App.Names.Transfer,
                        item_transfer_detail.id_transfer,
                        item_transfer_detail.id_transfer_detail,
                        app_currencyfx,
                        item_transfer_detail.item_product,
                        app_location_dest,
                        item_transfer_detail.quantity_destination,
                        item_transfer_detail.item_transfer.trans_date,
                        Items_InStockLIST.Sum(x => (x.item_movement_value.Sum(y => y.unit_value) / (x.item_movement_value.Count() != 0 ? x.item_movement_value.Count() : 1))) / count,
                        stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""),
                        null
                        );
                item_movement_dest._parent = Items_InStockLIST.FirstOrDefault();
                base.item_movement.Add(item_movement_dest);
            }
        }