/**** * 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); }