/// <summary> /// Get Default Locator /// </summary> /// <returns>(first) default locator</returns> public MLocator GetDefaultLocator() { MLocator[] locators = GetLocators(false); // ordered by x,y,z MLocator loc1 = null; for (int i = 0; i < locators.Length; i++) { MLocator locIn = locators[i]; if (locIn.IsDefault() && locIn.IsActive()) { return(locIn); } if (loc1 == null || loc1.GetPriorityNo() > locIn.GetPriorityNo()) { loc1 = locIn; } } // No Default - return highest priority if (locators.Length > 0) { log.Warning("No default Locator for " + GetName()); return(loc1); } // No Locator - create one MLocator loc = new MLocator(this, "Standard"); loc.SetIsDefault(true); loc.Save(); log.Info("Created default locator for " + GetName()); return(loc); }
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); }
public static MStorageDetail GetCreate(Ctx ctx, int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID, String type, Trx trx) { if (M_Locator_ID == 0) { throw new ArgumentException("M_Locator_ID=0"); } if (M_Product_ID == 0) { throw new ArgumentException("M_Product_ID=0"); } MStorageDetail retValue = GetForUpdate(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, type, trx); if (retValue != null) { return(retValue); } // Insert row based on locator MLocator locator = new MLocator(ctx, M_Locator_ID, trx); if (locator.Get_ID() != M_Locator_ID) { throw new ArgumentException("Not found M_Locator_ID=" + M_Locator_ID); } // retValue = new MStorageDetail(locator, M_Product_ID, M_AttributeSetInstance_ID, type); retValue.Save(trx); s_log.Fine("New " + retValue); 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); }
/// <summary> /// Get oldest Default Locator of warehouse with locator /// </summary> /// <param name="ctx">context</param> /// <param name="M_Locator_ID">locator</param> /// <returns>locator or null</returns> public static MLocator GetDefault(Ctx ctx, int M_Locator_ID) { Trx trxName = null; MLocator retValue = null; String sql = "SELECT * FROM M_Locator l " + "WHERE IsDefault='Y'" + " AND EXISTS (SELECT * FROM M_Locator lx " + "WHERE l.M_Warehouse_ID=lx.M_Warehouse_ID AND lx.M_Locator_ID=" + M_Locator_ID + ") " + "ORDER BY Created"; DataSet ds = null; try { ds = DataBase.DB.ExecuteDataset(sql, null, trxName); if (ds.Tables.Count > 0) { DataRow rs = null; int totCount = ds.Tables[0].Rows.Count; for (int i = 0; i < totCount; i++) { rs = ds.Tables[0].Rows[i]; retValue = new MLocator(ctx, rs, trxName); } } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } return(retValue); }
/// <summary> /// Get M_Warehouse_ID of Locator /// </summary> /// <returns>warehouse</returns> public int GetM_Warehouse_ID() { if (_M_Warehouse_ID == 0) { MLocator loc = MLocator.Get(GetCtx(), GetM_Locator_ID()); _M_Warehouse_ID = loc.GetM_Warehouse_ID(); } return(_M_Warehouse_ID); }
/// <summary> /// Standard Constructors /// </summary> /// <param name="locator"></param> /// <param name="M_Product_ID"></param> /// <param name="M_AttributeSetInstance_ID"></param> /// <param name="type"></param> public MStorageDetail(MLocator locator, int M_Product_ID, int M_AttributeSetInstance_ID, String type) : this(locator.GetCtx(), 0, locator.Get_TrxName()) { SetClientOrg(locator); SetM_Locator_ID(locator.GetM_Locator_ID()); SetM_Product_ID(M_Product_ID); SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID); SetQtyType(type);//type.GetValue() SetQty(Env.ZERO); }
public static MLocator GetDefaultLocatorOfOrg(Ctx ctx, int AD_Org_ID) { MLocator retValue = null; List <int> defaultlocators = new List <int>(); List <int> locators = new List <int>(); String sql = "SELECT M_Locator_ID, IsDefault FROM M_Locator WHERE (AD_Org_ID=" + AD_Org_ID + " OR 0=" + AD_Org_ID + ")"; IDataReader idr = null; try { idr = DB.ExecuteReader(sql); while (idr != null && idr.Read()) { if (Util.GetValueOfString(idr[1]) == "Y") { defaultlocators.Add(Util.GetValueOfInt(idr[0])); break; } else { locators.Add(Util.GetValueOfInt(idr[0])); } } if (idr != null) { idr.Close(); idr = null; } if (defaultlocators.Count > 0) { retValue = MLocator.Get(ctx, Util.GetValueOfInt(defaultlocators[0])); return(retValue); } if (locators.Count > 0) { retValue = MLocator.Get(ctx, Util.GetValueOfInt(locators[0])); return(retValue); } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } finally { if (idr != null) { idr.Close(); idr = null; } } return(retValue); }
/// <summary> /// Get Data Direct from Table /// </summary> /// <param name="keyValue">integer key value</param> /// <param name="saveInCache">saveInCache save in cache</param> /// <param name="trxName"></param> /// <returns></returns> public NamePair GetDirect(Object keyValue, bool saveInCache, Trx trxName) { MLocator loc = GetMLocator(keyValue, trxName); if (loc == null) { return(null); } // int key = loc.GetM_Locator_ID(); KeyNamePair retValue = new KeyNamePair(key, loc.ToString()); if (saveInCache) { _lookup.Add(key, retValue); } return(retValue); }
/** * Get array of active Locators for Product and warehouse ordered by priority * @param product product * @param M_Warehouse_ID wh * @return product locators */ public static MLocator[] GetLocators(MProduct product, int M_Warehouse_ID) { List <MLocator> list = new List <MLocator>(); String sql = "SELECT * FROM M_Locator l " + "WHERE l.IsActive='Y'" + " AND (M_Locator_ID IN (SELECT M_Locator_ID FROM M_Product WHERE M_Product_ID=" + product.GetM_Product_ID() + ")" + " OR M_Locator_ID IN (SELECT M_Locator_ID FROM M_ProductLocator WHERE M_Product_ID=" + product.GetM_Product_ID() + " AND IsActive='Y'))" + " AND M_Warehouse_ID=" + M_Warehouse_ID + "ORDER BY PriorityNo DESC"; DataTable dt = null; IDataReader idr = null; try { idr = DataBase.DB.ExecuteReader(sql, null, product.Get_TrxName()); dt = new DataTable(); dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows) { list.Add(new MLocator(product.GetCtx(), dr, product.Get_TrxName())); } } catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, sql, e); } finally { if (idr != null) { idr.Close(); } dt = null; } MLocator[] retValue = new MLocator[list.Count]; retValue = list.ToArray(); return(retValue); }
/// <summary> /// Get Locator from Cache /// </summary> /// <param name="ctx">context</param> /// <param name="M_Locator_ID">id</param> /// <returns>MLocator</returns> public static MLocator Get(Ctx ctx, int M_Locator_ID) { if (cache == null) { cache = new CCache <int, MLocator>("M_Locator", 20); } int key = M_Locator_ID; MLocator retValue = null; if (cache.ContainsKey(key)) { retValue = (MLocator)cache[key]; } if (retValue != null) { return(retValue); } retValue = new MLocator(ctx, M_Locator_ID, null); if (retValue.Get_ID() != 0) { cache.Add(key, retValue); } return(retValue); }
/// <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); }
/// <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</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); }
/// <summary> /// Process Issue /// </summary> /// <returns>true if processed</returns> public bool Process() { if (!Save()) { return(false); } if (GetM_Product_ID() == 0) { log.Log(Level.SEVERE, "No Product"); return(false); } MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); // If not a stocked Item nothing to do if (!product.IsStocked()) { SetProcessed(true); return(Save()); } /** @todo Transaction */ // ** Create Material Transactions ** MTransaction mTrx = new MTransaction(GetCtx(), GetAD_Org_ID(), MTransaction.MOVEMENTTYPE_WorkOrderPlus, GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Decimal.Negate(GetMovementQty()), GetMovementDate(), Get_TrxName()); mTrx.SetC_ProjectIssue_ID(GetC_ProjectIssue_ID()); // MLocator loc = MLocator.Get(GetCtx(), GetM_Locator_ID()); if (MStorage.Add(GetCtx(), loc.GetM_Warehouse_ID(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), GetM_AttributeSetInstance_ID(), Decimal.Negate(GetMovementQty()), null, null, Get_TrxName())) { if (mTrx.Save(Get_TrxName())) { SetProcessed(true); if (Save()) { return(true); } else { log.Log(Level.SEVERE, "Issue not saved"); // requires trx !! } } else { log.Log(Level.SEVERE, "Transaction not saved"); // requires trx !! } } else { log.Log(Level.SEVERE, "Storage not updated"); // OK } // return(false); }
public void UpdateStockSummary() { StringBuilder Qry = new StringBuilder(); decimal OpeningStock = 0, movementQty = 0; MProductStockSummary Trs = null; MLocator loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName()); int AD_Org_ID = loc.GetAD_Org_ID(); Qry.Append("SELECT M_ProductStockSummary_ID FROM M_ProductStockSummary WHERE IsActive = 'Y' AND M_Product_ID = " + GetM_Product_ID() + " AND AD_Org_ID = " + AD_Org_ID + " AND MovementFromDate = " + GlobalVariable.TO_DATE(GetMovementDate(), true)); int M_ProductStockSummary_ID = Util.GetValueOfInt(DB.ExecuteScalar(Qry.ToString(), null, Get_Trx())); Qry.Clear(); Qry.Append("SELECT Count(*) FROM M_ProductStockSummary WHERE IsActive = 'Y' AND M_Product_ID = " + GetM_Product_ID() + " AND AD_Org_ID = " + AD_Org_ID + " AND MovementFromDate < " + GlobalVariable.TO_DATE(GetMovementDate(), true)); int existOld = Util.GetValueOfInt(DB.ExecuteScalar(Qry.ToString(), null, Get_Trx())); if (existOld > 0) { Qry.Clear(); Qry.Append("SELECT QtyCloseStockOrg FROM M_ProductStockSummary WHERE IsActive = 'Y' AND M_Product_ID = " + GetM_Product_ID() + " AND AD_Org_ID = " + AD_Org_ID + " AND MovementFromDate < " + GlobalVariable.TO_DATE(GetMovementDate(), true) + " ORDER BY MovementFromDate DESC"); OpeningStock = Util.GetValueOfDecimal(DB.ExecuteScalar(Qry.ToString(), null, Get_Trx())); } if (M_ProductStockSummary_ID > 0) { Trs = new MProductStockSummary(GetCtx(), M_ProductStockSummary_ID, Get_TrxName()); Trs.SetQtyOpenStockOrg(OpeningStock); Trs.SetQtyCloseStockOrg(Trs.GetQtyCloseStockOrg() + GetMovementQty()); } else { Trs = new MProductStockSummary(GetCtx(), AD_Org_ID, GetM_Product_ID(), 0, GetCurrentQty(), GetMovementDate(), Get_TrxName()); Trs.SetQtyOpenStockOrg(OpeningStock); } Qry.Append("SELECT Count(*) FROM M_ProductStockSummary WHERE IsActive = 'Y' AND M_Product_ID = " + GetM_Product_ID() + " AND AD_Org_ID = " + AD_Org_ID + " AND MovementFromDate > " + GlobalVariable.TO_DATE(GetMovementDate(), true)); int existRec = Util.GetValueOfInt(DB.ExecuteScalar(Qry.ToString(), null, Get_Trx())); if (existRec > 0) { Trs.SetIsStockSummarized(false); } if (!Trs.Save()) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "StockSummaryNotSaved")); } else { if (existOld > 0) { Qry.Clear(); Qry.Append("SELECT M_ProductStockSummary_ID FROM M_ProductStockSummary WHERE IsActive = 'Y' AND M_Product_ID = " + GetM_Product_ID() + " AND AD_Org_ID = " + AD_Org_ID + " AND MovementFromDate < " + GlobalVariable.TO_DATE(GetMovementDate(), true) + " ORDER BY MovementFromDate DESC"); int oldSummary_ID = Util.GetValueOfInt(DB.ExecuteScalar(Qry.ToString(), null, Get_Trx())); MProductStockSummary oldTrs = new MProductStockSummary(GetCtx(), oldSummary_ID, Get_Trx()); oldTrs.SetMovementToDate(Convert.ToDateTime(GetMovementDate()).AddDays(-1)); oldTrs.Save(); } } }
public void UpdateTransactionSummary() { StringBuilder Qry = new StringBuilder(); decimal OpeningStock = 0, movementQty = 0; MTransactionSummary Trs = null; Qry.Append("SELECT M_TransactionSummary_ID FROM M_TransactionSummary WHERE IsActive = 'Y' AND M_Product_ID = " + GetM_Product_ID() + " AND M_Locator_ID = " + GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + " AND MovementDate = " + GlobalVariable.TO_DATE(GetMovementDate(), true)); int M_TransactionSummary_ID = Util.GetValueOfInt(DB.ExecuteScalar(Qry.ToString(), null, Get_Trx())); Qry.Clear(); Qry.Append("SELECT Count(*) FROM M_TransactionSummary WHERE IsActive = 'Y' AND M_Product_ID = " + GetM_Product_ID() + " AND M_Locator_ID = " + GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + " AND MovementDate < " + GlobalVariable.TO_DATE(GetMovementDate(), true)); int existOld = Util.GetValueOfInt(DB.ExecuteScalar(Qry.ToString(), null, Get_Trx())); Qry.Clear(); if (existOld > 0) { Qry.Append("SELECT ClosingStock FROM M_TransactionSummary WHERE IsActive = 'Y' AND M_Product_ID = " + GetM_Product_ID() + " AND M_Locator_ID = " + GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + " AND MovementDate < " + GlobalVariable.TO_DATE(GetMovementDate(), true) + " ORDER BY MovementDate DESC"); } else { Qry.Append("SELECT NVL(GetStockofWarehouse(" + GetM_Product_ID() + "," + GetM_Locator_ID() + ",0," + GetM_AttributeSetInstance_ID() + "," + GlobalVariable.TO_DATE(Convert.ToDateTime(GetMovementDate()).AddDays(-1), true) + "," + GetAD_Client_ID() + "," + GetAD_Org_ID() + "),0) AS Stock FROM DUAL"); } OpeningStock = Util.GetValueOfDecimal(DB.ExecuteScalar(Qry.ToString(), null, Get_Trx())); if (M_TransactionSummary_ID > 0) { Trs = new MTransactionSummary(GetCtx(), M_TransactionSummary_ID, Get_TrxName()); Trs.SetOpeningStock(OpeningStock); Trs.SetClosingStock(GetCurrentQty()); Qry.Clear(); Qry.Append("SELECT SUM(MovementQty) FROM M_Transaction WHERE MovementType = '" + GetMovementType() + "' AND M_Product_ID = " + GetM_Product_ID() + " AND M_Locator_ID = " + GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + "AND movementdate = " + GlobalVariable.TO_DATE(GetMovementDate(), true)); movementQty = Util.GetValueOfDecimal(DB.ExecuteScalar(Qry.ToString(), null, Get_Trx())); } else { MLocator loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName()); Trs = new MTransactionSummary(GetCtx(), loc.GetAD_Org_ID(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), OpeningStock, GetCurrentQty(), GetMovementDate(), Get_TrxName()); movementQty = GetMovementQty(); } if (GetMovementType() == MOVEMENTTYPE_CustomerReturns) { Trs.SetQtyCustReturn(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_CustomerShipment) { Trs.SetQtyCustShipment(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_InventoryIn) { Trs.SetQtyInventoryIn(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_InventoryOut) { Trs.SetQtyInventoryOut(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_MovementFrom) { Trs.SetQtyMoveOut(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_MovementTo) { Trs.SetQtyMoveTo(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_Production_) { Trs.SetQtyProductionOut(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_ProductionPlus) { Trs.SetQtyProductionIn(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_VendorReceipts) { Trs.SetQtyMaterialIn(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_VendorReturns) { Trs.SetQtyMaterialOut(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_WorkOrderPlus) { Trs.SetQtyWorkOrderIn(movementQty); } else if (GetMovementType() == MOVEMENTTYPE_WorkOrder_) { Trs.SetQtyWorkOrderOut(movementQty); } if (!Trs.Save()) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "TrxSummaryNotSaved")); } }
/// <summary> /// Constructor called from BOM Drop /// </summary> /// <param name="workorder"></param> /// <param name="workorderoperation"></param> /// <param name="product"></param> /// <param name="QtyRequired"></param> /// <param name="SupplyType"></param> /// <param name="locator"></param> public MVAMFGMWorkOrderComponent(ViennaAdvantage.Model.MVAMFGMWorkOrder workorder, MVAMFGMWorkOrderOperation workorderoperation, ViennaAdvantage.Model.MProduct product, Decimal QtyRequired, String SupplyType, int M_AttributeSetInstance_ID, VAdvantage.Model.MLocator locator) : this(workorderoperation.GetCtx(), 0, workorderoperation.Get_TrxName()) { if (workorderoperation.Get_ID() == 0) { throw new Exception("Header not saved"); } SetVAMFG_M_WorkOrderOperation_ID(workorderoperation.GetVAMFG_M_WorkOrderOperation_ID()); // parent SetM_Product_ID(product.GetM_Product_ID()); SetC_UOM_ID(product.GetC_UOM_ID()); SetVAMFG_QtyRequired(QtyRequired); SetVAMFG_SupplyType(SupplyType); // Changes done b y Vivek Kumar assigned by Mukesh on 16/11/2017 // Changes done to save AttributesetInstance at Work Order component SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID); if (locator != null) { SetM_Locator_ID(locator.GetM_Locator_ID()); } SetWorkOrder(workorder); }
/// <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); }
/// <summary> ///Load Lookup /// </summary> private void Load() { // log.config("MLocatorLookup Loader.run " + m_AD_Column_ID); // Set Info - see VLocator.actionText int only_Warehouse_ID = GetOnly_Warehouse_ID(); int only_Product_ID = GetOnly_Product_ID(); bool?only_IsSOTrx = IsOnly_Outgoing(); //int sqlParaCount = 0; StringBuilder sql = new StringBuilder("SELECT * FROM M_Locator ") .Append(" WHERE IsActive='Y'"); if (only_Warehouse_ID != 0) { sql.Append(" AND M_Warehouse_ID=@w"); } if (only_Product_ID != 0) { sql.Append(" AND (IsDefault='Y' "); // Default Locator // Something already stored sql.Append("OR EXISTS (SELECT * FROM M_Storage s ") // Storage Locator .Append("WHERE s.M_Locator_ID=M_Locator.M_Locator_ID AND s.M_Product_ID=@p)"); if (only_IsSOTrx == null || !only_IsSOTrx.Value) { // Default Product sql.Append("OR EXISTS (SELECT * FROM M_Product p ") // Default Product Locator .Append("WHERE p.M_Locator_ID=M_Locator.M_Locator_ID AND p.M_Product_ID=@p)"); // Product Locators sql.Append("OR EXISTS (SELECT * FROM M_ProductLocator pl ") // Product Locator .Append("WHERE pl.M_Locator_ID=M_Locator.M_Locator_ID AND pl.M_Product_ID=@p)"); // No locators defined for the warehouse sql.Append("OR 0 = (SELECT COUNT(*) "); sql.Append("FROM M_ProductLocator pl"); sql.Append(" INNER JOIN M_Locator l2 ON (pl.M_Locator_ID=l2.M_Locator_ID) "); sql.Append("WHERE pl.M_Product_ID=@p AND l2.M_Warehouse_ID=M_Locator.M_Warehouse_ID )"); } sql.Append(" ) "); } String finalSql = MRole.GetDefault((Context)GetCtx(), false).AddAccessSQL( sql.ToString(), "M_Locator", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); //if (_loader.ThreadState == ThreadState.Suspended) //{ // log.log(Level.SEVERE, "Interrupted"); // return; //} // Reset _lookup.Clear(); int rows = 0; try { List <System.Data.SqlClient.SqlParameter> para = new List <System.Data.SqlClient.SqlParameter>(); // int index = 1; if (only_Warehouse_ID != 0) { // pstmt.setInt(index++, only_Warehouse_ID); para.Add(new System.Data.SqlClient.SqlParameter("@w", only_Warehouse_ID)); } if (only_Product_ID != 0) { para.Add(new System.Data.SqlClient.SqlParameter("@p", only_Product_ID)); } DataSet ds = DataBase.DB.ExecuteDataset(finalSql, para.ToArray(), null); // foreach (DataRow dr in ds.Tables[0].Rows) { // Max out if (rows++ > _maxRows) { log.Warning("Over Max Rows - " + rows); break; } MLocator loc = new MLocator((Context)GetCtx(), dr, null); int M_Locator_ID = loc.GetM_Locator_ID(); KeyNamePair pp = new KeyNamePair(M_Locator_ID, loc.ToString()); _lookup.Add(M_Locator_ID, pp); } ds.Dispose(); ds = null; } catch (Exception e) { log.Log(Level.SEVERE, finalSql, e); } log.Fine("Complete #" + _lookup.Count); if (_lookup.Count == 0) { log.Finer(finalSql); } }