/// <summary> /// Get Warehouses for Org /// </summary> /// <param name="ctx">context</param> /// <param name="AD_Org_ID">id</param> /// <returns>warehouse</returns> public static MWarehouse[] GetForOrg(Ctx ctx, int AD_Org_ID) { List <MWarehouse> list = new List <MWarehouse>(); String sql = "SELECT * FROM M_Warehouse WHERE AD_Org_ID=" + AD_Org_ID + " ORDER BY Created"; try { DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null); if (ds.Tables.Count > 0) { DataRow dr = null; int totCount = ds.Tables[0].Rows.Count; for (int i = 0; i < totCount; i++) { dr = ds.Tables[0].Rows[i]; list.Add(new MWarehouse(ctx, dr, null)); } } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } MWarehouse[] retValue = new MWarehouse[list.Count]; retValue = list.ToArray(); return(retValue); }
/// <summary> /// Get the Locator with the combination or create new one /// </summary> /// <param name="ctx">context</param> /// <param name="M_Warehouse_ID">id</param> /// <param name="value">value</param> /// <param name="X">x</param> /// <param name="Y">y</param> /// <param name="Z">z</param> /// <returns>locator</returns> public static MLocator Get(Ctx ctx, int M_Warehouse_ID, String value, String X, String Y, String Z) { MLocator retValue = null; String sql = "SELECT * FROM M_Locator WHERE M_Warehouse_ID=" + M_Warehouse_ID + " AND " + "X='" + X + "' AND Y='" + Y + "' AND Z='" + Z + "'"; DataSet ds = null; try { ds = DataBase.DB.ExecuteDataset(sql, null, null); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { DataRow rs = ds.Tables[0].Rows[0]; retValue = new MLocator(ctx, rs, null); } } catch (Exception ex) { _log.Log(Level.SEVERE, "get", ex); } // if (retValue == null) { MWarehouse wh = MWarehouse.Get(ctx, M_Warehouse_ID); retValue = new MLocator(wh, HttpUtility.HtmlEncode(value)); retValue.SetXYZ(HttpUtility.HtmlEncode(X), HttpUtility.HtmlEncode(Y), HttpUtility.HtmlEncode(Z)); if (!retValue.Save()) { retValue = null; } } return(retValue); }
} // toString /// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true if can be saved</returns> protected override Boolean BeforeSave(Boolean newRecord) { // Ctx to start with / if (!GetWebContext().StartsWith("/")) { SetWebContext("/" + GetWebContext()); } // Org to Warehouse if (newRecord || Is_ValueChanged("M_Warehouse_ID") || GetAD_Org_ID() == 0) { MWarehouse wh = new MWarehouse(GetCtx(), GetM_Warehouse_ID(), Get_TrxName()); SetAD_Org_ID(wh.GetAD_Org_ID()); } String url = GetURL(); if (url == null) { url = ""; } Boolean urlOK = url.StartsWith("http://") || url.StartsWith("https://"); if (!urlOK) // || url.indexOf("localhost") != -1) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "URL") + " - e.g. http://www.ViennaAdvantage.com"); return(false); } return(true); } // beforeSave
public static MLocator Get(Ctx ctx, int M_Warehouse_ID, String value, String X, String Y, String Z, String Position, String Bin) { MLocator retValue = null; String sql = "SELECT * FROM M_Locator WHERE M_Warehouse_ID=" + M_Warehouse_ID + " AND " + "X='" + X + "' AND Y='" + Y + "' AND Z='" + Z + "'"; DataSet ds = null; try { ds = DB.ExecuteDataset(sql, null, null); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { DataRow idr = ds.Tables[0].Rows[0]; retValue = new MLocator(ctx, idr, null); } } catch (Exception ex) { _log.Log(Level.SEVERE, "get", ex); } // if (retValue == null) { MWarehouse wh = MWarehouse.Get(ctx, M_Warehouse_ID); retValue = new MLocator(wh, value); retValue.SetXYZ(X, Y, Z, Position, Bin); if (!retValue.Save()) { retValue = null; } } return(retValue); }
} // setM_Product_ID /// <summary> /// Set (default) Locator based on qty. /// /// </summary> /// <param name="Qty">Qty quantity</param> public void SetM_Locator_ID(Decimal Qty) { // Locator established if (GetM_Locator_ID() != 0) { return; } // No Product if (GetM_Product_ID() == 0) { Set_ValueNoCheck("M_Locator_ID", null); return; } VAdvantage.Model.MOrg org = new VAdvantage.Model.MOrg(GetCtx(), GetAD_Org_ID(), Get_TrxName()); // Get existing Location int M_Locator_ID = VAdvantage.Model.MStorage.GetM_Locator_ID(org.GetM_Warehouse_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Qty, Get_TrxName()); // Get default Location if (M_Locator_ID == 0) { VAdvantage.Model.MProduct product = VAdvantage.Model.MProduct.Get(GetCtx(), GetM_Product_ID()); M_Locator_ID = VAdvantage.Model.MProductLocator.GetFirstM_Locator_ID(product, org.GetM_Warehouse_ID()); if (M_Locator_ID == 0) { VAdvantage.Model.MWarehouse wh = VAdvantage.Model.MWarehouse.Get(GetCtx(), org.GetM_Warehouse_ID()); M_Locator_ID = wh.GetDefaultM_Locator_ID(); } } base.SetM_Locator_ID(M_Locator_ID); } // setM_Locator_ID
/** * Set (default) Locator based on qty. * @param Qty quantity * Assumes Warehouse is set */ public void SetM_Locator_ID(Decimal Qty) { // Locator esatblished if (GetM_Locator_ID() != 0) { return; } // No Product if (GetM_Product_ID() == 0) { Set_ValueNoCheck("M_Locator_ID", null); return; } // Get existing Location int M_Locator_ID = MStorage.GetM_Locator_ID(GetM_Warehouse_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Qty, Get_TrxName()); // Get default Location if (M_Locator_ID == 0) { MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); M_Locator_ID = MProductLocator.GetFirstM_Locator_ID(product, GetM_Warehouse_ID()); if (M_Locator_ID == 0) { MWarehouse wh = MWarehouse.Get(GetCtx(), GetM_Warehouse_ID()); M_Locator_ID = wh.GetDefaultM_Locator_ID(); } } SetM_Locator_ID(M_Locator_ID); }
/// <summary> /// New Locator Constructor with XYZ=000 /// </summary> /// <param name="warehouse">parent</param> /// <param name="value">value</param> public MLocator(MWarehouse warehouse, String value) : this(warehouse.GetCtx(), 0, warehouse.Get_TrxName()) { SetClientOrg(warehouse); SetM_Warehouse_ID(warehouse.GetM_Warehouse_ID()); // Parent SetValue(value); SetXYZ("0", "0", "0"); }
/// <summary> /// Get Warehouse Name /// </summary> /// <returns>name</returns> public String GetWarehouseName() { MWarehouse wh = MWarehouse.Get(GetCtx(), GetM_Warehouse_ID()); if (wh.Get_ID() == 0) { return("<" + GetM_Warehouse_ID() + ">"); } return(wh.GetName()); }
/// <summary> /// New Locator Constructor with XYZ=000 /// </summary> /// <param name="warehouse">parent</param> /// <param name="value">value</param> public MLocator(MWarehouse warehouse, String value) : this(warehouse.GetCtx(), 0, warehouse.Get_TrxName()) { SetClientOrg(warehouse); SetM_Warehouse_ID(warehouse.GetM_Warehouse_ID()); // Parent SetValue(value); // Added by Mohit VAWMS 20-8-2015 if (Env.HasModulePrefix("VAWMS_", out mInfo)) { SetXYZ("0", "0", "0", "0", "0"); } else { SetXYZ("0", "0", "0"); } //End }
/// <summary> /// Get from Cache /// </summary> /// <param name="ctx">context</param> /// <param name="M_Warehouse_ID">id</param> /// <returns>warehouse</returns> public static MWarehouse Get(Ctx ctx, int M_Warehouse_ID) { int key = M_Warehouse_ID; MWarehouse retValue = null; if (cache.ContainsKey(key)) { retValue = (MWarehouse)cache[key]; } if (retValue != null) { return(retValue); } // retValue = new MWarehouse(ctx, M_Warehouse_ID, null); cache.Add(key, retValue); return(retValue); }
protected override bool BeforeSave(bool newRecord) { // Movement Quantity can not be less than 0 when planned is greater than 0 if (GetPlannedQty() > 0 && GetMovementQty() < 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbelesszero")); return(false); } // Movement Quantity can not be greater than 0 when planned is less than 0 if (GetPlannedQty() < 0 && GetMovementQty() > 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbegrtzero")); return(false); } // when warehouse disallow negative inventory is false then on hand qty can't be in negative wh = MWarehouse.Get(GetCtx(), GetM_Warehouse_ID()); if (wh.IsDisallowNegativeInv() && GetM_Product_ID() > 0) { product = MProduct.Get(GetCtx(), GetM_Product_ID()); string qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); //if (GetM_AttributeSetInstance_ID() != 0) //{ qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID(); //} Decimal?OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); qry = @"SELECT NVL(SUM(MovementQty) , 0) FROM M_ProductionLine WHERE IsActive = 'Y' AND M_Locator_ID=" + GetM_Locator_ID() + @" AND m_product_id=" + GetM_Product_ID() + @" AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID() + @" AND M_Production_ID = " + GetM_Production_ID(); if (!newRecord) { qry += @" AND M_ProductionLine_ID <> " + GetM_ProductionLine_ID(); } Decimal?moveQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); if ((OnHandQty + GetMovementQty() + moveQty) < 0) { log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } } return(true); }
} // getC_Currency_ID /// <summary> /// Get Default Org Warehouse /// </summary> /// <returns>warehouse</returns> public new int GetM_Warehouse_ID() { int M_Warehouse_ID = base.GetM_Warehouse_ID(); if (M_Warehouse_ID != 0) { return(M_Warehouse_ID); } // MWarehouse[] whss = MWarehouse.GetForOrg(GetCtx(), GetAD_Org_ID()); if (whss.Length > 0) { M_Warehouse_ID = whss[0].GetM_Warehouse_ID(); SetM_Warehouse_ID(M_Warehouse_ID); return(M_Warehouse_ID); } log.Warning("No Warehouse for AD_Org_ID=" + GetAD_Org_ID()); return(0); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord"></param> /// <returns></returns> protected override Boolean BeforeSave(Boolean newRecord) { //Check for lock on Locator and Product //if (Is_ValueChanged("Qty") && IsType(X_Ref_Quantity_Type.ON_HAND) && // MCycleCountLock.LockExists(GetCtx(), GetM_Product_ID(), GetM_Locator_ID(), Get_TrxName())) //{ // s_log.SaveError("Error", Msg.GetMsg(GetCtx(), "LocatorLocked")); // return false; //} if (isBulkUpdate) { // validation must already done at storage level not detail/type level // see Storage.Record.validate() return(base.BeforeSave(newRecord)); } // Negative Inventory check if (newRecord || (Is_ValueChanged("Qty") && (IsType(X_Ref_Quantity_Type.ON_HAND) || IsType(X_Ref_Quantity_Type.DEDICATED) || IsType(X_Ref_Quantity_Type.ALLOCATED) || IsType(X_Ref_Quantity_Type.EXPECTED))) ) { MWarehouse wh = MWarehouse.Get(GetCtx(), GetM_Warehouse_ID()); if (wh.IsDisallowNegativeInv()) { if (Env.Signum(GetQty()) < 0) { s_log.SaveError("Error", Msg.GetMsg(GetCtx(), "NegativeInventoryDisallowed")); return(false); } Decimal qtyOnHand = Env.ZERO; Decimal qtyDedicated = Env.ZERO; Decimal qtyAllocated = Env.ZERO; String sql = "SELECT SUM(QtyOnHand),SUM(QtyDedicated),SUM(QtyAllocated) " + "FROM M_Storage_V s" + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) " + "WHERE s.M_Product_ID=" + GetM_Product_ID() // #1 + " AND l.M_Warehouse_ID=" + GetM_Warehouse_ID() + " AND l.M_Locator_ID=" + GetM_Locator_ID(); IDataReader idr = null; try { idr = DB.ExecuteReader(sql, null, Get_TrxName()); if (idr.Read()) { qtyOnHand = VAdvantage.Utility.Util.GetValueOfDecimal(idr[0]); if (idr.IsDBNull(0))//if (idr.wasNull()) { qtyOnHand = Env.ZERO; } qtyDedicated = VAdvantage.Utility.Util.GetValueOfDecimal(idr[1]); if (idr.IsDBNull(1))// wasNull()) { qtyDedicated = Env.ZERO; } qtyAllocated = VAdvantage.Utility.Util.GetValueOfDecimal(idr[2]); if (idr.IsDBNull(2))// wasNull()) { qtyAllocated = Env.ZERO; } } idr.Close(); } catch (Exception e) { s_log.Log(Level.SEVERE, sql, e); } finally { if (idr != null) { idr.Close(); idr = null; } } Decimal?asiQtyOnHand = Decimal.Zero; Decimal?asiQtyDedicated = Decimal.Zero; Decimal?asiQtyAllocated = Decimal.Zero; if (IsType(X_Ref_Quantity_Type.ON_HAND)) { if (newRecord) { qtyOnHand = Decimal.Add(qtyOnHand, GetQty()); } else { qtyOnHand = Decimal.Subtract(Decimal.Add(qtyOnHand, GetQty()), Util.GetValueOfDecimal(Get_ValueOld("Qty"))); } asiQtyOnHand = GetQty(); asiQtyAllocated = MStorageDetail.GetQty(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), X_Ref_Quantity_Type.ALLOCATED, Get_TrxName()); asiQtyDedicated = MStorageDetail.GetQty(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), X_Ref_Quantity_Type.DEDICATED, Get_TrxName()); } else if (IsType(X_Ref_Quantity_Type.DEDICATED)) { if (newRecord) { qtyDedicated = Decimal.Add(qtyDedicated, GetQty()); } else { qtyDedicated = Decimal.Subtract(Decimal.Add(qtyDedicated, GetQty()), Util.GetValueOfDecimal(Get_ValueOld("Qty"))); } asiQtyOnHand = MStorageDetail.GetQty(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), X_Ref_Quantity_Type.ON_HAND, Get_TrxName()); asiQtyAllocated = MStorageDetail.GetQty(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), X_Ref_Quantity_Type.ALLOCATED, Get_TrxName()); asiQtyDedicated = GetQty(); } else if (IsType(X_Ref_Quantity_Type.ALLOCATED)) { if (newRecord) { qtyAllocated = Decimal.Add(qtyAllocated, GetQty()); } else { qtyAllocated = Decimal.Subtract(Decimal.Add(qtyAllocated, GetQty()), Util.GetValueOfDecimal(Get_ValueOld("Qty"))); } asiQtyOnHand = MStorageDetail.GetQty(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), X_Ref_Quantity_Type.ON_HAND, Get_TrxName()); asiQtyAllocated = GetQty(); asiQtyDedicated = MStorageDetail.GetQty(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), X_Ref_Quantity_Type.DEDICATED, Get_TrxName()); } asiQtyOnHand = asiQtyOnHand == null ? Env.ZERO : asiQtyOnHand; asiQtyDedicated = asiQtyDedicated == null ? Env.ZERO : asiQtyDedicated; asiQtyAllocated = asiQtyAllocated == null ? Env.ZERO : asiQtyAllocated; if (qtyOnHand.CompareTo(Decimal.Add(qtyDedicated, qtyAllocated)) < 0 || asiQtyOnHand.Value.CompareTo(Decimal.Add(asiQtyDedicated.Value, asiQtyAllocated.Value)) < 0) { s_log.SaveError("Error", Msg.GetMsg(GetCtx(), "NegativeInventoryDisallowed")); return(false); } } } return(base.BeforeSave(newRecord)); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true</returns> protected override Boolean BeforeSave(Boolean newRecord) { Decimal VA024_ProvisionPrice = 0; MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); // By vikas // Get Old Value of AttributeSetInstance_ID _mvlOldAttId = Util.GetValueOfInt(Get_ValueOld("M_AttributeSetInstance_ID")); // Set Line No if (GetLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID(); int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetLine(ii); } // Check Locator For Header Warehouse MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName()); MLocator loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName()); Tuple <string, string, string> aInfo = null; if (Env.HasModulePrefix("DTD001_", out aInfo)) { if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID()) { } else { String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'"; int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetM_Locator_ID(ii); } } if (GetM_Locator_ID() == GetM_LocatorTo_ID()) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement return(false); } if (Env.Signum(GetMovementQty()) == 0 && Util.GetValueOfInt(GetTargetQty()) == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty")); return(false); } //Amit Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged")); return(false); } } //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0) if (Env.IsModuleInstalled("VA203_")) { if (GetM_RequisitionLine_ID() > 0) { MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx()); // Trx used to handle query stuck problem if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame")); return(false); } } } // IF Doc Status = InProgress then No record Save MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx()); // Trx used to handle query stuck problem if (newRecord && move.GetDocStatus() == "IP") { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate")); return(false); } // change to set Converted Quantity in Movement quantity if there is differnce in UOM of Base Product and UOM Selected on line if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID")) { Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered")); if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID"))) { SetMovementQty(MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered")))); } } // Qty Precision if (newRecord || Is_ValueChanged("QtyEntered")) { SetMovementQty(GetMovementQty()); } MWarehouse wh = null; MWarehouse whTo = null; //string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID(); //M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry)); wh = MWarehouse.Get(GetCtx(), mov.GetDTD001_MWarehouseSource_ID()); whTo = MWarehouse.Get(GetCtx(), mov.GetM_Warehouse_ID()); string qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_LocatorTo_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } OnHandQtyTo = Convert.ToDecimal(DB.ExecuteScalar(qry)); // SI_0635 : System is giving error of insufficient qty if disallow is true in TO warehouse and false in From warehouse // when record is in completed & closed stage - then no need to check qty availablity in warehouse if ((wh.IsDisallowNegativeInv() || whTo.IsDisallowNegativeInv()) && (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE" || move.GetDocStatus() == "VO"))) { if (wh.IsDisallowNegativeInv() && (OnHandQty - GetMovementQty()) < 0) { // check for From Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } else if (whTo.IsDisallowNegativeInv() && (OnHandQtyTo + GetMovementQty()) < 0) { // check for To Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQtyTo); return(false); } } if (Env.HasModulePrefix("DTD001_", out mInfo)) { qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry)); qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("MovementQty")); //if (wh.IsDisallowNegativeInv() == true) //{ // if ((qtyAvailable < (GetMovementQty() - qtyReserved))) // { // log.SaveError("Message", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "DTD001_QtyNotAvailable")); // return false; // } //} } //By Amit - 17-April-2017 if (Env.IsModuleInstalled("VA024_")) { // checking are we moving product from one warehouse to other warehouse if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT CASE WHEN ((SELECT CASE WHEN o.IsLegalEntity = 'Y' THEN w.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o.LegalEntityOrg ) END FROM m_warehouse w INNER JOIN ad_org o ON o.AD_Org_ID = w.AD_Org_ID WHERE w.m_warehouse_id = m.DTD001_MWarehouseSource_ID)) = (SELECT CASE WHEN o2.IsLegalEntity = 'Y' THEN w2.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o2.LegalEntityOrg) END FROM m_warehouse w2 INNER JOIN ad_org o2 ON o2.AD_Org_ID = w2.AD_Org_ID WHERE M_Warehouse_ID = m.M_Warehouse_ID ) THEN 0 ELSE (SELECT ad_org_id FROM m_warehouse WHERE M_Warehouse_ID = m.M_Warehouse_ID ) END AS result FROM m_movement m WHERE m_movement_id = " + GetM_Movement_ID(), null, Get_Trx())) > 0) { MMovement inventory = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx()); try { string qry1 = @"SELECT SUM(o.VA024_UnitPrice) FROM VA024_t_ObsoleteInventory o WHERE o.IsActive = 'Y' AND o.M_Product_ID = " + GetM_Product_ID() + @" and ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" + " AND o.AD_Org_ID = " + GetAD_Org_ID(); VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())); SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetMovementQty())); qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + GetMovementQty(); qry1 += @" FROM m_product p INNER JOIN va024_t_obsoleteinventory oi ON p.m_product_id = oi.M_product_ID INNER JOIN m_product_category pc ON pc.m_product_category_ID = p.m_product_category_ID INNER JOIN AD_client c ON c.AD_Client_ID = p.Ad_Client_ID INNER JOIN AD_ClientInfo ci ON c.AD_Client_ID = ci.Ad_Client_ID INNER JOIN m_cost ct ON ( p.M_Product_ID = ct.M_Product_ID AND ci.C_AcctSchema1_ID = ct.C_AcctSchema_ID ) INNER JOIN c_acctschema asch ON (asch.C_AcctSchema_ID = ci.C_AcctSchema1_ID) INNER JOIN va024_obsoleteinvline oil ON oil.va024_obsoleteinvline_ID = oi.va024_obsoleteinvline_ID "; qry1 += @" WHERE ct.AD_Org_ID = CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel = 'C' OR pc.costinglevel = 'B')) THEN 0 WHEN (pc.costinglevel IS NULL AND asch.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel = 'C' OR asch.costinglevel = 'B')) THEN 0 END AND ct.m_costelement_id = CASE WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod != 'C') THEN (SELECT MIN(m_costelement_id) FROM m_costelement WHERE m_costelement.costingmethod =pc.costingmethod AND m_costelement.Ad_Client_ID = oi.ad_client_id ) WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod = 'C' ) THEN pc.m_costelement_id WHEN ( pc.costingmethod IS NULL AND asch.costingmethod != 'C') THEN (SELECT MIN(m_costelement_id) FROM m_costelement WHERE m_costelement.costingmethod = asch.costingmethod AND m_costelement.Ad_Client_ID = oi.ad_client_id ) WHEN ( pc.costingmethod IS NULL AND asch.costingmethod = 'C') THEN asch.m_costelement_id END AND NVL(ct.M_Attributesetinstance_ID , 0) = CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel = 'C' OR pc.costinglevel = 'O')) THEN 0 WHEN ( pc.costinglevel IS NULL AND asch.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel = 'C' OR asch.costinglevel = 'O')) THEN 0 END AND p.M_Product_ID = " + GetM_Product_ID(); SetVA024_CostPrice(Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()))); } catch { } } } // Mandatory Instance if (GetM_AttributeSetInstanceTo_ID() == 0) { if (GetM_AttributeSetInstance_ID() != 0) // Set to from { SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID()); } else { if (Env.HasModulePrefix("DTD001_", out mInfo)) { //MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); //if (mas.IsInstanceAttribute() // && (mas.IsMandatory() || mas.IsMandatoryAlways())) //{ // log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); // return false; //} // Code Addeded by Bharat as Discussed with Mukesh Sir if (String.IsNullOrEmpty(GetDTD001_AttributeNumber())) { return(true); } else { if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } } } else { if (product != null) { if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)) { return(true); } else { //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); //ShowMessage.Info("a", true, "Product is not of Attribute Type", null); log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } //Check No Of Attributes Are Equal To Quantity Or Less Than int Count = CountAttributes(GetDTD001_AttributeNumber()); if (Count != GetMovementQty()) { if (Count > GetMovementQty()) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater")); return(false); } else { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess")); return(false); } } } } } else { //MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); if (mas.IsInstanceAttribute() && (mas.IsMandatory() || mas.IsMandatoryAlways())) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); return(false); } } } } } // ASI return(true); }
/** * Set Product - Callout * @param oldM_Product_ID old value * @param newM_Product_ID new value * @param windowNo window * @throws Exception */ //@UICallout public void SetM_Product_ID(String oldM_Product_ID, String newM_Product_ID, int windowNo) { if (newM_Product_ID == null || newM_Product_ID.Length == 0) { return; } int M_Product_ID = int.Parse(newM_Product_ID); if (M_Product_ID == 0) { SetM_AttributeSetInstance_ID(0); return; } // base.SetM_Product_ID(M_Product_ID); SetC_Charge_ID(0); // Set Attribute & Locator int M_Locator_ID = 0; if (GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "M_Product_ID") == M_Product_ID && GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "M_AttributeSetInstance_ID") != 0) { SetM_AttributeSetInstance_ID(GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "M_AttributeSetInstance_ID")); // Locator from Info Window - ASI M_Locator_ID = GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "M_Locator_ID"); if (M_Locator_ID != 0) { SetM_Locator_ID(M_Locator_ID); } } else { SetM_AttributeSetInstance_ID(0); } // bool IsSOTrx = GetCtx().IsSOTrx(windowNo); if (IsSOTrx) { return; } // PO - Set UOM/Locator/Qty MProduct product = GetProduct(); SetC_UOM_ID(product.GetC_UOM_ID()); Decimal QtyEntered = GetQtyEntered(); SetMovementQty(QtyEntered); if (M_Locator_ID != 0) { ; // already set via ASI } else { int M_Warehouse_ID = GetCtx().GetContextAsInt(windowNo, "M_Warehouse_ID"); M_Locator_ID = MProductLocator.GetFirstM_Locator_ID(product, M_Warehouse_ID); if (M_Locator_ID != 0) { SetM_Locator_ID(M_Locator_ID); } else { MWarehouse wh = MWarehouse.Get(GetCtx(), M_Warehouse_ID); SetM_Locator_ID(wh.GetDefaultM_Locator_ID()); } } }
/// <summary> /// detail Add /// Warehouse must already be validated /// diffQty must always be positive; negative values are not processed /// </summary> /// <param name="ctx"></param> /// <param name="M_Warehouse_ID"></param> /// <param name="M_Locator_ID"></param> /// <param name="M_Product_ID"></param> /// <param name="M_AttributeSetInstance_ID"></param> /// <param name="reservationAttributeSetInstance_ID"></param> /// <param name="diffQty"></param> /// <param name="type"></param> /// <param name="trx"></param> /// <returns></returns> public static Boolean Add(Ctx ctx, int M_Warehouse_ID, int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID, int reservationAttributeSetInstance_ID, Decimal diffQty, String type, Trx trx) { StringBuilder diffText = new StringBuilder("("); MStorageDetail storage = null; storage = MStorageDetail.GetCreate(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, type, trx); // Verify if (storage.GetM_Locator_ID() != M_Locator_ID && storage.GetM_Product_ID() != M_Product_ID && storage.GetM_AttributeSetInstance_ID() != M_AttributeSetInstance_ID) { s_log.Severe("No Storage found - M_Locator_ID=" + M_Locator_ID + ",M_Product_ID=" + M_Product_ID + ",ASI=" + M_AttributeSetInstance_ID); return(false); } MStorageDetail storageASI = null; if ((M_AttributeSetInstance_ID != reservationAttributeSetInstance_ID) && (type == X_Ref_Quantity_Type.RESERVED || type == X_Ref_Quantity_Type.ORDERED)) { int reservationM_Locator_ID = M_Locator_ID; if (reservationAttributeSetInstance_ID == 0) { MWarehouse wh = MWarehouse.Get(ctx, M_Warehouse_ID); reservationM_Locator_ID = wh.GetDefaultM_Locator_ID(); } storageASI = MStorageDetail.Get(ctx, reservationM_Locator_ID, M_Product_ID, reservationAttributeSetInstance_ID, type, true, trx); if (storageASI == null) // create if not existing - should not happen { MProduct product = MProduct.Get(ctx, M_Product_ID); int xM_Locator_ID = MProductLocator.GetFirstM_Locator_ID(product, M_Warehouse_ID); if (xM_Locator_ID == 0) { MWarehouse wh = MWarehouse.Get(ctx, M_Warehouse_ID); xM_Locator_ID = wh.GetDefaultM_Locator_ID(); } storageASI = MStorageDetail.GetCreate(ctx, xM_Locator_ID, M_Product_ID, reservationAttributeSetInstance_ID, type, trx); } } Boolean changed = false; if (Env.Signum(diffQty) != 0) { if (storageASI == null) { storage.SetQty(Decimal.Add(storage.GetQty(), diffQty)); } else { storageASI.SetQty(Decimal.Add(storageASI.GetQty(), diffQty)); } diffText.Append(type.ToString()).Append("=").Append(diffQty); changed = true; } if (changed) { diffText.Append(") -> ").Append(storage.ToString()); s_log.Fine(diffText.ToString()); if (storageASI != null) { storageASI.Save(trx); // No AttributeSetInstance } // (reserved/ordered) return(storage.Save(trx)); } return(true); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true if can be saved</returns> protected override bool BeforeSave(bool newRecord) { if (newRecord && _isManualEntry) { // Product requires ASI if (GetM_AttributeSetInstance_ID() == 0) { MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); if (product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); if (mas.IsInstanceAttribute() && (mas.IsMandatory() || mas.IsMandatoryAlways())) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstance_ID")); return(false); } } } // No ASI } // new or manual // Set Line No if (GetLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_InventoryLine WHERE M_Inventory_ID=" + GetM_Inventory_ID(); int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetLine(ii); } int M_Warehouse_ID = 0; MWarehouse wh = null; string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID(); M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry)); wh = MWarehouse.Get(GetCtx(), M_Warehouse_ID); qry = "SELECT QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); if (wh.IsDisallowNegativeInv() == true) { if (GetQtyCount() < 0) { if (wh.IsDisallowNegativeInv() == true) { //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null); return(false); } } else if ((GetQtyInternalUse() > 0)) { if ((OnHandQty - GetQtyInternalUse()) < 0) { if (wh.IsDisallowNegativeInv() == true) { //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null); return(false); } } } else if ((GetQtyInternalUse() < 0)) { if (wh.IsDisallowNegativeInv() == true) { //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null); return(false); } } } // Enforce Qty UOM if (newRecord || Is_ValueChanged("QtyCount")) { SetQtyCount(GetQtyCount()); } if (newRecord || Is_ValueChanged("QtyInternalUse")) { SetQtyInternalUse(GetQtyInternalUse()); } // InternalUse Inventory if (IsInternalUse() && Env.Signum(GetQtyInternalUse()) == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "QtyInternalUse")); return(false); } if (Env.Signum(GetQtyInternalUse()) != 0) { if (!INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType())) { SetInventoryType(INVENTORYTYPE_ChargeAccount); } // if (GetC_Charge_ID() == 0) { log.SaveError("InternalUseNeedsCharge", ""); return(false); } } else if (INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType())) { if (GetC_Charge_ID() == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "C_Charge_ID")); return(false); } } else if (GetC_Charge_ID() != 0) { SetC_Charge_ID(0); } // Set AD_Org to parent if not charge if (GetC_Charge_ID() == 0) { SetAD_Org_ID(GetParent().GetAD_Org_ID()); } return(true); }
// Added by Mohit VAWMS 20-8-2015 protected override Boolean BeforeSave(Boolean newRecord) { if (Env.HasModulePrefix("VAWMS_", out mInfo)) { // Check Storage if (Is_ValueChanged("IsActive") && IsActive()) // now not active { if (checkStock(GetCtx(), Get_ID(), Get_TrxName())) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "LocatorHasStock")); return(false); } } // storage // JID:1888 Checks for the duplicate Searchkey int count = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(Value) FROM M_Locator WHERE Value= '" + GetValue() + "' AND M_Locator_ID !=" + GetM_Locator_ID())); if (count > 0) { log.SaveError("", Msg.GetMsg(GetCtx(), "SearchKeyUnique")); return(false); } if (newRecord || Is_ValueChanged("X") || Is_ValueChanged("Y") || Is_ValueChanged("Z") || Is_ValueChanged("POSITION") || Is_ValueChanged("Bin")) { MWarehouse wh = new MWarehouse(GetCtx(), GetM_Warehouse_ID(), Get_TrxName()); //if (GetBin() != null && GetPOSITION() != null || GetPOSITION()==null) //{ // log.SaveError("Error", Msg.GetMsg(GetCtx(), "PositionMandatorySegment")); // return false; //} //if (GetX() == null || GetX().Length == 0 || !Util.isAlphaNumeric(GetX()) || // GetY() == null || GetY().Length == 0 || !Util.isAlphaNumeric(GetY()) || // GetZ() == null || GetZ().Length == 0 || !Util.isAlphaNumeric(GetZ()) || // (GetBin() != null && GetBin().Length != 0 && !Util.isAlphaNumeric(GetBin())) || // (GetPOSITION() != null && GetPOSITION().Length != 0 && !Util.isAlphaNumeric(GetPOSITION()))) //if (GetX() == null || GetX().Length == 0 || // GetY() == null || GetY().Length == 0 || // GetZ() == null || GetZ().Length == 0 || // (GetBin() != null && GetBin().Length != 0) || // (GetPOSITION() != null && GetPOSITION().Length != 0)) //{ // log.SaveError("Error", Msg.GetMsg(GetCtx(), "SegmentNotAlphaNumeric")); // return false; //} //String combination = GetX().concat(wh.GetSeparator()); //combination = combination.(GetY()).concat(wh.GetSeparator()); //combination = combination.concat(GetZ()); //if (GetPOSITION() != null && GetPOSITION().Length != 0) // combination = combination.concat(wh.GetSeparator()).concat(GetPOSITION()); //if (GetBin() != null && GetBin().Length != 0) // combination = combination.concat(wh.GetSeparator()).concat(GetBin()); StringBuilder combination = new StringBuilder(); combination.Append(GetX()).Append(wh.GetSeparator()); combination = combination.Append(GetY()).Append(wh.GetSeparator()); combination = combination.Append(GetZ()); if (GetPOSITION() != null && GetPOSITION().Length != 0) { combination = combination.Append(wh.GetSeparator()).Append(GetPOSITION()); } if (GetBin() != null && GetBin().Length != 0) { combination = combination.Append(wh.GetSeparator()).Append(GetBin()); } log.Fine("Set Locator Combination :" + combination); //String sql = "SELECT count(*) FROM M_Locator WHERE M_Locator_ID<>?" + // " AND M_Warehouse_ID = ?" + // " AND UPPER(LocatorCombination) = UPPER(?)"; String sql = "SELECT count(*) FROM M_Locator WHERE M_Locator_ID<>" + GetM_Locator_ID() + " AND M_Warehouse_ID =" + GetM_Warehouse_ID() + " AND UPPER(LocatorCombination) = UPPER('" + combination + "')"; //int ii = QueryUtil.GetSQLValue(Get_TrxName(), sql, GetM_Locator_ID(), GetM_Warehouse_ID(), combination); int ii = Convert.ToInt32(DB.ExecuteScalar(sql, null, Get_TrxName())); if (ii != 0) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "CombinationNotUnique")); return(false); } SetLocatorCombination(combination.ToString()); } if (newRecord || Is_ValueChanged("IsAvailableToPromise") || Is_ValueChanged("IsAvailableForAllocation")) { if (IsAvailableForAllocation() && !IsAvailableToPromise()) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "InvalidCombination")); return(false); } } return(true); } return(true); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true</returns> protected override Boolean BeforeSave(Boolean newRecord) { Decimal VA024_ProvisionPrice = 0; MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); // chck pallet Functionality applicable or not bool isContainrApplicable = MTransaction.ProductContainerApplicable(GetCtx()); // Get Old Value of AttributeSetInstance_ID _mvlOldAttId = Util.GetValueOfInt(Get_ValueOld("M_AttributeSetInstance_ID")); // Set Line No if (GetLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID(); int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetLine(ii); } // JID_0775: System is not checking on move line that the attribute set instance is mandatory. if (GetM_AttributeSetInstance_ID() == 0) { if (product != null && product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); if (mas.IsMandatory() || mas.IsMandatoryAlways()) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstance_ID")); return(false); } } } // Check Locator For Header Warehouse MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName()); MLocator loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName()); Tuple <string, string, string> aInfo = null; if (Env.HasModulePrefix("DTD001_", out aInfo)) { if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID()) { } else { String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'"; int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetM_Locator_ID(ii); } } // when we try to move product from container to container which are in same locator then no need to check this case if (GetM_Locator_ID() == GetM_LocatorTo_ID() && (Get_ColumnIndex("M_ProductContainer_ID") > 0 && Get_ColumnIndex("Ref_M_ProductContainerTo_ID") > 0 && !(GetM_ProductContainer_ID() > 0 || GetRef_M_ProductContainerTo_ID() > 0))) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement return(false); } if (Env.Signum(GetMovementQty()) == 0 && Util.GetValueOfInt(GetTargetQty()) == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty")); return(false); } Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged")); return(false); } } //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0) if (Env.IsModuleInstalled("VA203_")) { if (GetM_RequisitionLine_ID() > 0) { MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx()); // Trx used to handle query stuck problem if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame")); return(false); } } } // IF Doc Status = InProgress then No record Save MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx()); // Trx used to handle query stuck problem if (newRecord && move.GetDocStatus() == "IP") { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate")); return(false); } // Qty Precision if (newRecord || Is_ValueChanged("QtyEntered")) { SetQtyEntered(GetQtyEntered()); } // change to set Converted Quantity in Movement quantity if there is differnce in UOM of Base Product and UOM Selected on line if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID")) { Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered")); if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID"))) { SetMovementQty(MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered")))); } } // Qty Precision if (newRecord || Is_ValueChanged("QtyEntered")) { SetMovementQty(GetMovementQty()); } string qry; if (!mov.IsProcessing() || newRecord) { MWarehouse wh = null; MWarehouse whTo = null; wh = MWarehouse.Get(GetCtx(), mov.GetDTD001_MWarehouseSource_ID()); whTo = MWarehouse.Get(GetCtx(), MLocator.Get(GetCtx(), GetM_LocatorTo_ID()).GetM_Warehouse_ID()); qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetDTD001_AttributeNumber() == null || GetM_AttributeSetInstance_ID() > 0) { qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID(); } OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_LocatorTo_ID() + " and m_product_id=" + GetM_Product_ID(); qry += " AND NVL(M_AttributeSetInstance_ID, 0) =" + GetM_AttributeSetInstance_ID(); OnHandQtyTo = Convert.ToDecimal(DB.ExecuteScalar(qry)); // SI_0635 : System is giving error of insufficient qty if disallow is true in TO warehouse and false in From warehouse // when record is in completed & closed stage - then no need to check qty availablity in warehouse if ((wh.IsDisallowNegativeInv() || whTo.IsDisallowNegativeInv()) && (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE" || move.GetDocStatus() == "VO"))) { // pick container current qty from transaction based on locator / product / ASI / Container / Movement Date if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0) { // qry = @"SELECT SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS CurrentQty FROM m_transaction t // INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + // " AND t.AD_Client_ID = " + GetAD_Client_ID() + // @" AND t.M_Locator_ID = " + (move.IsReversal() && GetMovementQty() < 0 ? GetM_LocatorTo_ID() : GetM_Locator_ID()) + // " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() + // " AND NVL(t.M_ProductContainer_ID, 0) = " + (move.IsReversal() && !IsMoveFullContainer() && GetMovementQty() < 0 ? GetRef_M_ProductContainerTo_ID() : GetM_ProductContainer_ID()); // containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null)); // dont use Transaction here - otherwise impact goes wrong on completion // qry = @"SELECT SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS CurrentQty FROM m_transaction t // INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + // " AND t.AD_Client_ID = " + GetAD_Client_ID() + // @" AND t.M_Locator_ID = " + (move.IsReversal() && GetMovementQty() < 0 ? GetM_Locator_ID() : GetM_LocatorTo_ID()) + // " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() + // " AND NVL(t.M_ProductContainer_ID, 0) = " + (move.IsReversal() && !IsMoveFullContainer() && GetMovementQty() < 0 ? GetM_ProductContainer_ID() : GetRef_M_ProductContainerTo_ID()); // containerQtyTo = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null)); // dont use Transaction here - otherwise impact goes wrong on completion qry = @"SELECT DISTINCT First_VALUE(t.ContainerCurrentQty) OVER (PARTITION BY t.M_Product_ID, t.M_AttributeSetInstance_ID ORDER BY t.MovementDate DESC, t.M_Transaction_ID DESC) AS CurrentQty FROM m_transaction t INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + " AND t.AD_Client_ID = " + GetAD_Client_ID() + @" AND t.M_Locator_ID = " + GetM_Locator_ID() + " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_ProductContainer_ID, 0) = " + GetM_ProductContainer_ID(); // In Case of Attribute Number do not check qty with attribute from storage if (GetDTD001_AttributeNumber() == null || GetM_AttributeSetInstance_ID() > 0) { qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID(); } containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null)); // dont use Transaction here - otherwise impact goes wrong on completion qry = @"SELECT DISTINCT First_VALUE(t.ContainerCurrentQty) OVER (PARTITION BY t.M_Product_ID, t.M_AttributeSetInstance_ID ORDER BY t.MovementDate DESC, t.M_Transaction_ID DESC) AS CurrentQty FROM m_transaction t INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + " AND t.AD_Client_ID = " + GetAD_Client_ID() + @" AND t.M_Locator_ID = " + GetM_LocatorTo_ID() + " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() + " AND NVL(t.M_ProductContainer_ID, 0) = " + GetRef_M_ProductContainerTo_ID(); containerQtyTo = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null)); // dont use Transaction here - otherwise impact goes wrong on completion } if (wh.IsDisallowNegativeInv() && (OnHandQty - GetMovementQty()) < 0) { // check for From Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } else if (isContainrApplicable && wh.IsDisallowNegativeInv() && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQty - GetMovementQty()) < 0) { // check container qty - for From Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainer") + containerQty); return(false); } else if (whTo.IsDisallowNegativeInv() && (OnHandQtyTo + GetMovementQty()) < 0) { // check for To Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQtyTo); return(false); } else if (isContainrApplicable && whTo.IsDisallowNegativeInv() && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQtyTo + GetMovementQty()) < 0) { // check for To Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainerTo") + containerQtyTo); return(false); } } } if (Env.IsModuleInstalled("DTD001_")) { // not used this variable, that why commented //qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); //if (GetM_AttributeSetInstance_ID() != 0) //{ // qry += " AND NVL(M_AttributeSetInstance_ID , 0) = " + GetM_AttributeSetInstance_ID(); //} //qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry)); qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("MovementQty")); //if (wh.IsDisallowNegativeInv() == true) //{ // if ((qtyAvailable < (GetMovementQty() - qtyReserved))) // { // log.SaveError("Message", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "DTD001_QtyNotAvailable")); // return false; // } //} } //By Amit - 17-April-2017 if (Env.IsModuleInstalled("VA024_")) { // checking are we moving product from one warehouse to other warehouse if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT CASE WHEN ((SELECT CASE WHEN o.IsLegalEntity = 'Y' THEN w.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o.LegalEntityOrg ) END FROM m_warehouse w INNER JOIN ad_org o ON o.AD_Org_ID = w.AD_Org_ID WHERE w.m_warehouse_id = m.DTD001_MWarehouseSource_ID)) = (SELECT CASE WHEN o2.IsLegalEntity = 'Y' THEN w2.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o2.LegalEntityOrg) END FROM m_warehouse w2 INNER JOIN ad_org o2 ON o2.AD_Org_ID = w2.AD_Org_ID WHERE M_Warehouse_ID = m.M_Warehouse_ID ) THEN 0 ELSE (SELECT ad_org_id FROM m_warehouse WHERE M_Warehouse_ID = m.M_Warehouse_ID ) END AS result FROM m_movement m WHERE m_movement_id = " + GetM_Movement_ID(), null, Get_Trx())) > 0) { string qry1 = @"SELECT SUM(o.VA024_UnitPrice) FROM VA024_t_ObsoleteInventory o WHERE o.IsActive = 'Y' AND o.M_Product_ID = " + GetM_Product_ID() + @" and ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" + " AND o.AD_Org_ID = " + GetAD_Org_ID(); VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())); SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetMovementQty())); // is used to get cost of binded cost method / costing level of primary accounting schema Decimal cost = MCost.GetproductCosts(move.GetAD_Client_ID(), move.GetAD_Org_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx(), move.GetDTD001_MWarehouseSource_ID()); SetVA024_CostPrice((cost - VA024_ProvisionPrice) * GetMovementQty()); } } // Mandatory Instance if (GetM_AttributeSetInstanceTo_ID() == 0) { if (GetM_AttributeSetInstance_ID() != 0) // Set to from { SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID()); } else { if (Env.HasModulePrefix("DTD001_", out mInfo)) { //MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); //if (mas.IsInstanceAttribute() // && (mas.IsMandatory() || mas.IsMandatoryAlways())) //{ // log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); // return false; //} // Code Addeded by Bharat as Discussed with Mukesh Sir if (String.IsNullOrEmpty(GetDTD001_AttributeNumber())) { return(true); } else { if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } } //JID_1422: Check No Of Attributes Are Equal To Quantity Or Less Than int Count = CountAttributes(GetDTD001_AttributeNumber()); if (Count != GetQtyEntered()) { if (Count > GetQtyEntered()) { log.SaveError("DTD001_MovementAttrbtGreater", ""); return(false); } else { log.SaveError("DTD001_MovementAttrbtLess", ""); return(false); } } } else { if (product != null) { if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)) { return(true); } else { //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); //ShowMessage.Info("a", true, "Product is not of Attribute Type", null); log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } //Check No Of Attributes Are Equal To Quantity Or Less Than //int Count = CountAttributes(GetDTD001_AttributeNumber()); //if (Count != GetMovementQty()) //{ // if (Count > GetMovementQty()) // { // log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater")); // return false; // } // else // { // log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess")); // return false; // } //} } } } else { //MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); if (mas.IsInstanceAttribute() && (mas.IsMandatory() || mas.IsMandatoryAlways())) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); return(false); } } } } } // ASI return(true); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true if can be saved</returns> protected override bool BeforeSave(bool newRecord) { Decimal VA024_ProvisionPrice = 0; MInventory inventory = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx()); MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); if (newRecord && _isManualEntry) { // Product requires ASI if (GetM_AttributeSetInstance_ID() == 0) { if (product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); //uncomment by Amit on behalf of Mandeep 7-3-2016 //if (mas.IsInstanceAttribute() // && (mas.IsMandatory() || mas.IsMandatoryAlways())) if (mas.IsMandatory() || mas.IsMandatoryAlways()) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstance_ID")); return(false); } } } // No ASI } // new or manual // not to create Internal use Inventory with -ve qty -- but during reversal system will create record with -ve qty // duing reversal -- ReversalDoc_ID contain refernce o orignal record id if (IsInternalUse() && Get_ColumnIndex("ReversalDoc_ID") > 0 && GetReversalDoc_ID() == 0 && GetQtyInternalUse() < 0) { log.SaveError("", Msg.GetMsg(GetCtx(), "VIS_CantbeNegative")); return(false); } // Set Line No if (GetLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_InventoryLine WHERE M_Inventory_ID=" + GetM_Inventory_ID(); int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetLine(ii); } // SI_0644.1 : Enforce UOM Precision - Rounding Quantities if (newRecord || Is_ValueChanged("QtyInternalUse")) { SetQtyInternalUse(GetQtyInternalUse()); } // change to set Converted Quantity in Internal Use Qty and AsonDateQty and difference qty if there is differnce in UOM of Base Product and UOM Selected on line if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID")) { Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered")); if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID"))) { qty = MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered"))); if (IsInternalUse()) { SetQtyInternalUse(qty); } else { SetAsOnDateCount(qty); SetDifferenceQty(qty); } } } // SI_0644 - As on date and difference should be according to the precision of UOM attached. if (newRecord || Is_ValueChanged("AsOnDateCount")) { if (product != null) { int precision = product.GetUOMPrecision(); SetAsOnDateCount(Decimal.Round(GetAsOnDateCount(), precision, MidpointRounding.AwayFromZero)); } } // SI_0644 - As on date and difference should be according to the precision of UOM attached. if (newRecord || Is_ValueChanged("DifferenceQty")) { if (product != null) { int precision = product.GetUOMPrecision(); SetDifferenceQty(Decimal.Round(GetDifferenceQty(), precision, MidpointRounding.AwayFromZero)); } } // SI_0682_1 Need to update the reserved qty on requisition line by internal use line save aslo and should work as work in inventory move. if (Env.IsModuleInstalled("DTD001_") && IsInternalUse()) { qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("QtyInternalUse")); } int M_Warehouse_ID = 0; MWarehouse wh = null; string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID(); M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry, null, Get_TrxName())); wh = MWarehouse.Get(GetCtx(), M_Warehouse_ID); qry = "SELECT QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry, null, Get_TrxName())); // when record is in completed & closed stage - then no need to check qty availablity in warehouse if (wh.IsDisallowNegativeInv() == true && (!(inventory.GetDocStatus() == "CO" || inventory.GetDocStatus() == "CL" || inventory.GetDocStatus() == "RE" || inventory.GetDocStatus() == "VO"))) { #region DisallowNegativeInv = True if (!IsInternalUse() && GetDifferenceQty() > 0) { if ((OnHandQty - GetDifferenceQty()) < 0) { log.SaveError("Info", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } } else if (IsInternalUse()) { if ((OnHandQty - GetQtyInternalUse()) < 0) { log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } } #endregion } // Enforce Qty UOM if (newRecord || Is_ValueChanged("QtyCount")) { SetQtyCount(GetQtyCount()); } // InternalUse Inventory if (IsInternalUse() && Env.Signum(GetQtyInternalUse()) == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "QtyInternalUse")); return(false); } if (Env.Signum(GetQtyInternalUse()) != 0) { if (!INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType())) { SetInventoryType(INVENTORYTYPE_ChargeAccount); } // if (GetC_Charge_ID() == 0) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "InternalUseNeedsCharge")); return(false); } } else if (INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType())) { if (GetC_Charge_ID() == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "C_Charge_ID")); return(false); } } else if (GetC_Charge_ID() != 0) { SetC_Charge_ID(0); } // Set AD_Org to parent if not charge if (GetC_Charge_ID() == 0) { SetAD_Org_ID(GetParent().GetAD_Org_ID()); } // By Amit for Obsolete Inventory - 25-May-2016 if (Env.IsModuleInstalled("VA024_")) { //MInventory inventory = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx()); //shipment and Return to vendor if (inventory.IsInternalUse() || (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0)) { try { string qry1 = @"SELECT SUM(o.VA024_UnitPrice) FROM VA024_t_ObsoleteInventory o WHERE o.IsActive = 'Y' AND o.M_Product_ID = " + GetM_Product_ID() + @" and ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" + " AND o.AD_Org_ID = " + GetAD_Org_ID(); //+" AND M_Warehouse_ID = " + inventory.GetM_Warehouse_ID(); VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())); if (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0) { SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * (GetQtyBook() - GetQtyCount()))); } else { SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetQtyInternalUse())); } if (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0) { qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + (GetQtyBook() - GetQtyCount()); } else { qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + GetQtyInternalUse(); } qry1 += @" FROM m_product p INNER JOIN va024_t_obsoleteinventory oi ON p.m_product_id = oi.M_product_ID INNER JOIN m_product_category pc ON pc.m_product_category_ID = p.m_product_category_ID INNER JOIN AD_client c ON c.AD_Client_ID = p.Ad_Client_ID INNER JOIN AD_ClientInfo ci ON c.AD_Client_ID = ci.Ad_Client_ID INNER JOIN m_cost ct ON ( p.M_Product_ID = ct.M_Product_ID AND ci.C_AcctSchema1_ID = ct.C_AcctSchema_ID ) INNER JOIN c_acctschema asch ON (asch.C_AcctSchema_ID = ci.C_AcctSchema1_ID) INNER JOIN va024_obsoleteinvline oil ON oil.va024_obsoleteinvline_ID = oi.va024_obsoleteinvline_ID "; qry1 += @" WHERE ct.AD_Org_ID = CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel = 'C' OR pc.costinglevel = 'B')) THEN 0 WHEN (pc.costinglevel IS NULL AND asch.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel = 'C' OR asch.costinglevel = 'B')) THEN 0 END AND ct.m_costelement_id = CASE WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod != 'C') THEN (SELECT MIN(m_costelement_id) FROM m_costelement WHERE m_costelement.costingmethod =pc.costingmethod AND m_costelement.Ad_Client_ID = oi.ad_client_id ) WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod = 'C' ) THEN pc.m_costelement_id WHEN ( pc.costingmethod IS NULL AND asch.costingmethod != 'C') THEN (SELECT MIN(m_costelement_id) FROM m_costelement WHERE m_costelement.costingmethod = asch.costingmethod AND m_costelement.Ad_Client_ID = oi.ad_client_id ) WHEN ( pc.costingmethod IS NULL AND asch.costingmethod = 'C') THEN asch.m_costelement_id END AND NVL(ct.M_Attributesetinstance_ID , 0) = CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel = 'C' OR pc.costinglevel = 'O')) THEN 0 WHEN ( pc.costinglevel IS NULL AND asch.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel = 'C' OR asch.costinglevel = 'O')) THEN 0 END AND p.M_Product_ID = " + GetM_Product_ID(); SetVA024_CostPrice(Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()))); } catch { } } } return(true); }
/**** * Before Save * @param newRecord new * @return save */ protected override bool BeforeSave(bool newRecord) { log.Fine(""); if (GetC_Charge_ID() == 0 && GetM_Product_ID() == 0) { return(false); } // Get Line No if (GetLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM M_InOutLine WHERE M_InOut_ID=" + GetM_InOut_ID(); int ii = Utility.Util.GetValueOfInt(DataBase.DB.ExecuteScalar(sql, null, null)); SetLine(ii); } // UOM if (GetC_UOM_ID() == 0) { SetC_UOM_ID(GetCtx().GetContextAsInt("#C_UOM_ID")); } if (GetC_UOM_ID() == 0) { int C_UOM_ID = MUOM.GetDefault_UOM_ID(GetCtx()); if (C_UOM_ID > 0) { SetC_UOM_ID(C_UOM_ID); } } MInOut inO = new MInOut(Env.GetCtx(), GetM_InOut_ID(), null); // true in case of Shipment and False in case of MR if (inO.IsSOTrx() == true) { int M_Warehouse_ID = 0; MWarehouse wh = null; StringBuilder qry = new StringBuilder(); qry.Append("select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID()); M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry.ToString())); wh = MWarehouse.Get(GetCtx(), M_Warehouse_ID); qry.Clear(); qry.Append("SELECT QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID()); if (GetM_AttributeSetInstance_ID() != 0) { qry.Append(" AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID()); } OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry.ToString())); if (wh.IsDisallowNegativeInv() == true) { if (GetQtyEntered() < 0) { return(false); } else if ((OnHandQty - GetQtyEntered()) < 0) { return(false); } } } //else //{ //MProduct pro = new MProduct(GetCtx(), GetM_Product_ID(), null); //String qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inO.GetC_BPartner_ID(); //int uom = Util.GetValueOfInt(DB.ExecuteScalar(qryUom)); //if (pro.GetC_UOM_ID() != 0) //{ // if (pro.GetC_UOM_ID() != uom && uom != 0) // { // decimal? Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + GetM_Product_ID() + " AND IsActive='Y'")); // if (Res > 0) // { // SetQtyEntered(GetQtyEntered() * Res); // //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty); // } // else // { // decimal? res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'")); // if (res > 0) // { // SetQtyEntered(GetQtyEntered() * res); // //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); // } // } // SetC_UOM_ID(uom); // } // else // { // SetC_UOM_ID(pro.GetC_UOM_ID()); // } //} //} // Qty Precision if (newRecord || Is_ValueChanged("QtyEntered")) { SetQtyEntered(GetQtyEntered()); } if (newRecord || Is_ValueChanged("MovementQty")) { SetMovementQty(GetMovementQty()); } // Order Line if (GetC_OrderLine_ID() == 0) { if (GetParent().IsSOTrx()) { log.SaveError("FillMandatory", Msg.Translate(GetCtx(), "C_Order_ID")); return(false); } } // if (getC_Charge_ID() == 0 && getM_Product_ID() == 0) // ; /** Qty on instance ASI * if (getM_AttributeSetInstance_ID() != 0) * { * MProduct product = getProduct(); * int M_AttributeSet_ID = product.getM_AttributeSet_ID(); * bool isInstance = M_AttributeSet_ID != 0; * if (isInstance) * { * MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID); * isInstance = mas.isInstanceAttribute(); * } * // Max * if (isInstance) * { * MStorage storage = MStorage.get(getCtx(), getM_Locator_ID(), * getM_Product_ID(), getM_AttributeSetInstance_ID(), get_TrxName()); * if (storage != null) * { * Decimal qty = storage.getQtyOnHand(); * if (getMovementQty().compareTo(qty) > 0) * { * log.warning("Qty - Stock=" + qty + ", Movement=" + getMovementQty()); * log.saveError("QtyInsufficient", "=" + qty); * return false; * } * } * } * } /**/ //Mandatory Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { if (GetM_AttributeSetInstance_ID() != 0) // Set to from { SetM_AttributeSetInstance_ID(GetM_AttributeSetInstance_ID()); } else { MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); //if (mas.IsInstanceAttribute() // && (mas.IsMandatory() || mas.IsMandatoryAlways())) //{ // log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); // return false; //} MInOut inout = new MInOut(Env.GetCtx(), GetM_InOut_ID(), Get_Trx()); if (inout.GetDescription() != "RC" && Util.GetValueOfBool(IsDTD001_IsAttributeNo()) == false) { if (GetDTD001_Attribute() == "" || GetDTD001_Attribute() == null) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_Attribute")); return(false); } //Check No Of Attributes Are Equal To Quantity Or Less Than int Count = CountAttributes(GetDTD001_Attribute()); if (Count != GetQtyEntered()) { if (Count > GetQtyEntered()) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MaterialAtrbteGreater")); return(false); } else { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MaterialAtrbteless")); return(false); } } } } else { if (product != null) { if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_Attribute() == "" || GetDTD001_Attribute() == null)) { return(true); } else { //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); //ShowMessage.Info("a", true, "Product is not of Attribute Type", null); log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_Attribute")); return(false); } } } } } return(true); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true</returns> protected override Boolean BeforeSave(Boolean newRecord) { // Set Line No if (GetLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID(); int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetLine(ii); } // Check Locator For Header Warehouse MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName()); MLocator loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName()); Tuple <string, string, string> aInfo = null; if (Env.HasModulePrefix("DTD001_", out aInfo)) { if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID()) { } else { String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'"; int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetM_Locator_ID(ii); } } if (GetM_Locator_ID() == GetM_LocatorTo_ID()) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement return(false); } if (Env.Signum(GetMovementQty()) == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty")); return(false); } //Amit Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged")); return(false); } } if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0) { if (GetM_RequisitionLine_ID() > 0) { MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null); if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame")); return(false); } } } // IF Doc Status = InProgress then No record Save MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), null); if (newRecord && move.GetDocStatus() == "IP") { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate")); return(false); } // Qty Precision if (newRecord || Is_ValueChanged("QtyEntered")) { SetMovementQty(GetMovementQty()); } int M_Warehouse_ID = 0; MWarehouse wh = null; string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID(); M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry)); wh = MWarehouse.Get(GetCtx(), M_Warehouse_ID); qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); if (wh.IsDisallowNegativeInv() == true) { if (GetDescription() != "RC") { if (GetMovementQty() < 0) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "Qty Available " + OnHandQty)); //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null); return(false); } else if ((OnHandQty - GetMovementQty()) < 0) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "Qty Available " + OnHandQty)); //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null); return(false); } } } if (Env.HasModulePrefix("DTD001_", out mInfo)) { qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry)); qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("MovementQty")); if (wh.IsDisallowNegativeInv() == true) { if ((qtyAvailable < (GetMovementQty() - qtyReserved))) { log.SaveError("Message", Msg.GetElement(GetCtx(), "DTD001_QtyNotAvailable")); return(false); } } } // Mandatory Instance if (GetM_AttributeSetInstanceTo_ID() == 0) { if (GetM_AttributeSetInstance_ID() != 0) // Set to from { SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID()); } else { if (Env.HasModulePrefix("DTD001_", out mInfo)) { MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); //if (mas.IsInstanceAttribute() // && (mas.IsMandatory() || mas.IsMandatoryAlways())) //{ // log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); // return false; //} if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } } else { if (product != null) { if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)) { return(true); } else { //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); //ShowMessage.Info("a", true, "Product is not of Attribute Type", null); log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } //Check No Of Attributes Are Equal To Quantity Or Less Than int Count = CountAttributes(GetDTD001_AttributeNumber()); if (Count != GetMovementQty()) { if (Count > GetMovementQty()) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater")); return(false); } else { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess")); return(false); } } } } } else { MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); if (mas.IsInstanceAttribute() && (mas.IsMandatory() || mas.IsMandatoryAlways())) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); return(false); } } } } } // ASI return(true); }
public Boolean Validate() { MWarehouse wh = MWarehouse.Get(refDetail.GetCtx(), GetM_Warehouse_ID()); if (wh.IsDisallowNegativeInv()) { if (Env.Signum(GetQtyOnHand()) < 0 || Env.Signum(GetQtyDedicated()) < 0 || Env.Signum(GetQtyAllocated()) < 0 || Env.Signum(GetQtyExpected()) < 0) { _log.SaveError("Error", Msg.GetMsg(refDetail.GetCtx(), "NegativeInventoryDisallowed")); return(false); } Decimal qtyOnHand = Env.ZERO; Decimal qtyDedicated = Env.ZERO; Decimal qtyAllocated = Env.ZERO; String sql = "SELECT COALESCE(SUM(QtyOnHand),0),COALESCE(SUM(QtyDedicated),0),COALESCE(SUM(QtyAllocated),0) " + "FROM M_Storage_V s" + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) " + "WHERE s.M_Product_ID=" + GetM_Product_ID() // #1 + " AND l.M_Warehouse_ID=" + GetM_Warehouse_ID() + " AND l.M_Locator_ID=" + GetM_Locator_ID() + " AND M_AttributeSetInstance_ID<>" + GetM_AttributeSetInstance_ID(); IDataReader idr = null; try { idr = DB.ExecuteReader(sql, null, refDetail.Get_TrxName()); if (idr.Read()) { qtyOnHand = Util.GetValueOfDecimal(idr[0]); qtyDedicated = Util.GetValueOfDecimal(idr[1]); qtyAllocated = Util.GetValueOfDecimal(idr[2]); } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } finally { if (idr != null) { idr.Close(); idr = null; } } qtyOnHand = Decimal.Add(qtyOnHand, GetQtyOnHand()); qtyDedicated = Decimal.Add(qtyDedicated, GetQtyDedicated()); qtyAllocated = Decimal.Add(qtyAllocated, GetQtyAllocated()); if (Env.Signum(qtyOnHand) < 0 || qtyOnHand.CompareTo(Decimal.Add(qtyDedicated, qtyAllocated)) < 0 || GetQtyOnHand().CompareTo(Decimal.Add(GetQtyDedicated(), GetQtyAllocated())) < 0) { _log.SaveError("Error", Msg.GetMsg(refDetail.GetCtx(), "NegativeInventoryDisallowed")); return(false); } } return(true); }
/// <summary> /// Create Difference Document. /// Creates one or two inventory lines /// </summary> /// <param name="move">movement</param> /// <param name="confirm">confirm line</param> /// <returns>true if created</returns> private Boolean CreateDifferenceDoc(MMovement move, MMovementLineConfirm confirm) { string query = ""; int result = 0; decimal currentQty = 0; MMovementLine mLine = confirm.GetLine(); // Difference - Create Inventory Difference for Source Location if (Env.ZERO.CompareTo(confirm.GetDifferenceQty()) != 0) { // Get Warehouse for Source MLocator loc = MLocator.Get(GetCtx(), mLine.GetM_Locator_ID()); if (_inventoryFrom != null && _inventoryFrom.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID()) { _inventoryFrom = null; } if (_inventoryFrom == null) { MWarehouse wh = MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID()); _inventoryFrom = new MInventory(wh); _inventoryFrom.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo()); if (!_inventoryFrom.Save(Get_TrxName())) { _processMsg += "Inventory not created"; return(false); } // First Inventory if (GetM_Inventory_ID() == 0) { SetM_Inventory_ID(_inventoryFrom.GetM_Inventory_ID()); _inventoryInfo = _inventoryFrom.GetDocumentNo(); } else { _inventoryInfo += "," + _inventoryFrom.GetDocumentNo(); } } log.Info("createDifferenceDoc - Difference=" + confirm.GetDifferenceQty()); MInventoryLine line = new MInventoryLine(_inventoryFrom, mLine.GetM_Locator_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(), confirm.GetDifferenceQty(), Env.ZERO); //Added By amit 11-jun-2015 //Opening Stock , Qunatity Book => CurrentQty From Transaction of MovementDate //As On Date Count = Opening Stock - Diff Qty //Qty Count = Qty Book - Diff Qty query = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate = " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); result = Util.GetValueOfInt(DB.ExecuteScalar(query)); if (result > 0) { query = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID = (SELECT MAX(M_Transaction_ID) FROM M_Transaction WHERE movementdate = (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query)); } else { query = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); result = Util.GetValueOfInt(DB.ExecuteScalar(query)); if (result > 0) { query = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID = (SELECT MAX(M_Transaction_ID) FROM M_Transaction WHERE movementdate = (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query)); } } //End line.SetAdjustmentType("D"); line.SetDifferenceQty(Util.GetValueOfDecimal(confirm.GetDifferenceQty())); line.SetQtyBook(currentQty); line.SetOpeningStock(currentQty); line.SetAsOnDateCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetOpeningStock()), Util.GetValueOfDecimal(confirm.GetDifferenceQty()))); line.SetQtyCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetQtyBook()), Util.GetValueOfDecimal(confirm.GetDifferenceQty()))); line.SetDescription(Msg.Translate(GetCtx(), "DifferenceQty")); if (!line.Save(Get_TrxName())) { _processMsg += "Inventory Line not created"; return(false); } confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID()); } // Difference // Scrapped - Create Inventory Difference for TarGet Location if (Env.ZERO.CompareTo(confirm.GetScrappedQty()) != 0) { // Get Warehouse for TarGet MLocator loc = MLocator.Get(GetCtx(), mLine.GetM_LocatorTo_ID()); if (_inventoryTo != null && _inventoryTo.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID()) { _inventoryTo = null; } if (_inventoryTo == null) { MWarehouse wh = MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID()); _inventoryTo = new MInventory(wh); _inventoryTo.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo()); if (!_inventoryTo.Save(Get_TrxName())) { _processMsg += "Inventory not created"; return(false); } // First Inventory if (GetM_Inventory_ID() == 0) { SetM_Inventory_ID(_inventoryTo.GetM_Inventory_ID()); _inventoryInfo = _inventoryTo.GetDocumentNo(); } else { _inventoryInfo += "," + _inventoryTo.GetDocumentNo(); } } log.Info("CreateDifferenceDoc - Scrapped=" + confirm.GetScrappedQty()); MInventoryLine line = new MInventoryLine(_inventoryTo, mLine.GetM_LocatorTo_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(), confirm.GetScrappedQty(), Env.ZERO); line.SetDescription(Msg.Translate(GetCtx(), "ScrappedQty")); if (!line.Save(Get_TrxName())) { _processMsg += "Inventory Line not created"; return(false); } confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID()); } // Scrapped return(true); }
/** * Create Difference Document * @param inout shipment/receipt * @param confirm confirm line * @return true if created */ private bool CreateDifferenceDoc(MInOut inout, MInOutLineConfirm confirm) { if (_processMsg == null) { _processMsg = ""; } else if (_processMsg.Length > 0) { _processMsg += "; "; } // Credit Memo if linked Document if (Env.Signum(confirm.GetDifferenceQty()) != 0 && !inout.IsSOTrx() && !inout.IsReturnTrx() && inout.GetRef_InOut_ID() != 0) { log.Info("Difference=" + confirm.GetDifferenceQty()); if (_creditMemo == null) { _creditMemo = new MInvoice(inout, null); _creditMemo.SetDescription(Msg.Translate(GetCtx(), "M_InOutConfirm_ID") + " " + GetDocumentNo()); _creditMemo.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_APCREDITMEMO); if (!_creditMemo.Save(Get_TrxName())) { _processMsg += "Credit Memo not created"; return(false); } SetC_Invoice_ID(_creditMemo.GetC_Invoice_ID()); } MInvoiceLine line = new MInvoiceLine(_creditMemo); line.SetShipLine(confirm.GetLine()); line.SetQty(confirm.GetDifferenceQty()); // Entered/Invoiced if (!line.Save(Get_TrxName())) { _processMsg += "Credit Memo Line not created"; return(false); } confirm.SetC_InvoiceLine_ID(line.GetC_InvoiceLine_ID()); } // Create Inventory Difference if (Env.Signum(confirm.GetScrappedQty()) != 0) { log.Info("Scrapped=" + confirm.GetScrappedQty()); if (_inventory == null) { MWarehouse wh = MWarehouse.Get(GetCtx(), inout.GetM_Warehouse_ID()); _inventory = new MInventory(wh); _inventory.SetDescription(Msg.Translate(GetCtx(), "M_InOutConfirm_ID") + " " + GetDocumentNo()); if (!_inventory.Save(Get_TrxName())) { _processMsg += "Inventory not created"; return(false); } SetM_Inventory_ID(_inventory.GetM_Inventory_ID()); } MInOutLine ioLine = confirm.GetLine(); MInventoryLine line = new MInventoryLine(_inventory, ioLine.GetM_Locator_ID(), ioLine.GetM_Product_ID(), ioLine.GetM_AttributeSetInstance_ID(), confirm.GetScrappedQty(), Env.ZERO); if (!line.Save(Get_TrxName())) { _processMsg += "Inventory Line not created"; return(false); } confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID()); } // if (!confirm.Save(Get_TrxName())) { _processMsg += "Confirmation Line not saved"; return(false); } return(true); }