protected void btnSave_Click(object sender, EventArgs e) { DataTable productList = (DataTable)Page.ViewState["ProductList"]; Inventory inv = new Inventory(); Inventory inventoryData = new Inventory(); Product prod = new Product(); InventoryRMA rma = new InventoryRMA(); InventoryHistory his = new InventoryHistory(); InventoryManager iManager = new InventoryManager(this); CompanyManager cManager = new CompanyManager(this); if (productList.Rows.Count <= 1) { ShowError(Resources.Exception.InsertProduct); return; } foreach (DataRow row in productList.Rows) { if (row.Table.Rows.IndexOf(row) != 0) { if (!CheckIfCanSale(Convert.ToInt16(row["ProductId"]), Convert.ToInt16(row["Quantity"]))) { ShowError(Resources.Exception.InvalidStockQuantity + " Linha: " + Convert.ToInt16((row.Table.Rows.IndexOf(row)) + 1).ToString()); return; } } } productList.Rows.RemoveAt(0); try { foreach (DataRow row in productList.Rows) { inv.CompanyId = Company.CompanyId; inv.DepositId = Deposit.DepositId; inv.ProductId = Convert.ToInt16(row["ProductId"]); inv.Quantity = Convert.ToInt16(row["Quantity"]); inventoryData = iManager.GetProductInventory(Company.CompanyId, inv.ProductId, inv.DepositId); if (inventoryData != null) { rma.CompanyId = inv.CompanyId; rma.DepositId = inv.DepositId; rma.ModifiedDate = DateTime.Now; rma.ProductId = inv.ProductId; rma.Quantity = inv.Quantity; rma.Substituted = false; rma.SupplierId = Convert.ToInt16(inventoryData.SupplierId); iManager.InventoryDrop(inv, inv.Quantity, (int)DropType.RMA, null); iManager.InsertStockRMA(rma); } } InSuccess(); } catch (Exception ex) { ShowError(Resources.Exception.nonSentProductToRMA); } }
/// <summary> /// this method delete RMA /// </summary> /// <param name="RMAId"></param> public void DeleteRMA(int RMAId) { /* * This method performs all functions * necessary for the exclusion of an RMA */ var inventory = new Inventory(); var rma = new InventoryRMA(); var inventoryManager = new InventoryManager(this); var history = new InventoryHistory(); rma = inventoryManager.RetrieveRMA(RMAId); //retrieve the RMA by RMAId inventory = inventoryManager.GetProductInventory(rma.CompanyId, rma.ProductId, rma.DepositId); //Retrieve The Inventory //set InventotyHistory history.CompanyId = inventory.CompanyId; history.CurrencyRateId = inventory.CurrencyRateId; history.DepositId = rma.DepositId; history.FiscalNumber = inventory.FiscalNumber; history.InventoryEntryTypeId = (int)EntryType.RMA; history.Localization = inventory.Localization; history.LogDate = DateTime.Now; history.MinimumRequired = inventory.MinimumRequired; history.ProductId = rma.ProductId; history.Profit = inventory.Profit; history.Quantity = rma.Quantity; history.RealCost = inventory.RealCost; history.SupplierId = inventory.SupplierId; history.UnitPrice = inventory.UnitPrice; //set quantity and AverageCost in inventory inventory.Quantity += rma.Quantity; inventory.AverageCosts = (((inventory.Quantity * inventory.RealCost) + (rma.Quantity * inventory.RealCost)) / (inventory.Quantity + rma.Quantity)); //applay the changes inventoryManager.InsertHistory(history); DbContext.InventoryRMAs.DeleteOnSubmit(rma); DbContext.SubmitChanges(); }
/// <summary> /// Método para inserir um RMA (Defeito/Troca) na tabela, qualquer dado nesta tabela, consta como /// se o produto estivesse em trânsito, aguardando uma confirmação da troca pelo usuário /// </summary> /// <param name="entity"></param> public void InsertStockRMA(InventoryRMA entity) { DbContext.InventoryRMAs.InsertOnSubmit(entity); DbContext.SubmitChanges(); }