/// <summary> /// Load Invoice Line /// </summary> /// <param name="move"></param> /// <returns>document lines (DocLine_Material)</returns> private DocLine[] LoadLines(MMovement move) { List <DocLine> list = new List <DocLine>(); MMovementLine[] lines = move.GetLines(false); for (int i = 0; i < lines.Length; i++) { MMovementLine line = lines[i]; DocLine docLine = new DocLine(line, this); docLine.SetQty(line.GetMovementQty(), false); // log.Fine(docLine.ToString()); list.Add(docLine); } // Return Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); return(dls); }
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> /// Process /// </summary> /// <returns>info</returns> protected override String DoIt() { log.Info("M_Movement_ID=" + _m_Movement_ID + ", M_Locator_ID=" + _m_Locator_ID + ", M_LocatorTo_ID=" + _m_LocatorTo_ID + ", M_Product_ID=" + _m_product_ID + ", M_Product_Category_ID=" + _m_Product_Category_ID + ", QtyRange=" + _qtyRange + ", DeleteOld=" + _deleteOld); _movement = new MMovement(GetCtx(), _m_Movement_ID, Get_Trx()); if (_movement.Get_ID() == 0) { throw new SystemException("Not found: M_Movement_ID=" + _m_Movement_ID); } if (_movement.IsProcessed()) { throw new SystemException("@M_Movement_ID@ @Processed@"); } // String sqlQry = ""; if (_deleteOld) { sqlQry = "DELETE FROM M_MovementLine WHERE Processed='N' " + "AND M_Movement_ID=" + _m_Movement_ID; int no = DB.ExecuteQuery(sqlQry, null, Get_Trx()); log.Fine("doIt - Deleted #" + no); } // Create Null Storage records if (_qtyRange != null && _qtyRange.Equals("=")) { sqlQry = "INSERT INTO M_Storage " + "(AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy," + " M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID," + " qtyOnHand, QtyReserved, QtyOrdered, DateLastInventory) " + "SELECT l.AD_CLIENT_ID, l.AD_ORG_ID, 'Y', SysDate, 0,SysDate, 0," + " l.M_Locator_ID, p.M_Product_ID, 0," + " 0,0,0,null " + "FROM M_Locator l" + " INNER JOIN M_Product p ON (l.AD_Client_ID=p.AD_Client_ID) " + "WHERE l.M_Warehouse_ID=" + _movement.GetM_Warehouse_ID(); if (_m_Locator_ID != 0) { sqlQry += " AND l.M_Locator_ID=" + _m_Locator_ID; } sqlQry += " AND l.IsDefault='Y'" + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'" + " AND NOT EXISTS (SELECT * FROM M_Storage s" + " INNER JOIN M_Locator sl ON (s.M_Locator_ID=sl.M_Locator_ID) " + "WHERE sl.M_Warehouse_ID=l.M_Warehouse_ID" + " AND s.M_Product_ID=p.M_Product_ID)"; int no = DB.ExecuteQuery(sqlQry, null, Get_Trx()); log.Fine("'0' Inserted #" + no); } StringBuilder sql = new StringBuilder( "SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID," + " s.qtyOnHand, p.M_AttributeSet_ID " + "FROM M_Product p" + " INNER JOIN M_Storage s ON (s.M_Product_ID=p.M_Product_ID)" + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) " + "WHERE l.M_Warehouse_ID=" + _movement.GetDTD001_MWarehouseSource_ID() + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'"); // if (_m_Locator_ID != 0) { sql.Append(" AND s.M_Locator_ID=" + _m_Locator_ID); } // if (_m_product_ID != null && !string.IsNullOrEmpty(_m_product_ID)) { sql.Append(" AND p.M_Product_ID IN ( " + _m_product_ID + ") "); } // if (_m_Product_Category_ID != 0) { sql.Append(" AND p.M_Product_Category_ID=" + _m_Product_Category_ID); } // Do not overwrite existing records if (!_deleteOld) { sql.Append(" AND NOT EXISTS (SELECT * FROM M_MovementLine il " + "WHERE il.M_Movement_ID=" + _m_Movement_ID + " AND il.M_Product_ID=s.M_Product_ID" + " AND il.M_Locator_ID=s.M_Locator_ID" + " AND COALESCE(il.M_AttributeSetInstance_ID,0)=COALESCE(s.M_AttributeSetInstance_ID,0))"); } // + " AND il.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID)"); // sql.Append(" ORDER BY l.Value, p.Value, s.qtyOnHand DESC"); // Locator/Product // int count = 0; IDataReader idr = null; try { idr = DB.ExecuteReader(sql.ToString(), null, Get_Trx()); while (idr.Read()) { int M_Product_ID = Util.GetValueOfInt(idr[0]); int M_Locator_ID = Util.GetValueOfInt(idr[1]); int M_AttributeSetInstance_ID = Util.GetValueOfInt(idr[2]); Decimal qtyOnHand = Util.GetValueOfDecimal(idr[3]); if (qtyOnHand == null) { qtyOnHand = Env.ZERO; } int M_AttributeSet_ID = Util.GetValueOfInt(idr[4]); // int compare = qtyOnHand.CompareTo(Env.ZERO); if (_qtyRange == null || (_qtyRange.Equals(">") && compare > 0) || (_qtyRange.Equals("<") && compare < 0) || (_qtyRange.Equals("=") && compare == 0) || (_qtyRange.Equals("N") && compare != 0)) { //Save data on Movement Line _line = new MMovementLine(GetCtx(), 0, Get_Trx()); _line.SetAD_Client_ID(_movement.GetAD_Client_ID()); _line.SetAD_Org_ID(_movement.GetAD_Org_ID()); _line.SetM_Movement_ID(_m_Movement_ID); _line.SetM_Locator_ID(_m_Locator_ID); _line.SetM_LocatorTo_ID(_m_LocatorTo_ID); _line.SetMovementQty(qtyOnHand); _line.SetProcessed(false); _line.SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID); _line.SetM_Product_ID(M_Product_ID); if (!_line.Save()) { log.Info("Movement Line Not Created for M_Product_ID = " + M_Product_ID + " M_AttributeSetInstance = " + M_AttributeSetInstance_ID); } else { count = count + 1; } } } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql.ToString(), e); } // return("@M_MovementLine_ID@ - #" + count); }
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> /// Process /// </summary> /// <returns>info</returns> protected override String DoIt() { log.Info("M_Movement_ID=" + _m_Movement_ID + ", M_Locator_ID=" + _m_Locator_ID + ", M_LocatorTo_ID=" + _m_LocatorTo_ID + ", M_Product_ID=" + _m_product_ID + ", M_Product_Category_ID=" + _m_Product_Category_ID + ", QtyRange=" + _qtyRange + ", DeleteOld=" + _deleteOld); _movement = new MMovement(GetCtx(), _m_Movement_ID, Get_Trx()); if (_movement.Get_ID() == 0) { throw new SystemException("Not found: M_Movement_ID=" + _m_Movement_ID); } if (_movement.IsProcessed()) { throw new SystemException("@M_Movement_ID@ @Processed@"); } // is used to check Container applicable into system isContainerApplicable = MTransaction.ProductContainerApplicable(GetCtx()); // String sqlQry = ""; if (_deleteOld) { sqlQry = "DELETE FROM M_MovementLine WHERE Processed='N' " + "AND M_Movement_ID=" + _m_Movement_ID; int no = DB.ExecuteQuery(sqlQry, null, Get_Trx()); log.Fine("doIt - Deleted #" + no); } // Create Null Storage records if (_qtyRange != null && _qtyRange.Equals("=")) { sqlQry = "INSERT INTO M_Storage " + "(AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy," + " M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID," + " qtyOnHand, QtyReserved, QtyOrdered, DateLastInventory) " + "SELECT l.AD_CLIENT_ID, l.AD_ORG_ID, 'Y', SysDate, 0,SysDate, 0," + " l.M_Locator_ID, p.M_Product_ID, 0," + " 0,0,0,null " + "FROM M_Locator l" + " INNER JOIN M_Product p ON (l.AD_Client_ID=p.AD_Client_ID) " + "WHERE l.M_Warehouse_ID=" + _movement.GetM_Warehouse_ID(); if (_m_Locator_ID != 0) { sqlQry += " AND l.M_Locator_ID=" + _m_Locator_ID; } sqlQry += " AND l.IsDefault='Y'" + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'" + " AND NOT EXISTS (SELECT * FROM M_Storage s" + " INNER JOIN M_Locator sl ON (s.M_Locator_ID=sl.M_Locator_ID) " + "WHERE sl.M_Warehouse_ID=l.M_Warehouse_ID" + " AND s.M_Product_ID=p.M_Product_ID)"; int no = DB.ExecuteQuery(sqlQry, null, Get_Trx()); log.Fine("'0' Inserted #" + no); } StringBuilder sql = null; if (!isContainerApplicable) { sql = new StringBuilder( "SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID," + " s.qtyOnHand, p.M_AttributeSet_ID, 0 AS M_ProductContainer_ID " + "FROM M_Product p" + " INNER JOIN M_Storage s ON (s.M_Product_ID=p.M_Product_ID)" + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) " + "WHERE l.M_Warehouse_ID=" + _movement.GetDTD001_MWarehouseSource_ID() + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'"); } else { sql = new StringBuilder( "SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID," + " NVL(SUM(s.Qty) , 0) AS qtyOnHand , p.M_AttributeSet_ID, s.M_ProductContainer_ID " + "FROM M_Product p" + " INNER JOIN M_ContainerStorage s ON (s.M_Product_ID=p.M_Product_ID)" + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) " + "WHERE l.M_Warehouse_ID=" + _movement.GetDTD001_MWarehouseSource_ID() + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'"); } // if (_m_Locator_ID != 0) { sql.Append(" AND s.M_Locator_ID=" + _m_Locator_ID); } // if (_m_product_ID != null && !string.IsNullOrEmpty(_m_product_ID)) { sql.Append(" AND p.M_Product_ID IN ( " + _m_product_ID + ") "); } // if (_m_Product_Category_ID != 0) { sql.Append(" AND p.M_Product_Category_ID=" + _m_Product_Category_ID); } // Do not overwrite existing records if (!_deleteOld) { sql.Append(" AND NOT EXISTS (SELECT * FROM M_MovementLine il " + "WHERE il.M_Movement_ID=" + _m_Movement_ID + " AND il.M_Product_ID=s.M_Product_ID" + " AND il.M_Locator_ID=s.M_Locator_ID" + " AND COALESCE(il.M_AttributeSetInstance_ID,0)=COALESCE(s.M_AttributeSetInstance_ID,0)"); if (!isContainerApplicable) { sql.Append(@" ) "); } else { sql.Append(@" AND COALESCE(il.M_ProductContainer_ID,0)=COALESCE(s.M_ProductContainer_ID,0) ) "); } } // if (!isContainerApplicable) { sql.Append(" ORDER BY l.Value, p.Value, s.qtyOnHand DESC"); // Locator/Product } else { sql.Append(@" GROUP BY s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID, p.M_AttributeSet_ID, s.M_ProductContainer_ID, s.Qty ORDER BY s.M_Locator_ID, s.M_Product_ID, s.Qty DESC, s.M_AttributeSetInstance_ID, p.M_AttributeSet_ID,s.M_ProductContainer_ID"); // Locator/Product } // int count = 0; IDataReader idr = null; DataTable dt = null; MProduct product = null; try { idr = DB.ExecuteReader(sql.ToString(), null, Get_Trx()); dt = new DataTable(); dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows) // while (idr.Read()) { int M_Product_ID = Util.GetValueOfInt(dr[0]); product = MProduct.Get(GetCtx(), M_Product_ID); int M_Locator_ID = Util.GetValueOfInt(dr[1]); int M_AttributeSetInstance_ID = Util.GetValueOfInt(dr[2]); Decimal qtyOnHand = Util.GetValueOfDecimal(dr[3]); //if (qtyOnHand == null) commented by manjot Because Decimal is Never equals to Null // qtyOnHand = Env.ZERO; int M_AttributeSet_ID = Util.GetValueOfInt(dr[4]); //container int container_Id = Util.GetValueOfInt(dr[5]); // int compare = qtyOnHand.CompareTo(Env.ZERO); if (_qtyRange == null || (_qtyRange.Equals(">") && compare > 0) || (_qtyRange.Equals("<") && compare < 0) || (_qtyRange.Equals("=") && compare == 0) || (_qtyRange.Equals("N") && compare != 0)) { //Save data on Movement Line _line = new MMovementLine(GetCtx(), 0, Get_Trx()); _line.SetAD_Client_ID(_movement.GetAD_Client_ID()); _line.SetAD_Org_ID(_movement.GetAD_Org_ID()); _line.SetM_Movement_ID(_m_Movement_ID); _line.SetM_Locator_ID(_m_Locator_ID); _line.SetM_LocatorTo_ID(_m_LocatorTo_ID); _line.SetMovementQty(qtyOnHand); _line.SetProcessed(false); _line.SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID); _line.SetM_Product_ID(M_Product_ID); if (isContainerApplicable && _line.Get_ColumnIndex("M_ProductContainer_ID") > 0) { _line.SetM_ProductContainer_ID(container_Id); } if (_line.Get_ColumnIndex("C_UOM_ID") > 0 && product != null) { _line.SetC_UOM_ID(product.GetC_UOM_ID()); } if (_line.Get_ColumnIndex("QtyEntered") > 0) { _line.SetQtyEntered(qtyOnHand); } if (!_line.Save()) { return(GetRetrievedError(_line, "Movement Line Not Created for M_Product_ID = " + M_Product_ID + " M_AttributeSetInstance = " + M_AttributeSetInstance_ID)); //log.Info("Movement Line Not Created for M_Product_ID = " + M_Product_ID + " M_AttributeSetInstance = " + M_AttributeSetInstance_ID); } else { count = count + 1; } } } //idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql.ToString(), e); } // return("@M_MovementLine_ID@ - #" + count); }
} // createRequisition /// <summary> /// Create Inventory Movements /// </summary> private void CreateMovements() { int noMoves = 0; String info = ""; // MClient client = null; MMovement move = null; int M_Warehouse_ID = 0; int M_WarehouseSource_ID = 0; MWarehouse whSource = null; MWarehouse whTarget = null; string param = ""; if (_M_WareSource != null) { param = _M_WareSource; } else { param = "M_WarehouseSource_ID IS NOT NULL"; } X_T_Replenish[] replenishs = GetReplenish(param);; for (int i = 0; i < replenishs.Length; i++) { X_T_Replenish replenish = replenishs[i]; if (whSource == null || whSource.GetM_WarehouseSource_ID() != replenish.GetM_WarehouseSource_ID()) { whSource = MWarehouse.Get(GetCtx(), replenish.GetM_WarehouseSource_ID()); } if (whTarget == null || whTarget.GetM_Warehouse_ID() != replenish.GetM_Warehouse_ID()) { whTarget = MWarehouse.Get(GetCtx(), replenish.GetM_Warehouse_ID()); } if (client == null || client.GetAD_Client_ID() != whSource.GetAD_Client_ID()) { client = MClient.Get(GetCtx(), whSource.GetAD_Client_ID()); } // if (move == null || M_WarehouseSource_ID != replenish.GetM_WarehouseSource_ID() || M_Warehouse_ID != replenish.GetM_Warehouse_ID()) { M_WarehouseSource_ID = replenish.GetM_WarehouseSource_ID(); M_Warehouse_ID = replenish.GetM_Warehouse_ID(); move = new MMovement(GetCtx(), 0, Get_TrxName()); move.SetC_DocType_ID(_C_DocType_ID); move.SetDescription(Msg.GetMsg(GetCtx(), "Replenishment") + ": " + whSource.GetName() + "->" + whTarget.GetName()); // Set Org move.SetAD_Org_ID(whSource.GetAD_Org_ID()); if (!move.Save()) { return; } log.Fine(move.ToString()); noMoves++; info += " - " + move.GetDocumentNo(); } MProduct product = MProduct.Get(GetCtx(), replenish.GetM_Product_ID()); // To int M_LocatorTo_ID = GetLocator_ID(product, whTarget); // From: Look-up Storage MProductCategory pc = MProductCategory.Get(GetCtx(), product.GetM_Product_Category_ID()); String MMPolicy = pc.GetMMPolicy(); if (MMPolicy == null || MMPolicy.Length == 0) { MMPolicy = client.GetMMPolicy(); } // MStorage[] storages = MStorage.GetWarehouse(GetCtx(), whSource.GetM_Warehouse_ID(), replenish.GetM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.Equals(MMPolicy), Get_TrxName()); if (storages == null || storages.Length == 0) { AddLog("No Inventory in " + whSource.GetName() + " for " + product.GetName()); continue; } // Decimal target = replenish.GetQtyToOrder(); for (int j = 0; j < storages.Length; j++) { MStorage storage = storages[j]; //if (storage.GetQtyOnHand().signum() <= 0) if (Env.Signum(storage.GetQtyOnHand()) <= 0) { continue; } Decimal moveQty = target; if (storage.GetQtyOnHand().CompareTo(moveQty) < 0) { moveQty = storage.GetQtyOnHand(); } // MMovementLine line = new MMovementLine(move); line.SetM_Product_ID(replenish.GetM_Product_ID()); line.SetMovementQty(moveQty); if (replenish.GetQtyToOrder().CompareTo(moveQty) != 0) { line.SetDescription("Total: " + replenish.GetQtyToOrder()); } line.SetM_Locator_ID(storage.GetM_Locator_ID()); // from line.SetM_AttributeSetInstance_ID(storage.GetM_AttributeSetInstance_ID()); line.SetM_LocatorTo_ID(M_LocatorTo_ID); // to line.SetM_AttributeSetInstanceTo_ID(storage.GetM_AttributeSetInstance_ID()); line.Save(); // //target = target.subtract(moveQty); target = Decimal.Subtract(target, moveQty); //if (target.signum() == 0) if (Env.Signum(target) == 0) { break; } } if (Env.Signum(target) != 0) { AddLog("Insufficient Inventory in " + whSource.GetName() + " for " + product.GetName() + " Qty=" + target); } } if (replenishs.Length == 0) { _info = "No Source Warehouse"; log.Warning(_info); } else { _info = "#" + noMoves + info; log.Info(_info); } } // createRequisition
/// <summary> /// Move stock to location /// </summary> /// <param name="target">storage</param> /// <returns>no of movements</returns> private int Move(MStorage target) { log.Info(target.ToString()); Decimal qty = Decimal.Negate(target.GetQtyOnHand());//.negate(); // Create Movement MMovement mh = new MMovement(GetCtx(), 0, Get_Trx()); mh.SetC_DocType_ID(_C_DocType_ID); mh.SetDescription(GetName()); if (!mh.Save()) { return(0); } int lines = 0; MStorage[] sources = GetSources(target.GetM_Product_ID(), target.GetM_Locator_ID()); for (int i = 0; i < sources.Length; i++) { MStorage source = sources[i]; // Movement Line MMovementLine ml = new MMovementLine(mh); ml.SetM_Product_ID(target.GetM_Product_ID()); ml.SetM_LocatorTo_ID(target.GetM_Locator_ID()); ml.SetM_AttributeSetInstanceTo_ID(target.GetM_AttributeSetInstance_ID()); // From ml.SetM_Locator_ID(source.GetM_Locator_ID()); ml.SetM_AttributeSetInstance_ID(source.GetM_AttributeSetInstance_ID()); Decimal qtyMove = qty; if (qtyMove.CompareTo(source.GetQtyOnHand()) > 0) { qtyMove = source.GetQtyOnHand(); } ml.SetMovementQty(qtyMove); // lines++; ml.SetLine(lines * 10); if (!ml.Save()) { return(0); } qty = Decimal.Subtract(qty, qtyMove); if (Env.Signum(qty) <= 0) { break; } } // for all movements // Process //mh.ProcessIt(MMovement.ACTION_Complete); mh.ProcessIt(DocActionVariables.ACTION_COMPLETE); mh.Save(); AddLog(0, null, new Decimal(lines), "@M_Movement_ID@ " + mh.GetDocumentNo() + " (" + MRefList.Get(GetCtx(), MMovement.DOCSTATUS_AD_Reference_ID, mh.GetDocStatus(), Get_Trx()) + ")"); EliminateReservation(target); return(lines); }
/// <summary> /// is used to save data in case of Full move container / full qty move /// </summary> /// <param name="movementId">movement header refernce</param> /// <param name="fromLocatorId">From Locator - from where we have to move product</param> /// <param name="fromContainerId">From Container - from which container, we have to move product</param> /// <param name="toLocatorId">To Locator - where we are moving product</param> /// <param name="toContainerId">To container - in which container we are moving product</param> /// <param name="lineNo"></param> /// <param name="isMoveFullContainerQty">Is Container also move with Product</param> /// <param name="trx">Self created Trx</param> /// <returns>Message : lines inserted or not</returns> public String SaveMoveLinewithFullContainer(int movementId, int fromLocatorId, int fromContainerId, int toLocatorId, int toContainerId, int lineNo, bool isMoveFullContainerQty, Trx trx) { MMovement movement = new MMovement(_ctx, movementId, trx); string childContainerId = null; StringBuilder error = new StringBuilder(); // Get Path upto selected container string sql = @"SELECT sys_connect_by_path(m_productcontainer_id,'->') tree FROM m_productcontainer WHERE m_productcontainer_id = " + fromContainerId + @" START WITH ref_m_container_id IS NULL CONNECT BY prior m_productcontainer_id = ref_m_container_id ORDER BY tree "; string pathContainer = Util.GetValueOfString(DB.ExecuteScalar(sql, null, trx)); // child records with Parent Id if (!isMoveFullContainerQty) { sql = @"SELECT tree, m_productcontainer_id FROM (SELECT sys_connect_by_path(m_productcontainer_id,'->') tree , m_productcontainer_id FROM m_productcontainer START WITH ref_m_container_id IS NULL CONNECT BY prior m_productcontainer_id = ref_m_container_id ORDER BY tree ) WHERE tree LIKE ('" + pathContainer + "%') "; DataSet ds = DB.ExecuteDataset(sql, null, trx); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (String.IsNullOrEmpty(childContainerId)) { childContainerId = Util.GetValueOfString(ds.Tables[0].Rows[i]["m_productcontainer_id"]); } else { childContainerId += "," + Util.GetValueOfString(ds.Tables[0].Rows[i]["m_productcontainer_id"]); } } } ds.Dispose(); } else { childContainerId = fromContainerId.ToString(); } // check is same container already moved to another container // Ex :: p1 -> c1 and p1 -> c2 // OR also check -- is any other container is moving into exist target container // Ex :: p1 -> c1 and p2 -> p1 if (!isMoveFullContainerQty) { if (!IsContainerMoved(movementId, pathContainer, childContainerId, toContainerId, trx)) { return(Msg.GetMsg(_ctx, "VIS_AlreadyMoved")); } } // not to move Parent container to its child container if (toContainerId > 0 && childContainerId.Contains(toContainerId.ToString())) { //Parent cant be Move to its own child return(Msg.GetMsg(_ctx, "VIS_cantMoveParentTochild")); } // Get All records of Parent Container and child container sql = @"SELECT * FROM ( SELECT p.M_PRODUCT_ID, p.NAME, p.C_UOM_ID, u.Name AS UomName, t.M_ATTRIBUTESETINSTANCE_ID, t.M_ProductContainer_ID, SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS ContainerCurrentQty FROM M_Transaction t INNER JOIN M_Product p ON p.M_Product_ID = t.M_Product_ID INNER JOIN C_UOM u ON u.C_UOM_ID = p.C_UOM_ID WHERE t.IsActive = 'Y' AND NVL(t.M_ProductContainer_ID, 0) IN ( " + childContainerId + @" ) AND t.MovementDate <=" + GlobalVariable.TO_DATE(movement.GetMovementDate(), true) + @" AND t.M_Locator_ID = " + fromLocatorId + @" AND t.AD_Client_ID = " + movement.GetAD_Client_ID() + @" GROUP BY p.M_PRODUCT_ID, p.NAME, p.C_UOM_ID, u.Name, t.M_ATTRIBUTESETINSTANCE_ID, t.M_ProductContainer_ID ) t WHERE ContainerCurrentQty <> 0 "; DataSet dsRecords = DB.ExecuteDataset(sql, null, trx); if (dsRecords != null && dsRecords.Tables.Count > 0 && dsRecords.Tables[0].Rows.Count > 0) { int movementlineId = 0; MMovementLine moveline = null; MProduct product = null; for (int i = 0; i < dsRecords.Tables[0].Rows.Count; i++) { movementlineId = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(M_MovementLine_ID, 0) AS M_Movement_ID FROM M_MovementLine WHERE M_Movement_ID = " + Util.GetValueOfInt(movementId) + @" AND M_Product_ID = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"]) + @" AND NVL(M_AttributeSetInstance_ID, 0) = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]) + @" AND M_Locator_ID = " + Util.GetValueOfInt(fromLocatorId) + @" AND NVL(M_ProductContainer_ID, 0) = " + Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]) + @" AND M_LocatorTo_ID = " + Util.GetValueOfInt(toLocatorId) + @" AND NVL(Ref_M_ProductContainerTo_ID, 0) = " + toContainerId + @" AND AD_Org_ID = " + movement.GetAD_Org_ID())); if (movementlineId > 0) { moveline = new MMovementLine(_ctx, movementlineId, trx); } else { moveline = new MMovementLine(_ctx, 0, trx); } if (movementlineId == 0) { #region Create new record of movement line lineNo += 10; moveline.SetAD_Client_ID(movement.GetAD_Client_ID()); moveline.SetAD_Org_ID(movement.GetAD_Org_ID()); moveline.SetM_Movement_ID(movement.GetM_Movement_ID()); moveline.SetLine(lineNo); moveline.SetM_Product_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"])); moveline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_AttributeSetInstance_ID"])); moveline.SetC_UOM_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["C_UOM_ID"])); moveline.SetM_Locator_ID(fromLocatorId); moveline.SetM_LocatorTo_ID(toLocatorId); moveline.SetM_ProductContainer_ID(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"])); moveline.SetRef_M_ProductContainerTo_ID(toContainerId); moveline.SetQtyEntered(Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"])); moveline.SetMovementQty(Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"])); moveline.SetMoveFullContainer(isMoveFullContainerQty ? false : true); // when move full container, then only need to update IsParentMove and Target container (which represent - to which container we are moving) // and set true value on those line which container are moving, not on its child container if (!isMoveFullContainerQty) { moveline.SetIsParentMove(Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_ProductContainer_ID"]) == fromContainerId ? true : false); moveline.SetTargetContainer_ID(fromContainerId); } #endregion } else { #region Update record of movement line moveline.SetQtyEntered(Decimal.Add(moveline.GetQtyEntered(), Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"]))); moveline.SetMovementQty(Decimal.Add(moveline.GetMovementQty(), Util.GetValueOfDecimal(dsRecords.Tables[0].Rows[i]["ContainerCurrentQty"]))); moveline.SetMoveFullContainer(true); #endregion } if (!moveline.Save(trx)) { #region Save error catch and rollback product = MProduct.Get(_ctx, Util.GetValueOfInt(dsRecords.Tables[0].Rows[i]["M_Product_ID"])); ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { _log.SaveError("Movement line not inserted through Move Container Form : ", pp.GetName()); if (String.IsNullOrEmpty(error.ToString())) { error.Append(Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName()); } else { error.Append(" , " + Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName()); } } trx.Rollback(); #endregion } else { trx.Commit(); } } } else { return(Msg.GetMsg(_ctx, "VIS_ContainerhaveNoRecord")); } return(String.IsNullOrEmpty(error.ToString()) ? "VIS_SuccessFullyInserted" : error.ToString()); }
/// <summary> /// Is used to save data on movememt line /// </summary> /// <param name="mData"></param> /// <returns></returns> public String SaveMovementLine(List <Dictionary <string, string> > mData) { StringBuilder error = new StringBuilder(); bool isMoveFullContainer = false; bool isMoveFullContainerQty = false; Trx trx = Trx.GetTrx("Movement"); if (mData.Count > 0) { isMoveFullContainer = Util.GetValueOfBool(mData[0]["IsFullMoveContainer"]); //to delete all the movement lines where MoveFullContainer is False if (isMoveFullContainer) { DB.ExecuteQuery("DELETE FROM M_MovementLine WHERE M_Movement_ID = " + Util.GetValueOfInt(mData[0]["M_Movement_ID"]) + " AND MoveFullContainer= 'N' ", null, null); } // Lines not inserted, as movement line already has a full move container line. if (!isMoveFullContainer) { if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(MoveFullContainer) FROM M_MovementLine WHERE MoveFullContainer= 'Y' AND M_Movement_ID = " + Util.GetValueOfInt(mData[0]["M_Movement_ID"]), null, trx)) > 0) { trx.Close(); return(Msg.GetMsg(_ctx, "VIS_LinehaveFullContainer")); } } // Get Line No int lineNo = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(MAX(Line),0) AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + Util.GetValueOfInt(mData[0]["M_Movement_ID"]), null, trx)); isMoveFullContainerQty = Util.GetValueOfBool(mData[0]["IsfullContainerQtyWise"]); if (!isMoveFullContainer && !isMoveFullContainerQty) { goto moveFullContainer; } else if (isMoveFullContainer || isMoveFullContainerQty) { error.Clear(); error.Append(SaveMoveLinewithFullContainer(Util.GetValueOfInt(mData[0]["M_Movement_ID"]), Util.GetValueOfInt(mData[0]["FromLocator"]), Util.GetValueOfInt(mData[0]["FromContainer"]), Util.GetValueOfInt(mData[0]["ToLocator"]), Util.GetValueOfInt(mData[0]["ToContainer"]), lineNo, isMoveFullContainerQty, trx)); trx.Close(); return(error.ToString()); } moveFullContainer: MMovementLine moveline = null; MProduct product = null; int moveId = 0; for (int i = 0; i < mData.Count; i++) { #region Quantity Only MMovement move = new MMovement(_ctx, Util.GetValueOfInt(mData[i]["M_Movement_ID"]), null); moveId = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT NVL(M_MovementLine_ID, 0) AS M_Movement_ID FROM M_MovementLine WHERE M_Movement_ID = " + Util.GetValueOfInt(mData[i]["M_Movement_ID"]) + @" AND M_Product_ID = " + Util.GetValueOfInt(mData[i]["M_Product_ID"]) + @" AND NVL(M_AttributeSetInstance_ID, 0) = " + Util.GetValueOfInt(mData[i]["M_AttributeSetInstance_ID"]) + @" AND M_Locator_ID = " + Util.GetValueOfInt(mData[i]["FromLocator"]) + @" AND NVL(M_ProductContainer_ID, 0) = " + Util.GetValueOfInt(mData[i]["FromContainer"]) + @" AND M_LocatorTo_ID = " + Util.GetValueOfInt(mData[i]["ToLocator"]) + @" AND NVL(Ref_M_ProductContainerTo_ID, 0) = " + Util.GetValueOfInt(mData[i]["ToContainer"]) + @" AND AD_Org_ID = " + move.GetAD_Org_ID())); if (moveId > 0) { moveline = new MMovementLine(_ctx, moveId, trx); } else { moveline = new MMovementLine(_ctx, 0, trx); } if (moveId == 0) { #region Create new record of movement line lineNo += 10; moveline.SetAD_Client_ID(move.GetAD_Client_ID()); moveline.SetAD_Org_ID(move.GetAD_Org_ID()); moveline.SetM_Movement_ID(move.GetM_Movement_ID()); moveline.SetLine(lineNo); moveline.SetM_Product_ID(Util.GetValueOfInt(mData[i]["M_Product_ID"])); moveline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(mData[i]["M_AttributeSetInstance_ID"])); moveline.SetC_UOM_ID(Util.GetValueOfInt(mData[i]["C_UOM_ID"])); moveline.SetM_Locator_ID(Util.GetValueOfInt(mData[i]["FromLocator"])); moveline.SetM_LocatorTo_ID(Util.GetValueOfInt(mData[i]["ToLocator"])); moveline.SetM_ProductContainer_ID(Util.GetValueOfInt(mData[i]["FromContainer"])); moveline.SetRef_M_ProductContainerTo_ID(Util.GetValueOfInt(mData[i]["ToContainer"])); moveline.SetQtyEntered(Util.GetValueOfDecimal(mData[i]["MoveQty"])); moveline.SetMovementQty(Util.GetValueOfDecimal(mData[i]["MoveQty"])); moveline.SetMoveFullContainer(Util.GetValueOfBool(mData[i]["IsFullMoveContainer"])); #endregion } else { #region Update record of movement line moveline.SetQtyEntered(Decimal.Add(moveline.GetQtyEntered(), Util.GetValueOfDecimal(mData[i]["MoveQty"]))); moveline.SetMovementQty(Decimal.Add(moveline.GetMovementQty(), Util.GetValueOfDecimal(mData[i]["MoveQty"]))); moveline.SetMoveFullContainer(Util.GetValueOfBool(mData[i]["IsFullMoveContainer"])); #endregion } if (!moveline.Save(trx)) { #region Save error catch and rollback product = MProduct.Get(_ctx, Util.GetValueOfInt(mData[i]["M_Product_ID"])); ValueNamePair pp = VLogger.RetrieveError(); if (pp != null) { _log.SaveError("Movement line not inserted through Move Container Form : ", pp.GetName()); if (String.IsNullOrEmpty(error.ToString())) { error.Append(Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName()); } else { error.Append(" , " + Msg.GetMsg(_ctx, "VIS_MoveLineNotSaveFor") + product.GetName() + Msg.GetMsg(_ctx, "VIS_DueTo") + pp.GetName()); } } trx.Rollback(); #endregion } else { trx.Commit(); } #endregion } } trx.Close(); return(String.IsNullOrEmpty(error.ToString()) ? "VIS_SuccessFullyInserted" : error.ToString()); }