/** * Set Value, Name, Description * @param invoice * @param deliveryCount count * @param product product * @param partner partner */ public void SetValueNameDescription(MInvoice invoice, int deliveryCount, MProduct product, MBPartner partner) { String documentNo = "_" + invoice.GetDocumentNo(); if (deliveryCount > 1) { documentNo += "_" + deliveryCount; } // Value String value = partner.GetValue() + "_" + product.GetValue(); if (value.Length > 40 - documentNo.Length) { value = value.Substring(0, 40 - documentNo.Length) + documentNo; } // Change to set Value from Document Sequence // SetValue(value); // Change to set only name of product as value in Asset // Name MProduct.afterSave // String name = partner.GetName() + " - " + product.GetName(); String name = product.GetName(); if (name.Length > 60) { name = name.Substring(0, 60); } SetName(name); // Description String description = product.GetDescription(); SetDescription(description); }
/// <summary> /// Set Shipment Line /// </summary> /// <param name="line">shipment line</param> public void SetInOutLine(MInOutLine line) { SetM_InOutLine_ID(line.GetM_InOutLine_ID()); SetTargetQty(line.GetMovementQty()); // Confirmations in Storage UOM SetConfirmedQty(GetTargetQty()); // suggestion // Enhaced by Siddaraju 2-12-2016 only for gulf oil if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM AD_ModuleInfo WHERE IsActive = 'Y' AND Prefix LIKE 'GOM01_'", null, null)) > 0) { _M_Product_ID = line.GetM_Product_ID(); if (_M_Product_ID > 0) { MProduct Prod1 = new MProduct(GetCtx(), _M_Product_ID, Get_TrxName()); SetGOM01_ItemName(Prod1.GetName()); SetGOM01_ItemDescription(Prod1.GetDescription()); SetGOM01_ItemCode(Prod1.GetValue()); } } //end _line = line; }
/** * Perform process. * @return Message * @throws Exception */ //@Override protected override String DoIt() { if (0 == p_M_WorkOrderTransaction_ID) { throw new Exception("@FillMandatory@ @M_WorkOrderTransaction_ID@"); } ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction woTxn = new ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction(GetCtx(), p_M_WorkOrderTransaction_ID, Get_TrxName()); ViennaAdvantage.Model.MVAMFGMWorkOrder wo = new ViennaAdvantage.Model.MVAMFGMWorkOrder(GetCtx(), woTxn.GetVAMFG_M_WorkOrder_ID(), Get_TrxName()); VAdvantage.Model.MBOM bom = new VAdvantage.Model.MBOM(GetCtx(), wo.GetM_BOM_ID(), Get_TrxName()); MBOMProduct[] BOMproducts = MBOMProduct.GetOfBOM(bom); for (int i = 0; i < BOMproducts.Length; i++) { string prodensity = "SELECT nvl(GOM01_DENSITY,0) FROM VAMFG_M_WorkOrder WHERE VAMFG_M_WorkOrder_ID =" + woTxn.GetVAMFG_M_WorkOrder_ID(); decimal DenQty = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(prodensity)); if (DenQty == 0) { DenQty = 1; } MBOMProduct BOMproduct = BOMproducts[i]; decimal qtyReqd = (p_Qty * BOMproduct.GetBOMQty()) * DenQty; //string qry = "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(woTxn.GetVAMFG_DateTrx(), true) + " AND M_Product_ID = " + BOMproduct.GetM_ProductBOM_ID() + " AND M_Locator_ID = " + woTxn.GetM_Locator_ID() + // " AND M_AttributeSetInstance_ID = " + BOMproduct.GetM_AttributeSetInstance_ID() + ") AND M_Product_ID = " + BOMproduct.GetM_ProductBOM_ID() + " AND M_Locator_ID = " + woTxn.GetM_Locator_ID() + // " AND M_AttributeSetInstance_ID = " + BOMproduct.GetM_AttributeSetInstance_ID() + ") AND AD_Org_ID = " + woTxn.GetAD_Org_ID() + " AND M_Product_ID = " + BOMproduct.GetM_ProductBOM_ID() + // " AND M_Locator_ID = " + woTxn.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + BOMproduct.GetM_AttributeSetInstance_ID(); //decimal CurrentQty = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(qry)); //if (CurrentQty < qtyReqd) //{ // ViennaAdvantage.Model.MProduct product = new ViennaAdvantage.Model.MProduct(GetCtx(), BOMproduct.GetM_ProductBOM_ID(), Get_Trx()); // return "Insufficient qty in warehouse for : " + product.GetName(); //} VAdvantage.Model.MStorage st = VAdvantage.Model.MStorage.Get(Env.GetCtx(), woTxn.GetM_Locator_ID(), BOMproduct.GetM_ProductBOM_ID(), BOMproduct.GetM_AttributeSetInstance_ID(), Get_TrxName()); if (st == null) { ViennaAdvantage.Model.MProduct product = new ViennaAdvantage.Model.MProduct(GetCtx(), BOMproduct.GetM_ProductBOM_ID(), Get_Trx()); return("Insufficient qty in warehouse for : " + product.GetName()); } decimal CurrentQty = st.GetQtyOnHand(); if (CurrentQty < qtyReqd) { ViennaAdvantage.Model.MProduct product = new ViennaAdvantage.Model.MProduct(GetCtx(), BOMproduct.GetM_ProductBOM_ID(), Get_Trx()); return("Insufficient qty in warehouse for : " + product.GetName()); } } if (p_Qty == 0) { //MVAMFGMWorkOrder wo = new MVAMFGMWorkOrder(GetCtx(), woTxn.GetVAMFG_M_WorkOrder_ID(), Get_TrxName()); // p_Qty = wo.GetVAMFG_QtyEntered().subtract(wo.GetVAMFG_QtyAssembled()); string prdOrdQry = "SELECT SUM(wkt.VAMFG_QtyEntered) AS ProdOrder FROM VAMFG_M_WrkOdrTransaction wkt WHERE wkt.VAMFG_WorkOrderTxnType ='CI' AND wkt.M_Product_ID = " + woTxn.GetM_Product_ID() + " AND wkt.VAMFG_M_Workorder_ID = " + woTxn.GetVAMFG_M_WorkOrder_ID() + " AND wkt.DocStatus ='CO'"; Decimal ProdOrdQty = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(prdOrdQry, null, Get_TrxName())); p_Qty = Decimal.Subtract(wo.GetVAMFG_QtyEntered(), (ProdOrdQty)); //p_Qty = Decimal.Subtract(wo.GetVAMFG_QtyEntered(), (wo.GetVAMFG_QtyAssembled())); //log.Info ("@Quantity@ = " + wo.GetVAMFG_QtyEntered().subtract(wo.GetVAMFG_QtyAssembled().add(wo.GetVAMFG_QtyScrapped()))); log.Info("@Quantity@ = " + Decimal.Subtract(wo.GetVAMFG_QtyEntered(), Decimal.Add(wo.GetVAMFG_QtyAssembled(), (wo.GetVAMFG_QtyScrapped())))); } //woTxn.SetVAMFG_QtyEntered(p_Qty.setScale(MUOM.GetPrecision(GetCtx(), woTxn.GetC_UOM_ID()), Decimal.ROUND_HALF_UP)); woTxn.SetVAMFG_QtyEntered(Decimal.Round((p_Qty), VAdvantage.Model.MUOM.GetPrecision(woTxn.GetCtx(), woTxn.GetC_UOM_ID()), MidpointRounding.AwayFromZero)); // Added by Bharat on 20/12/2016 to Set Density and Liter values for production execution Process of Gulf Oil. Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("GOM01_", out mInfo)) { woTxn.SetGOM01_Density(wo.GetGOM01_Density()); Decimal qtyKg = Decimal.Multiply(wo.GetGOM01_Density(), woTxn.GetVAMFG_QtyEntered()); woTxn.SetGOM01_Quantity(Decimal.Round((qtyKg), MUOM.GetPrecision(woTxn.GetCtx(), woTxn.GetC_UOM_ID()), MidpointRounding.AwayFromZero)); } woTxn.Save(); ViennaAdvantage.Process.MWorkOrderTxnUtil prodTxnLines = new ViennaAdvantage.Process.MWorkOrderTxnUtil(true); // Done by Bharat on 24 Jan 2018 to delete lines as when process runs multiple times it creates duplicate lines. int no = DB.ExecuteQuery("DELETE FROM VAMFG_M_WrkOdrTrnsctionLine WHERE VAMFG_M_WrkOdrTransaction_ID = " + p_M_WorkOrderTransaction_ID, null, Get_TrxName()); ViennaAdvantage.Model.MVAMFGMWrkOdrTrnsctionLine[] wotlines = prodTxnLines.GenerateComponentTxnLine(GetCtx(), p_M_WorkOrderTransaction_ID, p_Qty, X_VAMFG_M_WorkOrderComponent.VAMFG_SUPPLYTYPE_Push, Get_TrxName()); if (wotlines != null && wotlines.Length > 0) { return("Generated " + wotlines.Length + " line(s) for component(s): " + VLogger.RetrieveInfo().GetName()); } else { return("Generated 0 lines for components."); } }
/// <summary> /// Generates Resource Transaction Lines against WO Txn between & /// including specified operation VAMFG_SeqNo; skips the optional operations unless /// they are either the starting operation sequence or ending operation sequence /// </summary> /// <param name="ctx"></param> /// <param name="M_WorkOrderTransaction_ID"></param> /// <param name="Qty"></param> /// <param name="OperationFrom"></param> /// <param name="OperationTo"></param> /// <param name="trx"></param> /// <param name="automatic"></param> /// <returns></returns> public MVAMFGMWrkOdrRscTxnLine[] GenerateResourceTxnLine(Ctx ctx, int M_WorkOrderTransaction_ID, Decimal?Qty, Decimal?OperationFrom, Decimal?OperationTo, Trx trx, bool automatic) { if (0 >= M_WorkOrderTransaction_ID) { log.Severe("No Work Order Transaction ID specified"); return(null); } if (OperationFrom.Value.CompareTo(OperationTo) > 0) { log.Severe("Operation Numbers not correct."); return(null); } if (Qty != null && Qty.Value.CompareTo(Decimal.Zero) <= 0) { log.Severe("Number of product assemblies must be positive"); return(null); } ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction wot = new ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction(ctx, M_WorkOrderTransaction_ID, trx); if (wot != null && !(wot.GetVAMFG_WorkOrderTxnType().Equals(X_VAMFG_M_WrkOdrTransaction.VAMFG_WORKORDERTXNTYPE_ResourceUsage) && (wot.GetDocStatus().Equals(X_VAMFG_M_WrkOdrTransaction.DOCSTATUS_Drafted) || wot.GetDocStatus().Equals(X_VAMFG_M_WrkOdrTransaction.DOCSTATUS_InProgress)))) { log.Severe("Work Order transaction type not correct."); return(null); } //ArrayList<MVAMFGMWrkOdrRscTxnLine> wortLines = new ArrayList<MVAMFGMWrkOdrRscTxnLine>(); // List<MVAMFGMWrkOdrRscTxnLine> wortLines=new List<MVAMFGMWrkOdrRscTxnLine>(); System.Collections.ArrayList wortLines = new System.Collections.ArrayList(); ViennaAdvantage.Model.MVAMFGMWorkOrder wo = new ViennaAdvantage.Model.MVAMFGMWorkOrder(ctx, wot.GetVAMFG_M_WorkOrder_ID(), trx); int resTxnLineSeqNo = DB.GetSQLValue(trx, "SELECT Max(VAMFG_SeqNo) FROM MVAMFGMWrkOdrRscTxnLine WHERE VAMFG_M_WrkOdrTransaction_ID =" + M_WorkOrderTransaction_ID); StringBuilder wc = new StringBuilder(); if (OperationFrom.Value.CompareTo(Decimal.Zero) > 0) { wc.Append(" VAMFG_SeqNo >= ").Append(OperationFrom); if (OperationTo.Value.CompareTo(Decimal.Zero) > 0) { wc.Append(" AND VAMFG_SeqNo <= ").Append(OperationTo); } } else if (OperationTo.Value.CompareTo(Decimal.Zero) > 0) { wc.Append(" VAMFG_SeqNo <= ").Append(OperationTo); } // Don't consider the optional operations, but include the "From" and "To" operations even if they are optional wc.Append(" AND (VAMFG_IsOptional <> 'Y' "); if (OperationFrom.Value.CompareTo(Decimal.Zero) > 0) { wc.Append(" OR VAMFG_SeqNo = ").Append(OperationFrom); } if (OperationTo.Value.CompareTo(Decimal.Zero) > 0) { wc.Append(" OR VAMFG_SeqNo = ").Append(OperationTo); } wc.Append(" )"); ViennaAdvantage.CMFG.Model.MVAMFGMWorkOrder worder = new CMFG.Model.MVAMFGMWorkOrder(ctx, wo.GetVAMFG_M_WorkOrder_ID(), trx); String whereClause = (wc.Length > 0 ? wc.ToString() : null); MVAMFGMWorkOrderOperation[] woos = MVAMFGMWorkOrderOperation.GetOfWorkOrder(worder, whereClause, "VAMFG_SeqNo"); StringBuilder response = new StringBuilder(); foreach (MVAMFGMWorkOrderOperation woo in woos) { MVAMFGMWorkOrderResource[] wors = MVAMFGMWorkOrderResource.GetofWorkOrderOperation(woo, null, null); foreach (MVAMFGMWorkOrderResource wor in wors) { String chargeType = wor.GetVAMFG_ChargeType(); if (!((chargeType.Equals(X_VAMFG_M_WorkOrderResource.VAMFG_CHARGETYPE_Automatic) && automatic) || (chargeType.Equals(X_VAMFG_M_WorkOrderResource.VAMFG_CHARGETYPE_Manual) && !automatic))) { continue; } //calculated values Decimal resAmt = Decimal.Zero; //Resource amount to be charged //if product assembly quantity, Qty, is null then derive based on how many have already been charged //if estimated amt as indicated by WorkOrder Resource is already, then don't charge any more if (Qty == null) { Decimal resCharged = wor.GetVAMFG_QtySpent(); Decimal resReq = Decimal.Multiply(wo.GetVAMFG_QtyEntered(), (wor.GetVAMFG_QtyRequired())); resAmt = Decimal.Subtract(resReq, (resCharged)); if (resAmt.CompareTo(Decimal.Zero) <= 0) { log.Warning("Estimated Resource usage has been already charged."); continue; } } else { resAmt = Decimal.Multiply(Qty.Value, (wor.GetVAMFG_QtyRequired())); } MVAMFGMWrkOdrRscTxnLine wortl = new MVAMFGMWrkOdrRscTxnLine(ctx, 0, trx); //wortl.SetVAMFG_QtyEntered(resAmt.setScale(MUOM.getPrecision(ctx, wor.getC_UOM_ID()), Decimal.ROUND_HALF_UP)); wortl.SetVAMFG_QtyEntered(Decimal.Round((resAmt), VAdvantage.Model.MUOM.GetPrecision(ctx, wor.GetC_UOM_ID()), MidpointRounding.AwayFromZero)); // set fields from parent Work Order Transaction wortl.SetVAMFG_M_WrkOdrTransaction_ID(M_WorkOrderTransaction_ID); wortl.SetClientOrg(wot); // set fields from Work Order Resource wortl.Setresourceinfo(wor); //increase the VAMFG_SeqNo for each WOResourceTxnLine resTxnLineSeqNo += 10; wortl.SetVAMFG_SeqNo(resTxnLineSeqNo); wortl.SetIsActive(true); //Add to the return ArrayList wortLines.Add(wortl); ViennaAdvantage.Model.MProduct product = ViennaAdvantage.Model.MProduct.Get(ctx, wortl.GetM_Product_ID()); response.Append(product.GetName() + ": ").Append(wortl.GetVAMFG_QtyEntered()); if (!wortl.Save()) { log.Severe("Could not save resource transaction line."); } } } if (save) { try { if (!VAdvantage.Model.PO.SaveAll(trx, wortLines)) { log.Severe("Could not save resource transaction line."); return(null); } } catch { } } log.SaveInfo("Info", response.ToString()); // return (MVAMFGMWrkOdrRscTxnLine[])wortLines.ToArray(); MVAMFGMWrkOdrRscTxnLine[] newObject = null; try { newObject = (MVAMFGMWrkOdrRscTxnLine[])wortLines.ToArray(typeof(MVAMFGMWrkOdrRscTxnLine)); return(newObject); } catch { } return((MVAMFGMWrkOdrRscTxnLine[])wortLines.ToArray()); }
/** * Create Trial Asset * @param ctx context * @param user user * @param entityType entity type * @return asset or null if no product found */ public static MAsset GetTrial(Ctx ctx, MUser user, String entityType) { if (user == null) { _log.Warning("Cannot create Trial - No User"); return(null); } if (Util.IsEmpty(entityType)) { _log.Warning("Cannot create Trial - No Entity Type"); return(null); } MProduct product = MProduct.GetTrial(ctx, entityType); if (product == null) { _log.Warning("No Trial for Entity Type=" + entityType); return(null); } // DateTime now = Convert.ToDateTime(CommonFunctions.CurrentTimeMillis()); // MAsset asset = new MAsset(ctx, 0, null); asset.SetClientOrg(user); asset.SetAssetServiceDate(now); asset.SetIsOwned(false); asset.SetIsTrialPhase(true); // MBPartner partner = new MBPartner(ctx, user.GetC_BPartner_ID(), null); String documentNo = "Trial"; // Value String value = partner.GetValue() + "_" + product.GetValue(); if (value.Length > 40 - documentNo.Length) { value = value.Substring(0, 40 - documentNo.Length) + documentNo; } asset.SetValue(value); // Name MProduct.afterSave String name = "Trial " + partner.GetName() + " - " + product.GetName(); if (name.Length > 60) { name = name.Substring(0, 60); } asset.SetName(name); // Description String description = product.GetDescription(); asset.SetDescription(description); // User asset.SetAD_User_ID(user.GetAD_User_ID()); asset.SetC_BPartner_ID(user.GetC_BPartner_ID()); // Product asset.SetM_Product_ID(product.GetM_Product_ID()); asset.SetA_Asset_Group_ID(product.GetA_Asset_Group_ID()); asset.SetQty(new Decimal(product.GetSupportUnits())); // Guarantee & Version asset.SetGuaranteeDate(TimeUtil.AddDays(now, product.GetTrialPhaseDays())); asset.SetVersionNo(product.GetVersionNo()); // return(asset); }
protected override bool BeforeSave(bool newRecord) { // Movement Quantity can not be less than 0 when planned is greater than 0 if (GetPlannedQty() > 0 && GetMovementQty() < 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbelesszero")); return(false); } // Movement Quantity can not be greater than 0 when planned is less than 0 if (GetPlannedQty() < 0 && GetMovementQty() > 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbegrtzero")); return(false); } MProduct product = new MProduct(GetCtx(), GetM_Product_ID(), Get_TrxName()); if (newRecord && product != null) { if (Util.GetValueOfString(product.Get_Value("IsSlopeOil")) == "True" && GetMovementQty() < 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbelesszero")); return(false); } if (Util.GetValueOfString(product.Get_Value("IsSlopeOil")) == "False" && GetMovementQty() > 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbegrtzero")); return(false); } } X_M_ProductionPlan plan = new X_M_ProductionPlan(GetCtx(), GetM_ProductionPlan_ID(), Get_TrxName()); if (Util.GetValueOfDecimal(plan.Get_Value("GOM01_ComponentLimit")) > 0 && GetPlannedQty() < 0) { decimal ComputedQty = (GetPlannedQty() * Util.GetValueOfDecimal(plan.Get_Value("GOM01_ComponentLimit"))) / 100; ComputedQty = decimal.Negate(GetPlannedQty() + ComputedQty); if (decimal.Negate(GetMovementQty()) > ComputedQty) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "GOM01_QtyConsumption")); return(false); } } // when warehouse disallow negative inventory is false then on hand qty can't be in negative wh = MWarehouse.Get(GetCtx(), GetM_Warehouse_ID()); if (wh.IsDisallowNegativeInv() && GetM_Product_ID() > 0) { product = MProduct.Get(GetCtx(), GetM_Product_ID()); string qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); //if (GetM_AttributeSetInstance_ID() != 0) //{ qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID(); //} Decimal?OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); qry = @"SELECT NVL(SUM(MovementQty) , 0) FROM M_ProductionLine WHERE IsActive = 'Y' AND M_Locator_ID=" + GetM_Locator_ID() + @" AND m_product_id=" + GetM_Product_ID() + @" AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID() + @" AND M_Production_ID = " + GetM_Production_ID(); if (!newRecord) { qry += @" AND M_ProductionLine_ID <> " + GetM_ProductionLine_ID(); } Decimal?moveQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); if ((OnHandQty + GetMovementQty() + moveQty) < 0) { log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } } return(true); }
/// <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); }