/* Get Attribute Set * @return set or null */ public MAttributeSet GetAttributeSet() { if (GetM_AttributeSet_ID() != 0) { return(MAttributeSet.Get(GetCtx(), GetM_AttributeSet_ID())); } return(null); }
/* Has the Product Instance Attribute * @return true if instance attributes */ public bool IsInstanceAttribute() { if (GetM_AttributeSet_ID() == 0) { return(false); } MAttributeSet mas = MAttributeSet.Get(GetCtx(), GetM_AttributeSet_ID()); return(mas.IsInstanceAttribute()); }
/// <summary> /// Create/Add to Inventory Line /// </summary> /// <param name="M_Locator_ID">locator</param> /// <param name="M_Product_ID">product</param> /// <param name="M_AttributeSetInstance_ID">asi</param> /// <param name="qtyOnHand">quantity</param> /// <param name="M_AttributeSet_ID">attribute set</param> /// <returns>lines added</returns> private int CreateInventoryLine(int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID, Decimal qtyOnHand, Decimal currentQty, int M_AttributeSet_ID) { Boolean oneLinePerASI = false; if (M_AttributeSet_ID != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), M_AttributeSet_ID); oneLinePerASI = mas.IsInstanceAttribute(); } if (oneLinePerASI) { MInventoryLine line = new MInventoryLine(_inventory, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, qtyOnHand, qtyOnHand); // book/count line.SetOpeningStock(currentQty); if (line.Save()) { return(1); } return(0); } if (Env.Signum(qtyOnHand) == 0) { M_AttributeSetInstance_ID = 0; } if (_line != null && _line.GetM_Locator_ID() == M_Locator_ID && _line.GetM_Product_ID() == M_Product_ID) { if (Env.Signum(qtyOnHand) == 0) { return(0); } // Same ASI (usually 0) if (_line.GetM_AttributeSetInstance_ID() == M_AttributeSetInstance_ID) { _line.SetQtyBook(Decimal.Add(_line.GetQtyBook(), qtyOnHand)); _line.SetQtyCount(Decimal.Add(_line.GetQtyCount(), qtyOnHand)); _line.SetOpeningStock((Decimal.Add(_line.GetOpeningStock(), currentQty))); _line.Save(); return(0); } // Save Old Line info else if (_line.GetM_AttributeSetInstance_ID() != 0) { MInventoryLineMA ma = new MInventoryLineMA(_line, _line.GetM_AttributeSetInstance_ID(), _line.GetQtyBook()); if (!ma.Save()) { ; } } _line.SetM_AttributeSetInstance_ID(0); _line.SetQtyBook(Decimal.Add(_line.GetQtyBook(), qtyOnHand)); _line.SetQtyCount(Decimal.Add(_line.GetQtyCount(), qtyOnHand)); _line.SetOpeningStock((Decimal.Add(_line.GetOpeningStock(), currentQty))); _line.Save(); // MInventoryLineMA ma1 = new MInventoryLineMA(_line, M_AttributeSetInstance_ID, qtyOnHand); if (!ma1.Save()) { ; } return(0); } // new line _line = new MInventoryLine(_inventory, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, qtyOnHand, qtyOnHand); // book/count _line.SetOpeningStock(currentQty); if (_line.Save()) { return(1); } return(0); }
/// <summary> /// Create/Add to Inventory Line /// </summary> /// <param name="M_Locator_ID">locator</param> /// <param name="M_Product_ID">product</param> /// <param name="M_AttributeSetInstance_ID">asi</param> /// <param name="qtyOnHand">quantity</param> /// <param name="M_AttributeSet_ID">attribute set</param> /// <returns>lines added</returns> private int CreateInventoryLine(int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID, Decimal qtyOnHand, Decimal currentQty, int M_AttributeSet_ID) { Boolean oneLinePerASI = false; if (M_AttributeSet_ID != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), M_AttributeSet_ID); oneLinePerASI = mas.IsInstanceAttribute(); } if (oneLinePerASI) { MInventoryLine line = new MInventoryLine(_inventory, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, qtyOnHand, qtyOnHand); // book/count line.SetOpeningStock(currentQty); line.SetAsOnDateCount(line.GetQtyCount()); // JID_0903: On creating the lines from physical inventory count system is not updating the UOM and Qty on physical inventory line. if (line.Get_ColumnIndex("QtyEntered") > 0) { line.Set_Value("QtyEntered", line.GetQtyCount()); } if (line.Get_ColumnIndex("C_UOM_ID") > 0) { MProduct prd = new MProduct(GetCtx(), M_Product_ID, Get_Trx()); line.Set_Value("C_UOM_ID", prd.GetC_UOM_ID()); } if (line.Get_ColumnIndex("IsFromProcess") >= 0) { line.SetIsFromProcess(true); } if (line.Save()) { return(1); } return(0); } if (Env.Signum(qtyOnHand) == 0) { M_AttributeSetInstance_ID = 0; } if (_line != null && _line.GetM_Locator_ID() == M_Locator_ID && _line.GetM_Product_ID() == M_Product_ID) { if (Env.Signum(qtyOnHand) == 0) { return(0); } // Same ASI (usually 0) if (_line.GetM_AttributeSetInstance_ID() == M_AttributeSetInstance_ID) { _line.SetQtyBook(Decimal.Add(_line.GetQtyBook(), qtyOnHand)); _line.SetQtyCount(Decimal.Add(_line.GetQtyCount(), qtyOnHand)); _line.SetOpeningStock((Decimal.Add(_line.GetOpeningStock(), currentQty))); _line.SetAsOnDateCount(_line.GetQtyCount()); // JID_0903: On creating the lines from physical inventory count system is not updating the UOM and Qty on physical inventory line. if (_line.Get_ColumnIndex("QtyEntered") > 0) { _line.Set_Value("QtyEntered", _line.GetQtyCount()); } if (_line.Get_ColumnIndex("C_UOM_ID") > 0) { MProduct prd = new MProduct(GetCtx(), M_Product_ID, Get_Trx()); _line.Set_Value("C_UOM_ID", prd.GetC_UOM_ID()); } if (_line.Get_ColumnIndex("IsFromProcess") >= 0) { _line.SetIsFromProcess(true); } _line.Save(); return(0); } // Save Old Line info else if (_line.GetM_AttributeSetInstance_ID() != 0) { MInventoryLineMA ma = new MInventoryLineMA(_line, _line.GetM_AttributeSetInstance_ID(), _line.GetQtyBook()); if (!ma.Save()) { ; } } _line.SetM_AttributeSetInstance_ID(0); _line.SetQtyBook(Decimal.Add(_line.GetQtyBook(), qtyOnHand)); _line.SetQtyCount(Decimal.Add(_line.GetQtyCount(), qtyOnHand)); _line.SetOpeningStock((Decimal.Add(_line.GetOpeningStock(), currentQty))); _line.SetAsOnDateCount(_line.GetQtyCount()); // JID_0903: On creating the lines from physical inventory count system is not updating the UOM and Qty on physical inventory line. if (_line.Get_ColumnIndex("QtyEntered") > 0) { _line.Set_Value("QtyEntered", _line.GetQtyCount()); } if (_line.Get_ColumnIndex("C_UOM_ID") > 0) { MProduct prd = new MProduct(GetCtx(), M_Product_ID, Get_Trx()); _line.Set_Value("C_UOM_ID", prd.GetC_UOM_ID()); } if (_line.Get_ColumnIndex("IsFromProcess") >= 0) { _line.SetIsFromProcess(true); } _line.Save(); // MInventoryLineMA ma1 = new MInventoryLineMA(_line, M_AttributeSetInstance_ID, qtyOnHand); if (!ma1.Save()) { ; } return(0); } // new line _line = new MInventoryLine(_inventory, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, qtyOnHand, qtyOnHand); // book/count _line.SetOpeningStock(currentQty); _line.SetAsOnDateCount(_line.GetQtyCount()); // JID_0903: On creating the lines from physical inventory count system is not updating the UOM and Qty on physical inventory line. if (_line.Get_ColumnIndex("QtyEntered") > 0) { _line.Set_Value("QtyEntered", _line.GetQtyCount()); } if (_line.Get_ColumnIndex("C_UOM_ID") > 0) { MProduct prd = new MProduct(GetCtx(), M_Product_ID, Get_Trx()); _line.Set_Value("C_UOM_ID", prd.GetC_UOM_ID()); } if (_line.Get_ColumnIndex("IsFromProcess") >= 0) { _line.SetIsFromProcess(true); } if (_line.Save()) { return(1); } return(0); }
/// <summary> /// Create Line /// </summary> /// <param name="order">order</param> /// <param name="orderLine">line</param> /// <param name="qty">Quantity</param> /// <param name="storages">storage info</param> /// <param name="force">force delivery</param> private void CreateLine(MOrder order, MOrderLine orderLine, Decimal qty, MStorage[] storages, bool force) { // Complete last Shipment - can have multiple shipments if (_lastC_BPartner_Location_ID != orderLine.GetC_BPartner_Location_ID()) { CompleteShipment(); } _lastC_BPartner_Location_ID = orderLine.GetC_BPartner_Location_ID(); // Create New Shipment if (_shipment == null) { _shipment = new MInOut(order, 0, _movementDate); _shipment.SetM_Warehouse_ID(orderLine.GetM_Warehouse_ID()); // sets Org too if (order.GetC_BPartner_ID() != orderLine.GetC_BPartner_ID()) { _shipment.SetC_BPartner_ID(orderLine.GetC_BPartner_ID()); } if (order.GetC_BPartner_Location_ID() != orderLine.GetC_BPartner_Location_ID()) { _shipment.SetC_BPartner_Location_ID(orderLine.GetC_BPartner_Location_ID()); } if (!_shipment.Save()) { throw new Exception("Could not create Shipment"); } } // Non Inventory Lines if (storages == null) { MInOutLine line = new MInOutLine(_shipment); line.SetOrderLine(orderLine, 0, Env.ZERO); line.SetQty(qty); // Correct UOM if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0) { line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(qty, orderLine.GetQtyEntered()), orderLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero)); } line.SetLine(_line + orderLine.GetLine()); //Amit 27-jan-2014 if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0) { line.SetDTD001_IsAttributeNo(true); } if (!line.Save()) { throw new Exception("Could not create Shipment Line"); } log.Fine(line.ToString()); return; } // Product MProduct product = orderLine.GetProduct(); bool linePerASI = false; if (product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); linePerASI = mas.IsInstanceAttribute(); } // Inventory Lines List <MInOutLine> list = new List <MInOutLine>(); Decimal toDeliver = qty; for (int i = 0; i < storages.Length; i++) { MStorage storage = storages[i]; Decimal deliver = toDeliver; // Not enough On Hand if (deliver.CompareTo(storage.GetQtyOnHand()) > 0 && Env.Signum(storage.GetQtyOnHand()) >= 0) // positive storage { if (!force || // Adjust to OnHand Qty (i + 1 != storages.Length)) // if force don't adjust last location { deliver = storage.GetQtyOnHand(); } } if (Env.Signum(deliver) == 0) // zero deliver { continue; } int M_Locator_ID = storage.GetM_Locator_ID(); // MInOutLine line = null; if (!linePerASI) // find line with Locator { for (int n = 0; n < list.Count; n++) { MInOutLine test = (MInOutLine)list[n]; if (test.GetM_Locator_ID() == M_Locator_ID) { line = test; break; } } } if (line == null) // new line { line = new MInOutLine(_shipment); line.SetOrderLine(orderLine, M_Locator_ID, order.IsSOTrx() ? deliver : Env.ZERO); line.SetQty(deliver); list.Add(line); } else { // existing line line.SetQty(Decimal.Add(line.GetMovementQty(), deliver)); } if (orderLine.GetQtyEntered().CompareTo(orderLine.GetQtyOrdered()) != 0) { line.SetQtyEntered(Decimal.Round(Decimal.Divide(Decimal.Multiply(line.GetMovementQty(), orderLine.GetQtyEntered()), orderLine.GetQtyOrdered()), 12, MidpointRounding.AwayFromZero)); } line.SetLine(_line + orderLine.GetLine()); if (linePerASI) { line.SetM_AttributeSetInstance_ID(storage.GetM_AttributeSetInstance_ID()); } //Amit 27-jan-2014 if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='DTD001_'")) > 0) { line.SetDTD001_IsAttributeNo(true); } if (!line.Save()) { throw new Exception("Could not create Shipment Line"); } log.Fine("ToDeliver=" + qty + "/" + deliver + " - " + line); toDeliver = Decimal.Subtract(toDeliver, deliver); // Temp adjustment storage.SetQtyOnHand(Decimal.Subtract(storage.GetQtyOnHand(), deliver)); // if (Env.Signum(toDeliver) == 0) { break; } } if (Env.Signum(toDeliver) != 0) { throw new Exception("Not All Delivered - Remainder=" + toDeliver); } }
/// <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 = 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" || inventory.GetDocStatus() == "IP"))) { #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); }