/// <summary> /// is used to save Product container /// </summary> /// <param name="warehouseId">Warehouse where we create container</param> /// <param name="locatorId">Locator - in which locator we place container</param> /// <param name="value">Search key of the container</param> /// <param name="name">name of teh container</param> /// <param name="height">height of the container</param> /// <param name="width">width of the container</param> /// <param name="parentContainerId">Parent of the nw container</param> /// <returns>Save Or Not Saved message</returns> /// <writer>Amit Bansal</writer> public string SaveProductContainer(int warehouseId, int locatorId, string value, string name, Decimal height, Decimal width, int parentContainerId) { MLocator m_locator = null; MWarehouse m_warehouse = null; // when warehouse ID is ZERO, then extract it from Locator if (warehouseId == 0 && locatorId > 0) { m_locator = MLocator.Get(_ctx, locatorId); warehouseId = m_locator.GetM_Warehouse_ID(); } // when locator ID is ZERO, then extract it either from Parent Conatiner or from Warehouse else if (warehouseId > 0 && locatorId == 0) { if (parentContainerId == 0) { m_warehouse = MWarehouse.Get(_ctx, warehouseId); locatorId = m_warehouse.GetDefaultM_Locator_ID(); } else { locatorId = Util.GetValueOfInt(DB.ExecuteScalar("SELECT M_Locator_ID FROM M_ProductContainer WHERE M_ProductContainer_ID = " + parentContainerId, null, null)); } } // need to check warehouse and locator shoyld be active during ceation of Product Container m_warehouse = MWarehouse.Get(_ctx, warehouseId); m_locator = MLocator.Get(_ctx, locatorId); if (!m_warehouse.IsActive()) { return(Msg.GetMsg(_ctx, "VIS_WarehouseNotActive")); } else if (!m_locator.IsActive()) { return(Msg.GetMsg(_ctx, "VIS_LocatorNotActive")); } // Create Product Container in Locator Organization MProductContainer container = new MProductContainer(_ctx, 0, null); container.SetAD_Org_ID(m_locator.GetAD_Org_ID()); container.SetValue(value); container.SetName(name); container.SetM_Warehouse_ID(warehouseId); container.SetM_Locator_ID(locatorId); container.SetHeight(height); container.SetWidth(width); container.SetRef_M_Container_ID(parentContainerId); if (!container.Save()) { ValueNamePair pp = VLogger.RetrieveError(); return(Msg.GetMsg(_ctx, "VIS_ContainernotSaved") + " " + (pp != null ? pp.GetName() : "")); } else { return(""); } }
protected override string DoIt() { Qry = "TRUNCATE TABLE M_TransactionSummary"; int no = DB.ExecuteQuery(Qry); sql.Append(@" SELECT TR.M_PRODUCT_ID , TR.M_LOCATOR_ID , TR.M_ATTRIBUTESETINSTANCE_ID , TR.M_TRANSACTION_ID , TR.CURRENTQTY , TR.MOVEMENTQTY , TR.MOVEMENTTYPE , TR.MOVEMENTDATE , TR.AD_ORG_ID FROM M_TRANSACTION TR INNER JOIN M_PRODUCT PR ON PR.M_PRODUCT_ID =TR.M_PRODUCT_ID WHERE TR.ISACTIVE = 'Y' AND PR.ISACTIVE ='Y'"); if (productId > 0) { sql.Append(@" AND PR.M_PRODUCT_ID IN ( " + productId + " )"); } sql.Append(@" ORDER BY TR.M_PRODUCT_ID , TR.M_LOCATOR_ID , TR.M_ATTRIBUTESETINSTANCE_ID , TR.MOVEMENTDATE , TR.M_TRANSACTION_ID ASC "); dsTransaction = new DataSet(); try { dsTransaction = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); if (dsTransaction != null) { if (dsTransaction.Tables.Count > 0) { if (dsTransaction.Tables[0].Rows.Count > 0) { int i = 0; log.Info(" =====> Transaction Summary Entering Started at " + DateTime.Now.ToString() + " , Total Transactions To Correct = " + dsTransaction.Tables[0].Rows.Count + " <===== "); for (i = 0; i < dsTransaction.Tables[0].Rows.Count; i++) { if (i % 10000 == 0) { log.Info(" =====> " + i + " Transactions Updated till " + DateTime.Now.ToString() + "<===== "); } _M_Product_ID = Util.GetValueOfInt(dsTransaction.Tables[0].Rows[i]["M_Product_ID"]); _M_Locator_ID = Util.GetValueOfInt(dsTransaction.Tables[0].Rows[i]["M_Locator_ID"]); _M_AttributeSetInstance_ID = Util.GetValueOfInt(dsTransaction.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]); _moveType = Util.GetValueOfString(dsTransaction.Tables[0].Rows[i]["MovementType"]); _moveDate = Util.GetValueOfDateTime(dsTransaction.Tables[0].Rows[i]["MovementDate"]); _moveQty = Util.GetValueOfDecimal(dsTransaction.Tables[0].Rows[i]["MovementQty"]); _currentQty = Util.GetValueOfDecimal(dsTransaction.Tables[0].Rows[i]["CurrentQty"]); sql.Clear(); sql.Append(@"Select M_TransactionSummary_ID From M_TransactionSummary Where M_Product_ID=" + _M_Product_ID + @" AND M_AttributeSetInstance_ID=" + _M_AttributeSetInstance_ID + @" AND M_Locator_ID=" + _M_Locator_ID + @" AND MovementDate=" + GlobalVariable.TO_DATE(_moveDate, true)); int M_TransactionSummary_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql.ToString())); if (M_TransactionSummary_ID > 0) { Trs = new MTransactionSummary(GetCtx(), M_TransactionSummary_ID, Get_TrxName()); Trs.SetClosingStock(_currentQty); } else { Qry = "SELECT Count(*) FROM M_TransactionSummary WHERE IsActive = 'Y' AND M_Product_ID = " + _M_Product_ID + " AND M_Locator_ID = " + _M_Locator_ID + " AND M_AttributeSetInstance_ID = " + _M_AttributeSetInstance_ID + " AND movementdate < " + GlobalVariable.TO_DATE(_moveDate, true); int existOld = Util.GetValueOfInt(DB.ExecuteScalar(Qry)); if (existOld > 0) { Qry = "SELECT ClosingStock FROM M_TransactionSummary WHERE IsActive = 'Y' AND M_Product_ID = " + _M_Product_ID + " AND M_Locator_ID = " + _M_Locator_ID + " AND M_AttributeSetInstance_ID = " + _M_AttributeSetInstance_ID + " AND movementdate < " + GlobalVariable.TO_DATE(_moveDate, true) + " ORDER BY MovementDate DESC"; } else { Qry = "SELECT NVL(GetStockofWarehouse(" + _M_Product_ID + "," + _M_Locator_ID + ",0," + _M_AttributeSetInstance_ID + "," + GlobalVariable.TO_DATE(Convert.ToDateTime(_moveDate).AddDays(-1), true) + "," + GetAD_Client_ID() + "," + GetAD_Org_ID() + "),0) AS Stock FROM DUAL"; } OpeningStock = Util.GetValueOfDecimal(DB.ExecuteScalar(Qry)); MLocator loc = new MLocator(GetCtx(), _M_Locator_ID, Get_TrxName()); Trs = new MTransactionSummary(GetCtx(), loc.GetAD_Org_ID(), _M_Locator_ID, _M_Product_ID, _M_AttributeSetInstance_ID, OpeningStock, _currentQty, _moveDate, Get_TrxName()); } if (_moveType == MTransaction.MOVEMENTTYPE_CustomerReturns) { Trs.SetQtyCustReturn(Trs.GetQtyCustReturn() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_CustomerShipment) { Trs.SetQtyCustShipment(Trs.GetQtyCustShipment() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_InventoryIn) { Trs.SetQtyInventoryIn(Trs.GetQtyInventoryIn() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_InventoryOut) { Trs.SetQtyInventoryOut(Trs.GetQtyInventoryOut() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_MovementFrom) { Trs.SetQtyMoveOut(Trs.GetQtyMoveOut() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_MovementTo) { Trs.SetQtyMoveTo(Trs.GetQtyMoveTo() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_Production_) { Trs.SetQtyProductionOut(Trs.GetQtyProductionOut() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_ProductionPlus) { Trs.SetQtyProductionIn(Trs.GetQtyProductionIn() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_VendorReceipts) { Trs.SetQtyMaterialIn(Trs.GetQtyMaterialIn() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_VendorReturns) { Trs.SetQtyMaterialOut(Trs.GetQtyMaterialOut() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_WorkOrderPlus) { Trs.SetQtyWorkOrderIn(Trs.GetQtyWorkOrderIn() + _moveQty); } else if (_moveType == MTransaction.MOVEMENTTYPE_WorkOrder_) { Trs.SetQtyWorkOrderOut(Trs.GetQtyWorkOrderOut() + _moveQty); } if (!Trs.Save()) { log.Info(Msg.GetMsg(GetCtx(), "TrxSummaryNotSaved")); Rollback(); } else { log.Info(Msg.GetMsg(GetCtx(), "TrxSummarySaved")); Commit(); } } } } } } catch (Exception e) { if (dsTransaction != null) { dsTransaction.Dispose(); } return(Msg.GetMsg(GetCtx(), "NotCompleted")); } finally { if (dsTransaction != null) { dsTransaction.Dispose(); } } log.Info(" =====> Transaction Correction End at " + DateTime.Now.ToString() + " <===== "); return(Msg.GetMsg(GetCtx(), "SucessfullyCompleted")); }