From 7172287be86d90d46764cd297b633e9814a0f763 Mon Sep 17 00:00:00 2001 From: vpj-cd Date: Fri, 15 Aug 2008 09:19:59 +0000 Subject: [PATCH] Refactory and Improve in write code --- base/src/org/eevolution/model/MPPMRP.java | 958 +++++++----------- base/src/org/eevolution/process/MRP.java | 6 +- .../process/RollupBillOfMaterial.java | 2 +- 3 files changed, 380 insertions(+), 586 deletions(-) diff --git a/base/src/org/eevolution/model/MPPMRP.java b/base/src/org/eevolution/model/MPPMRP.java index 1821ef8908..08c70bd7aa 100644 --- a/base/src/org/eevolution/model/MPPMRP.java +++ b/base/src/org/eevolution/model/MPPMRP.java @@ -34,6 +34,7 @@ import org.compiere.model.MRequisitionLine; import org.compiere.model.MResource; import org.compiere.model.MResourceType; import org.compiere.model.MSequence; +import org.compiere.model.MTable; import org.compiere.model.MWarehouse; import org.compiere.model.X_C_DocType; import org.compiere.model.X_M_Forecast; @@ -52,15 +53,12 @@ import org.compiere.wf.MWorkflow; * @version $Id: MPPMRP.java,v 1.4 2004/05/13 06:05:22 vpj-cd Exp $ */ public class MPPMRP extends X_PP_MRP -{ - - - /** Cache */ - //private static CCache s_cache = new CCache ("M_Product_Costing", 20); +{ /************************************************************************** * Default Constructor * @param ctx context - * @param M_Product_Costing_ID id + * @param PP_MRP_ID id + * @param trxName Transaction Name */ public MPPMRP(Properties ctx, int PP_MRP_ID,String trxName) { @@ -68,16 +66,6 @@ public class MPPMRP extends X_PP_MRP if (PP_MRP_ID == 0) { setDateSimulation(new Timestamp (System.currentTimeMillis())); - /* - setC_AcctSchema_ID(0); - setCostCumAmt(); - setCostCumQty(); - setCostLLAmt(); - setCostTLAmt(); - setM_Product_ID(); - setM_Warehouse_ID(); - setPP_Cost_Element_ID(); - stS_Resource_ID();*/ } } // MPPMRP @@ -98,123 +86,99 @@ public class MPPMRP extends X_PP_MRP { if (!newRecord) - return success; - - /*MPPProductPlanning pp = MPPProductPlanning.getSupplyWarehouse( Env.getCtx() , getAD_Org_ID() , getM_Product_ID() , getM_Warehouse_ID()); - - if(pp != null) - { - setS_Resource_ID(pp.getS_Resource_ID()); - setPlanner_ID(pp.getPlanner_ID()); - } */ + return success; return true; } - public static int M_ForecastLine(X_M_ForecastLine fl,boolean delete) + /** + * Create MRP record based in Forecast Line + * @param X_M_ForecastLine Forecast Line + * @param delete Indicate if this record is delete + */ + public static void M_ForecastLine(X_M_ForecastLine fl,boolean delete) { String sql = null; String trxName = fl.get_TrxName(); + Properties m_ctx =fl.getCtx(); if (delete) { sql = "DELETE FROM PP_MRP WHERE M_ForecastLine_ID = "+ fl.getM_ForecastLine_ID() +" AND AD_Client_ID = " + fl.getAD_Client_ID(); DB.executeUpdate(sql, trxName); - return 0; + return; } - MPPMRP mrp = null; - //MPeriod period = new MPeriod(Env.getCtx(),fl.getC_Period_ID(),null); - MWarehouse[] w = MWarehouse.getForOrg(Env.getCtx(),fl.getAD_Org_ID()); - - - X_M_Forecast f = new X_M_Forecast(Env.getCtx(),fl.getM_Forecast_ID(), trxName); - sql = new String("SELECT mrp.PP_MRP_ID FROM PP_MRP mrp WHERE mrp.M_ForecastLine_ID = ? "); - - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql, trxName); - pstmt.setInt(1, fl.getM_ForecastLine_ID()); - ResultSet rs = pstmt.executeQuery (); - boolean records = false; - - while (rs.next()) - { - records = true; - mrp = new MPPMRP(Env.getCtx(), rs.getInt(1),trxName); - mrp.setAD_Org_ID(fl.getAD_Org_ID()); - mrp.setDescription(f.getDescription()); - mrp.setName("MRP"); - mrp.setQty(fl.getQty()); - /* - mrp.setDatePromised(fl.getDatePromised()); - mrp.setDateStartSchedule(fl.getDatePromised()); - mrp.setDateFinishSchedule(fl.getDatePromised()); - mrp.setDateOrdered(fl.getDatePromised()); - mrp.setM_Product_ID(fl.getM_Product_ID()); - */ - mrp.setDatePromised(fl.getDatePromised()); - mrp.setDateStartSchedule(mrp.getDatePromised()); - mrp.setDateFinishSchedule(mrp.getDatePromised()); - mrp.setDateOrdered(mrp.getDatePromised()); - mrp.setM_Product_ID(fl.getM_Product_ID()); - int M_Warehouse_ID = fl.getM_Warehouse_ID(); - - if(M_Warehouse_ID == 0) - { - //int M_Warehouse_ID = DB.getSQLValue(null,"SELECT M_Warehouse_ID FROM ", fl.getAD_Org_ID()); - mrp.setM_Warehouse_ID(w[0].getM_Warehouse_ID()); - } - else - { - mrp.setM_Warehouse_ID(M_Warehouse_ID); - } - mrp.setDocStatus("IP"); - mrp.save(); + MWarehouse[] w = MWarehouse.getForOrg(m_ctx,fl.getAD_Org_ID()); + X_M_Forecast f = new X_M_Forecast(m_ctx,fl.getM_Forecast_ID(), trxName); + String WhereClause = "M_ForecastLine_ID=?"; + MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(WhereClause, new Object[]{fl.getM_ForecastLine_ID()}, trxName); + if(mrp!=null) + { + mrp.setAD_Org_ID(fl.getAD_Org_ID()); + mrp.setDescription(f.getDescription()); + mrp.setName("MRP"); + mrp.setQty(fl.getQty()); + /* + mrp.setDatePromised(fl.getDatePromised()); + mrp.setDateStartSchedule(fl.getDatePromised()); + mrp.setDateFinishSchedule(fl.getDatePromised()); + mrp.setDateOrdered(fl.getDatePromised()); + mrp.setM_Product_ID(fl.getM_Product_ID()); + */ + mrp.setDatePromised(fl.getDatePromised()); + mrp.setDateStartSchedule(mrp.getDatePromised()); + mrp.setDateFinishSchedule(mrp.getDatePromised()); + mrp.setDateOrdered(mrp.getDatePromised()); + mrp.setM_Product_ID(fl.getM_Product_ID()); + int M_Warehouse_ID = fl.getM_Warehouse_ID(); + if(M_Warehouse_ID == 0) + { + mrp.setM_Warehouse_ID(w[0].getM_Warehouse_ID()); } - - if (!records) + else { - mrp = new MPPMRP(Env.getCtx(), 0,trxName); - mrp.setM_ForecastLine_ID(fl.getM_ForecastLine_ID()); - mrp.setAD_Org_ID(fl.getAD_Org_ID()); - mrp.setName("MRP"); - mrp.setDescription(f.getDescription()); - mrp.setM_Forecast_ID(f.getM_Forecast_ID()); - mrp.setQty(fl.getQty()); - /*mrp.setDatePromised(fl.getDatePromised()); - mrp.setDateStartSchedule(fl.getDatePromised()); - mrp.setDateFinishSchedule(fl.getDatePromised()); - mrp.setDateOrdered(fl.getDatePromised());*/ - mrp.setDatePromised(fl.getDatePromised()); - mrp.setDateStartSchedule(mrp.getDatePromised()); - mrp.setDateFinishSchedule(mrp.getDatePromised()); - mrp.setDateOrdered(mrp.getDatePromised()); - mrp.setM_Product_ID(fl.getM_Product_ID()); - mrp.setM_Warehouse_ID(fl.getM_Warehouse_ID()); - mrp.setDocStatus("IP"); - mrp.setOrderType(MPPMRP.ORDERTYPE_Forecast); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); - mrp.save(); - + mrp.setM_Warehouse_ID(M_Warehouse_ID); } - - rs.close(); - pstmt.close(); - + mrp.setDocStatus("IP"); + mrp.saveEx(); } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); - } - - return mrp.getPP_MRP_ID(); + else + { + mrp = new MPPMRP(m_ctx, 0,trxName); + mrp.setM_ForecastLine_ID(fl.getM_ForecastLine_ID()); + mrp.setAD_Org_ID(fl.getAD_Org_ID()); + mrp.setName("MRP"); + mrp.setDescription(f.getDescription()); + mrp.setM_Forecast_ID(f.getM_Forecast_ID()); + mrp.setQty(fl.getQty()); + /*mrp.setDatePromised(fl.getDatePromised()); + mrp.setDateStartSchedule(fl.getDatePromised()); + mrp.setDateFinishSchedule(fl.getDatePromised()); + mrp.setDateOrdered(fl.getDatePromised());*/ + mrp.setDatePromised(fl.getDatePromised()); + mrp.setDateStartSchedule(mrp.getDatePromised()); + mrp.setDateFinishSchedule(mrp.getDatePromised()); + mrp.setDateOrdered(mrp.getDatePromised()); + mrp.setM_Product_ID(fl.getM_Product_ID()); + mrp.setM_Warehouse_ID(fl.getM_Warehouse_ID()); + mrp.setDocStatus("IP"); + mrp.setOrderType(MPPMRP.ORDERTYPE_Forecast); + mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); + mrp.saveEx(); + } + + return; } - - - - public static int C_OrderLine(MOrderLine ol, boolean delete) + + /** + * Create MRP record based in Order Line + * @param MOrderLine + * @param delete Indicate if this record is delete + * @return + */ + public static void C_OrderLine(MOrderLine ol, boolean delete) { + Properties m_ctx = ol.getCtx(); String sql = null; String trxName = ol.getParent().get_TrxName(); if (delete) @@ -224,109 +188,83 @@ public class MPPMRP extends X_PP_MRP int PP_Order_ID = DB.getSQLValue(trxName,"SELECT PP_Order_ID FROM PP_Order o WHERE o.AD_Client_ID = ? AND o.C_OrderLine_ID = ? ", ol.getAD_Client_ID(),ol.getC_OrderLine_ID()); if (PP_Order_ID != -1 ) { - MPPOrder order = new MPPOrder(Env.getCtx(), PP_Order_ID,trxName); + MPPOrder order = new MPPOrder(m_ctx, PP_Order_ID,trxName); if (MPPOrder.DOCSTATUS_Completed != order.getDocStatus() || MPPOrder.DOCSTATUS_Closed != order.getDocStatus()) order.delete(true,trxName); } - return 0; + return; } - - MPPMRP mrp = null; - sql = new String("SELECT mrp.PP_MRP_ID FROM PP_MRP mrp WHERE mrp.C_OrderLine_ID = ? "); - - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql, trxName); - pstmt.setInt(1, ol.getC_OrderLine_ID()); - ResultSet rs = pstmt.executeQuery (); - boolean records = false; - - while (rs.next()) - { - records = true; - mrp = new MPPMRP(Env.getCtx(), rs.getInt(1),trxName); - mrp.setDescription(ol.getDescription()); - mrp.setName("MRP"); - mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); - mrp.setDatePromised(ol.getDatePromised()); - mrp.setDateStartSchedule(ol.getDatePromised()); - mrp.setDateFinishSchedule(ol.getDatePromised()); - mrp.setDateOrdered(ol.getDateOrdered()); - mrp.setM_Product_ID(ol.getM_Product_ID()); - mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID()); - mrp.setDocStatus(ol.getParent().getDocStatus()); - mrp.save(); + String WhereClause = "AD_Client_ID = ? AND C_OrderLine_ID = ?"; + MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(WhereClause, new Object[]{ ol.getAD_Client_ID(),ol.getC_OrderLine_ID()}, trxName); + if(mrp!=null) + { + mrp.setDescription(ol.getDescription()); + mrp.setName("MRP"); + mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); + mrp.setDatePromised(ol.getDatePromised()); + mrp.setDateStartSchedule(ol.getDatePromised()); + mrp.setDateFinishSchedule(ol.getDatePromised()); + mrp.setDateOrdered(ol.getDateOrdered()); + mrp.setM_Product_ID(ol.getM_Product_ID()); + mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID()); + mrp.setDocStatus(ol.getParent().getDocStatus()); + mrp.saveEx(); + } + else + { + mrp = new MPPMRP(m_ctx, 0,trxName); + mrp.setC_OrderLine_ID(ol.getC_OrderLine_ID()); + mrp.setName("MRP"); + mrp.setDescription(ol.getDescription()); + mrp.setC_Order_ID(ol.getC_Order_ID()); + mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); + mrp.setDatePromised(ol.getDatePromised()); + mrp.setDateStartSchedule(ol.getDatePromised()); + mrp.setDateFinishSchedule(ol.getDatePromised()); + mrp.setDateOrdered(ol.getDateOrdered()); + mrp.setM_Product_ID(ol.getM_Product_ID()); + mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID()); + mrp.setDocStatus(ol.getParent().getDocStatus()); + if (ol.getParent().isSOTrx()) + { + mrp.setOrderType(MPPMRP.ORDERTYPE_SalesOrder); + mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); } - - if (!records) + else { - mrp = new MPPMRP(Env.getCtx(), 0,trxName); - mrp.setC_OrderLine_ID(ol.getC_OrderLine_ID()); - mrp.setName("MRP"); - mrp.setDescription(ol.getDescription()); - mrp.setC_Order_ID(ol.getC_Order_ID()); - mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); - mrp.setDatePromised(ol.getDatePromised()); - mrp.setDateStartSchedule(ol.getDatePromised()); - mrp.setDateFinishSchedule(ol.getDatePromised()); - mrp.setDateOrdered(ol.getDateOrdered()); - mrp.setM_Product_ID(ol.getM_Product_ID()); - mrp.setM_Warehouse_ID(ol.getM_Warehouse_ID()); - mrp.setDocStatus(ol.getParent().getDocStatus()); - - if (ol.getParent().isSOTrx()) - { - mrp.setOrderType(MPPMRP.ORDERTYPE_SalesOrder); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); - } - else - { - mrp.setOrderType(MPPMRP.ORDERTYPE_PurchaseOrder); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); - } - mrp.save(); - + mrp.setOrderType(MPPMRP.ORDERTYPE_PurchaseOrder); + mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); } - - rs.close(); - pstmt.close(); - - } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); + mrp.saveEx(); } - - int PP_Order_ID = DB.getSQLValue(trxName,"SELECT PP_Order_ID FROM PP_Order o WHERE o.AD_Client_ID = ? AND o.C_OrderLine_ID = ? ", ol.getAD_Client_ID(),ol.getC_OrderLine_ID()); - if (PP_Order_ID == -1 ) + MPPOrder order = (MPPOrder) MTable.get(m_ctx, MPPOrder.Table_ID).getPO("AD_Client_ID = ? AND C_OrderLine_ID = ? ", new Object[]{ol.getAD_Client_ID(),ol.getC_OrderLine_ID()},trxName); + if (order == null ) { - MProduct product = MProduct.get(Env.getCtx(),ol.getM_Product_ID()); - int PP_Product_BOM_ID = DB.getSQLValue(trxName,"SELECT PP_Product_BOM_ID FROM PP_Product_BOM bom WHERE bom.AD_Client_ID = ? AND bom.Value = ? ", ol.getAD_Client_ID(),product.getValue()); - if (PP_Product_BOM_ID != -1) + MProduct product = MProduct.get(m_ctx,ol.getM_Product_ID()); + WhereClause = "AD_Client_ID = ? AND Value = ?"; + MPPProductBOM bom = (MPPProductBOM) MTable.get(m_ctx, MPPProductBOM.Table_ID).getPO(WhereClause,new Object[]{ ol.getAD_Client_ID(),product.getValue()}, trxName); + if (bom != null) { - X_PP_Product_BOM bom = new X_PP_Product_BOM(Env.getCtx(),PP_Product_BOM_ID, trxName); - if (bom.getBOMType().equals(bom.BOMTYPE_Make_To_Order)) - { - int S_Resource_ID = DB.getSQLValue(trxName,"SELECT S_Resource_ID FROM S_Resource r WHERE r.ManufacturingResourceType = 'PT' AND r.IsManufacturingResource = 'Y' AND r.AD_Client_ID = ? AND r.M_Warehouse_ID = ? " - //+ "AND ROWNUM = 1" - , ol.getAD_Client_ID(),ol.getM_Warehouse_ID()); - int AD_Workflow_ID = DB.getSQLValue(trxName,"SELECT AD_Workflow_ID FROM AD_Workflow wf WHERE wf.AD_Client_ID = ? AND wf.Value = ? ", ol.getAD_Client_ID(),product.getValue()); - if (S_Resource_ID != -1 && AD_Workflow_ID != -1) + if (bom.getBOMType().equals(MPPProductBOM.BOMTYPE_Make_To_Order)) + { + WhereClause = "ManufacturingResourceType = 'PT' AND IsManufacturingResource = 'Y' AND AD_Client_ID = ? AND M_Warehouse_ID = ?"; + MResource m_resource = (MResource)MTable.get(m_ctx,MResource.Table_ID).getPO(WhereClause, new Object[]{ ol.getAD_Client_ID(),ol.getM_Warehouse_ID()}, trxName); + WhereClause = "AD_Client_ID = ? AND Value = ?"; + MWorkflow m_workflow = (MWorkflow)MTable.get(m_ctx,MWorkflow.Table_ID).getPO(WhereClause, new Object[]{ ol.getAD_Client_ID(),product.getValue()}, trxName); + if (m_resource != null && m_workflow != null) { - MDocType[] doc = MDocType.getOfDocBaseType(Env.getCtx(),X_C_DocType.DOCBASETYPE_ManufacturingOrder); - int C_DocType_ID = doc[0].getC_DocType_ID(); - //int C_DocType_ID = MPPMRP.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder, false); - MPPOrder order = new MPPOrder(Env.getCtx(), 0 , trxName); + MDocType[] doc = MDocType.getOfDocBaseType(m_ctx,X_C_DocType.DOCBASETYPE_ManufacturingOrder); + int C_DocType_ID = doc[0].getC_DocType_ID(); + order = new MPPOrder(m_ctx, 0 , trxName); order.setC_OrderLine_ID(ol.getC_OrderLine_ID()); order.setDocumentNo(MSequence.getDocumentNo(C_DocType_ID,trxName,true)); - order.setS_Resource_ID(S_Resource_ID); + order.setS_Resource_ID(m_resource.getS_Resource_ID()); order.setM_Warehouse_ID(ol.getM_Warehouse_ID()); order.setM_Product_ID(ol.getM_Product_ID()); order.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID()); - order.setPP_Product_BOM_ID(PP_Product_BOM_ID); - order.setAD_Workflow_ID(AD_Workflow_ID); + order.setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID()); + order.setAD_Workflow_ID(m_workflow.getAD_Workflow_ID()); //order.setPlanner_ID(SupplyPlanner_ID); order.setLine(10); order.setQtyDelivered(Env.ZERO); @@ -334,7 +272,7 @@ public class MPPMRP extends X_PP_MRP order.setQtyScrap(Env.ZERO); order.setDateOrdered(ol.getDateOrdered()); order.setDatePromised(ol.getDatePromised()); - order.setDateStartSchedule(TimeUtil.addDays(ol.getDatePromised(), (MPPMRP.getDays(S_Resource_ID,AD_Workflow_ID, ol.getQtyOrdered())).negate().intValue())); + order.setDateStartSchedule(TimeUtil.addDays(ol.getDatePromised(), (MPPMRP.getDays(m_ctx,m_resource.getS_Resource_ID(),m_workflow.getAD_Workflow_ID(), ol.getQtyOrdered(),ol.get_TrxName())).negate().intValue())); order.setDateFinishSchedule(ol.getDatePromised()); order.setQtyEntered(ol.getQtyEntered()); order.setQtyOrdered(ol.getQtyOrdered()); @@ -343,11 +281,11 @@ public class MPPMRP extends X_PP_MRP order.setProcessed(false); order.setC_DocTypeTarget_ID(C_DocType_ID); order.setC_DocType_ID(C_DocType_ID); - order.setPriorityRule(order.PRIORITYRULE_High); + order.setPriorityRule(MPPOrder.PRIORITYRULE_High); order.save(trxName); order.prepareIt(); - order.setDocAction(order.DOCSTATUS_Completed); - order.save(); + order.setDocAction(MPPOrder.DOCSTATUS_Completed); + order.saveEx(); } } } @@ -355,18 +293,22 @@ public class MPPMRP extends X_PP_MRP else { - MPPOrder order = new MPPOrder(Env.getCtx(), PP_Order_ID , trxName); - if (order.DOCSTATUS_Completed != order.getDocStatus() || order.DOCSTATUS_Closed != order.getDocStatus()) + if (MPPOrder.DOCSTATUS_Completed != order.getDocStatus() || MPPOrder.DOCSTATUS_Closed != order.getDocStatus()) { order.setQtyEntered(ol.getQtyEntered()); order.setDatePromised(ol.getDatePromised()); - order.save(); + order.saveEx(); } } - return mrp.getPP_MRP_ID(); + return; } + /** + * Create MRP record based in Manufacturing Order + * @param MPPOrder Manufacturing Order + * @param delete Indicate if this record is delete + */ public static void PP_Order(MPPOrder o, boolean delete) { @@ -379,92 +321,51 @@ public class MPPMRP extends X_PP_MRP DB.executeUpdate(sql ,trxName); return; } - - - sql = new String("SELECT * FROM PP_MRP WHERE TypeMRP = 'S' AND OrderType='MOP' AND PP_Order_ID = ? "); - MPPMRP mrp = null; - - - PreparedStatement pstmt = null; - try + String WhereClause = "TypeMRP = 'S' AND OrderType='MOP' AND AD_Client_ID=? AND PP_Order_ID = ?"; + MPPMRP mrp = (MPPMRP)MTable.get(m_ctx,MPPMRP.Table_ID).getPO(WhereClause, new Object[]{o.getAD_Client_ID() , o.getPP_Order_ID()}, trxName); + if(mrp != null) + { + mrp.setDescription(o.getDescription()); + mrp.setName(o.getDocumentNo()); + mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered())); + mrp.setDatePromised(o.getDatePromised()); + mrp.setDateOrdered(o.getDateOrdered()); + mrp.setDateStartSchedule(o.getDateStartSchedule()); + mrp.setDateFinishSchedule(o.getDateFinishSchedule()); + mrp.setM_Product_ID(o.getM_Product_ID()); + mrp.setM_Warehouse_ID(o.getM_Warehouse_ID()); + mrp.setS_Resource_ID(o.getS_Resource_ID()); + mrp.setDocStatus(o.getDocStatus()); + mrp.saveEx(); + } + else { - pstmt = DB.prepareStatement (sql,trxName); - pstmt.setInt(1, o.getPP_Order_ID()); - ResultSet rs = pstmt.executeQuery (); - boolean records = false; - - while (rs.next()) - { - records = true; - mrp = new MPPMRP(m_ctx, rs ,trxName); - mrp.setDescription(o.getDescription()); - mrp.setName(o.getDocumentNo()); - mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered())); - mrp.setDatePromised(o.getDatePromised()); - mrp.setDateOrdered(o.getDateOrdered()); - mrp.setDateStartSchedule(o.getDateStartSchedule()); - mrp.setDateFinishSchedule(o.getDateFinishSchedule()); - mrp.setM_Product_ID(o.getM_Product_ID()); - mrp.setM_Warehouse_ID(o.getM_Warehouse_ID()); - mrp.setS_Resource_ID(o.getS_Resource_ID()); - mrp.setDocStatus(o.getDocStatus()); - mrp.save(); - } - - if (!records) - { - mrp = new MPPMRP(Env.getCtx(), 0, trxName); - mrp.setPP_Order_ID(o.getPP_Order_ID()); - mrp.setDescription(o.getDescription()); - mrp.setName(o.getDocumentNo()); - mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered())); - mrp.setDatePromised(o.getDatePromised()); - mrp.setDateOrdered(o.getDateOrdered()); - mrp.setDateStartSchedule(o.getDateStartSchedule()); - mrp.setDateFinishSchedule(o.getDateStartSchedule()); - mrp.setM_Product_ID(o.getM_Product_ID()); - mrp.setM_Warehouse_ID(o.getM_Warehouse_ID()); - mrp.setS_Resource_ID(o.getS_Resource_ID()); - mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); - mrp.setDocStatus(o.getDocStatus()); - mrp.save(); - } - rs.close(); - pstmt.close(); - } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); - } - - - - /*sql = new String("SELECT * FROM PP_Order_BOMLine bl WHERE bl.PP_Order_ID= ? "); - pstmt = null; - try - { - pstmt = DB.prepareStatement (sql,trxName); - pstmt.setInt(1, o.getPP_Order_ID()); - ResultSet rs = pstmt.executeQuery (); - - while (rs.next()) - { - MPPOrderBOMLine ol = new MPPOrderBOMLine(Env.getCtx(),rs,trxName); - PP_Order_BOMLine(ol,false); - } - rs.close(); - pstmt.close(); - - } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); - }*/ + mrp = new MPPMRP(m_ctx, 0, trxName); + mrp.setPP_Order_ID(o.getPP_Order_ID()); + mrp.setDescription(o.getDescription()); + mrp.setName(o.getDocumentNo()); + mrp.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered())); + mrp.setDatePromised(o.getDatePromised()); + mrp.setDateOrdered(o.getDateOrdered()); + mrp.setDateStartSchedule(o.getDateStartSchedule()); + mrp.setDateFinishSchedule(o.getDateStartSchedule()); + mrp.setM_Product_ID(o.getM_Product_ID()); + mrp.setM_Warehouse_ID(o.getM_Warehouse_ID()); + mrp.setS_Resource_ID(o.getS_Resource_ID()); + mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder); + mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); + mrp.setDocStatus(o.getDocStatus()); + mrp.saveEx(); + } return ; } + /** + * Create MRP record based in Manufacturing Order BOM Line + * @param MPPOrderBOMLine Order BOM Line + * @param delete indicate if this record is delete + */ public static void PP_Order_BOMLine(MPPOrderBOMLine obl,boolean delete) { String sql = null; @@ -477,70 +378,53 @@ public class MPPMRP extends X_PP_MRP return; } - sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.TypeMRP = 'D' AND mrp.OrderType='MOP' AND mrp.PP_Order_BOMLine_ID = ? "); - + String WhereClause = "TypeMRP = 'D' AND OrderType='MOP' AND AD_Client_ID=? AND PP_Order_BOMLine_ID = ? "; + MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(WhereClause, new Object[]{obl.getAD_Client_ID(),obl.getPP_Order_BOMLine_ID()}, trxName); MPPOrder o = obl.getParent(); - MPPMRP mrp = null; - PreparedStatement pstmt = null; - try + if(mrp!=null) { - pstmt = DB.prepareStatement (sql, trxName); - pstmt.setInt(1, obl.getPP_Order_BOMLine_ID()); - ResultSet rs = pstmt.executeQuery (); - boolean records = false; - while (rs.next()) - { - records = true; - mrp = new MPPMRP(m_ctx , rs,trxName); - mrp.setName(o.getDocumentNo()); - mrp.setDescription(o.getDescription()); - mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered())); - mrp.setDatePromised(o.getDatePromised()); - mrp.setDateOrdered(o.getDateOrdered()); - mrp.setDateStartSchedule(o.getDateStartSchedule()); - mrp.setDateFinishSchedule(o.getDateFinishSchedule()); - mrp.setM_Product_ID(obl.getM_Product_ID()); - mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID()); - mrp.setS_Resource_ID(o.getS_Resource_ID()); - mrp.setDocStatus(o.getDocStatus()); - mrp.save(); - } - - if (!records) - { - mrp = new MPPMRP(m_ctx , 0,trxName); - mrp.setPP_Order_BOMLine_ID(obl.getPP_Order_BOMLine_ID()); - mrp.setName(o.getDocumentNo()); - mrp.setDescription(o.getDescription()); - mrp.setPP_Order_ID(o.getPP_Order_ID()); - mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered())); - mrp.setDatePromised(o.getDatePromised()); - mrp.setDateOrdered(o.getDateOrdered()); - mrp.setDateStartSchedule(o.getDateStartSchedule()); - mrp.setDateFinishSchedule(o.getDateFinishSchedule()); - mrp.setM_Product_ID(obl.getM_Product_ID()); - mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID()); - mrp.setS_Resource_ID(o.getS_Resource_ID()); - mrp.setDocStatus(o.getDocStatus()); - mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); - mrp.save(); - - } - - rs.close(); - pstmt.close(); + mrp.setName(o.getDocumentNo()); + mrp.setDescription(o.getDescription()); + mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered())); + mrp.setDatePromised(o.getDatePromised()); + mrp.setDateOrdered(o.getDateOrdered()); + mrp.setDateStartSchedule(o.getDateStartSchedule()); + mrp.setDateFinishSchedule(o.getDateFinishSchedule()); + mrp.setM_Product_ID(obl.getM_Product_ID()); + mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID()); + mrp.setS_Resource_ID(o.getS_Resource_ID()); + mrp.setDocStatus(o.getDocStatus()); + mrp.saveEx(); + } + else + { + mrp = new MPPMRP(m_ctx , 0,trxName); + mrp.setPP_Order_BOMLine_ID(obl.getPP_Order_BOMLine_ID()); + mrp.setName(o.getDocumentNo()); + mrp.setDescription(o.getDescription()); + mrp.setPP_Order_ID(o.getPP_Order_ID()); + mrp.setQty(obl.getQtyRequiered().subtract(obl.getQtyDelivered())); + mrp.setDatePromised(o.getDatePromised()); + mrp.setDateOrdered(o.getDateOrdered()); + mrp.setDateStartSchedule(o.getDateStartSchedule()); + mrp.setDateFinishSchedule(o.getDateFinishSchedule()); + mrp.setM_Product_ID(obl.getM_Product_ID()); + mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID()); + mrp.setS_Resource_ID(o.getS_Resource_ID()); + mrp.setDocStatus(o.getDocStatus()); + mrp.setOrderType(MPPMRP.ORDERTYPE_ManufacturingOrder); + mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); + mrp.saveEx(); } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); - } - return; - } + /** + * Create MRP record based in Distribution Order + * @param MDDOrder Distribution Order + * @param delete Indicate if this record is delete + */ public static void DD_Order(MDDOrder o, boolean delete) { String sql = null; @@ -554,6 +438,11 @@ public class MPPMRP extends X_PP_MRP } } + /** + * Create MRP record based in Distribution Order Line + * @param MDDOrderLine Distribution Order Line + * @param delete Indicate if this record is delete + */ public static void DD_Order_Line(MDDOrderLine ol, boolean delete) { String sql = null; @@ -565,291 +454,196 @@ public class MPPMRP extends X_PP_MRP DB.executeUpdate(sql ,trxName); return; } - - sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.TypeMRP = 'D' AND mrp.OrderType='DOO' AND mrp.DD_OrderLine_ID = ? "); - MPPMRP mrp = null; + String whereClause = "TypeMRP = 'D' AND OrderType='DOO' AND AD_Client_ID=? AND DD_OrderLine_ID = ?"; + MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(whereClause, new Object[]{ol.getAD_Client_ID(),ol.getDD_OrderLine_ID()}, trxName); MLocator source = MLocator.get( m_ctx , ol.getM_Locator_ID()); MLocator target = MLocator.get( m_ctx , ol.getM_LocatorTo_ID()); - PreparedStatement pstmt = null; - try + if(mrp!=null) + { + mrp.setAD_Org_ID(source.getAD_Org_ID()); + mrp.setName("MRP"); + mrp.setDescription(ol.getDescription()); + mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); + mrp.setDatePromised(ol.getDatePromised()); + mrp.setDateOrdered(ol.getDateOrdered()); + mrp.setM_Product_ID(ol.getM_Product_ID()); + mrp.setM_Warehouse_ID(source.getM_Warehouse_ID()); + mrp.setDocStatus(ol.getParent().getDocStatus()); + mrp.saveEx(); + } + else { - pstmt = DB.prepareStatement (sql, trxName); - pstmt.setInt(1, ol.getDD_OrderLine_ID()); - ResultSet rs = pstmt.executeQuery (); - boolean records = false; - while (rs.next()) - { - records = true; - mrp = new MPPMRP(m_ctx , rs, trxName); - mrp.setAD_Org_ID(source.getAD_Org_ID()); - mrp.setName("MRP"); - mrp.setDescription(ol.getDescription()); - mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); - mrp.setDatePromised(ol.getDatePromised()); - mrp.setDateOrdered(ol.getDateOrdered()); - mrp.setM_Product_ID(ol.getM_Product_ID()); - mrp.setM_Warehouse_ID(source.getM_Warehouse_ID()); - mrp.setDocStatus(ol.getParent().getDocStatus()); - mrp.save(); - } - - if (!records) - { - mrp = new MPPMRP( m_ctx , 0 ,trxName); - mrp.setAD_Org_ID(source.getAD_Org_ID()); - mrp.setName("MRP"); - mrp.setDescription(ol.getDescription()); - mrp.setDD_Order_ID(ol.getDD_Order_ID()); - mrp.setDD_OrderLine_ID(ol.getDD_OrderLine_ID()); - mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); - mrp.setDatePromised(ol.getDatePromised()); - mrp.setDateOrdered(ol.getDateOrdered()); - mrp.setM_Product_ID(ol.getM_Product_ID()); - mrp.setM_Warehouse_ID(source.getM_Warehouse_ID()); - mrp.setDocStatus(ol.getParent().getDocStatus()); - mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); - mrp.save(); - - } - - rs.close(); - pstmt.close(); + mrp = new MPPMRP(m_ctx , 0 ,trxName); + mrp.setAD_Org_ID(source.getAD_Org_ID()); + mrp.setName("MRP"); + mrp.setDescription(ol.getDescription()); + mrp.setDD_Order_ID(ol.getDD_Order_ID()); + mrp.setDD_OrderLine_ID(ol.getDD_OrderLine_ID()); + mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); + mrp.setDatePromised(ol.getDatePromised()); + mrp.setDateOrdered(ol.getDateOrdered()); + mrp.setM_Product_ID(ol.getM_Product_ID()); + mrp.setM_Warehouse_ID(source.getM_Warehouse_ID()); + mrp.setDocStatus(ol.getParent().getDocStatus()); + mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder); + mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); + mrp.saveEx(); } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); - } - - sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.TypeMRP = 'S' AND mrp.OrderType='DOO' AND mrp.DD_OrderLine_ID = ? "); - - - pstmt = null; - try - { - pstmt = DB.prepareStatement (sql, trxName); - pstmt.setInt(1, ol.getDD_OrderLine_ID()); - ResultSet rs = pstmt.executeQuery (); - boolean records = false; - while (rs.next()) - { - records = true; - mrp = new MPPMRP( m_ctx , rs, trxName); - mrp.setAD_Org_ID(target.getAD_Org_ID()); - mrp.setName("MRP"); - mrp.setDescription(ol.getDescription()); - mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); - mrp.setDatePromised(ol.getDatePromised()); - mrp.setDateOrdered(ol.getDateOrdered()); - mrp.setM_Product_ID(ol.getM_Product_ID()); - mrp.setM_Warehouse_ID(target.getM_Warehouse_ID()); - mrp.setDocStatus(ol.getParent().getDocStatus()); - mrp.save(); - } - - if (!records) - { - mrp = new MPPMRP( m_ctx , 0,trxName); - mrp.setAD_Org_ID(target.getAD_Org_ID()); - mrp.setName("MRP"); - mrp.setDescription(ol.getDescription()); - mrp.setDD_Order_ID(ol.getDD_Order_ID()); - mrp.setDD_OrderLine_ID(ol.getDD_OrderLine_ID()); - mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); - mrp.setDatePromised(ol.getDatePromised()); - mrp.setDateOrdered(ol.getDateOrdered()); - mrp.setM_Product_ID(ol.getM_Product_ID()); - mrp.setM_Warehouse_ID(target.getM_Warehouse_ID()); - mrp.setDocStatus(ol.getParent().getDocStatus()); - mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); - mrp.save(); - - } - - rs.close(); - pstmt.close(); - - } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); - } + whereClause ="TypeMRP='S' AND OrderType='DOO' AND AD_Client_ID=? AND DD_OrderLine_ID = ? "; + mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(whereClause, new Object[]{ol.getAD_Client_ID(),ol.getDD_OrderLine_ID()}, trxName); + if(mrp!=null) + { + mrp.setAD_Org_ID(target.getAD_Org_ID()); + mrp.setName("MRP"); + mrp.setDescription(ol.getDescription()); + mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); + mrp.setDatePromised(ol.getDatePromised()); + mrp.setDateOrdered(ol.getDateOrdered()); + mrp.setM_Product_ID(ol.getM_Product_ID()); + mrp.setM_Warehouse_ID(target.getM_Warehouse_ID()); + mrp.setDocStatus(ol.getParent().getDocStatus()); + mrp.save(); + } + else + { + mrp = new MPPMRP( m_ctx , 0,trxName); + mrp.setAD_Org_ID(target.getAD_Org_ID()); + mrp.setName("MRP"); + mrp.setDescription(ol.getDescription()); + mrp.setDD_Order_ID(ol.getDD_Order_ID()); + mrp.setDD_OrderLine_ID(ol.getDD_OrderLine_ID()); + mrp.setQty(ol.getQtyOrdered().subtract(ol.getQtyDelivered())); + mrp.setDatePromised(ol.getDatePromised()); + mrp.setDateOrdered(ol.getDateOrdered()); + mrp.setM_Product_ID(ol.getM_Product_ID()); + mrp.setM_Warehouse_ID(target.getM_Warehouse_ID()); + mrp.setDocStatus(ol.getParent().getDocStatus()); + mrp.setOrderType(MPPMRP.ORDERTYPE_DistributionOrder); + mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); + mrp.saveEx(); + } return; - } - - public static int M_RequisitionLine( MRequisitionLine rl , boolean delete) + /** + * Create MRP record based in Requisition Line + * @param MRequisitionLine Requisition Line + * @param delete Indicate if this record is delete + */ + public static void M_RequisitionLine( MRequisitionLine rl , boolean delete) { String sql = null; String trxName = rl.get_TrxName(); + Properties m_ctx = rl.getCtx(); if (delete) { sql = "DELETE FROM PP_MRP WHERE M_RequisitionLine_ID = "+ rl.getM_RequisitionLine_ID() +" AND AD_Client_ID = " + rl.getAD_Client_ID(); DB.executeUpdate(sql,trxName); //reorder by hamed - return 0; + return; } - sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.M_RequisitionLine_ID = ? "); - MRequisition r = new MRequisition(Env.getCtx(), rl.getM_Requisition_ID(),trxName); - MPPMRP mrp = null; - - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql,trxName); - pstmt.setInt(1, rl.getM_RequisitionLine_ID()); - ResultSet rs = pstmt.executeQuery (); - boolean records = false; - while (rs.next()) - { - records = true; - mrp = new MPPMRP(Env.getCtx(), rs,trxName); - mrp.setName("MRP"); - mrp.setDescription(rl.getDescription()); - mrp.setQty(rl.getQty()); - mrp.setDatePromised(r.getDateRequired()); - mrp.setDateStartSchedule(r.getDateRequired()); - mrp.setDateFinishSchedule(r.getDateRequired()); - mrp.setDateOrdered(r.getDateRequired()); - mrp.setM_Product_ID(rl.getM_Product_ID()); - mrp.setM_Warehouse_ID(r.getM_Warehouse_ID()); - mrp.setDocStatus(r.getDocStatus()); - mrp.save(); - } - - if (!records) - { - mrp = new MPPMRP(Env.getCtx(), 0,trxName); - mrp.setM_Requisition_ID(rl.getM_Requisition_ID()); - mrp.setM_RequisitionLine_ID(rl.getM_RequisitionLine_ID()); - mrp.setName("MRP"); - mrp.setDescription(rl.getDescription()); - mrp.setQty(rl.getQty()); - mrp.setDatePromised(r.getDateRequired()); - mrp.setDateOrdered(r.getDateRequired()); - mrp.setDateStartSchedule(r.getDateRequired()); - mrp.setDateFinishSchedule(r.getDateRequired()); - mrp.setM_Product_ID(rl.getM_Product_ID()); - mrp.setM_Warehouse_ID(r.getM_Warehouse_ID()); - mrp.setDocStatus(r.getDocStatus()); - mrp.setOrderType(MPPMRP.ORDERTYPE_MaterialRequisition); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); - mrp.setIsAvailable(true); - mrp.save(); - - } - - rs.close(); - pstmt.close(); - + String whereClause = new String("AD_Client_ID=? AND M_RequisitionLine_ID = ? "); + MPPMRP mrp = (MPPMRP)MTable.get(m_ctx, MPPMRP.Table_ID).getPO(whereClause, new Object[]{rl.getAD_Client_ID(),rl.getM_RequisitionLine_ID()}, trxName); + MRequisition r = new MRequisition(m_ctx, rl.getM_Requisition_ID(),trxName); + if(mrp!=null) + { + mrp.setName("MRP"); + mrp.setDescription(rl.getDescription()); + mrp.setQty(rl.getQty()); + mrp.setDatePromised(r.getDateRequired()); + mrp.setDateStartSchedule(r.getDateRequired()); + mrp.setDateFinishSchedule(r.getDateRequired()); + mrp.setDateOrdered(r.getDateRequired()); + mrp.setM_Product_ID(rl.getM_Product_ID()); + mrp.setM_Warehouse_ID(r.getM_Warehouse_ID()); + mrp.setDocStatus(r.getDocStatus()); + mrp.saveEx(); } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); + else + { + mrp = new MPPMRP(m_ctx, 0,trxName); + mrp.setM_Requisition_ID(rl.getM_Requisition_ID()); + mrp.setM_RequisitionLine_ID(rl.getM_RequisitionLine_ID()); + mrp.setName("MRP"); + mrp.setDescription(rl.getDescription()); + mrp.setQty(rl.getQty()); + mrp.setDatePromised(r.getDateRequired()); + mrp.setDateOrdered(r.getDateRequired()); + mrp.setDateStartSchedule(r.getDateRequired()); + mrp.setDateFinishSchedule(r.getDateRequired()); + mrp.setM_Product_ID(rl.getM_Product_ID()); + mrp.setM_Warehouse_ID(r.getM_Warehouse_ID()); + mrp.setDocStatus(r.getDocStatus()); + mrp.setOrderType(MPPMRP.ORDERTYPE_MaterialRequisition); + mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); + mrp.setIsAvailable(true); + mrp.saveEx(); } - - return mrp.getPP_MRP_ID(); - + return; } - public static int M_Requisition( MRequisition r) + /** + * Create MRP record based in Requisition + * @param MRequisitio Requisition + * @param delete Indicate if this record is delete + */ + public static void M_Requisition(MRequisition r) { String trxName = r.get_TrxName(); - String sql = new String("SELECT * FROM PP_MRP mrp WHERE mrp.M_Requisition_ID = ? "); - - MPPMRP mrp = null; - - - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql,trxName); - pstmt.setInt(1, r.getM_Requisition_ID()); - ResultSet rs = pstmt.executeQuery (); - boolean records = false; - while (rs.next()) - { - records = true; - mrp = new MPPMRP(Env.getCtx(), rs ,trxName); + String WhereClause = "AD_Client_ID=? AND M_Requisition_ID=?"; + MPPMRP mrp = (MPPMRP)MTable.get(r.getCtx(),MRequisition.Table_ID).getPO(WhereClause, new Object[]{r.getAD_Client_ID(), r.getM_Requisition_ID()},trxName); + if(mrp!=null) + { mrp.setDocStatus(r.getDocStatus()); - mrp.save(); - } - - rs.close(); - pstmt.close(); - - } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); - } - - return mrp.getPP_MRP_ID(); + mrp.saveEx(); + } + return; } - - public static BigDecimal getOnHand(int AD_Client_ID, int M_Warehouse_ID ,int M_Product_ID) - { - BigDecimal OnHand = Env.ZERO; - String sql = "SELECT SUM(bomQtyOnHand (M_Product_ID ,"+M_Warehouse_ID+",0)) AS OnHand FROM M_Product WHERE AD_Client_ID="+AD_Client_ID+" AND M_Product_ID=" + M_Product_ID; - - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); - while (rs.next()) - { - OnHand = rs.getBigDecimal("OnHand"); - } - rs.close(); - pstmt.close(); - - } - catch (SQLException ex) - { - log.log(Level.SEVERE, "doIt - " + sql , ex); - return null; - } - - if (OnHand == null) - OnHand = Env.ZERO; - return OnHand; + /** + * Get Qty Onhand + * @param AD_Client_ID + * @param M_Warehouse_ID + * @param M_Product_ID + * @return + */ + public static BigDecimal getQtyOnHand(int AD_Client_ID, int M_Warehouse_ID ,int M_Product_ID,String trxName) + { + String sql = "SELECT SUM(bomQtyOnHand (M_Product_ID ,"+M_Warehouse_ID+",0)) AS OnHand FROM M_Product WHERE AD_Client_ID=? AND M_Product_ID=?"; + BigDecimal QtyOnHand = DB.getSQLValueBD(trxName, sql, new Object[]{AD_Client_ID,M_Product_ID}); + if (QtyOnHand == null) + QtyOnHand = Env.ZERO; + return QtyOnHand; } - public static int getMaxLowLevel(Properties ctx) + public static int getMaxLowLevel(Properties ctx, String trxName) { int LowLevel = 0; int AD_Client_ID = Env.getAD_Client_ID(ctx); // String sql = "SELECT MAX("+MProduct.COLUMNNAME_LowLevel+") FROM M_Product" +" WHERE AD_Client_ID=? AND "+MProduct.COLUMNNAME_LowLevel+" IS NOT NULL"; - LowLevel = DB.getSQLValue(null, sql, AD_Client_ID); + LowLevel = DB.getSQLValue(trxName, sql, AD_Client_ID); return LowLevel + 1; } - public static BigDecimal getDays(int S_Resource_ID, int AD_Workflow_ID, BigDecimal QtyOrdered) + public static BigDecimal getDays(Properties ctx ,int S_Resource_ID, int AD_Workflow_ID, BigDecimal QtyOrdered, String trxName) { if (S_Resource_ID == 0) return Env.ZERO; - MResource S_Resource = MResource.get(Env.getCtx(),S_Resource_ID); - MResourceType S_ResourceType = MResourceType.get(Env.getCtx(),S_Resource.getS_ResourceType_ID()); + MResource S_Resource = MResource.get(ctx,S_Resource_ID); + MResourceType S_ResourceType = MResourceType.get(ctx,S_Resource.getS_ResourceType_ID()); BigDecimal AvailableDayTime = Env.ZERO; int AvailableDays = 0; - - long hours = 0; - if (S_ResourceType.isDateSlot()) AvailableDayTime = new BigDecimal(getHoursAvailable(S_ResourceType.getTimeSlotStart(),S_ResourceType.getTimeSlotEnd())); else @@ -879,7 +673,7 @@ public class MPPMRP extends X_PP_MRP if (S_ResourceType.isOnSunday()) AvailableDays =+ 1; - MWorkflow wf = new MWorkflow(Env.getCtx(),AD_Workflow_ID,null); + MWorkflow wf = new MWorkflow(ctx,AD_Workflow_ID,trxName); BigDecimal RequiredTime = Env.ZERO ;//wf.getQueuingTime().add(wf.getSetupTime()).add(wf.getDuration().multiply(QtyOrdered)).add(wf.getWaitingTime()).add(wf.getMovingTime()); // Weekly Factor diff --git a/base/src/org/eevolution/process/MRP.java b/base/src/org/eevolution/process/MRP.java index 821933f83c..0748c41ef8 100644 --- a/base/src/org/eevolution/process/MRP.java +++ b/base/src/org/eevolution/process/MRP.java @@ -335,7 +335,7 @@ public class MRP extends SvrProcess //String Order_Policy = MPPProductPlanning.ORDER_POLICY_LoteForLote; - int lowlevel = MPPMRP.getMaxLowLevel(getCtx()); + int lowlevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName()); int Level = lowlevel; log.info("Low Level Is :"+lowlevel); // Calculate MRP for all levels @@ -569,7 +569,7 @@ public class MRP extends SvrProcess //QtyOnHand = getOnHand(M_Product_ID); - QtyProjectOnHand = MPPMRP.getOnHand(AD_Client_ID , m_product_planning.getM_Warehouse_ID() , m_product_planning.getM_Product_ID()); + QtyProjectOnHand = MPPMRP.getQtyOnHand(AD_Client_ID , m_product_planning.getM_Warehouse_ID() , m_product_planning.getM_Product_ID(), get_TrxName()); if(QtyProjectOnHand == null) QtyProjectOnHand = Env.ZERO; @@ -933,7 +933,7 @@ public class MRP extends SvrProcess order.setDatePromised(DemandDateStartSchedule); if (m_product_planning.getDeliveryTime_Promised().compareTo(Env.ZERO) == 0) - order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, (MPPMRP.getDays(order.getS_Resource_ID(),order.getAD_Workflow_ID(), QtyPlanned).add(m_product_planning.getTransfertTime())).negate().intValue())); + order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, (MPPMRP.getDays(order.getCtx(),order.getS_Resource_ID(),order.getAD_Workflow_ID(), QtyPlanned,order.get_TrxName()).add(m_product_planning.getTransfertTime())).negate().intValue())); else order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, (m_product_planning.getDeliveryTime_Promised().add(m_product_planning.getTransfertTime())).negate().intValue())); order.setDateFinishSchedule(DemandDateStartSchedule); diff --git a/base/src/org/eevolution/process/RollupBillOfMaterial.java b/base/src/org/eevolution/process/RollupBillOfMaterial.java index fc7814b0cf..c1af00dbfb 100644 --- a/base/src/org/eevolution/process/RollupBillOfMaterial.java +++ b/base/src/org/eevolution/process/RollupBillOfMaterial.java @@ -107,7 +107,7 @@ public class RollupBillOfMaterial extends SvrProcess protected String doIt() throws Exception { - int lowlevel = MPPMRP.getMaxLowLevel(getCtx()); + int lowlevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName()); // Calculate Rollup for all levels for (int index = lowlevel ; index >= 0 ; index--) {