From ff4df8636d4f2b5106f717cbdc1faa952a046051 Mon Sep 17 00:00:00 2001 From: vpj-cd Date: Sat, 30 Aug 2008 01:34:55 +0000 Subject: [PATCH] [ 2083255 ] Let Calculate Material Plant for every Plant, Org, Wh http://sourceforge.net/tracker/index.php?func=detail&aid=2083255&group_id=176962&atid=879335 --- base/src/org/eevolution/process/MRP.java | 72 +++++++++++++---- .../src/org/eevolution/process/MRPUpdate.java | 78 +++++++++++++++---- migration/352a-trunk/278_FR_2083255_MRP.sql | 15 ++++ .../postgresql/278_FR_2083255_MRP.sql | 15 ++++ 4 files changed, 148 insertions(+), 32 deletions(-) create mode 100644 migration/352a-trunk/278_FR_2083255_MRP.sql create mode 100644 migration/352a-trunk/postgresql/278_FR_2083255_MRP.sql diff --git a/base/src/org/eevolution/process/MRP.java b/base/src/org/eevolution/process/MRP.java index ccc290c703..1848590b84 100644 --- a/base/src/org/eevolution/process/MRP.java +++ b/base/src/org/eevolution/process/MRP.java @@ -22,6 +22,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -184,21 +185,62 @@ public class MRP extends SvrProcess log.info("Type Document to Requisition:"+ DocTypeReq); log.info("Type Document to Manufacturing Order:" + DocTypeMO); log.info("Type Document to Distribution Order:" + DocTypeDO); - if(p_M_Warehouse_ID==0) - { - MWarehouse[] ws = MWarehouse.getForOrg(getCtx(), p_AD_Org_ID); - for(MWarehouse w : ws) - { - - runMRP(m_AD_Client_ID,p_AD_Org_ID,p_S_Resource_ID,w.getM_Warehouse_ID()); - result = result + "
finish MRP to Warehouse " +w.getName(); - } - } - else - { - runMRP(m_AD_Client_ID,p_AD_Org_ID,p_S_Resource_ID,p_M_Warehouse_ID); - } - + + ArrayList parameters = new ArrayList(); + StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType+"='"+ + MResource.MANUFACTURINGRESOURCETYPE_Plant+ "' AND AD_Client_ID=?"); + parameters.add(m_AD_Client_ID); + + if (p_S_Resource_ID > 0) + { + whereClause.append(" AND S_Resource_ID=?"); + parameters.add(p_S_Resource_ID); + } + + List plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()) + .setParameters(parameters) + .list(); + + for(MResource plant : plants) + { + log.info("Run MRP to Plant: " + plant.getName()); + parameters = new ArrayList(); + whereClause = new StringBuffer("AD_Client_ID=?"); + parameters.add(m_AD_Client_ID); + + if (p_AD_Org_ID > 0) + { + whereClause.append(" AND AD_Org_ID=?"); + parameters.add(p_AD_Org_ID); + } + + + List organizations = new Query(getCtx(),MOrg.Table_Name, whereClause.toString(), get_TrxName()) + .setParameters(parameters) + .list(); + + for (MOrg organization : organizations) + { + log.info("Run MRP to Organization: " + organization.getName()); + if(p_M_Warehouse_ID==0) + { + MWarehouse[] ws = MWarehouse.getForOrg(getCtx(), organization.getAD_Org_ID()); + for(MWarehouse w : ws) + { + log.info("Run MRP to Wharehouse: " + w.getName()); + runMRP(m_AD_Client_ID,organization.getAD_Org_ID(),plant.getS_Resource_ID(),w.getM_Warehouse_ID()); + result = result + "
finish MRP to Warehouse " +w.getName(); + } + } + else + { + runMRP(m_AD_Client_ID,organization.getAD_Org_ID(),plant.getS_Resource_ID(),p_M_Warehouse_ID); + } + result = result + "
finish MRP to Organization " +organization.getName(); + } + result = result + "
finish MRP to Plant " +plant.getName(); + } + return result; } diff --git a/base/src/org/eevolution/process/MRPUpdate.java b/base/src/org/eevolution/process/MRPUpdate.java index 337e28182a..f1b96200bd 100644 --- a/base/src/org/eevolution/process/MRPUpdate.java +++ b/base/src/org/eevolution/process/MRPUpdate.java @@ -17,9 +17,13 @@ package org.eevolution.process; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; +import org.compiere.model.MOrg; import org.compiere.model.MRequisition; +import org.compiere.model.MResource; import org.compiere.model.MWarehouse; import org.compiere.model.PO; import org.compiere.model.POResultSet; @@ -87,24 +91,64 @@ public class MRPUpdate extends SvrProcess */ protected String doIt() throws Exception { - if(p_M_Warehouse_ID==0) - { - MWarehouse[] ws = MWarehouse.getForOrg(getCtx(), p_AD_Org_ID); - for(MWarehouse w : ws) - { - if(!deleteRecord(m_AD_Client_ID,p_AD_Org_ID,p_S_Resource_ID,w.getM_Warehouse_ID())) - throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); - if(!createRecord(m_AD_Client_ID,p_AD_Org_ID,p_S_Resource_ID,w.getM_Warehouse_ID())) - throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); + ArrayList parameters = new ArrayList(); + StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType+"='"+ + MResource.MANUFACTURINGRESOURCETYPE_Plant+ "' AND AD_Client_ID=?"); + parameters.add(m_AD_Client_ID); + + if (p_S_Resource_ID > 0) + { + whereClause.append(" AND S_Resource_ID=?"); + parameters.add(p_S_Resource_ID); + } + + List plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()) + .setParameters(parameters) + .list(); + + for(MResource plant : plants) + { + log.info("Create MRP record to Plant: " + plant.getName()); + parameters = new ArrayList(); + whereClause = new StringBuffer("AD_Client_ID=?"); + parameters.add(m_AD_Client_ID); + + if (p_AD_Org_ID > 0) + { + whereClause.append(" AND AD_Org_ID=?"); + parameters.add(p_AD_Org_ID); + } + + + List organizations = new Query(getCtx(),MOrg.Table_Name, whereClause.toString(), get_TrxName()) + .setParameters(parameters) + .list(); + + for (MOrg organization : organizations) + { + log.info("Create MRP record to Organization: " + organization.getName()); + + if(p_M_Warehouse_ID==0) + { + MWarehouse[] ws = MWarehouse.getForOrg(getCtx(), p_AD_Org_ID); + for(MWarehouse w : ws) + { + log.info("Create MRP record to Warehouse: " + organization.getName()); + if(!deleteRecord(m_AD_Client_ID,organization.get_ID(),plant.get_ID(),w.get_ID())) + throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); + if(!createRecord(m_AD_Client_ID,organization.get_ID(),plant.get_ID(),w.get_ID())) + throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); + } + } + else + { + if(!deleteRecord(m_AD_Client_ID,p_AD_Org_ID,plant.get_ID(),p_M_Warehouse_ID)) + throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); + if(!createRecord(m_AD_Client_ID,p_AD_Org_ID,plant.get_ID(),p_M_Warehouse_ID)) + throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); + } } - } - else - { - if(!deleteRecord(m_AD_Client_ID,p_AD_Org_ID,p_S_Resource_ID,p_M_Warehouse_ID)) - throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); - if(!createRecord(m_AD_Client_ID,p_AD_Org_ID,p_S_Resource_ID,p_M_Warehouse_ID)) - throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); - } + } return Msg.getMsg(getCtx(), "ProcessOK"); } diff --git a/migration/352a-trunk/278_FR_2083255_MRP.sql b/migration/352a-trunk/278_FR_2083255_MRP.sql new file mode 100644 index 0000000000..437d266f7b --- /dev/null +++ b/migration/352a-trunk/278_FR_2083255_MRP.sql @@ -0,0 +1,15 @@ +-- Aug 29, 2008 7:06:38 PM CDT +-- MRP Run to Multiple Plant +UPDATE AD_Process_Para SET AD_Val_Rule_ID=148, IsMandatory='N',Updated=TO_DATE('2008-08-29 19:06:38','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53054 +; + +-- Aug 29, 2008 7:09:28 PM CDT +-- MRP Run to Multiple Plant +UPDATE AD_Process_Para SET IsMandatory='N',Updated=TO_DATE('2008-08-29 19:09:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53132 +; + +-- Aug 29, 2008 7:10:33 PM CDT +-- MRP Run to Multiple Plant +UPDATE AD_Process_Para SET IsMandatory='N',Updated=TO_DATE('2008-08-29 19:10:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53207 +; + diff --git a/migration/352a-trunk/postgresql/278_FR_2083255_MRP.sql b/migration/352a-trunk/postgresql/278_FR_2083255_MRP.sql new file mode 100644 index 0000000000..b353c02d70 --- /dev/null +++ b/migration/352a-trunk/postgresql/278_FR_2083255_MRP.sql @@ -0,0 +1,15 @@ +-- Aug 29, 2008 7:06:38 PM CDT +-- MRP Run to Multiple Plant +UPDATE AD_Process_Para SET AD_Val_Rule_ID=148, IsMandatory='N',Updated=TO_TIMESTAMP('2008-08-29 19:06:38','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53054 +; + +-- Aug 29, 2008 7:09:28 PM CDT +-- MRP Run to Multiple Plant +UPDATE AD_Process_Para SET IsMandatory='N',Updated=TO_TIMESTAMP('2008-08-29 19:09:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53132 +; + +-- Aug 29, 2008 7:10:33 PM CDT +-- MRP Run to Multiple Plant +UPDATE AD_Process_Para SET IsMandatory='N',Updated=TO_TIMESTAMP('2008-08-29 19:10:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53207 +; +