/// <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); } } }
private void toolBar_btnApprove_Click(object sender) { item_transfer item_transfer = item_transferViewSource.View.CurrentItem as item_transfer; if ((item_transfer.number == null || item_transfer.number == string.Empty) && item_transfer.app_document_range != null) { entity.Brillo.Logic.Document _Document = new entity.Brillo.Logic.Document(); if (item_transfer.id_branch > 0) { if (dbContext.app_branch.Where(x => x.id_branch == item_transfer.id_branch).FirstOrDefault() != null) { entity.Brillo.Logic.Range.branch_Code = dbContext.app_branch.Where(x => x.id_branch == item_transfer.id_branch).FirstOrDefault().code; } } if (item_transfer.id_terminal > 0) { if (dbContext.app_terminal.Where(x => x.id_terminal == item_transfer.id_terminal).FirstOrDefault() != null) { entity.Brillo.Logic.Range.terminal_Code = dbContext.app_terminal.Where(x => x.id_terminal == item_transfer.id_terminal).FirstOrDefault().code; } } if (item_transfer.id_user > 0) { if (dbContext.security_user.Where(x => x.id_user == item_transfer.id_user).FirstOrDefault() != null) { entity.Brillo.Logic.Range.user_Code = dbContext.security_user.Where(x => x.id_user == item_transfer.id_user).FirstOrDefault().code; } } if (item_transfer.id_project > 0) { if (dbContext.projects.Where(x => x.id_project == item_transfer.id_project).FirstOrDefault() != null) { entity.Brillo.Logic.Range.project_Code = dbContext.projects.Where(x => x.id_project == item_transfer.id_project).FirstOrDefault().code; } } app_document_range app_document_range = item_transfer.app_document_range; item_transfer.number = entity.Brillo.Logic.Range.calc_Range(app_document_range, true); } item_transfer.user_requested = dbContext.security_user.Where(x => x.id_user == CurrentSession.Id_User).FirstOrDefault(); item_transfer.user_given = dbContext.security_user.Where(x => x.id_user == CurrentSession.Id_User).FirstOrDefault(); item_transfer.status = Status.Transfer.Approved; dbContext.SaveChanges(); for (int i = 0; i < item_transfer_detailDataGrid.Items.Count; i++) { entity.Brillo.Logic.Stock stock = new entity.Brillo.Logic.Stock(); item_transfer_detail item_transfer_detail = (item_transfer_detail)item_transfer_detailDataGrid.Items[i]; List <entity.Brillo.StockList> Items_InStockLIST; app_currencyfx app_currencyfx = ProductMovementDB.app_currencyfx.Where(x => x.app_currency.is_active).FirstOrDefault(); app_location app_location = item_transfer_detail.item_transfer.app_location_origin; if (itemMovement.item_movement != null) { entity.Brillo.Stock stockBrillo = new entity.Brillo.Stock(); Items_InStockLIST = stockBrillo.ScalarMovement(itemMovement.item_movement); } else { entity.Brillo.Stock stockBrillo = new entity.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(ProductMovementDB, Items_InStockLIST, Status.Stock.InStock, entity.App.Names.Movement, 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(entity.App.Names.Movement, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", "")); ProductMovementDB.item_movement.AddRange(item_movement_originList); //Credit Movement to Destination item_movement item_movement_dest; item_movement parent_item_movement = item_movement_originList.FirstOrDefault(); List <item_movement_dimension> DimensionList = null; if (item_movement_originList.FirstOrDefault().item_movement_dimension.Count() > 0) { DimensionList = new List <item_movement_dimension>(); foreach (item_movement_dimension item_movement_dimension in item_movement_originList.FirstOrDefault().item_movement_dimension) { item_movement_dimension _item_movement_dimension = new item_movement_dimension(); _item_movement_dimension.id_dimension = item_movement_dimension.id_dimension; _item_movement_dimension.value = item_movement_dimension.value; DimensionList.Add(_item_movement_dimension); } } item_movement_dest = stock.CreditOnly_Movement( Status.Stock.InStock, entity.App.Names.Movement, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfx, item_transfer_detail.item_product, item_transfer_detail.item_transfer.app_location_destination, item_transfer_detail.quantity_destination, item_transfer_detail.item_transfer.trans_date, item_movement_originList.Sum(x => (x.item_movement_value.Sum(y => y.unit_value) / (x.item_movement_value.Count() != 0 ? x.item_movement_value.Count() : 1))), stock.comment_Generator(entity.App.Names.Movement, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""), DimensionList ); //item_movement_dest._parent = Items_InStockLIST.FirstOrDefault(); ProductMovementDB.item_movement.Add(item_movement_dest); item_transfer.status = Status.Transfer.Approved; } if (item_transfer.status == Status.Transfer.Approved && item_transfer.app_document_range != null) { entity.Brillo.Document.Start.Automatic(item_transfer, item_transfer.app_document_range); } if (ProductMovementDB.SaveChanges() > 0) { toolBar.msgSaved(ProductMovementDB.NumberOfRecords); itemMovement = new Configs.itemMovement(); } }