/* Set Qty Entered - enforce entered UOM * @param QtyEntered */ public void SetQtyEntered(Decimal QtyEntered) { if (QtyEntered != 0 && GetC_UOM_ID() != 0) { int precision = MUOM.GetPrecision(GetCtx(), GetC_UOM_ID()); //QtyEntered = QtyEntered.setScale(precision, Decimal.ROUND_HALF_UP); QtyEntered = Decimal.Round(QtyEntered, precision, MidpointRounding.AwayFromZero); } base.SetQtyEntered(QtyEntered); }
/** * Get UOM Standard Precision * @return UOM Standard Precision */ public int GetUOMPrecision() { if (_precision == null) { int C_UOM_ID = GetC_UOM_ID(); if (C_UOM_ID == 0) return 0; // EA _precision = (int)MUOM.GetPrecision(GetCtx(), C_UOM_ID); } return (int)_precision; }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true if can be saved</returns> protected override bool BeforeSave(bool newRecord) { // chck pallet Functionality applicable or not bool isContainrApplicable = MTransaction.ProductContainerApplicable(GetCtx()); 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()); } //JID_0680 set quantity according to precision if (Is_ValueChanged("C_UOM_ID")) { Set_Value("QtyEntered", Math.Round(Util.GetValueOfDecimal(Get_Value("QtyEntered")), MUOM.GetPrecision(GetCtx(), Util.GetValueOfInt(Get_Value("C_UOM_ID"))))); } // 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 { //JID_1392 if (GetAdjustmentType() == ADJUSTMENTTYPE_AsOnDateCount) { SetAsOnDateCount(qty); SetDifferenceQty(Decimal.Negate(qty.Value)); } else if (GetAdjustmentType() == ADJUSTMENTTYPE_QuantityDifference) { SetAsOnDateCount(Decimal.Negate(qty.Value)); 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")); } // no need to check when record is in processing if (!inventory.IsProcessing() || newRecord) { 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() + " AND NVL(M_AttributeSetInstance_ID, 0)=" + 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"))) { // pick container current qty from transaction based on locator / product / ASI / Container / Movement Date if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0) { 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(inventory.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_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() + " AND NVL(t.M_ProductContainer_ID, 0) = " + GetM_ProductContainer_ID(); containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry, null, null)); // dont use Transaction here - otherwise impact goes wrong on completion } #region DisallowNegativeInv = True if (!IsInternalUse() && GetDifferenceQty() > 0) { if ((OnHandQty - GetDifferenceQty()) < 0) { log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQty - GetDifferenceQty()) < 0) { log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainer") + containerQty); return(false); } } else if (IsInternalUse()) { if ((OnHandQty - GetQtyInternalUse()) < 0) { log.SaveError("", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQty - GetQtyInternalUse()) < 0) { log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainer") + containerQty); 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); }
/** * Set Qty * @param windowNo window * @param columnName column */ private void SetQty(int windowNo, String columnName) { int M_Product_ID = GetM_Product_ID(); log.Log(Level.WARNING, "qty - init - M_Product_ID=" + M_Product_ID); Decimal MovementQty, QtyEntered; int C_UOM_To_ID = GetC_UOM_ID(); // No Product if (M_Product_ID == 0) { QtyEntered = GetQtyEntered(); SetMovementQty(QtyEntered); } // UOM Changed - convert from Entered -> Product else if (columnName.Equals("C_UOM_ID")) { QtyEntered = GetQtyEntered(); //Decimal QtyEntered1 = QtyEntered.setScale(MUOM.GetPrecision(GetCtx(), C_UOM_To_ID), Decimal.ROUND_HALF_UP); Decimal QtyEntered1 = Decimal.Round(QtyEntered, MUOM.GetPrecision(GetCtx(), C_UOM_To_ID), MidpointRounding.AwayFromZero); if (QtyEntered.CompareTo(QtyEntered1) != 0) { log.Fine("Corrected QtyEntered Scale UOM=" + C_UOM_To_ID + "; QtyEntered=" + QtyEntered + "->" + QtyEntered1); QtyEntered = QtyEntered1; SetQtyEntered(QtyEntered); } MovementQty = (Decimal)MUOMConversion.ConvertProductFrom(GetCtx(), M_Product_ID, C_UOM_To_ID, QtyEntered); if (MovementQty == null) { MovementQty = QtyEntered; } bool conversion = QtyEntered.CompareTo(MovementQty) != 0; log.Fine("UOM=" + C_UOM_To_ID + ", QtyEntered=" + QtyEntered + " -> " + conversion + " MovementQty=" + MovementQty); //p_changeVO.setContext(getCtx(), windowNo, "UOMConversion", conversion); SetMovementQty(MovementQty); } // No UOM defined else if (C_UOM_To_ID == 0) { QtyEntered = GetQtyEntered(); SetMovementQty(QtyEntered); } // QtyEntered changed - calculate MovementQty else if (columnName.Equals("QtyEntered")) { QtyEntered = GetQtyEntered(); Decimal QtyEntered1 = Decimal.Round(QtyEntered, MUOM.GetPrecision(GetCtx(), C_UOM_To_ID), MidpointRounding.AwayFromZero); if (QtyEntered.CompareTo(QtyEntered1) != 0) { log.Fine("Corrected QtyEntered Scale UOM=" + C_UOM_To_ID + "; QtyEntered=" + QtyEntered + "->" + QtyEntered1); QtyEntered = QtyEntered1; SetQtyEntered(QtyEntered); } MovementQty = (Decimal)MUOMConversion.ConvertProductFrom(GetCtx(), M_Product_ID, C_UOM_To_ID, QtyEntered); if (MovementQty == null) { MovementQty = QtyEntered; } bool conversion = QtyEntered.CompareTo(MovementQty) != 0; log.Fine("UOM=" + C_UOM_To_ID + ", QtyEntered=" + QtyEntered + " -> " + conversion + " MovementQty=" + MovementQty); //p_changeVO.setContext(getCtx(), windowNo, "UOMConversion", conversion); SetMovementQty(MovementQty); } // MovementQty changed - calculate QtyEntered (should not happen) else if (columnName.Equals("MovementQty")) { MovementQty = GetMovementQty(); int precision = MProduct.Get(GetCtx(), M_Product_ID).GetUOMPrecision(); //Decimal MovementQty1 = MovementQty.setScale(precision, Decimal.ROUND_HALF_UP); Decimal MovementQty1 = Decimal.Round(MovementQty, precision, MidpointRounding.AwayFromZero);// Env.Scale(MovementQty); if (MovementQty.CompareTo(MovementQty1) != 0) { log.Fine("Corrected MovementQty " + MovementQty + "->" + MovementQty1); MovementQty = MovementQty1; SetMovementQty(MovementQty); } QtyEntered = (Decimal)MUOMConversion.ConvertProductTo(GetCtx(), M_Product_ID, C_UOM_To_ID, MovementQty); if (QtyEntered == null) { QtyEntered = MovementQty; } bool conversion = MovementQty.CompareTo(QtyEntered) != 0; log.Fine("UOM=" + C_UOM_To_ID + ", MovementQty=" + MovementQty + " -> " + conversion + " QtyEntered=" + QtyEntered); //p_changeVO.setContext(getCtx(), windowNo, "UOMConversion", conversion); SetQtyEntered(QtyEntered); } // RMA : Check qty returned is more than qty shipped bool IsReturnTrx = GetParent().IsReturnTrx(); if (M_Product_ID != 0 && IsReturnTrx) { int oLine_ID = GetC_OrderLine_ID(); MOrderLine oLine = new MOrderLine(GetCtx(), oLine_ID, null); if (oLine.Get_ID() != 0) { int orig_IOLine_ID = oLine.GetOrig_InOutLine_ID(); if (orig_IOLine_ID != 0) { MInOutLine orig_IOLine = new MInOutLine(GetCtx(), orig_IOLine_ID, null); Decimal shippedQty = orig_IOLine.GetMovementQty(); MovementQty = GetMovementQty(); if (shippedQty.CompareTo(MovementQty) < 0) { if (GetCtx().IsSOTrx(windowNo)) { // p_changeVO.addError(Msg.getMsg(getCtx(), "QtyShippedLessThanQtyReturned", shippedQty)); } else { // p_changeVO.addError(Msg.getMsg(getCtx(), "QtyReceivedLessThanQtyReturned", shippedQty)); } SetMovementQty(shippedQty); MovementQty = shippedQty; QtyEntered = (Decimal)MUOMConversion.ConvertProductTo(GetCtx(), M_Product_ID, C_UOM_To_ID, MovementQty); if (QtyEntered == null) { QtyEntered = MovementQty; } SetQtyEntered(QtyEntered); log.Fine("QtyEntered : " + QtyEntered.ToString() + "MovementQty : " + MovementQty.ToString()); } } } } }