public bool SetProductQty1(int recordID, string keyColName, List <string> product, List <string> attribute, List <string> qty, List <string> oline_ID, List <string> locID, int LocToID, List <string> AssetID, int lineID, VAdvantage.Utility.Ctx ctx) { if (keyColName.ToUpper().Trim() == "M_MOVEMENT_ID") { MMovement inv = new MMovement(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MMovementLine invline = new MMovementLine(ctx, lineID, null); invline.SetAD_Client_ID(inv.GetAD_Client_ID()); invline.SetAD_Org_ID(inv.GetAD_Org_ID()); invline.SetM_Locator_ID(Util.GetValueOfInt(locID[i])); invline.SetM_LocatorTo_ID(LocToID); invline.SetM_Product_ID(Util.GetValueOfInt(product[i])); invline.SetMovementQty(Util.GetValueOfDecimal(qty[i])); invline.SetM_Movement_ID(recordID); if (Util.GetValueOfInt(AssetID[i]) > 0) { invline.SetA_Asset_ID(Util.GetValueOfInt(AssetID[i])); } if (Util.GetValueOfInt(oline_ID[i]) > 0) { invline.SetM_RequisitionLine_ID(Util.GetValueOfInt(oline_ID[i])); } if (Util.GetValueOfInt(attribute[i]) != 0) { invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!invline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "M_INVENTORY_ID") { MInventory inv = new MInventory(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MInventoryLine invline = new MInventoryLine(ctx, lineID, null); invline.SetAD_Client_ID(inv.GetAD_Client_ID()); invline.SetAD_Org_ID(inv.GetAD_Org_ID()); invline.SetM_Product_ID(Util.GetValueOfInt(product[i])); invline.SetQtyInternalUse(Util.GetValueOfDecimal(qty[i])); invline.SetC_Charge_ID(Util.GetValueOfInt(AssetID[i])); invline.SetM_Inventory_ID(recordID); invline.SetIsInternalUse(true); invline.SetM_RequisitionLine_ID(Util.GetValueOfInt(oline_ID[i])); if (Util.GetValueOfInt(attribute[i]) != 0) { invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } else { invline.SetM_AttributeSetInstance_ID(0); } if (!invline.Save()) { } } } return(true); }
/// <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); }
public bool SetProductQty(int recordID, string keyColName, List <string> product, List <string> attribute, List <string> qty, List <string> qtybook, List <string> oline_ID, int ordID, List <string> locID, int lineID, VAdvantage.Utility.Ctx ctx) { if (keyColName.ToUpper().Trim() == "C_ORDER_ID") { MOrder ord = new MOrder(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MOrderLine oline = new MOrderLine(ctx, lineID, null); oline.SetAD_Client_ID(ord.GetAD_Client_ID()); oline.SetAD_Org_ID(ord.GetAD_Org_ID()); oline.SetM_Product_ID(Util.GetValueOfInt(product[i])); oline.SetQty(Util.GetValueOfDecimal(qty[i])); oline.SetC_Order_ID(recordID); if (Util.GetValueOfInt(attribute[i]) != 0) { oline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!ord.IsSOTrx()) { MProduct pro = new MProduct(ctx, oline.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=" + oline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + ord.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= " + oline.GetM_Product_ID() + " AND IsActive='Y'")); if (Res > 0) { oline.SetQtyEntered(oline.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) { oline.SetQtyEntered(oline.GetQtyEntered() * res); //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); } } oline.SetC_UOM_ID(uom); } else { oline.SetC_UOM_ID(pro.GetC_UOM_ID()); } } } if (!oline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "C_INVOICE_ID") { MInvoice inv = new MInvoice(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MInvoiceLine invline = new MInvoiceLine(ctx, lineID, null); invline.SetAD_Client_ID(inv.GetAD_Client_ID()); invline.SetAD_Org_ID(inv.GetAD_Org_ID()); invline.SetM_Product_ID(Util.GetValueOfInt(product[i])); invline.SetQty(Util.GetValueOfDecimal(qty[i])); invline.SetC_Invoice_ID(recordID); if (Util.GetValueOfInt(attribute[i]) != 0) { invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!inv.IsSOTrx()) { MProduct pro = new MProduct(ctx, invline.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=" + invline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inv.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= " + invline.GetM_Product_ID() + " AND IsActive='Y'")); if (Res > 0) { invline.SetQtyEntered(invline.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) { invline.SetQtyEntered(invline.GetQtyEntered() * res); //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); } } invline.SetC_UOM_ID(uom); } else { invline.SetC_UOM_ID(pro.GetC_UOM_ID()); } } } if (!invline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "M_INOUT_ID") { MInOut inv = new MInOut(ctx, recordID, null); if (ordID > 0) { inv.SetC_Order_ID(ordID); } if (inv.Save()) { for (int i = 0; i < product.Count; i++) { MInOutLine ioline = new MInOutLine(ctx, lineID, null); ioline.SetAD_Client_ID(inv.GetAD_Client_ID()); ioline.SetAD_Org_ID(inv.GetAD_Org_ID()); ioline.SetM_Product_ID(Util.GetValueOfInt(product[i])); ioline.SetQty(Util.GetValueOfDecimal(qty[i])); ioline.SetM_InOut_ID(recordID); ioline.SetC_OrderLine_ID(Util.GetValueOfInt(oline_ID[i])); ioline.SetM_Locator_ID(Util.GetValueOfInt(locID[i])); if (Util.GetValueOfInt(attribute[i]) != 0) { ioline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } if (!inv.IsSOTrx()) { MProduct pro = new MProduct(ctx, ioline.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=" + ioline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inv.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= " + ioline.GetM_Product_ID() + " AND IsActive='Y'")); if (Res > 0) { ioline.SetQtyEntered(ioline.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) { ioline.SetQtyEntered(ioline.GetQtyEntered() * res); //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty); } } ioline.SetC_UOM_ID(uom); } else { ioline.SetC_UOM_ID(pro.GetC_UOM_ID()); } } } if (!ioline.Save()) { } } } } else if (keyColName.ToUpper().Trim() == "M_PACKAGE_ID") { MPackage pkg = new MPackage(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MPackageLine mline = new MPackageLine(ctx, lineID, null); mline.SetAD_Client_ID(pkg.GetAD_Client_ID()); mline.SetAD_Org_ID(pkg.GetAD_Org_ID()); mline.SetM_Product_ID(Util.GetValueOfInt(product[i])); mline.SetQty(Util.GetValueOfDecimal(qty[i])); if (Util.GetValueOfInt(oline_ID[i]) > 0) { mline.SetM_MovementLine_ID(Util.GetValueOfInt(oline_ID[i])); MMovementLine mov = new MMovementLine(ctx, Util.GetValueOfInt(oline_ID[i]), null); mline.SetDTD001_TotalQty(mov.GetMovementQty()); } if (Util.GetValueOfInt(attribute[i]) != 0) { mline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } mline.SetM_Package_ID(recordID); if (!mline.Save()) { } } } else if (keyColName.ToUpper().Trim() == "M_INVENTORY_ID") { MInventory inv = new MInventory(ctx, recordID, null); for (int i = 0; i < product.Count; i++) { MInventoryLine invline = new MInventoryLine(ctx, lineID, null); invline.SetAD_Client_ID(inv.GetAD_Client_ID()); invline.SetAD_Org_ID(inv.GetAD_Org_ID()); invline.SetM_Locator_ID(Util.GetValueOfInt(locID[i])); invline.SetM_Product_ID(Util.GetValueOfInt(product[i])); invline.SetQtyCount(Util.GetValueOfDecimal(qty[i])); invline.SetQtyBook(Util.GetValueOfDecimal(qtybook[i])); invline.SetAsOnDateCount(Util.GetValueOfDecimal(qty[i])); invline.SetOpeningStock(Util.GetValueOfDecimal(qtybook[i])); invline.SetM_Inventory_ID(recordID); if (Util.GetValueOfInt(attribute[i]) != 0) { invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i])); } else { invline.SetM_AttributeSetInstance_ID(0); } if (!invline.Save()) { } } } return(true); }
/// <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); }