From bc45b9d555def9cff94ca99d8b459f835e7db70e Mon Sep 17 00:00:00 2001 From: vpj-cd Date: Mon, 9 Feb 2009 17:02:27 +0000 Subject: [PATCH] Remove Libero Contribution --- base/src/org/compiere/acct/Doc.java | 17 +- .../org/compiere/acct/DocLine_Payroll.java | 100 -- .../org/compiere/acct/Doc_CostCollector.java | 231 --- base/src/org/compiere/acct/Doc_Payroll.java | 197 --- .../org/compiere/process/DocumentEngine.java | 16 +- .../org/compiere/process/FactAcctReset.java | 12 +- .../ActivityProcessedException.java | 31 - .../model/CalloutCostCollector.java | 95 -- .../model/CalloutDistributionOrder.java | 195 --- .../org/eevolution/model/CalloutOrder.java | 171 --- .../org/eevolution/model/CalloutPayroll.java | 46 - .../org/eevolution/model/LiberoValidator.java | 255 ---- .../model/MDDNetworkDistribution.java | 107 -- .../model/MDDNetworkDistributionLine.java | 44 - base/src/org/eevolution/model/MEXPFormat.java | 215 --- .../org/eevolution/model/MEXPFormatLine.java | 106 -- .../org/eevolution/model/MEXPProcessor.java | 101 -- .../model/MEXPProcessorParameter.java | 59 - .../eevolution/model/MEXPProcessorType.java | 59 - .../org/eevolution/model/MHRAttribute.java | 56 - base/src/org/eevolution/model/MHRConcept.java | 200 --- .../eevolution/model/MHRConceptCategory.java | 91 -- .../org/eevolution/model/MHRDepartment.java | 93 -- .../src/org/eevolution/model/MHREmployee.java | 158 -- .../src/org/eevolution/model/MHRMovement.java | 127 -- base/src/org/eevolution/model/MHRPayroll.java | 142 -- .../eevolution/model/MHRPayrollConcept.java | 106 -- base/src/org/eevolution/model/MHRPeriod.java | 58 - base/src/org/eevolution/model/MHRProcess.java | 1135 -------------- base/src/org/eevolution/model/MHRYear.java | 128 -- .../org/eevolution/model/MIMPProcessor.java | 222 --- .../eevolution/model/MIMPProcessorLog.java | 83 - .../eevolution/model/MPPCostCollector.java | 1002 ------------- base/src/org/eevolution/model/MPPMRP.java | 917 ------------ base/src/org/eevolution/model/MPPOrder.java | 1330 ----------------- .../src/org/eevolution/model/MPPOrderBOM.java | 101 -- .../org/eevolution/model/MPPOrderBOMLine.java | 344 ----- .../eevolution/model/MPPOrderBOMLineMA.java | 127 -- .../org/eevolution/model/MPPOrderCost.java | 76 - .../org/eevolution/model/MPPOrderNode.java | 367 ----- .../eevolution/model/MPPOrderNodeAsset.java | 61 - .../eevolution/model/MPPOrderNodeNext.java | 170 --- .../eevolution/model/MPPOrderNodeProduct.java | 81 - .../eevolution/model/MPPOrderWorkflow.java | 593 -------- .../eevolution/model/MPPProductPlanning.java | 8 - .../org/eevolution/model/MPPWFNodeAsset.java | 73 - .../eevolution/model/MPPWFNodeProduct.java | 95 -- .../eevolution/model/MQMSpecification.java | 144 -- .../model/MQMSpecificationLine.java | 209 --- .../model/reasoner/CRPReasoner.java | 254 ---- .../model/reasoner/StorageReasoner.java | 221 --- .../model/wrapper/AbstractPOWrapper.java | 508 ------- .../model/wrapper/BOMLineWrapper.java | 424 ------ .../eevolution/model/wrapper/BOMWrapper.java | 287 ---- .../src/org/eevolution/msg/HTMLMessenger.java | 416 ------ .../org/eevolution/process/BankTransfer.java | 189 --- .../eevolution/process/ComponentChange.java | 185 --- .../org/eevolution/process/CopyFromBOM.java | 98 -- .../process/DistributionRunOrders.java | 375 ----- .../process/EnableNativeSequence.java | 103 -- base/src/org/eevolution/process/Export.java | 408 ----- .../process/ExportFormatGenerator.java | 324 ---- .../process/FixPaymentCashLine.java | 190 --- .../process/InvoiceCalculateTax.java | 91 -- .../eevolution/process/MovementGenerate.java | 714 --------- .../process/PP_Product_BOM_Check.java | 126 -- .../process/ProcessInfoHandler.java | 152 -- .../org/eevolution/tools/GenerateModel.java | 879 ----------- base/src/org/eevolution/tools/PLoader.java | 74 - .../swing/AbstractLimiterPlainDocument.java | 130 -- .../tools/swing/CharDefinition.java | 76 - .../org/eevolution/tools/swing/SwingTool.java | 267 ---- .../eevolution/tools/worker/MultiWorker.java | 105 -- .../eevolution/tools/worker/SingleWorker.java | 43 - client/src/org/compiere/grid/ed/VLookup.java | 4 +- .../adempiere/model/ExportModelValidator.java | 238 --- .../process/rpl/IExportProcessor.java | 46 - .../process/rpl/exp/ExportHelper.java | 599 -------- .../process/rpl/exp/HDDExportProcessor.java | 118 -- .../process/rpl/exp/ModelExporter.java | 168 --- .../process/rpl/exp/MultiplePublisher.java | 68 - .../process/rpl/exp/TopicExportProcessor.java | 210 --- .../org/adempiere/server/JAXPParserMaker.java | 112 -- .../server/SimpleMessageToTopic.java | 124 -- .../server/rpl/IImportProcessor.java | 57 - .../org/adempiere/server/rpl/XMLHelper.java | 140 -- .../server/rpl/imp/FileImportProcessor.java | 89 -- .../server/rpl/imp/ImportHelper.java | 671 --------- .../server/rpl/imp/ModelImporter.java | 154 -- .../server/rpl/imp/TopicImportProcessor.java | 130 -- .../server/rpl/imp/TopicListener.java | 309 ---- .../org/compiere/server/AdempiereServer.java | 3 - .../compiere/server/AdempiereServerMgr.java | 14 +- .../compiere/server/ReplicationProcessor.java | 168 --- 94 files changed, 20 insertions(+), 20395 deletions(-) delete mode 100644 base/src/org/compiere/acct/DocLine_Payroll.java delete mode 100644 base/src/org/compiere/acct/Doc_CostCollector.java delete mode 100644 base/src/org/compiere/acct/Doc_Payroll.java delete mode 100644 base/src/org/eevolution/exceptions/ActivityProcessedException.java delete mode 100644 base/src/org/eevolution/model/CalloutCostCollector.java delete mode 100644 base/src/org/eevolution/model/CalloutDistributionOrder.java delete mode 100644 base/src/org/eevolution/model/CalloutOrder.java delete mode 100644 base/src/org/eevolution/model/CalloutPayroll.java delete mode 100644 base/src/org/eevolution/model/LiberoValidator.java delete mode 100644 base/src/org/eevolution/model/MDDNetworkDistribution.java delete mode 100644 base/src/org/eevolution/model/MDDNetworkDistributionLine.java delete mode 100644 base/src/org/eevolution/model/MEXPFormat.java delete mode 100644 base/src/org/eevolution/model/MEXPFormatLine.java delete mode 100644 base/src/org/eevolution/model/MEXPProcessor.java delete mode 100644 base/src/org/eevolution/model/MEXPProcessorParameter.java delete mode 100644 base/src/org/eevolution/model/MEXPProcessorType.java delete mode 100644 base/src/org/eevolution/model/MHRAttribute.java delete mode 100644 base/src/org/eevolution/model/MHRConcept.java delete mode 100644 base/src/org/eevolution/model/MHRConceptCategory.java delete mode 100644 base/src/org/eevolution/model/MHRDepartment.java delete mode 100644 base/src/org/eevolution/model/MHREmployee.java delete mode 100644 base/src/org/eevolution/model/MHRMovement.java delete mode 100644 base/src/org/eevolution/model/MHRPayroll.java delete mode 100644 base/src/org/eevolution/model/MHRPayrollConcept.java delete mode 100644 base/src/org/eevolution/model/MHRPeriod.java delete mode 100644 base/src/org/eevolution/model/MHRProcess.java delete mode 100644 base/src/org/eevolution/model/MHRYear.java delete mode 100644 base/src/org/eevolution/model/MIMPProcessor.java delete mode 100644 base/src/org/eevolution/model/MIMPProcessorLog.java delete mode 100644 base/src/org/eevolution/model/MPPCostCollector.java delete mode 100644 base/src/org/eevolution/model/MPPMRP.java delete mode 100644 base/src/org/eevolution/model/MPPOrder.java delete mode 100644 base/src/org/eevolution/model/MPPOrderBOM.java delete mode 100644 base/src/org/eevolution/model/MPPOrderBOMLine.java delete mode 100644 base/src/org/eevolution/model/MPPOrderBOMLineMA.java delete mode 100644 base/src/org/eevolution/model/MPPOrderCost.java delete mode 100644 base/src/org/eevolution/model/MPPOrderNode.java delete mode 100644 base/src/org/eevolution/model/MPPOrderNodeAsset.java delete mode 100644 base/src/org/eevolution/model/MPPOrderNodeNext.java delete mode 100644 base/src/org/eevolution/model/MPPOrderNodeProduct.java delete mode 100644 base/src/org/eevolution/model/MPPOrderWorkflow.java delete mode 100644 base/src/org/eevolution/model/MPPWFNodeAsset.java delete mode 100644 base/src/org/eevolution/model/MPPWFNodeProduct.java delete mode 100644 base/src/org/eevolution/model/MQMSpecification.java delete mode 100644 base/src/org/eevolution/model/MQMSpecificationLine.java delete mode 100644 base/src/org/eevolution/model/reasoner/CRPReasoner.java delete mode 100644 base/src/org/eevolution/model/reasoner/StorageReasoner.java delete mode 100644 base/src/org/eevolution/model/wrapper/AbstractPOWrapper.java delete mode 100644 base/src/org/eevolution/model/wrapper/BOMLineWrapper.java delete mode 100644 base/src/org/eevolution/model/wrapper/BOMWrapper.java delete mode 100644 base/src/org/eevolution/msg/HTMLMessenger.java delete mode 100644 base/src/org/eevolution/process/BankTransfer.java delete mode 100644 base/src/org/eevolution/process/ComponentChange.java delete mode 100644 base/src/org/eevolution/process/CopyFromBOM.java delete mode 100644 base/src/org/eevolution/process/DistributionRunOrders.java delete mode 100644 base/src/org/eevolution/process/EnableNativeSequence.java delete mode 100644 base/src/org/eevolution/process/Export.java delete mode 100644 base/src/org/eevolution/process/ExportFormatGenerator.java delete mode 100644 base/src/org/eevolution/process/FixPaymentCashLine.java delete mode 100644 base/src/org/eevolution/process/InvoiceCalculateTax.java delete mode 100644 base/src/org/eevolution/process/MovementGenerate.java delete mode 100755 base/src/org/eevolution/process/PP_Product_BOM_Check.java delete mode 100644 base/src/org/eevolution/process/ProcessInfoHandler.java delete mode 100644 base/src/org/eevolution/tools/GenerateModel.java delete mode 100644 base/src/org/eevolution/tools/PLoader.java delete mode 100644 base/src/org/eevolution/tools/swing/AbstractLimiterPlainDocument.java delete mode 100644 base/src/org/eevolution/tools/swing/CharDefinition.java delete mode 100644 base/src/org/eevolution/tools/swing/SwingTool.java delete mode 100644 base/src/org/eevolution/tools/worker/MultiWorker.java delete mode 100644 base/src/org/eevolution/tools/worker/SingleWorker.java delete mode 100644 extend/src/org/adempiere/model/ExportModelValidator.java delete mode 100644 extend/src/org/adempiere/process/rpl/IExportProcessor.java delete mode 100644 extend/src/org/adempiere/process/rpl/exp/ExportHelper.java delete mode 100644 extend/src/org/adempiere/process/rpl/exp/HDDExportProcessor.java delete mode 100644 extend/src/org/adempiere/process/rpl/exp/ModelExporter.java delete mode 100644 extend/src/org/adempiere/process/rpl/exp/MultiplePublisher.java delete mode 100644 extend/src/org/adempiere/process/rpl/exp/TopicExportProcessor.java delete mode 100644 serverRoot/src/main/server/org/adempiere/server/JAXPParserMaker.java delete mode 100644 serverRoot/src/main/server/org/adempiere/server/SimpleMessageToTopic.java delete mode 100644 serverRoot/src/main/server/org/adempiere/server/rpl/IImportProcessor.java delete mode 100644 serverRoot/src/main/server/org/adempiere/server/rpl/XMLHelper.java delete mode 100644 serverRoot/src/main/server/org/adempiere/server/rpl/imp/FileImportProcessor.java delete mode 100644 serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java delete mode 100644 serverRoot/src/main/server/org/adempiere/server/rpl/imp/ModelImporter.java delete mode 100644 serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicImportProcessor.java delete mode 100644 serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicListener.java delete mode 100644 serverRoot/src/main/server/org/compiere/server/ReplicationProcessor.java diff --git a/base/src/org/compiere/acct/Doc.java b/base/src/org/compiere/acct/Doc.java index e5f6bb59cd..e7b2cfedb6 100644 --- a/base/src/org/compiere/acct/Doc.java +++ b/base/src/org/compiere/acct/Doc.java @@ -60,8 +60,8 @@ import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.util.Trx; -import org.eevolution.model.MHRProcess; -import org.eevolution.model.MPPCostCollector; +import org.eevolution.model.X_HR_Process; +import org.eevolution.model.X_PP_Cost_Collector; /** * Posting Document Root. @@ -141,8 +141,6 @@ public abstract class Doc MMatchPO.Table_ID, // M_MatchPO MProjectIssue.Table_ID, // C_ProjectIssue MRequisition.Table_ID, // M_Requisition - MHRProcess.Table_ID, // HR_Process - MPPCostCollector.Table_ID // PP_CostCollector }; /** Table Names of documents */ @@ -162,8 +160,6 @@ public abstract class Doc MMatchPO.Table_Name, // M_MatchPO MProjectIssue.Table_Name, // C_ProjectIssue MRequisition.Table_Name, // M_Requisition - MHRProcess.Table_Name, // HR_Process - MPPCostCollector.Table_Name // PP_CostCollector }; /************************************************************************** @@ -226,10 +222,7 @@ public abstract class Doc public static final String DOCTYPE_ProjectIssue = "PJI"; /** Purchase Requisition */ public static final String DOCTYPE_PurchaseRequisition = "POR"; - /** Process Payroll **/ - public static final String DOCTYPE_Payroll = "HRP"; - /** Manufacturing Order */ - public static final String DOCTYPE_MOrder = "MOO"; + // Posting Status - AD_Reference_ID=234 // /** Document Status */ @@ -347,10 +340,6 @@ public abstract class Doc doc = new Doc_ProjectIssue (ass, rs, trxName); else if (AD_Table_ID == MRequisition.Table_ID) doc = new Doc_Requisition (ass, rs, trxName); - else if (AD_Table_ID == MHRProcess.Table_ID) - doc = new Doc_Payroll (ass, rs, trxName); - else if (AD_Table_ID == MPPCostCollector.Table_ID) - doc = new Doc_CostCollector (ass, rs, trxName); if (doc == null) s_log.log(Level.SEVERE, "Unknown AD_Table_ID=" + AD_Table_ID); return doc; diff --git a/base/src/org/compiere/acct/DocLine_Payroll.java b/base/src/org/compiere/acct/DocLine_Payroll.java deleted file mode 100644 index 6ec57f787b..0000000000 --- a/base/src/org/compiere/acct/DocLine_Payroll.java +++ /dev/null @@ -1,100 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.compiere.acct; - -import java.math.BigDecimal; - -import org.compiere.model.MBPartner; -import org.compiere.util.Env; -import org.eevolution.model.MHRConcept; -import org.eevolution.model.MHRMovement; - -/** - * Payroll Line - * - * @author Jorg Janke - * @version $Id: DocLine_Payroll.java,v 1.4 2005/10/17 23:43:52 jjanke Exp $ - */ -public class DocLine_Payroll extends DocLine -{ - /** - * Constructor - * @param line Payroll line - * @param doc header - */ - public DocLine_Payroll (MHRMovement line, Doc_Payroll doc) - { - super (line, doc); - int C_BPartner_ID = line.getC_BPartner_ID(); - MBPartner bpartner = new MBPartner(Env.getCtx(),C_BPartner_ID,null); - //MHREmployee employee = new MHREmployee(Env.getCtx(),C_BPartner_ID,null); - MHRConcept concept = new MHRConcept(Env.getCtx(),line.getHR_Concept_ID(),null); - // - m_HR_Concept_ID = concept.getHR_Concept_ID(); - m_HR_Process_ID = line.getHR_Process_ID(); - m_C_BPartner_ID = C_BPartner_ID; - m_HR_Department_ID = line.getHR_Department_ID(); - m_C_BP_Group_ID = bpartner.getC_BP_Group_ID(); - //m_C_Activity_ID = employee.getC_Activity_ID(); - m_AccountSign = concept.getAccountSign(); - m_Amount = line.getAmount(); - setAmount(line.getAmount()); - } // DocLine_Payroll - - // References - private int m_HR_Process_ID = 0; - private int m_HR_Concept_ID = 0; - private int m_C_BPartner_ID = 0; - private int m_C_Activity_ID = 0; - private String m_AccountSign = ""; - private BigDecimal m_Amount = Env.ZERO; - private int m_HR_Department_ID = 0; - private int m_C_BP_Group_ID = 0; - - public int getHR_Process_ID(){ - return m_HR_Process_ID; - } - - public int getHR_Concept_ID(){ - return m_HR_Concept_ID; - } - - public String getAccountSign(){ - return m_AccountSign; - } - - public int getC_BPartner_ID(){ - return m_C_BPartner_ID; - } - - public int getC_Activity_ID(){ - return m_C_Activity_ID; - } - - - public BigDecimal getAmount() { - return m_Amount; - } - - public int getHR_Department_ID() { - return m_HR_Department_ID; - } - - public int getC_BP_Group_ID() { - return m_C_BP_Group_ID; - } - -} // DocLine_Payroll diff --git a/base/src/org/compiere/acct/Doc_CostCollector.java b/base/src/org/compiere/acct/Doc_CostCollector.java deleted file mode 100644 index 1b68a155ac..0000000000 --- a/base/src/org/compiere/acct/Doc_CostCollector.java +++ /dev/null @@ -1,231 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.compiere.acct; - -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.Collection; - -import org.compiere.model.MAccount; -import org.compiere.model.MAcctSchema; -import org.compiere.model.MCost; -import org.compiere.model.MCostElement; -import org.compiere.model.MProduct; -import org.compiere.model.MRefList; -import org.compiere.model.ProductCost; -import org.compiere.model.Query; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.compiere.wf.MWFNode; -import org.eevolution.model.MPPCostCollector; -import org.eevolution.model.MPPOrderBOMLine; -import org.eevolution.model.MPPOrderNode; - -/** - * Post Cost Collector - *
- *  Table:              PP_Cost_Collector
- *  Document Types:     MOP
- *  
- * @author victor.perez@e-evolution.com http://www.e-evolution.com - */ -public class Doc_CostCollector extends Doc -{ - - - /** - * Constructor - * @param ass accounting schemata - * @param rs record - * @param trxName trx - */ - protected Doc_CostCollector (MAcctSchema[] ass, ResultSet rs, String trxName) - { - super(ass, MPPCostCollector.class, rs, DOCTYPE_MOrder, trxName); - } //Doc Cost Collector - - - /** Pseudo Line */ - private DocLine m_line = null; - - /** Collector Cost */ - private MPPCostCollector m_cc = null; - - /** - * Load Document Details - * @return error message or null - */ - protected String loadDocumentDetails() - { - setC_Currency_ID (NO_CURRENCY); - m_cc = (MPPCostCollector)getPO(); - setDateDoc (m_cc.getMovementDate()); - setDateAcct(m_cc.getMovementDate()); - - // Pseudo Line - m_line = new DocLine (m_cc, this); - m_line.setQty (m_cc.getMovementQty(), false); // sets Trx and Storage Qty - - // Pseudo Line Check - if (m_line.getM_Product_ID() == 0) - log.warning(m_line.toString() + " - No Product"); - log.fine(m_line.toString()); - return null; - } // loadDocumentDetails - - /** - * Get Balance - * @return Zero (always balanced) - */ - public BigDecimal getBalance() - { - BigDecimal retValue = Env.ZERO; - return retValue; - } // getBalance - - /** - * Create Facts (the accounting logic) for - * @param as accounting schema - * @return Fact - */ - public ArrayList createFacts (MAcctSchema as) - { - log.info("Start Create Facts for Cost Collector"); - - //TODO: I need write the rule for calculate variances - // create Fact Header - Fact fact = new Fact(this, as, Fact.POST_Actual); - setC_Currency_ID (as.getC_Currency_ID()); - MProduct product = MProduct.get(getCtx(), m_cc.getM_Product_ID()); - - if(MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt.equals(m_cc.getCostCollectorType())) - { - //Finish good - MAccount debit = m_line.getAccount(ProductCost.ACCTTYPE_P_Asset, as); - MAccount credit = m_line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as); - BigDecimal cost = Env.ZERO; - - Collection elements = MCostElement.getByCostingMethod(getCtx(), as.getCostingMethod()); - for(MCostElement element : elements) - { - cost = MCost.getCostByCostType(product, as, m_cc.getAD_Org_ID(), m_cc.getM_AttributeSetInstance_ID(), - as.getM_CostType_ID() , element.getCostElementType(),m_cc.getMovementQty()); - createLines(element.getCostElementType(), as, fact, product, debit, credit, cost,m_cc.getMovementQty()); - log.info("Account Fact for Cost Element:" + element.getName() + " Cost:" + cost); - } - - //Account Scrap - if(m_cc.getScrappedQty().signum() != 0) - { - credit = m_line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as); - debit = m_line.getAccount(ProductCost.ACCTTYPE_P_Scrap, as); - - for(MCostElement element : elements) - { - cost = MCost.getCostByCostType(product, as, m_cc.getAD_Org_ID(), m_cc.getM_AttributeSetInstance_ID(), - as.getM_CostType_ID() , element.getCostElementType(),m_cc.getMovementQty()); - createLines(element.getCostElementType(), as, fact, product, debit, credit, cost,m_cc.getMovementQty()); - log.info("Account Fact for Cost Element:" + element.getName() + " Cost:" + cost); - } - } - } - else if (MPPCostCollector.COSTCOLLECTORTYPE_ComponentIssue.equals(m_cc.getCostCollectorType())) - { - - MAccount debit = m_line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as); - MAccount credit = m_line.getAccount(ProductCost.ACCTTYPE_P_Asset, as); - final String whereCluase = MPPOrderBOMLine.COLUMNNAME_PP_Order_BOMLine_ID - + "= ? AND " - + MPPOrderBOMLine.COLUMNNAME_IssueMethod - + "= ?"; - - boolean isFloorStock = new Query(m_cc.getCtx(),MPPOrderBOMLine.Table_Name,whereCluase, m_cc.get_TableName()) - .setOnlyActiveRecords(true) - .setParameters(new Object[]{m_cc.getPP_Order_BOMLine_ID(),MPPOrderBOMLine.ISSUEMETHOD_FloorStock}) - .match(); - if(isFloorStock) - { - credit = m_line.getAccount(ProductCost.ACCTTYPE_P_FloorStock, as); - } - - BigDecimal cost = Env.ZERO; - - Collection elements = MCostElement.getByCostingMethod(getCtx(), as.getCostingMethod()); - for(MCostElement element : elements) - { - cost = MCost.getCostByCostType(product, as, m_cc.getAD_Org_ID(), m_cc.getM_AttributeSetInstance_ID(), - as.getM_CostType_ID() , element.getCostElementType(),m_cc.getMovementQty()); - createLines(element.getCostElementType(), as, fact, product, debit, credit, cost,m_cc.getMovementQty()); - log.info("Account Fact for Cost Element:" + element.getName() + " Cost:" + cost); - } - } - else if (MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl.equals(m_cc.getCostCollectorType())) - { - MPPOrderNode activity = (MPPOrderNode) m_cc.getPP_Order_Node(); - MWFNode node = (MWFNode) activity.getAD_WF_Node(); - if(MPPOrderNode.DOCSTATUS_Completed.equals(activity.getDocAction())) - { - //Labor Rate - MAccount debit = m_line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as); - MAccount credit = m_line.getAccount(ProductCost.ACCTTYPE_P_Labor, as); - BigDecimal labor = node.getCostForCostElementType(MCostElement.COSTELEMENTTYPE_Resource, as.getC_AcctSchema_ID(), as.getM_CostType_ID(), m_cc.getAD_Org_ID(), m_cc.getSetupTimeReal().intValue(), m_cc.getDurationReal().intValue()); - createLines(MCostElement.COSTELEMENTTYPE_Resource, as, fact, product, debit, credit, labor, m_cc.getMovementQty()); - //Burden Rate - debit = m_line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as); - credit = m_line.getAccount(ProductCost.ACCTTYPE_P_Burden, as); - BigDecimal burden = node.getCostForCostElementType(MCostElement.COSTELEMENTTYPE_BurdenMOverhead, as.getC_AcctSchema_ID(), as.getM_CostType_ID(), m_cc.getAD_Org_ID(), m_cc.getSetupTimeReal().intValue(), m_cc.getDurationReal().intValue()); - createLines(MCostElement.COSTELEMENTTYPE_BurdenMOverhead, as, fact, product, debit, credit, burden, m_cc.getMovementQty()); - } - } - - log.info("End CreateFacts Manufacturing"+fact); - // - ArrayList facts = new ArrayList(); - facts.add(fact); - return facts; - } // createFact - - private void createLines(String CostElementType, MAcctSchema as ,Fact fact , MProduct product,MAccount debit, MAccount credit, BigDecimal cost, BigDecimal qty) - { - if(cost == null | debit == null | credit == null) - return; - - log.info("CostElementType: " +CostElementType + "Product: "+product.getName()+" Debit: " + debit.getDescription() + " Credit: "+ credit.getDescription() + " Cost: " + cost +" Qunatity: "+ qty); - // Line pointers - FactLine dr = null; - FactLine cr = null; - if(cost.signum() != 0 & qty != null) - { - dr = fact.createLine(m_line, debit , as.getC_Currency_ID(), cost, null); - dr.setQty(qty); - String desc = MRefList.getListName(getCtx(), MCostElement.COSTELEMENTTYPE_AD_Reference_ID, CostElementType); - dr.addDescription(Msg.translate(m_cc.getCtx(), desc)); - dr.setC_Project_ID(m_cc.getC_Project_ID()); - dr.setC_Activity_ID(m_cc.getC_Activity_ID()); - dr.setC_Campaign_ID(m_cc.getC_Campaign_ID()); - dr.setM_Locator_ID(m_cc.getM_Locator_ID()); - - cr = fact.createLine(m_line, credit,as.getC_Currency_ID(), null, cost); - cr.setQty(qty); - cr.addDescription(Msg.translate(m_cc.getCtx(), desc)); - cr.setC_Project_ID(m_cc.getC_Project_ID()); - cr.setC_Activity_ID(m_cc.getC_Activity_ID()); - cr.setC_Campaign_ID(m_cc.getC_Campaign_ID()); - cr.setM_Locator_ID(m_cc.getM_Locator_ID()); - } - } -} // Doc Cost Collector diff --git a/base/src/org/compiere/acct/Doc_Payroll.java b/base/src/org/compiere/acct/Doc_Payroll.java deleted file mode 100644 index 63f0d33ae2..0000000000 --- a/base/src/org/compiere/acct/Doc_Payroll.java +++ /dev/null @@ -1,197 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.compiere.acct; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.logging.Level; - -import org.compiere.model.MAccount; -import org.compiere.model.MAcctSchema; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.eevolution.model.MHRMovement; -import org.eevolution.model.MHRProcess; - - -/** - * Post Invoice Documents. - *
- *  Table:              HR_Process (??)
- *  Document Types:     HR_Process
- *  
- * @author Oscar Gomez Islas - * @version $Id: Doc_Payroll.java,v 1.1 2007/01/20 00:40:02 ogomezi Exp $ - */ -public class Doc_Payroll extends Doc -{ - public MHRProcess process = null; - /** - * Constructor - * @param ass accounting schemata - * @param rs record - * @parem trxName trx - */ - protected Doc_Payroll (MAcctSchema[] ass, ResultSet rs, String trxName) - { - super(ass, MHRProcess.class, rs, DOCTYPE_Payroll, trxName); - } // Doc_Payroll - - /** - * Load Specific Document Details - * @return error message or null - */ - protected String loadDocumentDetails () - { - process = (MHRProcess)getPO(); - setDateDoc(getDateAcct()); - // Contained Objects - p_lines = loadLines(process); - log.fine("Lines=" + p_lines.length); - return null; - } // loadDocumentDetails - - - /** - * Load Payroll Line - * @param Payroll Process - * @return DocLine Array - */ - private DocLine[] loadLines(MHRProcess process) - { - ArrayList list = new ArrayList(); - MHRMovement[] lines = process.getLines(true); - for (int i = 0; i < lines.length; i++) - { - MHRMovement line = lines[i]; - DocLine_Payroll docLine = new DocLine_Payroll (line, this); - // - log.fine(docLine.toString()); - list.add(docLine); - } - // Return Array - DocLine[] dls = new DocLine[list.size()]; - list.toArray(dls); - return dls; - } // loadLines - - - /************************************************************************** - * Get Source Currency Balance - subtracts line amounts from total - no rounding - * @return positive amount, if total invoice is bigger than lines - */ - public BigDecimal getBalance() - { - BigDecimal retValue = Env.ZERO; - return Env.ZERO; - } // getBalance - - /** - * Create Facts (the accounting logic) for - * @param as account schema - * @return Fact - */ - public ArrayList createFacts (MAcctSchema as) - { - Fact fact = new Fact(this, as, Fact.POST_Actual); - String sql2= "SELECT m.HR_Concept_id,0,MAX(c.Name),SUM(ROUND(m.Amount,2)),MAX(c.AccountSign),MAX(CA.IsBalancing),e.ad_org_id,d.c_activity_id" // 1,2,3,4,5,6,7,8 - +" FROM HR_Movement m" - +" INNER JOIN HR_Concept_Acct ca ON (ca.HR_Concept_ID=m.HR_Concept_ID AND ca.IsActive = 'Y')" - +" INNER JOIN HR_Concept c ON (c.HR_Concept_ID=m.HR_Concept_ID AND c.IsActive = 'Y')" - +" INNER JOIN C_BPartner bp ON (bp.C_BPartner_ID = m.C_BPartner_ID)" - +" INNER JOIN hr_employee e ON (bp.c_bpartner_id=e.c_bpartner_id)" - +" INNER JOIN hr_department d ON (d.hr_department_id=e.hr_department_id)" - +" WHERE m.HR_Process_ID=? AND (m.Qty <> 0 OR m.Amount <> 0) AND c.AccountSign != 'N' AND ca.IsBalancing != 'Y'" - +" GROUP BY m.hr_concept_id,e.ad_org_id,d.c_activity_id" - +" order by e.ad_org_id,d.c_activity_id"; - - System.err.println("Consulta: " + sql2); - PreparedStatement pstmt2 = null; - try - { - pstmt2 = DB.prepareStatement (sql2, process.get_TrxName()); - pstmt2.setInt (1, process.getHR_Process_ID()); - ResultSet rs2 = pstmt2.executeQuery (); - while (rs2.next ()) - { - int AD_OrgTrx_ID=rs2.getInt(7); - int C_Activity_ID=rs2.getInt(8); - if(rs2.getString(5).equals("D")){ // --- Debit - MAccount accountBPD = MAccount.get (getCtx(), getAccountBalancing(as.getC_AcctSchema_ID(),rs2.getInt(1),rs2.getInt(2),"D")); - FactLine debit=fact.createLine(null, accountBPD,as.getC_Currency_ID(),rs2.getBigDecimal(4), null); - debit.setAD_OrgTrx_ID(AD_OrgTrx_ID); - debit.setC_Activity_ID(C_Activity_ID); - debit.save(); - MAccount accountBPC = MAccount.get (getCtx(),this.getAccountBalancing(as.getC_AcctSchema_ID(),rs2.getInt(1),rs2.getInt(2),"C")); - FactLine credit = fact.createLine(null,accountBPC ,as.getC_Currency_ID(),null,rs2.getBigDecimal(4)); - credit.setAD_OrgTrx_ID(AD_OrgTrx_ID); - credit.setC_Activity_ID(C_Activity_ID); - credit.save(); - } - else if(rs2.getString(5).equals("C")){ // --- Credit - MAccount accountBPC = MAccount.get (getCtx(),this.getAccountBalancing(as.getC_AcctSchema_ID(),rs2.getInt(1),rs2.getInt(2),"C")); - FactLine credit=fact.createLine(null, accountBPC,as.getC_Currency_ID(), null, rs2.getBigDecimal(4)); - credit.setAD_OrgTrx_ID(AD_OrgTrx_ID); - credit.setC_Activity_ID(C_Activity_ID); - credit.save(); - MAccount accountBPD = MAccount.get (getCtx(),this.getAccountBalancing(as.getC_AcctSchema_ID(),rs2.getInt(1),rs2.getInt(2),"D")); - FactLine debit=fact.createLine(null, accountBPD ,as.getC_Currency_ID(),rs2.getBigDecimal(4), null); - debit.setAD_OrgTrx_ID(AD_OrgTrx_ID); - debit.setC_Activity_ID(C_Activity_ID); - debit.save(); - } - } - rs2.close (); - pstmt2.close (); - pstmt2 = null; - } - catch (Exception e) - { - log.log(Level.SEVERE, sql2, e); - } - - ArrayList facts = new ArrayList(); - facts.add(fact); - return facts; - } - - - private int getAccount (int AcctSchema_ID, int HR_Concept_ID, int C_BP_Group_ID, String AccountSign) - { - String field = AccountSign.equals("D") ? "HR_Expense_Acct" : "HR_Revenue_Acct"; - int Account_ID; - String sqlAccount = "SELECT " +field+ " FROM HR_Concept_Acct WHERE " - +" HR_Concept_ID=" +HR_Concept_ID+ " AND C_AcctSchema_ID=" +AcctSchema_ID; - Account_ID = DB.getSQLValue(null, sqlAccount); - if (Account_ID < 0 ) - Account_ID = DB.getSQLValue(null, sqlAccount); - - MAccount account = MAccount.get (getCtx(), Account_ID); - return Account_ID; - } - - private int getAccountBalancing (int AcctSchema_ID, int HR_Concept_ID, int C_BP_Group_ID, String AccountSign) - { - String field = AccountSign.equals("D") ? "HR_Expense_Acct" : "HR_Revenue_Acct"; - int Account_ID; - String sqlAccount = "SELECT " +field+ " FROM HR_Concept_Acct WHERE " - +" HR_Concept_ID=" +HR_Concept_ID+ " AND C_AcctSchema_ID=" +AcctSchema_ID; - Account_ID = DB.getSQLValue(null, sqlAccount); - return Account_ID; - } -} // Doc_Payroll diff --git a/base/src/org/compiere/process/DocumentEngine.java b/base/src/org/compiere/process/DocumentEngine.java index ec40d6f17a..648ad6a9e8 100644 --- a/base/src/org/compiere/process/DocumentEngine.java +++ b/base/src/org/compiere/process/DocumentEngine.java @@ -44,10 +44,10 @@ import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Ini; -import org.eevolution.model.MDDOrder; -import org.eevolution.model.MHRProcess; -import org.eevolution.model.MPPCostCollector; -import org.eevolution.model.MPPOrder; +import org.eevolution.model.X_DD_Order; +import org.eevolution.model.X_HR_Process; +import org.eevolution.model.X_PP_Cost_Collector; +import org.eevolution.model.X_PP_Order; /** * Document Action Engine @@ -1044,7 +1044,7 @@ public class DocumentEngine implements DocAction /******************** * Manufacturing Order */ - else if (AD_Table_ID == MPPOrder.Table_ID) + else if (AD_Table_ID == X_PP_Order.Table_ID) { if (docStatus.equals(DocumentEngine.STATUS_Drafted) || docStatus.equals(DocumentEngine.STATUS_InProgress) @@ -1063,7 +1063,7 @@ public class DocumentEngine implements DocAction /******************** * Manufacturing Cost Collector */ - else if (AD_Table_ID == MPPCostCollector.Table_ID) + else if (AD_Table_ID == X_PP_Cost_Collector.Table_ID) { if (docStatus.equals(DocumentEngine.STATUS_Drafted) || docStatus.equals(DocumentEngine.STATUS_InProgress) @@ -1082,7 +1082,7 @@ public class DocumentEngine implements DocAction /******************** * Distribution Order */ - else if (AD_Table_ID == MDDOrder.Table_ID) + else if (AD_Table_ID == X_DD_Order.Table_ID) { if (docStatus.equals(DocumentEngine.STATUS_Drafted) || docStatus.equals(DocumentEngine.STATUS_InProgress) @@ -1101,7 +1101,7 @@ public class DocumentEngine implements DocAction /******************** * Payroll Process */ - else if (AD_Table_ID == MHRProcess.Table_ID) + else if (AD_Table_ID == X_HR_Process.Table_ID) { if (docStatus.equals(DocumentEngine.STATUS_Drafted) || docStatus.equals(DocumentEngine.STATUS_InProgress) diff --git a/base/src/org/compiere/process/FactAcctReset.java b/base/src/org/compiere/process/FactAcctReset.java index e3cdc863e8..70bec4ba60 100644 --- a/base/src/org/compiere/process/FactAcctReset.java +++ b/base/src/org/compiere/process/FactAcctReset.java @@ -42,9 +42,9 @@ import org.compiere.model.MRequisition; import org.compiere.model.X_M_Production; import org.compiere.util.DB; import org.compiere.util.TimeUtil; -import org.eevolution.model.MDDOrder; -import org.eevolution.model.MHRProcess; -import org.eevolution.model.MPPOrder; +import org.eevolution.model.X_DD_Order; +import org.eevolution.model.X_HR_Process; +import org.eevolution.model.X_PP_Order; /** * Accounting Fact Reset @@ -235,13 +235,13 @@ public class FactAcctReset extends SvrProcess docBaseType = "= '" + MPeriodControl.DOCBASETYPE_MatchInvoice + "'"; else if (AD_Table_ID == MMatchPO.Table_ID) docBaseType = "= '" + MPeriodControl.DOCBASETYPE_MatchPO + "'"; - else if (AD_Table_ID == MPPOrder.Table_ID) + else if (AD_Table_ID == X_PP_Order.Table_ID) docBaseType = "IN ('" + MPeriodControl.DOCBASETYPE_ManufacturingOrder + "','" + MPeriodControl.DOCBASETYPE_MaintenanceOrder + "','" + MPeriodControl.DOCBASETYPE_QualityOrder + "')"; - else if (AD_Table_ID == MDDOrder.Table_ID) + else if (AD_Table_ID == X_DD_Order.Table_ID) docBaseType = "= '" + MPeriodControl.DOCBASETYPE_DistributionOrder+ "'"; - else if (AD_Table_ID == MHRProcess.Table_ID) + else if (AD_Table_ID == X_HR_Process.Table_ID) docBaseType = "= '" + MPeriodControl.DOCBASETYPE_Payroll+ "'"; // if (docBaseType == null) diff --git a/base/src/org/eevolution/exceptions/ActivityProcessedException.java b/base/src/org/eevolution/exceptions/ActivityProcessedException.java deleted file mode 100644 index 640e7c6d1f..0000000000 --- a/base/src/org/eevolution/exceptions/ActivityProcessedException.java +++ /dev/null @@ -1,31 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - *****************************************************************************/ -package org.eevolution.exceptions; - -import org.adempiere.exceptions.AdempiereException; -import org.eevolution.model.MPPOrderNode; - -/** - * Throwed when we are trying to process/complete an Order Activity that is already processed/completed - * @author Teo Sarca, www.arhipac.ro - */ -public class ActivityProcessedException extends AdempiereException -{ - private static final long serialVersionUID = 1L; - - public ActivityProcessedException(MPPOrderNode activity) - { - super("Order Activity Already Processed - "+activity); // TODO: translate - } -} diff --git a/base/src/org/eevolution/model/CalloutCostCollector.java b/base/src/org/eevolution/model/CalloutCostCollector.java deleted file mode 100644 index 183138e13e..0000000000 --- a/base/src/org/eevolution/model/CalloutCostCollector.java +++ /dev/null @@ -1,95 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.math.BigDecimal; -import java.util.Properties; - -import org.compiere.model.CalloutEngine; -import org.compiere.model.GridField; -import org.compiere.model.GridTab; - -/** - * Cost Collector Callout - * - * @author Victor Perez www.e-evolution.com - * @author Teo Sarca, www.arhipac.ro - */ -public class CalloutCostCollector extends CalloutEngine -{ - public String Manufacture (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - Integer PP_Order_ID = (Integer)value; - if (PP_Order_ID == null || PP_Order_ID <= 0) - return ""; - // - MPPOrder order = new MPPOrder(ctx, PP_Order_ID, null); - mTab.setValue(MPPCostCollector.COLUMNNAME_AD_Org_ID, order.getAD_Org_ID()); - mTab.setValue(MPPCostCollector.COLUMNNAME_C_DocTypeTarget_ID, order.getC_DocType_ID()); - mTab.setValue(MPPCostCollector.COLUMNNAME_S_Resource_ID, order.getS_Resource_ID()); - mTab.setValue(MPPCostCollector.COLUMNNAME_M_Product_ID, order.getM_Product_ID()); - mTab.setValue(MPPCostCollector.COLUMNNAME_M_AttributeSetInstance_ID, order.getM_AttributeSetInstance_ID()); - mTab.setValue(MPPCostCollector.COLUMNNAME_M_Warehouse_ID, order.getM_Warehouse_ID()); - mTab.setValue(MPPCostCollector.COLUMNNAME_MovementQty, order.getQtyOrdered()); - // - MPPOrderWorkflow owf = order.getMPPOrderWorkflow(); - mTab.setValue(MPPCostCollector.COLUMNNAME_PP_Order_Workflow_ID, owf.getPP_Order_Workflow_ID()); -// mTab.setValue(MPPCostCollector.COLUMNNAME_DurationUnit, owf.getDurationUnit()); - // - return ""; - } - - public String node (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - Integer PP_Order_Node_ID = (Integer)value; - if (PP_Order_Node_ID == null || PP_Order_Node_ID <= 0) - return ""; - // - MPPOrderNode node = getPP_Order_Node(ctx, PP_Order_Node_ID); - mTab.setValue(MPPCostCollector.COLUMNNAME_IsSubcontracting, node.isSubcontracting()); - mTab.setValue(MPPCostCollector.COLUMNNAME_S_Resource_ID, node.getS_Resource_ID()); - - BigDecimal qtyToDeliver = node.getQtyRequiered() - .subtract(node.getQtyDelivered()); - mTab.setValue(MPPCostCollector.COLUMNNAME_MovementQty, qtyToDeliver); - // - int duration = node.getDuration(); - BigDecimal durationReal = qtyToDeliver.multiply(BigDecimal.valueOf(duration)); - mTab.setValue(MPPCostCollector.COLUMNNAME_DurationReal, durationReal); - - return ""; - } - - public String MovementType (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - return ""; - } - - private MPPOrderNode m_node = null; - private MPPOrderNode getPP_Order_Node(Properties ctx, int PP_Order_Node_ID) - { - if (m_node != null && m_node.get_ID() == PP_Order_Node_ID) - { - return m_node; - } - m_node = new MPPOrderNode(ctx, PP_Order_Node_ID, null); - return m_node; - } - -} - - diff --git a/base/src/org/eevolution/model/CalloutDistributionOrder.java b/base/src/org/eevolution/model/CalloutDistributionOrder.java deleted file mode 100644 index 9b85350919..0000000000 --- a/base/src/org/eevolution/model/CalloutDistributionOrder.java +++ /dev/null @@ -1,195 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.model; - -import java.math.BigDecimal; -import java.util.Properties; - -import org.compiere.model.CalloutEngine; -import org.compiere.model.GridField; -import org.compiere.model.GridTab; -import org.compiere.model.MLocator; -import org.compiere.model.MProduct; -import org.compiere.model.MStorage; -import org.compiere.model.MUOM; -import org.compiere.model.MUOMConversion; -import org.compiere.util.Env; -import org.compiere.util.Msg; - -/** - * Distribution Order Callout - * - * @author Victor Perez - * @version $Id: CalloutOrder.java,v 1.23 2004/08/27 21:24:12 vpj-cd Exp $ - */ -public class CalloutDistributionOrder extends CalloutEngine -{ - /** Debug Steps */ - private boolean steps = false; - - /** - * Order Line - Quantity. - * - called from C_UOM_ID, QtyEntered, QtyOrdered - * - enforces qty UOM relationship - * @param ctx context - * @param WindowNo current Window No - * @param mTab Grid Tab - * @param mField Grid Field - * @param value New Value - * @return null or error message - */ - public String qty (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - if (isCalloutActive() || value == null) - return ""; - int M_Product_ID = Env.getContextAsInt(ctx, WindowNo, "M_Product_ID"); - if (steps) log.warning("init - M_Product_ID=" + M_Product_ID + " - " ); - BigDecimal QtyOrdered = Env.ZERO; - BigDecimal QtyEntered; - - // No Product - if (M_Product_ID == 0) - { - QtyEntered = (BigDecimal)mTab.getValue("QtyEntered"); - QtyOrdered = QtyEntered; - mTab.setValue("QtyOrdered", QtyOrdered); - } - // UOM Changed - convert from Entered -> Product - else if (mField.getColumnName().equals("C_UOM_ID")) - { - int C_UOM_To_ID = ((Integer)value).intValue(); - QtyEntered = (BigDecimal)mTab.getValue("QtyEntered"); - BigDecimal QtyEntered1 = QtyEntered.setScale(MUOM.getPrecision(ctx, C_UOM_To_ID), BigDecimal.ROUND_HALF_UP); - if (QtyEntered.compareTo(QtyEntered1) != 0) - { - log.fine("Corrected QtyEntered Scale UOM=" + C_UOM_To_ID - + "; QtyEntered=" + QtyEntered + "->" + QtyEntered1); - QtyEntered = QtyEntered1; - mTab.setValue("QtyEntered", QtyEntered); - } - QtyOrdered = MUOMConversion.convertProductFrom (ctx, M_Product_ID, - C_UOM_To_ID, QtyEntered); - if (QtyOrdered == null) - QtyOrdered = QtyEntered; - boolean conversion = QtyEntered.compareTo(QtyOrdered) != 0; - Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N"); - mTab.setValue("QtyOrdered", QtyOrdered); - } - // QtyEntered changed - calculate QtyOrdered - else if (mField.getColumnName().equals("QtyEntered")) - { - int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID"); - QtyEntered = (BigDecimal)value; - BigDecimal QtyEntered1 = QtyEntered.setScale(MUOM.getPrecision(ctx, C_UOM_To_ID), BigDecimal.ROUND_HALF_UP); - if (QtyEntered.compareTo(QtyEntered1) != 0) - { - log.fine("Corrected QtyEntered Scale UOM=" + C_UOM_To_ID - + "; QtyEntered=" + QtyEntered + "->" + QtyEntered1); - QtyEntered = QtyEntered1; - mTab.setValue("QtyEntered", QtyEntered); - } - QtyOrdered = MUOMConversion.convertProductFrom (ctx, M_Product_ID, - C_UOM_To_ID, QtyEntered); - if (QtyOrdered == null) - QtyOrdered = QtyEntered; - boolean conversion = QtyEntered.compareTo(QtyOrdered) != 0; - log.fine("UOM=" + C_UOM_To_ID - + ", QtyEntered=" + QtyEntered - + " -> " + conversion - + " QtyOrdered=" + QtyOrdered); - Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N"); - mTab.setValue("QtyOrdered", QtyOrdered); - } - // QtyOrdered changed - calculate QtyEntered (should not happen) - else if (mField.getColumnName().equals("QtyOrdered")) - { - int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID"); - QtyOrdered = (BigDecimal)value; - int precision = MProduct.get(ctx, M_Product_ID).getUOMPrecision(); - BigDecimal QtyOrdered1 = QtyOrdered.setScale(precision, BigDecimal.ROUND_HALF_UP); - if (QtyOrdered.compareTo(QtyOrdered1) != 0) - { - log.fine("Corrected QtyOrdered Scale " - + QtyOrdered + "->" + QtyOrdered1); - QtyOrdered = QtyOrdered1; - mTab.setValue("QtyOrdered", QtyOrdered); - } - QtyEntered = MUOMConversion.convertProductTo (ctx, M_Product_ID, - C_UOM_To_ID, QtyOrdered); - if (QtyEntered == null) - QtyEntered = QtyOrdered; - boolean conversion = QtyOrdered.compareTo(QtyEntered) != 0; - log.fine("UOM=" + C_UOM_To_ID - + ", QtyOrdered=" + QtyOrdered - + " -> " + conversion - + " QtyEntered=" + QtyEntered); - Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N"); - mTab.setValue("QtyEntered", QtyEntered); - } - else - { - // QtyEntered = (BigDecimal)mTab.getValue("QtyEntered"); - QtyOrdered = (BigDecimal)mTab.getValue("QtyOrdered"); - } - - // Storage - if (M_Product_ID != 0 - && Env.isSOTrx(ctx, WindowNo) - && QtyOrdered.signum() > 0) // no negative (returns) - { - MProduct product = MProduct.get (ctx, M_Product_ID); - if (product.isStocked()) - { - int M_Locator_ID = Env.getContextAsInt(ctx, WindowNo, "M_Locator_ID"); - int M_AttributeSetInstance_ID = Env.getContextAsInt(ctx, WindowNo, "M_AttributeSetInstance_ID"); - int M_Warehouse_ID = MLocator.get(ctx, M_Locator_ID).getM_Warehouse_ID(); - - BigDecimal available = MStorage.getQtyAvailable - (M_Warehouse_ID, 0, M_Product_ID, M_AttributeSetInstance_ID, null); - if (available == null) - available = Env.ZERO; - if (available.signum() == 0) - mTab.fireDataStatusEEvent ("NoQtyAvailable", "0", false); - else if (available.compareTo(QtyOrdered) < 0) - mTab.fireDataStatusEEvent ("InsufficientQtyAvailable", available.toString(), false); - else - { - Integer DD_OrderLine_ID = (Integer)mTab.getValue("DD_OrderLine_ID"); - if (DD_OrderLine_ID == null) - DD_OrderLine_ID = new Integer(0); - BigDecimal notReserved = MDDOrderLine.getNotReserved(ctx, - M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, - DD_OrderLine_ID.intValue()); - if (notReserved == null) - notReserved = Env.ZERO; - BigDecimal total = available.subtract(notReserved); - if (total.compareTo(QtyOrdered) < 0) - { - String info = Msg.parseTranslation(ctx, "@QtyAvailable@=" + available - + " - @QtyNotReserved@=" + notReserved + " = " + total); - mTab.fireDataStatusEEvent ("InsufficientQtyAvailable", - info, false); - } - } - } - } - // - return ""; - } // qty - -} // CalloutOrder - diff --git a/base/src/org/eevolution/model/CalloutOrder.java b/base/src/org/eevolution/model/CalloutOrder.java deleted file mode 100644 index 52fe806dc5..0000000000 --- a/base/src/org/eevolution/model/CalloutOrder.java +++ /dev/null @@ -1,171 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.model; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.Properties; - -import org.compiere.model.CalloutEngine; -import org.compiere.model.GridField; -import org.compiere.model.GridTab; -import org.compiere.model.MProduct; -import org.compiere.model.MUOMConversion; -import org.compiere.util.Env; -import org.compiere.wf.MWorkflow; - -/** - * Order CalloutOrder - * - * @author Victor Perez - * @version $Id: CalloutOrder.java,v 1.23 2004/08/27 21:24:12 vpj-cd Exp $ - * - * @author Teo Sarca, www.arhipac.ro - */ -public class CalloutOrder extends CalloutEngine -{ - /** Debug Steps */ - private boolean steps = false; - - /** - * Order Line - Quantity. - * - called from C_UOM_ID, QtyEntered, QtyOrdered - * - enforces qty UOM relationship - * @param ctx Context - * @param WindowNo current Window No - * @param mTab Model Tab - * @param mField Model Field - * @param value The new value - */ - public String qty (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - if (value == null) - return ""; - - int M_Product_ID = Env.getContextAsInt(ctx, WindowNo, "M_Product_ID"); - if (steps) log.warning("qty - init - M_Product_ID=" + M_Product_ID + " - " ); - BigDecimal QtyOrdered = Env.ZERO ; - BigDecimal QtyEntered = Env.ZERO ; - - // No Product - if (M_Product_ID == 0) - { - QtyEntered = (BigDecimal)mTab.getValue("QtyEntered"); - mTab.setValue("QtyOrdered", QtyEntered); - } - // UOM Changed - convert from Entered -> Product - else if (mField.getColumnName().equals("C_UOM_ID")) - { - - int C_UOM_To_ID = ((Integer)value).intValue(); - QtyEntered = (BigDecimal)mTab.getValue("QtyEntered"); - QtyOrdered = MUOMConversion.convertProductFrom (ctx, M_Product_ID, - C_UOM_To_ID, QtyEntered); - if (QtyOrdered == null) - QtyOrdered = QtyEntered; - boolean conversion = QtyEntered.compareTo(QtyOrdered) != 0; - Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N"); - mTab.setValue("QtyOrdered", QtyOrdered); - } - // QtyEntered changed - calculate QtyOrdered - else if (mField.getColumnName().equals("QtyEntered")) - { - int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID"); - QtyEntered = (BigDecimal)value; - QtyOrdered = MUOMConversion.convertProductFrom (ctx, M_Product_ID, - C_UOM_To_ID, QtyEntered); - if (QtyOrdered == null) - QtyOrdered = QtyEntered; - boolean conversion = QtyEntered.compareTo(QtyOrdered) != 0; - log.fine("qty - UOM=" + C_UOM_To_ID - + ", QtyEntered=" + QtyEntered - + " -> " + conversion - + " QtyOrdered=" + QtyOrdered); - Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N"); - mTab.setValue("QtyOrdered", QtyOrdered); - } - // QtyOrdered changed - calculate QtyEntered - else if (mField.getColumnName().equals("QtyOrdered")) - { - int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID"); - QtyOrdered = (BigDecimal)value; - QtyEntered = MUOMConversion.convertProductTo (ctx, M_Product_ID, - C_UOM_To_ID, QtyOrdered); - if (QtyEntered == null) - QtyEntered = QtyOrdered; - boolean conversion = QtyOrdered.compareTo(QtyEntered) != 0; - log.fine("qty - UOM=" + C_UOM_To_ID - + ", QtyOrdered=" + QtyOrdered - + " -> " + conversion - + " QtyEntered=" + QtyEntered); - Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N"); - mTab.setValue("QtyEntered", QtyEntered); - } - return qtyBatch(ctx,WindowNo,mTab,mField,value); - //return ""; - } // qty - - public String qtyBatch (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - Integer AD_Workflow_ID = ((Integer)mTab.getValue(MPPOrder.COLUMNNAME_AD_Workflow_ID)); - // No workflow entered, or is just a new record: - if (AD_Workflow_ID == null) - return ""; - - BigDecimal p_QtyEntered = (BigDecimal)mTab.getValue(MPPOrder.COLUMNNAME_QtyEntered); - if (p_QtyEntered.equals(Env.ZERO)) - return ""; - - MWorkflow wf = MWorkflow.get(ctx , AD_Workflow_ID.intValue()); - BigDecimal Qty = null; - BigDecimal QtyBatchSize = wf.getQtyBatchSize().setScale(0, RoundingMode.UP); - - if (QtyBatchSize.equals(Env.ZERO)) - Qty = Env.ONE; - else - Qty = p_QtyEntered.divide(QtyBatchSize, 0, RoundingMode.UP); - - mTab.setValue(MPPOrder.COLUMNNAME_QtyBatchs, Qty); - mTab.setValue(MPPOrder.COLUMNNAME_QtyBatchSize, QtyBatchSize); - - return ""; - } - - public String product (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - if (isCalloutActive() || value == null) - return ""; - - MProduct product = MProduct.get(ctx, ((Number)value).intValue()); - if (product == null) - return ""; - mTab.setValue(MProduct.COLUMNNAME_C_UOM_ID,product.getC_UOM_ID()); - - int workflow_id = MWorkflow.getWorkflowSearchKey(product); - mTab.setValue(MPPOrder.COLUMNNAME_AD_Workflow_ID, workflow_id > 0 ? workflow_id : null); - - MPPProductBOM bom = MPPProductBOM.getDefault(product, null); - if (bom == null) - return ""; - - mTab.setValue(MPPOrder.COLUMNNAME_PP_Product_BOM_ID, bom.get_ID()); - mTab.setValue(MPPOrder.COLUMNNAME_C_UOM_ID,bom.getC_UOM_ID()); - - return ""; - } -} // CalloutOrder - diff --git a/base/src/org/eevolution/model/CalloutPayroll.java b/base/src/org/eevolution/model/CalloutPayroll.java deleted file mode 100644 index ec02d5423d..0000000000 --- a/base/src/org/eevolution/model/CalloutPayroll.java +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * The contents of this file are subject to the Compiere License Version 1.1 - * ("License"); You may not use this file except in compliance with the License - * You may obtain a copy of the License at http://www.compiere.org/license.html - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for - * the specific language governing rights and limitations under the License. - * The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial - * Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke - * are Copyright (C) 1999-2005 Jorg Janke. - * All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved. - * Contributor(s): ______________________________________. - *****************************************************************************/ -package org.eevolution.model; - -import java.util.Properties; - -import org.compiere.model.CalloutEngine; -import org.compiere.model.GridField; -import org.compiere.model.GridTab; -import org.compiere.util.DB; - -/** - * Payroll Callouts. - * org.eevolution.model.CalloutPayroll.* - * - * - * @version $Id: CalloutPayment.java,v 1.17 2005/11/06 01:17:27 jjanke Exp $ - */ -public class CalloutPayroll extends CalloutEngine -{ - public String ColumnType (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - if (value == null) - return ""; - final int HR_Concept_ID = (Integer) value; - if (HR_Concept_ID == 0) - return ""; - // - final String columnType = DB.getSQLValueStringEx(null, - "SELECT ColumnType FROM HR_Concept WHERE HR_Concept_ID=?", - HR_Concept_ID); - mTab.setValue(MHRAttribute.COLUMNNAME_ColumnType, columnType); - return ""; - } -} // CalloutPayroll diff --git a/base/src/org/eevolution/model/LiberoValidator.java b/base/src/org/eevolution/model/LiberoValidator.java deleted file mode 100644 index 225fe22051..0000000000 --- a/base/src/org/eevolution/model/LiberoValidator.java +++ /dev/null @@ -1,255 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.util.Collection; - -import org.compiere.model.MClient; -import org.compiere.model.MForecastLine; -import org.compiere.model.MInOut; -import org.compiere.model.MInOutLine; -import org.compiere.model.MOrder; -import org.compiere.model.MOrderLine; -import org.compiere.model.MRequisitionLine; -import org.compiere.model.ModelValidationEngine; -import org.compiere.model.ModelValidator; -import org.compiere.model.PO; -import org.compiere.model.Query; -import org.compiere.process.DocAction; -import org.compiere.util.CLogger; -import org.compiere.util.Msg; - - -/** - * Libero Validator - * - * @author Victor Perez - * @author Trifon Trifonov - *
  • [ 2270421 ] Can not complete Shipment (Customer)
  • - * @author Teo Sarca, www.arhipac.ro - */ -public class LiberoValidator implements ModelValidator -{ - /** Logger */ - private CLogger log = CLogger.getCLogger(getClass()); - /** Client */ - private int m_AD_Client_ID = -1; - - - public void initialize (ModelValidationEngine engine, MClient client) - { - //client = null for global validator - if (client != null) - { - m_AD_Client_ID = client.getAD_Client_ID(); - log.info(client.toString()); - } - else - { - log.info("Initializing global validator: "+this.toString()); - } - // Tables to be monitored - engine.addModelChange(MOrder.Table_Name, this); - engine.addModelChange(MOrderLine.Table_Name, this); - engine.addModelChange(MRequisitionLine.Table_Name, this); - engine.addModelChange(MForecastLine.Table_Name, this); - engine.addModelChange(MDDOrderLine.Table_Name, this); - engine.addModelChange(MPPOrder.Table_Name, this); - engine.addModelChange(MPPOrderBOMLine.Table_Name, this); - engine.addDocValidate(MInOut.Table_Name, this); - } // initialize - - public String modelChange (PO po, int type) throws Exception - { - log.info(po.get_TableName() + " Type: "+type); - boolean isChange = (TYPE_AFTER_NEW == type || (TYPE_AFTER_CHANGE == type && MPPMRP.isChanged(po))); - boolean isDelete = (TYPE_BEFORE_DELETE == type); - boolean isReleased = false; - boolean isVoided = false; - DocAction doc = null; - if (po instanceof DocAction) - { - doc = (DocAction)po; - } - else if (po instanceof MOrderLine) - { - doc = ((MOrderLine)po).getParent(); - } - if (doc != null) - { - String docStatus = doc.getDocStatus(); - isReleased = DocAction.STATUS_InProgress.equals(docStatus) - || DocAction.STATUS_Completed.equals(docStatus); - isVoided = DocAction.STATUS_Voided.equals(docStatus); - } - // - // - if (isDelete || isVoided) - { - MPPMRP.deleteMRP(po); - } - else if (po instanceof MOrder) - { - MOrder order = (MOrder)po; - // Create/Update a planning supply when isPurchase Order - // or when you change DatePromised or DocStatus and is Purchase Order - if (isChange && !order.isSOTrx()) - { - MPPMRP.C_Order(order, false); - } - // Update MRP when you change the status order to complete or in process for a sales order - // or you change DatePromised - else if (type == TYPE_AFTER_CHANGE && order.isSOTrx()) - { - if (isReleased || MPPMRP.isChanged(order)) - { - MPPMRP.C_Order(order, false); - } - } - - } - // - else if (po instanceof MOrderLine && isChange) - { - MOrderLine ol = (MOrderLine)po; - MOrder order = ol.getParent(); - // Create/Update a planning supply when isPurchase Order or you change relevant fields - if (!order.isSOTrx()) - { - MPPMRP.C_OrderLine(ol, false); - } - // Update MRP when Sales Order have document status in process or complete and - // you change relevant fields - else if(order.isSOTrx() && isReleased) - { - MPPMRP.C_OrderLine(ol, false); - } - } - // - else if (po instanceof MRequisitionLine && isChange) - { - MRequisitionLine rl = (MRequisitionLine)po; - MPPMRP.M_RequisitionLine(rl, false); - } - // - else if (po instanceof MForecastLine && isChange) - { - MForecastLine fl = (MForecastLine)po; - MPPMRP.M_ForecastLine(fl, false); - } - // - else if (po instanceof MDDOrderLine && isChange) - { - MDDOrderLine ol = (MDDOrderLine)po; - MPPMRP.DD_Order_Line(ol , false); - } - // - else if (po instanceof MPPOrder && isChange) - { - MPPOrder order = (MPPOrder)po; - MPPMRP.PP_Order(order, false); - } - // - else if (po instanceof MPPOrderBOMLine && isChange) - { - MPPOrderBOMLine obl = (MPPOrderBOMLine)po; - MPPMRP.PP_Order_BOMLine(obl, false); - } - // - return null; - } // modelChange - - public String docValidate (PO po, int timing) - { - log.info(po.get_TableName() + " Timing: "+timing); - if(po instanceof MInOut && timing == TIMING_BEFORE_COMPLETE) - { - MInOut inout = (MInOut)po; - if(inout.isSOTrx()) - { - final String whereClause = "C_OrderLine_ID IS NOT NULL" - +" AND EXISTS (SELECT 1 FROM M_InOutLine iol" - +" WHERE iol.M_InOut_ID=? AND PP_Order.C_OrderLine_ID = iol.C_OrderLine_ID) AND " - + MPPOrder.COLUMNNAME_DocStatus + " = ?"; - Collection orders = new Query(po.getCtx(), MPPOrder.Table_Name, whereClause, po.get_TrxName()) - .setParameters(new Object[]{inout.getM_InOut_ID(), MPPOrder.DOCSTATUS_InProgress}) - .list(); - for(MPPOrder order : orders) - { - String description = order.getDescription() != null ? order.getDescription() : "" - + Msg.translate(inout.getCtx(), MInOut.COLUMNNAME_M_InOut_ID) - + " : " - + Msg.translate(inout.getCtx(), MInOut.COLUMNNAME_DocumentNo); - - order.setDescription(description); - order.closeIt(); - order.setDocStatus(MPPOrder.DOCACTION_Close); - order.setDocAction(MPPOrder.DOCACTION_None); - order.saveEx(); - - } - } - } - else if (po instanceof MInOut && timing == TIMING_AFTER_COMPLETE) - { - MInOut inout = (MInOut)po; - - for (MInOutLine line : inout.getLines()) - { - final String whereClause = "C_OrderLine_ID=? AND PP_Cost_Collector_ID IS NOT NULL"; - Collection olines = new Query(po.getCtx(), MOrderLine.Table_Name, whereClause, po.get_TrxName()) - .setParameters(new Object[]{line.getC_OrderLine_ID()}) - .list(); - for (MOrderLine oline : olines) - { - if(oline.getQtyOrdered().compareTo(oline.getQtyDelivered()) >= 0) - { - MPPCostCollector cc = new MPPCostCollector(po.getCtx(), oline.getPP_Cost_Collector_ID(), po.get_TrxName()); - String docStatus = cc.completeIt(); - cc.setDocStatus(docStatus); - cc.setDocAction(MPPCostCollector.DOCACTION_Close); - cc.saveEx(); - return null; - } - } - } - } - return null; - } // docValidate - - /** - * User Login. - * Called when preferences are set - * @param AD_Org_ID org - * @param AD_Role_ID role - * @param AD_User_ID user - * @return error message or null - */ - public String login (int AD_Org_ID, int AD_Role_ID, int AD_User_ID) - { - return null; - } // login - - /** - * Get Client to be monitored - * @return AD_Client_ID client - */ - public int getAD_Client_ID() - { - return m_AD_Client_ID; - } // getAD_Client_ID -} // LiberoValidator diff --git a/base/src/org/eevolution/model/MDDNetworkDistribution.java b/base/src/org/eevolution/model/MDDNetworkDistribution.java deleted file mode 100644 index 3a07b7f818..0000000000 --- a/base/src/org/eevolution/model/MDDNetworkDistribution.java +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2008 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, SC ARHIPAC SERVICE SRL * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.compiere.model.Query; -import org.compiere.util.CCache; - -/** - * Network Distribution - * @author Victor Perez, e-Evolution,SC - * @author Teo Sarca, SC ARHIPAC SERVICE SRL - */ -public class MDDNetworkDistribution extends X_DD_NetworkDistribution -{ - private static final long serialVersionUID = 1L; - private static CCache s_cache = new CCache(MDDNetworkDistribution.Table_Name, 50); - - /** Standard Constructor */ - public MDDNetworkDistribution (Properties ctx, int DD_NetworkDistribution_ID, String trxName) - { - super (ctx, DD_NetworkDistribution_ID, trxName); - if (DD_NetworkDistribution_ID == 0) - { - } - } - - /** Load Constructor */ - public MDDNetworkDistribution (Properties ctx, ResultSet rs, String trxName) - { - super (ctx, rs, trxName); - } - - /** Network Lines */ - private MDDNetworkDistributionLine[] m_lines = null; - - /** - * Get from Cache - * @param ctx context - * @param M_Warehouse_ID id - * @return warehouse - */ - public static MDDNetworkDistribution get (Properties ctx, int DD_NetworkDistribution_ID) - { - MDDNetworkDistribution retValue = (MDDNetworkDistribution)s_cache.get(DD_NetworkDistribution_ID); - if (retValue != null) - return retValue; - // - retValue = new MDDNetworkDistribution (ctx,DD_NetworkDistribution_ID, null); - s_cache.put (DD_NetworkDistribution_ID, retValue); - return retValue; - } // get - - /** - * Get Lines - * @return array of lines MDDNetworkDistributionLine - */ - public MDDNetworkDistributionLine[] getLines() - { - if (m_lines != null) - return m_lines; - - List - list = new Query(getCtx(), MDDNetworkDistributionLine.Table_Name, "DD_NetworkDistribution_ID=?", get_TrxName()) - .setParameters(new Object[]{get_ID()}) - .setOrderBy("PriorityNo, M_Shipper_ID") - .list(); - m_lines = list.toArray (new MDDNetworkDistributionLine[list.size()]); - return m_lines; - } // getLines - - - /** - * Get Lines - * @param M_Warehouse_ID ID Warehouse - * @return array of lines MDDNetworkDistributionLine - */ - public MDDNetworkDistributionLine[] getLines(int M_Warehouse_ID) - { - List list = new ArrayList(); - for (MDDNetworkDistributionLine line : getLines()) - { - if (line.getM_Warehouse_ID() == M_Warehouse_ID) - list.add(line); - } - return list.toArray(new MDDNetworkDistributionLine[list.size()]); - } // getLines -} \ No newline at end of file diff --git a/base/src/org/eevolution/model/MDDNetworkDistributionLine.java b/base/src/org/eevolution/model/MDDNetworkDistributionLine.java deleted file mode 100644 index b956004fd5..0000000000 --- a/base/src/org/eevolution/model/MDDNetworkDistributionLine.java +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2008 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -/** - * Network Distribution - * @author Victor Perez,e-Evolution,SC - */ -public class MDDNetworkDistributionLine extends X_DD_NetworkDistributionLine -{ - private static final long serialVersionUID = 1L; - - /** Standard Constructor */ - public MDDNetworkDistributionLine (Properties ctx, int DD_NetworkDistributionLine_ID, String trxName) - { - super (ctx, DD_NetworkDistributionLine_ID, trxName); - if (DD_NetworkDistributionLine_ID == 0) - { - } - } - - /** Load Constructor */ - public MDDNetworkDistributionLine (Properties ctx, ResultSet rs, String trxName) - { - super (ctx, rs, trxName); - } -} \ No newline at end of file diff --git a/base/src/org/eevolution/model/MEXPFormat.java b/base/src/org/eevolution/model/MEXPFormat.java deleted file mode 100644 index 30f2f30cc6..0000000000 --- a/base/src/org/eevolution/model/MEXPFormat.java +++ /dev/null @@ -1,215 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * - Antonio Cañaveral, e-Evolution - * * - * Sponsors: * - * - e-Evolution (http://www.e-evolution.com/) * - **********************************************************************/ - -package org.eevolution.model; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.model.MTable; -import org.compiere.model.Query; -import org.compiere.util.CCache; -import org.compiere.util.CLogger; -import org.compiere.util.DB; - -/** - * @author Trifon N. Trifonov - * @author Antonio Cañaveral, e-Evolution - *
  • [ 2195090 ] Implementing ExportFormat cache - *
  • http://sourceforge.net/tracker/index.php?func=detail&aid=2195090&group_id=176962&atid=879335 - */ -public class MEXPFormat extends X_EXP_Format { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger (MEXPFormat.class); - - private static CCache s_cache = new CCache("MEXPFormat", 50 ); - - public MEXPFormat(Properties ctx, int EXP_Format_ID, String trxName) { - super(ctx, EXP_Format_ID, trxName); - } - - public MEXPFormat(Properties ctx, ResultSet rs, String trxName) { - super (ctx, rs, trxName); - } - - public MEXPFormatLine[] getFormatLines() { - return getFormatLinesOrderedBy(X_EXP_FormatLine.COLUMNNAME_Position); - } - - public MEXPFormatLine[] getFormatLinesOrderedBy(String orderBy) { - List resultList = new ArrayList(); - - StringBuffer sql = new StringBuffer("SELECT * ") - .append(" FROM ").append(X_EXP_FormatLine.Table_Name) - .append(" WHERE ").append(X_EXP_FormatLine.COLUMNNAME_EXP_Format_ID).append("=?") - .append(" AND IsActive = ?") - .append(" ORDER BY ").append(orderBy); - PreparedStatement pstmt = null; - MEXPFormatLine exportLine = null; - try { - pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - pstmt.setInt(1, getEXP_Format_ID()); - pstmt.setString(2, "Y"); - ResultSet rs = pstmt.executeQuery (); - while ( rs.next() ) { - exportLine = new MEXPFormatLine (getCtx(), rs, get_TrxName()); - resultList.add(exportLine); - } - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } - } - - MEXPFormatLine[] result = (MEXPFormatLine[])resultList.toArray( new MEXPFormatLine[0]); - return result; - } - - public MEXPFormatLine[] getUniqueColumns() throws SQLException { - List resultList = new ArrayList(); - - StringBuffer sql = new StringBuffer("SELECT * ") - .append(" FROM ").append(X_EXP_FormatLine.Table_Name) - .append(" WHERE ").append(X_EXP_FormatLine.COLUMNNAME_EXP_Format_ID).append("= ?") - .append(" AND IsActive = ?") - .append(" AND ").append(X_EXP_FormatLine.COLUMNNAME_IsPartUniqueIndex).append("= ?") - .append(" ORDER BY ").append(X_EXP_FormatLine.COLUMNNAME_Position); - PreparedStatement pstmt = null; - MEXPFormatLine exportLine = null; - log.info(sql.toString()); - - log.info("pstmt.setInt(1, getEXP_Format_ID() = " + getEXP_Format_ID()); - try { - pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - pstmt.setInt(1, getEXP_Format_ID()); - pstmt.setString(2, "Y"); - pstmt.setString(3, "Y"); - ResultSet rs = pstmt.executeQuery (); - while ( rs.next() ) { - exportLine = new MEXPFormatLine (getCtx(), rs, get_TrxName()); - resultList.add(exportLine); - } - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - throw e; - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } - } - - MEXPFormatLine[] result = (MEXPFormatLine[])resultList.toArray( new MEXPFormatLine[0]); - return result; - } - - - public static MEXPFormat getFormatByValueAD_Client_IDAndVersion(Properties ctx, String value, int AD_Client_ID, String version, String trxName) - throws SQLException - { - String key = new String(value+version); - MEXPFormat retValue=null; - if(retValue!=null) - return retValue; - - StringBuffer whereCluse = new StringBuffer(X_EXP_Format.COLUMNNAME_Value).append("=?") - .append(" AND AD_Client_ID = ?") - .append(" AND ").append(X_EXP_Format.COLUMNNAME_Version).append(" = ?"); - - retValue = (MEXPFormat) new Query(ctx,X_EXP_Format.Table_Name,whereCluse.toString(),trxName) - .setParameters(new Object[] {value,AD_Client_ID,version}).first(); - s_cache.put (key, retValue); - - return retValue; - } - - public static MEXPFormat getFormatByAD_Client_IDAD_Table_IDAndVersion(Properties ctx, int AD_Client_ID, int AD_Table_ID, String version, String trxName) throws SQLException - { - String key = new String(MTable.getTableName(ctx, AD_Table_ID)+version); - MEXPFormat retValue=null; - - retValue = (MEXPFormat)s_cache.get(key); - if(retValue!=null) - return retValue; - - StringBuffer whereCluse = new StringBuffer(" AD_Client_ID = ? ") - .append(" AND ").append(X_EXP_Format.COLUMNNAME_AD_Table_ID).append(" = ? ") - .append(" AND ").append(X_EXP_Format.COLUMNNAME_Version).append(" = ?"); - - retValue = (MEXPFormat) new Query(ctx,X_EXP_Format.Table_Name,whereCluse.toString(),trxName) - .setParameters(new Object[] {AD_Client_ID,AD_Table_ID,version}).first(); - - s_cache.put (key, retValue); - - return retValue; - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer ("X_EXP_Format[ID=").append(get_ID()).append("; Value = "+getValue()+"]"); - return sb.toString(); - - } - - /** - * Before Delete - * @return true of it can be deleted - */ - protected boolean beforeDelete () - { - int[] ids =MEXPFormatLine.getAllIDs(MEXPFormatLine.Table_Name, "EXP_Format_ID="+getEXP_Format_ID(), get_TrxName()); - for (int id : ids) - { - MEXPFormatLine line = new MEXPFormatLine(getCtx(), id, get_TrxName()); - line.delete(true); - } - return true; - } // beforeDelete -} diff --git a/base/src/org/eevolution/model/MEXPFormatLine.java b/base/src/org/eevolution/model/MEXPFormatLine.java deleted file mode 100644 index 134e1d2dc9..0000000000 --- a/base/src/org/eevolution/model/MEXPFormatLine.java +++ /dev/null @@ -1,106 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - e-Evolution (http://www.e-evolution.com/) * - **********************************************************************/ - -package org.eevolution.model; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.util.CLogger; -import org.compiere.util.DB; - -/** - * @author Trifon N. Trifonov - */ -public class MEXPFormatLine extends X_EXP_FormatLine { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger (X_EXP_FormatLine.class); - - - - public MEXPFormatLine(Properties ctx, int C_EDIFormat_Line_ID, String trxName) { - super(ctx, C_EDIFormat_Line_ID, trxName); - } - - public MEXPFormatLine (Properties ctx, ResultSet rs, String trxName) { - super (ctx, rs, trxName); - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer ("X_EXP_FormatLine[ID=").append(get_ID()).append("; Value="+getValue()+"; Type="+getType()+"]"); - return sb.toString(); - } - - public static MEXPFormatLine getFormatLineByValue(Properties ctx, String value, int EXP_Format_ID, String trxName) - throws SQLException - { - MEXPFormatLine result = null; - - StringBuffer sql = new StringBuffer("SELECT * ") - .append(" FROM ").append(X_EXP_FormatLine.Table_Name) - .append(" WHERE ").append(X_EXP_Format.COLUMNNAME_Value).append("=?") - //.append(" AND IsActive = ?") - //.append(" AND AD_Client_ID = ?") - .append(" AND ").append(X_EXP_Format.COLUMNNAME_EXP_Format_ID).append(" = ?") - ; - PreparedStatement pstmt = null; - try { - pstmt = DB.prepareStatement (sql.toString(), trxName); - pstmt.setString(1, value); - pstmt.setInt(2, EXP_Format_ID); - ResultSet rs = pstmt.executeQuery (); - if ( rs.next() ) { - result = new MEXPFormatLine (ctx, rs, trxName); - } - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - throw e; - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } - } - - return result; - } -} diff --git a/base/src/org/eevolution/model/MEXPProcessor.java b/base/src/org/eevolution/model/MEXPProcessor.java deleted file mode 100644 index b506ef23f4..0000000000 --- a/base/src/org/eevolution/model/MEXPProcessor.java +++ /dev/null @@ -1,101 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - e-Evolution (http://www.e-evolution.com/) * - **********************************************************************/ - -package org.eevolution.model; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.util.CLogger; -import org.compiere.util.DB; - -/** - * @author Trifon N. Trifonov - */ -public class MEXPProcessor extends X_EXP_Processor { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger (MEXPProcessor.class); - - - public MEXPProcessor(Properties ctx, int EXP_Processor_ID, String trxName) { - super(ctx, EXP_Processor_ID, trxName); - } - - public MEXPProcessor(Properties ctx, ResultSet rs, String trxName) { - super (ctx, rs, trxName); - } - - public X_EXP_ProcessorParameter[] getEXP_ProcessorParameters(String trxName) { - List resultList = new ArrayList(); - - StringBuffer sql = new StringBuffer("SELECT * ") - .append(" FROM ").append(X_EXP_ProcessorParameter.Table_Name) - .append(" WHERE ").append(X_EXP_ProcessorParameter.COLUMNNAME_EXP_Processor_ID).append("=?") // # 1 - .append(" AND IsActive = ?") // # 2 - //.append(" ORDER BY ").append(X_EXP_ProcessorParameter.COLUMNNAME_) - ; - PreparedStatement pstmt = null; - X_EXP_ProcessorParameter processorParameter = null; - try { - pstmt = DB.prepareStatement (sql.toString(), trxName); - pstmt.setInt(1, getEXP_Processor_ID()); - pstmt.setString(2, "Y"); - ResultSet rs = pstmt.executeQuery (); - while ( rs.next() ) { - processorParameter = new X_EXP_ProcessorParameter (getCtx(), rs, trxName); - resultList.add(processorParameter); - } - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } - } - X_EXP_ProcessorParameter[] result = (X_EXP_ProcessorParameter[])resultList.toArray( new X_EXP_ProcessorParameter[0]); - return result; - } - - -} diff --git a/base/src/org/eevolution/model/MEXPProcessorParameter.java b/base/src/org/eevolution/model/MEXPProcessorParameter.java deleted file mode 100644 index 30f742195c..0000000000 --- a/base/src/org/eevolution/model/MEXPProcessorParameter.java +++ /dev/null @@ -1,59 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - e-Evolution (http://www.e-evolution.com/) * - **********************************************************************/ - -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -import org.compiere.util.CLogger; - -/** - * @author Trifon N. Trifonov - */ -public class MEXPProcessorParameter extends X_EXP_ProcessorParameter { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger (MEXPProcessorParameter.class); - - - public MEXPProcessorParameter(Properties ctx, int EXP_ProcessorParameter_ID, String trxName) { - super(ctx, EXP_ProcessorParameter_ID, trxName); - } - - public MEXPProcessorParameter(Properties ctx, ResultSet rs, String trxName) { - super (ctx, rs, trxName); - } - -} diff --git a/base/src/org/eevolution/model/MEXPProcessorType.java b/base/src/org/eevolution/model/MEXPProcessorType.java deleted file mode 100644 index a768ad0c8e..0000000000 --- a/base/src/org/eevolution/model/MEXPProcessorType.java +++ /dev/null @@ -1,59 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - e-Evolution (http://www.e-evolution.com/) * - **********************************************************************/ - -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -import org.compiere.util.CLogger; - -/** - * @author Trifon N. Trifonov - */ -public class MEXPProcessorType extends X_EXP_Processor_Type { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger (MEXPProcessorType.class); - - - public MEXPProcessorType(Properties ctx, int EXP_Processor_Type_ID, String trxName) { - super(ctx, EXP_Processor_Type_ID, trxName); - } - - public MEXPProcessorType(Properties ctx, ResultSet rs, String trxName) { - super (ctx, rs, trxName); - } - -} diff --git a/base/src/org/eevolution/model/MHRAttribute.java b/base/src/org/eevolution/model/MHRAttribute.java deleted file mode 100644 index 1535393f0e..0000000000 --- a/base/src/org/eevolution/model/MHRAttribute.java +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -/** - * HR Attribute Model - * @author Cristina Ghita, www.arhipac.ro - * - */ -public class MHRAttribute extends X_HR_Attribute -{ - /** - * - */ - private static final long serialVersionUID = 3783311896401143394L; - - /** - * @param ctx - * @param HR_Attribute_ID - * @param trxName - */ - public MHRAttribute(Properties ctx, int HR_Attribute_ID, String trxName) - { - super(ctx, HR_Attribute_ID, trxName); - } - - /** - * @param ctx - * @param rs - * @param trxName - */ - public MHRAttribute(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - @Override - public I_HR_Concept getHR_Concept() - { - return MHRConcept.get(getCtx(), getHR_Concept_ID()); - } -} diff --git a/base/src/org/eevolution/model/MHRConcept.java b/base/src/org/eevolution/model/MHRConcept.java deleted file mode 100644 index 6bf9436d2b..0000000000 --- a/base/src/org/eevolution/model/MHRConcept.java +++ /dev/null @@ -1,200 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.compiere.model.Query; -import org.compiere.util.CCache; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Util; - -/** - * Payroll Concept for HRayroll Module - * - * @author Oscar Gómez Islas - * @version $Id: HRPayroll.java,v 1.0 2005/10/05 ogomezi - * - * @author Cristina Ghita, www.arhipac.ro - */ -public class MHRConcept extends X_HR_Concept -{ - /** - * - */ - private static final long serialVersionUID = 8736925494645172953L; - - /** Cache */ - private static CCache s_cache = new CCache(Table_Name, 100); - /** Cache by Value */ - private static CCache s_cacheValue = new CCache(Table_Name+"_Value", 100); - - public static MHRConcept get(Properties ctx, int HR_Concept_ID) - { - if (HR_Concept_ID <= 0) - return null; - // - MHRConcept concept = s_cache.get(HR_Concept_ID); - if (concept != null) - return concept; - // - concept = new MHRConcept(ctx, HR_Concept_ID, null); - if (concept.get_ID() != HR_Concept_ID) - { - concept = null; - } - else - { - s_cache.put(HR_Concept_ID, concept); - } - return concept; - } - - /** - * Get Concept by Value - * @param ctx - * @param value - * @return - */ - public static MHRConcept forValue(Properties ctx, String value) - { - if (Util.isEmpty(value, true)) - { - return null; - } - - int AD_Client_ID = Env.getAD_Client_ID(ctx); - final String key = AD_Client_ID+"#"+value; - MHRConcept concept = s_cacheValue.get(key); - if (concept != null) - { - return concept; - } - - final String whereClause = COLUMNNAME_Value+"=? AND AD_Client_ID IN (?,?)"; - concept = new Query(ctx, Table_Name, whereClause, null) - .setParameters(new Object[]{value, 0, AD_Client_ID}) - .setOnlyActiveRecords(true) - .setOrderBy("AD_Client_ID DESC") - .first(); - if (concept != null) - { - s_cacheValue.put(key, concept); - s_cache.put(concept.get_ID(), concept); - } - return concept; - } - - /** - * Get Employee's of Payroll Type - * @param payroll_id Payroll ID - * @param department_id Department ID - * @param employee_id Employee_ID - * @param sqlwhere Clause SQLWhere - * @return lines - */ - public static MHRConcept[] getConcepts (int payroll_id, int department_id, int employee_id, String sqlWhere) - { - Properties ctx = Env.getCtx(); - List params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - - whereClause.append("AD_Client_ID=?"); - params.add(Env.getAD_Client_ID(Env.getCtx())); - - whereClause.append(" AND EXISTS (SELECT 1 FROM HR_Attribute a WHERE a.HR_Concept_ID=HR_Concept.HR_Concept_ID ") - .append(" AND (a.HR_Payroll_ID=? OR a.HR_Payroll_ID IS NULL) )"); - params.add(payroll_id); - - if (department_id != 0 ) - { - whereClause.append(" AND HR_Concept.HR_Department_ID=?"); - params.add(department_id); - } - - if (Util.isEmpty(sqlWhere)) - { - whereClause.append(sqlWhere); - } - - List list = new Query(ctx, Table_Name, whereClause.toString(), null) - .setParameters(params) - .setOnlyActiveRecords(true) - .setOrderBy(COLUMNNAME_Value) - .list(); - return list.toArray(new MHRConcept[list.size()]); - } // getConcept - - /** - * Standard Constructor - * @param ctx context - * @param HR_Concept_ID - * @param trxName - */ - public MHRConcept (Properties ctx, int HR_Concept_ID, String trxName) - { - super (ctx, HR_Concept_ID, trxName); - if (HR_Concept_ID == 0) - { - setValue(""); - setName(""); - setDescription(""); - setIsEmployee(false); - setIsPrinted(false); - setHR_Payroll_ID(0); - setHR_Job_ID(0); - setHR_Department_ID(0); - } - } // HRConcept - - /** - * Load Constructor - * @param ctx context - * @param rs result set - * @param trxName - */ - public MHRConcept (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - public int getConceptAccountCR() - { - String sql = " HR_Expense_Acct FROM HR_Concept c " + - " INNER JOIN HR_Concept_Acct ca ON (c.HR_Concept_ID=ca.HR_Concept_ID)" + - " WHERE c.HR_Concept_ID " + getHR_Concept_ID(); - int result = DB.getSQLValue("ConceptCR", sql); - if (result > 0) - return result; - return 0; - } - - public int getConceptAccountDR() - { - String sql = " HR_Revenue_Acct FROM HR_Concept c " + - " INNER JOIN HR_Concept_Acct ca ON (c.HR_Concept_ID=ca.HR_Concept_ID)" + - " WHERE c.HR_Concept_ID " + getHR_Concept_ID(); - int result = DB.getSQLValue("ConceptCR", sql); - if (result > 0) - return result; - return 0; - } - -} // HRConcept \ No newline at end of file diff --git a/base/src/org/eevolution/model/MHRConceptCategory.java b/base/src/org/eevolution/model/MHRConceptCategory.java deleted file mode 100644 index 7ded7d8070..0000000000 --- a/base/src/org/eevolution/model/MHRConceptCategory.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * - */ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -import org.compiere.model.Query; -import org.compiere.util.CCache; -import org.compiere.util.Env; - -/** - * HR Concept Category - * - * @author Cristina Ghita, www.arhipac.ro - */ -public class MHRConceptCategory extends X_HR_Concept_Category -{ - - /** - * - */ - private static final long serialVersionUID = 8470029939291479283L; - - private static CCache s_cache = new CCache(Table_Name, 20); - private static CCache s_cacheValue = new CCache(Table_Name+"_Value", 20); - - public static MHRConceptCategory get(Properties ctx, int HR_Concept_Category_ID) - { - if (HR_Concept_Category_ID <= 0) - { - return null; - } - // Try cache - MHRConceptCategory cc = s_cache.get(HR_Concept_Category_ID); - if (cc != null) - { - return cc; - } - // Load from DB - cc = new MHRConceptCategory(ctx, HR_Concept_Category_ID, null); - if (cc.get_ID() != HR_Concept_Category_ID) - { - return null; - } - if (cc != null) - { - s_cache.put(HR_Concept_Category_ID, cc); - } - return cc; - } - - public static MHRConceptCategory forValue(Properties ctx, String value) - { - if (value == null) - { - return null; - } - final int AD_Client_ID = Env.getAD_Client_ID(ctx); - // Try cache - final String key = AD_Client_ID+"#"+value; - MHRConceptCategory cc = s_cacheValue.get(key); - if (cc != null) - { - return cc; - } - // Try database - final String whereClause = COLUMNNAME_Value+"=? AND AD_Client_ID IN (?,?)"; - cc = new Query(ctx, Table_Name, whereClause, null) - .setParameters(new Object[]{value, 0, AD_Client_ID}) - .setOnlyActiveRecords(true) - .setOrderBy("AD_Client_ID DESC") - .first(); - if (cc != null) - { - s_cacheValue.put(key, cc); - s_cache.put(cc.get_ID(), cc); - } - return cc; - } - - public MHRConceptCategory(Properties ctx, int HR_Concept_Category_ID, String trxName) - { - super(ctx, HR_Concept_Category_ID, trxName); - } - public MHRConceptCategory(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } -} diff --git a/base/src/org/eevolution/model/MHRDepartment.java b/base/src/org/eevolution/model/MHRDepartment.java deleted file mode 100644 index 4bc5dad095..0000000000 --- a/base/src/org/eevolution/model/MHRDepartment.java +++ /dev/null @@ -1,93 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.List; -import java.util.Properties; - -import org.compiere.model.Query; -import org.compiere.util.CCache; -import org.compiere.util.Env; - -/** - * @author Cristina Ghita, www.arhipac.ro - * - */ -public class MHRDepartment extends X_HR_Department -{ - /** - * - */ - private static final long serialVersionUID = 83878114891519775L; - - public static List getAll(Properties ctx) - { - List list = new Query(Env.getCtx(), X_HR_Department.Table_Name, "AD_Client_ID=?", null) - .setParameters(new Object[] {Env.getAD_Client_ID(ctx)}) - .setOrderBy(COLUMNNAME_Name) - .list(); - for (MHRDepartment dep : list) - { - s_cache.put(dep.get_ID(), dep); - } - return list; - } - - public static MHRDepartment get(Properties ctx, int HR_Department_ID) - { - if (HR_Department_ID <= 0) - { - return null; - } - - if (s_cache.size() == 0) - { - getAll(ctx); - } - MHRDepartment dep = s_cache.get(HR_Department_ID); - if (dep != null) - { - return dep; - } - dep = new MHRDepartment(ctx, HR_Department_ID, null); - if (dep.get_ID() == HR_Department_ID) - { - s_cache.put(HR_Department_ID, dep); - } - return dep; - } - - private static CCache s_cache = new CCache(Table_Name, 50, 0); - - /** - * @param ctx - * @param HR_Department_ID - * @param trxName - */ - public MHRDepartment(Properties ctx, int HR_Department_ID, String trxName) - { - super(ctx, HR_Department_ID, trxName); - } - - /** - * @param ctx - * @param rs - * @param trxName - */ - public MHRDepartment(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } -} diff --git a/base/src/org/eevolution/model/MHREmployee.java b/base/src/org/eevolution/model/MHREmployee.java deleted file mode 100644 index 101b2e87fc..0000000000 --- a/base/src/org/eevolution/model/MHREmployee.java +++ /dev/null @@ -1,158 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.compiere.model.MBPartner; -import org.compiere.model.Query; -import org.compiere.util.CCache; -import org.compiere.util.Env; - - -/** - * HR Employee Model - * - * @author Victor Perez - * @author Cristina Ghita, www.arhipac.ro - */ -public class MHREmployee extends X_HR_Employee -{ - /** - * - */ - private static final long serialVersionUID = -7083160315471023587L; - - public static MHREmployee get(Properties ctx, int HR_Employee_ID) - { - if (HR_Employee_ID <= 0) - return null; - // - MHREmployee employee = s_cache.get(HR_Employee_ID); - if (employee != null) - return employee; - // - employee = new MHREmployee(ctx, HR_Employee_ID, null); - if (employee.get_ID() != HR_Employee_ID) - { - employee = null; - } - else - { - s_cache.put(HR_Employee_ID, employee); - } - return employee; - } - - /** - * Get Employees of Process - * @param p HR Process - * @return Array of Business Partners - */ - public static MBPartner[] getEmployees (MHRProcess p) - { - List params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - whereClause.append(" EXISTS (SELECT 1 FROM HR_Employee e WHERE e.C_BPartner_ID = C_BPartner.C_BPartner_ID "); - - // Just active employee - whereClause.append(" AND e.IsActive=? "); - params.add(true); - - // This payroll not content periods, NOT IS a Regular Payroll > ogi-cd 28Nov2007 - if(p.getHR_Payroll_ID() != 0 && p.getHR_Period_ID() != 0) - { - whereClause.append(" AND (e.HR_Payroll_ID IS NULL OR e.HR_Payroll_ID=?) " ); - params.add(p.getHR_Payroll_ID()); - } - - // HR Period - if(p.getHR_Period_ID() != 0) - { - whereClause.append(" AND e.StartDate <=? "); - params.add(new X_HR_Period(p.getCtx(), p.getHR_Period_ID(), null).getEndDate()); - } - else - { - whereClause.append(" AND e.StartDate <=? "); - params.add(p.getDateAcct()); - } - - // Selected Department - if (p.getHR_Department_ID() != 0) - { - whereClause.append(" AND e.HR_Department_ID =? "); - params.add(p.getHR_Department_ID()); - } - - whereClause.append(" ) "); // end select from HR_Employee - - // Selected Employee - if (p.getC_BPartner_ID() != 0) - { - whereClause.append(" AND C_BPartner_ID =? "); - params.add(p.getC_BPartner_ID()); - } - - List list = new Query(p.getCtx(), MBPartner.Table_Name, whereClause.toString(), p.get_TrxName()) - .setParameters(params) - .setOnlyActiveRecords(true) - .setOrderBy(COLUMNNAME_Name) - .list(); - - return list.toArray(new MBPartner[list.size()]); - } // getEmployees - - public static MHREmployee getActiveEmployee(Properties ctx, int C_BPartner_ID, String trxName) - { - return new Query(ctx, Table_Name, COLUMNNAME_C_BPartner_ID+"=?", trxName) - .setOnlyActiveRecords(true) - .setParameters(new Object[]{C_BPartner_ID}) - .setOrderBy(COLUMNNAME_HR_Employee_ID+" DESC") // just in case... - .first(); - } - - /** Cache */ - private static CCache s_cache = new CCache(Table_Name, 1000); - - /************************************************************************** - * Invoice Line Constructor - * @param ctx context - * @param HR_Employee_ID ID Employee - * @param trxName transaction name - */ - public MHREmployee (Properties ctx, int HR_Employee_ID, String trxName) //-- - { - super (ctx, HR_Employee_ID, trxName); - if (HR_Employee_ID == 0) - { - setClientOrg(Env.getAD_Client_ID(Env.getCtx()), Env.getAD_Org_ID(Env.getCtx())); - } - } // MHREmployee - - /** - * Load Constructor - * @param ctx context - * @param rs result set record - */ - public MHREmployee (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } // MHREmployee -} // MHREmployee diff --git a/base/src/org/eevolution/model/MHRMovement.java b/base/src/org/eevolution/model/MHRMovement.java deleted file mode 100644 index 5e42af1858..0000000000 --- a/base/src/org/eevolution/model/MHRMovement.java +++ /dev/null @@ -1,127 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.Properties; - -import org.adempiere.exceptions.AdempiereException; -import org.compiere.util.Env; -import org.compiere.util.Util; - -/** - * Payroll Concept for HRayroll Module - * - * @author Oscar Gómez Islas - * @author Teo Sarca, www.arhipac.ro - */ -public class MHRMovement extends X_HR_Movement -{ - /** - * - */ - private static final long serialVersionUID = 6705848510397126140L; - - /** - * Standard Constructor - * @param ctx context - * @param HR_Concept_ID - * @param trxName - */ - public MHRMovement (Properties ctx, int HR_Movement_ID, String trxName) - { - super (ctx, HR_Movement_ID, trxName); - } - - /** - * Load Constructor - * @param ctx context - * @param rs result set - * @param trxName - */ - public MHRMovement (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - public MHRMovement (MHRProcess proc, MHRConcept concept) - { - this(proc.getCtx(), 0, proc.get_TrxName()); - } - - public void addAmount(BigDecimal amount) - { - setAmount(getAmount().add(amount != null ? amount : Env.ZERO)); - } - - public void addQty(BigDecimal qty) - { - setQty(getAmount().add(qty != null ? qty : Env.ZERO)); - } - - /** - * @return true if all movement values (Amount, Qty, Text) are empty or negative - */ - public boolean isEmpty() - { - return getQty().signum() < 0 - && getAmount().signum() < 0 - && Util.isEmpty(getTextMsg()); - } - - /** - * According to the concept type, it's saved in the column specified for the purpose - * @param columnType column type (see MHRConcept.COLUMNTYPE_*) - * @param value - */ - public void setColumnValue(Object value) - { - final String columnType = getColumnType(); - if (MHRConcept.COLUMNTYPE_Quantity.equals(columnType)) - { - BigDecimal qty = new BigDecimal(value.toString()); - setQty(qty); - setAmount(Env.ZERO); - } - else if(MHRConcept.COLUMNTYPE_Amount.equals(columnType)) - { - BigDecimal amount = new BigDecimal(value.toString()); - setAmount(amount); - setQty(Env.ZERO); - } - else if(MHRConcept.COLUMNTYPE_Text.equals(columnType)) - { - setTextMsg(value.toString().trim()); - } - else if(MHRConcept.COLUMNTYPE_Date.equals(columnType)) - { - if (value instanceof Timestamp) - { - setServiceDate((Timestamp)value); - } - else - { - setServiceDate(Timestamp.valueOf(value.toString().trim().substring(0, 10)+ " 00:00:00.0")); - } - } - else - { - throw new AdempiereException("@NotSupported@ @ColumnType@ - "+columnType); - } - - } -} // HRMovement \ No newline at end of file diff --git a/base/src/org/eevolution/model/MHRPayroll.java b/base/src/org/eevolution/model/MHRPayroll.java deleted file mode 100644 index 438dbdfdb8..0000000000 --- a/base/src/org/eevolution/model/MHRPayroll.java +++ /dev/null @@ -1,142 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -import org.compiere.model.MCalendar; -import org.compiere.model.Query; -import org.compiere.util.CCache; -import org.compiere.util.Env; -import org.compiere.util.Util; - -/** - * Payroll for HRayroll Module - * - * @author Oscar Gómez Islas - * @version $Id: HRPayroll.java,v 1.0 2005/10/05 ogomezi - * - * @author Cristina Ghita, www.arhipac.ro - */ -public class MHRPayroll extends X_HR_Payroll -{ - /** - * - */ - private static final long serialVersionUID = -1407037967021019961L; - /** Cache */ - private static CCache s_cache = new CCache(Table_Name, 10); - /** Cache */ - private static CCache s_cacheValue = new CCache(Table_Name+"_Value", 10); - - /** - * Get Payroll by Value - * @param ctx - * @param value - * @return payroll - */ - public static MHRPayroll forValue(Properties ctx, String value) - { - if (Util.isEmpty(value, true)) - { - return null; - } - - int AD_Client_ID = Env.getAD_Client_ID(ctx); - final String key = AD_Client_ID+"#"+value; - MHRPayroll payroll = s_cacheValue.get(key); - if (payroll != null) - { - return payroll; - } - - final String whereClause = COLUMNNAME_Value+"=? AND AD_Client_ID IN (?,?)"; - payroll = new Query(ctx, Table_Name, whereClause, null) - .setParameters(new Object[]{value, 0, AD_Client_ID}) - .setOnlyActiveRecords(true) - .setOrderBy("AD_Client_ID DESC") - .first(); - if (payroll != null) - { - s_cacheValue.put(key, payroll); - s_cache.put(payroll.get_ID(), payroll); - } - return payroll; - } - - /** - * Get Payroll by ID - * @param ctx - * @param HR_Payroll_ID - * @return payroll - */ - public static MHRPayroll get(Properties ctx, int HR_Payroll_ID) - { - if (HR_Payroll_ID <= 0) - return null; - // - MHRPayroll payroll = s_cache.get(HR_Payroll_ID); - if (payroll != null) - return payroll; - // - payroll = new MHRPayroll(ctx, HR_Payroll_ID, null); - if (payroll.get_ID() != HR_Payroll_ID) - { - payroll = null; - } - else - { - s_cache.put(HR_Payroll_ID, payroll); - } - return payroll; - } - - /** - * Standard Constructor - * @param ctx context - * @param HR_Payroll_ID id - */ - public MHRPayroll (Properties ctx, int HR_Payroll_ID, String trxName) - { - super (ctx, HR_Payroll_ID, trxName); - if (HR_Payroll_ID == 0) - { - setProcessing (false); // N - } - } // HRPayroll - - /** - * Load Constructor - * @param ctx context - * @param rs result set - */ - public MHRPayroll (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - /** - * Parent Constructor - * @param parent parent - */ - public MHRPayroll (MCalendar calendar) - { - this (calendar.getCtx(), 0, calendar.get_TrxName()); - setClientOrg(calendar); - //setC_Calendar_ID(calendar.getC_Calendar_ID()); - } // HRPayroll -} // MPayroll diff --git a/base/src/org/eevolution/model/MHRPayrollConcept.java b/base/src/org/eevolution/model/MHRPayrollConcept.java deleted file mode 100644 index 079ccb331f..0000000000 --- a/base/src/org/eevolution/model/MHRPayrollConcept.java +++ /dev/null @@ -1,106 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.List; -import java.util.Properties; - -import org.compiere.model.Query; -import org.compiere.util.DB; - -/** - * Payroll Concept for HRayroll Module - * - * @author Oscar Gómez Islas - * @version $Id: HRPayrollConcept.java,v 1.0 2005/10/05 ogomezi - * - * @author Cristina Ghita, www.arhipac.ro - */ -public class MHRPayrollConcept extends X_HR_PayrollConcept -{ - /** - * - */ - private static final long serialVersionUID = -4335196239535511224L; - - /** - * Standard Constructor - * @param ctx context - * @param HR_Concept_ID id - */ - public MHRPayrollConcept (Properties ctx, int HR_Concept_ID, String trxName) - { - super (ctx, HR_Concept_ID, trxName); - } // HRConcept - - /** - * Load Constructor - * @param ctx context - * @param rs result set - */ - public MHRPayrollConcept (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - /** - * Concept constructor - * @param concept - */ - public MHRPayrollConcept (MHRConcept concept, int payroll_id) - { - super(concept.getCtx(), 0, concept.get_TrxName()); - setHR_Payroll_ID(payroll_id); - setHR_Concept_ID(concept.get_ID()); - setName(concept.getName()); - //setAD_Rule_Engine_ID(concept.getAD_Rule_Engine_ID()); - //setIsIncluded(true); - setIsActive(true); - } - - /** - * Get Concept's of Payroll Type - * @param p HR process - * @return array of HR concepts - */ - public static MHRPayrollConcept[] getPayrollConcepts (MHRProcess p) - { - List list = new Query(p.getCtx(), Table_Name, COLUMNNAME_HR_Payroll_ID+"=?", null) - .setOnlyActiveRecords(true) - .setParameters(new Object[]{p.getHR_Payroll_ID()}) - .setOrderBy(COLUMNNAME_SeqNo) - .list(); - return list.toArray(new MHRPayrollConcept[list.size()]); - } - - @Override - protected boolean beforeSave(boolean newRecord) - { - if (getSeqNo() == 0) - { - String sql = "SELECT COALESCE(MAX(SeqNo),0) FROM HR_PayrollConcept WHERE HR_Payroll_ID=?"; - int lastSeqNo = DB.getSQLValueEx(get_TrxName(), sql, getHR_Payroll_ID()); - if (lastSeqNo < 0) - lastSeqNo = 0; - setSeqNo(lastSeqNo + 10); - } - - return true; - } - - -} \ No newline at end of file diff --git a/base/src/org/eevolution/model/MHRPeriod.java b/base/src/org/eevolution/model/MHRPeriod.java deleted file mode 100644 index 7763dd2cf1..0000000000 --- a/base/src/org/eevolution/model/MHRPeriod.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - */ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -import org.compiere.util.CCache; - -/** - * HR Period - * @author Teo Sarca, www.arhipac.ro - */ -public class MHRPeriod extends X_HR_Period -{ - /** - * - */ - private static final long serialVersionUID = -7787966459848200539L; - - private static CCache s_cache = new CCache(Table_Name, 20); - - public static MHRPeriod get(Properties ctx, int HR_Period_ID) - { - if (HR_Period_ID <= 0) - { - return null; - } - // - MHRPeriod period = s_cache.get(HR_Period_ID); - if (period != null) - { - return period; - } - // Try Load - period = new MHRPeriod(ctx, HR_Period_ID, null); - if (period.get_ID() == HR_Period_ID) - { - s_cache.put(HR_Period_ID, period); - } - else - { - period = null; - } - return period; - } - - public MHRPeriod(Properties ctx, int HR_Period_ID, String trxName) - { - super(ctx, HR_Period_ID, trxName); - } - public MHRPeriod(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - -} diff --git a/base/src/org/eevolution/model/MHRProcess.java b/base/src/org/eevolution/model/MHRProcess.java deleted file mode 100644 index 706b85b391..0000000000 --- a/base/src/org/eevolution/model/MHRProcess.java +++ /dev/null @@ -1,1135 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.io.File; -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; -import java.util.Properties; - -import org.adempiere.exceptions.AdempiereException; -import org.compiere.model.MBPartner; -import org.compiere.model.MDocType; -import org.compiere.model.MPeriod; -import org.compiere.model.MRule; -import org.compiere.model.ModelValidationEngine; -import org.compiere.model.ModelValidator; -import org.compiere.model.Query; -import org.compiere.model.Scriptlet; -import org.compiere.print.ReportEngine; -import org.compiere.process.DocAction; -import org.compiere.process.DocumentEngine; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.TimeUtil; -import org.compiere.util.Util; - -/** - * HR Process Model - * - * @author oscar.gomez@e-evolution.com, e-Evolution http://www.e-evolution.com - *
  • Original contributor of Payroll Functionality - * @author victor.perez@e-evolution.com, e-Evolution http://www.e-evolution.com - *
  • FR [ 2520591 ] Support multiples calendar for Org - * @see http://sourceforge.net/tracker2/?func=detail&atid=879335&aid=2520591&group_id=176962 - * @author Cristina Ghita, www.arhipac.ro - */ -public class MHRProcess extends X_HR_Process implements DocAction -{ - /** - * - */ - private static final long serialVersionUID = 833872861685006894L; - - public int m_C_BPartner_ID = 0; - public int m_HR_Concept_ID = 0; - public String m_columnType = ""; - public Timestamp m_dateFrom; - public Timestamp m_dateTo; - /** HR_Concept_ID->MHRMovement */ - public Hashtable m_movement = new Hashtable(); - public MHRPayrollConcept[] linesConcept; - - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger (MHREmployee.class); - - /************************************************************************** - * Default Constructor - * @param ctx context - * @param HR_Process_ID To load, (0 create new order) - */ - public MHRProcess(Properties ctx, int HR_Process_ID, String trxName) - { - super(ctx, HR_Process_ID,trxName); - if (HR_Process_ID == 0) - { - setDocStatus(DOCSTATUS_Drafted); - setDocAction(DOCACTION_Prepare); - setC_DocType_ID(0); - set_ValueNoCheck ("DocumentNo", null); - setProcessed(false); - setProcessing(false); - setPosted(false); - setHR_Department_ID(0); - setC_BPartner_ID(0); - } - } - - /** - * Load Constructor - * @param ctx context - * @param rs result set record - */ - public MHRProcess(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs,trxName); - } // MHRProcess - - @Override - public void setProcessed(boolean processed) - { - super.setProcessed(processed); - if (get_ID() <= 0) - { - return; - } - final String sql = "UPDATE HR_Process SET Processed=? WHERE HR_Process_ID=?"; - DB.executeUpdateEx(sql, new Object[]{processed, get_ID()}, get_TrxName()); - } // setProcessed - - @Override - protected boolean beforeSave(boolean newRecord) - { - if (getAD_Client_ID() == 0) - { - throw new AdempiereException("@AD_Client_ID@ = 0"); - } - if (getAD_Org_ID() == 0) - { - int context_AD_Org_ID = getAD_Org_ID(); - if (context_AD_Org_ID == 0) - { - throw new AdempiereException("@AD_Org_ID@ = *"); - } - setAD_Org_ID(context_AD_Org_ID); - log.warning("Changed Org to Context=" + context_AD_Org_ID); - } - setC_DocType_ID(getC_DocTypeTarget_ID()); - - return true; - } - - - /** - * Process document - * @param processAction document action - * @return true if performed - */ - public boolean processIt(String processAction) - { - DocumentEngine engine = new DocumentEngine(this, getDocStatus()); - return engine.processIt(processAction, getDocAction()); - } // processIt - - /** Process Message */ - private String m_processMsg = null; - /** Just Prepared Flag */ - private boolean m_justPrepared = false; - - - /** - * Unlock Document. - * @return true if success - */ - public boolean unlockIt() - { - log.info("unlockIt - " + toString()); - setProcessing(false); - return true; - } // unlockIt - - - /** - * Invalidate Document - * @return true if success - */ - public boolean invalidateIt() - { - log.info("invalidateIt - " + toString()); - setDocAction(DOCACTION_Prepare); - return true; - } // invalidateIt - - - /************************************************************************** - * Prepare Document - * @return new status (In Progress or Invalid) - */ - public String prepareIt() - { - log.info("prepareIt - " + toString()); - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE); - if (m_processMsg != null) - { - return DocAction.STATUS_Invalid; - } - - // Std Period open? - - MHRPeriod period = MHRPeriod.get(getCtx(), getHR_Period_ID()); - MPeriod.testPeriodOpen(getCtx(), period.getDateAcct(), getC_DocTypeTarget_ID(), getAD_Org_ID()); - - // New or in Progress/Invalid - if ( DOCSTATUS_Drafted.equals(getDocStatus()) - || DOCSTATUS_InProgress.equals(getDocStatus()) - || DOCSTATUS_Invalid.equals(getDocStatus()) - || getC_DocType_ID() == 0) - { - setC_DocType_ID(getC_DocTypeTarget_ID()); - } - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE); - if (m_processMsg != null) - return DocAction.STATUS_Invalid; - // - m_justPrepared = true; - if (!DOCACTION_Complete.equals(getDocAction())) - setDocAction(DOCACTION_Complete); - return DocAction.STATUS_InProgress; - } // prepareIt - - /** - * Complete Document - * @return new status (Complete, In Progress, Invalid, Waiting ..) - */ - public String completeIt() - { - // Re-Check - if (!m_justPrepared) - { - String status = prepareIt(); - if (!DocAction.STATUS_InProgress.equals(status)) - return status; - } - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE); - if (m_processMsg != null) - return DocAction.STATUS_Invalid; - - // Implicit Approval -// if (!isApproved()) -// approveIt(); - - HashMap scriptCtx = new HashMap(); - scriptCtx.put("process", this); - scriptCtx.put("_Process", getHR_Process_ID()); - scriptCtx.put("_Period", getHR_Period_ID()); - scriptCtx.put("_Payroll", getHR_Payroll_ID()); - scriptCtx.put("_Department", getHR_Department_ID()); - - log.info("info data - " + " Process: " +getHR_Process_ID()+ ", Period: " +getHR_Period_ID()+ ", Payroll: " +getHR_Payroll_ID()+ ", Department: " +getHR_Department_ID()); - MHRPeriod period = new MHRPeriod(getCtx(), getHR_Period_ID(), get_TrxName()); - if (period != null) - { - m_dateFrom = period.getStartDate(); - m_dateTo = period.getEndDate(); - scriptCtx.put("_From", period.getStartDate()); - scriptCtx.put("_To", period.getEndDate()); - } - - // RE-Process, delete movement except concept type Incidence - int no = DB.executeUpdateEx("DELETE FROM HR_Movement m WHERE HR_Process_ID=? AND IsRegistered<>?", - new Object[]{getHR_Process_ID(), true}, - get_TrxName()); - log.info("HR_Movement deleted #"+ no); - - linesConcept = MHRPayrollConcept.getPayrollConcepts(this); - MBPartner[] linesEmployee = MHREmployee.getEmployees(this); - // - int count = 1; - for(MBPartner bp : linesEmployee) //=============================================================== Employee - { - log.info("Employee " + count + " ---------------------- " + bp.getName()); - count++; - m_C_BPartner_ID = bp.getC_BPartner_ID(); - MHREmployee employee = MHREmployee.getActiveEmployee(getCtx(), m_C_BPartner_ID, get_TrxName()); - //scriptCtx.put("_DateBirth", employee.getDateBirth()); - scriptCtx.put("_DateStart", employee.getStartDate()); - scriptCtx.put("_DateEnd", employee.getEndDate() == null ? TimeUtil.getDay(2999, 12, 31) : employee.getEndDate()); - scriptCtx.put("_Days", org.compiere.util.TimeUtil.getDaysBetween(period.getStartDate(),period.getEndDate())+1); - scriptCtx.put("_C_BPartner_ID", bp.getC_BPartner_ID()); - - m_movement.clear(); - loadMovements(m_movement, m_C_BPartner_ID); - // - for(MHRPayrollConcept pc : linesConcept) // ==================================================== Concept - { - m_HR_Concept_ID = pc.getHR_Concept_ID(); - MHRConcept concept = MHRConcept.get(getCtx(), m_HR_Concept_ID); - m_columnType = concept.getColumnType(); - - List params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - whereClause.append("? >= ValidFrom AND ( ? <= ValidTo OR ValidTo IS NULL)"); - params.add(m_dateFrom); - params.add(m_dateTo); - whereClause.append(" AND HR_Concept_ID = ? "); - params.add(m_HR_Concept_ID); - whereClause.append(" AND EXISTS (SELECT 1 FROM HR_Concept conc WHERE conc.HR_Concept_ID = HR_Attribute.HR_Concept_ID )"); - - // Check the concept is within a valid range for the attribute - if (concept.isEmployee()) - { - whereClause.append(" AND C_BPartner_ID = ? AND (HR_Employee_ID = ? OR HR_Employee_ID IS NULL)"); - params.add(employee.getC_BPartner_ID()); - params.add(employee.get_ID()); - } - - MHRAttribute att = new Query(getCtx(), MHRAttribute.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(params) - .setOnlyActiveRecords(true) - .setOrderBy(MHRAttribute.COLUMNNAME_ValidFrom + " DESC") - .first(); - if (att == null || concept.isRegistered()) - { - log.info("Skip concept "+concept+" - attribute not found"); - continue; - } - - log.info("Concept - " + concept.getName()); - MHRMovement movement = new MHRMovement (getCtx(), 0, get_TrxName()); - movement.setC_BPartner_ID(m_C_BPartner_ID); - movement.setHR_Concept_ID(m_HR_Concept_ID); - movement.setHR_Concept_Category_ID(concept.getHR_Concept_Category_ID()); - movement.setHR_Process_ID(getHR_Process_ID()); - movement.setHR_Department_ID(employee.getHR_Department_ID()); - movement.setHR_Job_ID(employee.getHR_Job_ID()); - movement.setColumnType(m_columnType); - movement.setAD_Rule_ID(att.getAD_Rule_ID()); - movement.setValidFrom(m_dateFrom); - movement.setValidTo(m_dateTo); - movement.setIsPrinted(att.isPrinted()); - movement.setIsRegistered(concept.isRegistered()); - movement.setC_Activity_ID(employee.getC_Activity_ID()); - if (MHRConcept.TYPE_RuleEngine.equals(concept.getType())) - { - Object result = executeScript(scriptCtx, att.getAD_Rule_ID()); - if(result == null) - { - // TODO: throw exception ??? - log.warning("Variable (result) is null"); - continue; - } - movement.setColumnValue(result); - } - else - { - movement.setQty(att.getQty()); - movement.setAmount(att.getAmount()); - movement.setTextMsg(att.getTextMsg()); - movement.setServiceDate(att.getServiceDate()); - } - movement.setProcessed(true); - m_movement.put(m_HR_Concept_ID, movement); - } // concept - - // Save movements: - for (MHRPayrollConcept pc: linesConcept) - { - MHRMovement m = m_movement.get(pc.getHR_Concept_ID()); - if(m == null) - { - continue; - } - MHRConcept c = MHRConcept.get(getCtx(), pc.getHR_Concept_ID()); - if(!c.isRegistered() && !m.isEmpty()) - { - m.saveEx(); - } - else - { - log.fine("Skip saving "+m); - } - } - } // for each employee - // - // Save period & finish - period.setProcessed(true); - period.saveEx(); - // User Validation - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE); - if (m_processMsg != null) - { - return DocAction.STATUS_Invalid; - } - // - setProcessed(true); - setDocAction(DOCACTION_Close); - return DocAction.STATUS_Completed; - } // completeIt - - /** - * Approve Document - * @return true if success - */ - public boolean approveIt() { - return true; - } // approveIt - - - /** - * Reject Approval - * @return true if success - */ - public boolean rejectIt() { - log.info("rejectIt - " + toString()); - return true; - } // rejectIt - - /** - * Post Document - nothing - * @return true if success - */ - public boolean postIt() { - log.info("postIt - " + toString()); - return false; - } // postIt - - - /** - * Void Document. - * Set Qtys to 0 - Sales: reverse all documents - * @return true if success - */ - public boolean voidIt() { - log.info("voidIt - " + toString()); - setProcessed(true); - setDocAction(DOCACTION_None); - return true; - } // voidIt - - - /** - * Close Document. - * Cancel not delivered Qunatities - * @return true if success - */ - public boolean closeIt() - { - if (isProcessed()) - { - log.info(toString()); - setProcessed(true); - setDocAction(DOCACTION_None); - return true; - } - return false; - } // closeIt - - - /** - * Reverse Correction - same void - * @return true if success - */ - public boolean reverseCorrectIt() { - log.info("reverseCorrectIt - " + toString()); - return voidIt(); - } // reverseCorrectionIt - - - /** - * Reverse Accrual - none - * @return true if success - */ - public boolean reverseAccrualIt() { - log.info("reverseAccrualIt - " + toString()); - return false; - } // reverseAccrualIt - - - /** - * Re-activate. - * @return true if success - */ - public boolean reActivateIt() { - log.info("reActivateIt - " + toString()); - - org.compiere.model.MDocType dt = org.compiere.model.MDocType.get(getCtx(), getC_DocType_ID()); - String DocSubTypeSO = dt.getDocSubTypeSO(); - - // Reverse Direct Documents - if ( MDocType.DOCSUBTYPESO_OnCreditOrder.equals(DocSubTypeSO) // (W)illCall(I)nvoice - || MDocType.DOCSUBTYPESO_WarehouseOrder.equals(DocSubTypeSO) // (W)illCall(P)ickup - || MDocType.DOCSUBTYPESO_POSOrder.equals(DocSubTypeSO)) // (W)alkIn(R)eceipt - { - return false; - } - else { - log.fine("reActivateIt - Existing documents not modified - SubType=" + DocSubTypeSO); - } - - // Delete - String sql = "DELETE FROM HR_Movement WHERE HR_Process_ID =" + this.getHR_Process_ID() + " AND IsRegistered = 'N'" ; - int no = DB.executeUpdate(sql, get_TrxName()); - log.fine("HR_Process deleted #" + no); - - setDocAction(DOCACTION_Complete); - setProcessed(false); - return true; - } // reActivateIt - - - /** - * Get Document Owner (Responsible) - * @return AD_User_ID - */ - public int getDoc_User_ID() { - return 0; - } // getDoc_User_ID - - - /** - * Get Document Approval Amount - * @return amount - */ - public java.math.BigDecimal getApprovalAmt() { - return new BigDecimal(0); - } // getApprovalAmt - - /** - * - */ - public int getC_Currency_ID() { - return 0; - } - - public String getProcessMsg() { - return m_processMsg; - } - - public String getSummary(){ - return ""; - } - - /** - * Create PDF - * @return File or null - */ - public File createPDF () - { - try - { - File temp = File.createTempFile(get_TableName()+get_ID()+"_", ".pdf"); - return createPDF (temp); - } - catch (Exception e) - { - log.severe("Could not create PDF - " + e.getMessage()); - } - return null; - } // getPDF - - /** - * Create PDF file - * @param file output file - * @return file if success - */ - public File createPDF (File file) - { - ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.ORDER, 0); - if (re == null) - return null; - return re.getPDF(file); - } // createPDF - - /** - * Get Document Info - * @return document info (untranslated) - */ - public String getDocumentInfo() - { - org.compiere.model.MDocType dt = MDocType.get(getCtx(), getC_DocType_ID()); - return dt.getName() + " " + getDocumentNo(); - } // getDocumentInfo - - - /** - * Get Lines - * @param requery requery - * @return lines - */ - public MHRMovement[] getLines (boolean requery) - { - ArrayList params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - // For HR_Process: - whereClause.append(MHRMovement.COLUMNNAME_HR_Process_ID+"=?"); - params.add(getHR_Process_ID()); - // With Qty or Amounts - whereClause.append("AND (Qty <> 0 OR Amount <> 0)"); // TODO: it's really needed ? - // Only Active Concepts - whereClause.append(" AND EXISTS(SELECT 1 FROM HR_Concept c WHERE c.HR_Concept_ID=HR_Movement.HR_Concept_ID" - +" AND c.IsActive=?" - +" AND c.AccountSign<>?)"); // TODO : why ? - params.add(true); - params.add(MHRConcept.ACCOUNTSIGN_Natural); // TODO : why ? - // Concepts with accounting - whereClause.append(" AND EXISTS(SELECT 1 FROM HR_Concept_Acct ca WHERE ca.HR_Concept_ID=HR_Movement.HR_Concept_ID" - +" AND ca.IsActive=? AND ca.IsBalancing<>?)"); - params.add(true); - params.add(true); - // BPartner field is filled - whereClause.append(" AND C_BPartner_ID IS NOT NULL"); - // - // ORDER BY - StringBuffer orderByClause = new StringBuffer(); - orderByClause.append("(SELECT bp.C_BP_Group_ID FROM C_BPartner bp WHERE bp.C_BPartner_ID=HR_Movement.C_BPartner_ID)"); - // - List list = new Query (getCtx(), MHRMovement.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(params) - .setOrderBy(orderByClause.toString()) - .list(); - return list.toArray(new MHRMovement[list.size()]); - } - - /** - * Load HR_Movements and store them in a HR_Concept_ID->MHRMovement hashtable - * @param movements hashtable - * @param C_PBartner_ID - */ - private void loadMovements(Hashtable movements, int C_PBartner_ID) - { - final String whereClause = MHRMovement.COLUMNNAME_HR_Process_ID+"=?" - +" AND "+MHRMovement.COLUMNNAME_C_BPartner_ID+"=?"; - List list = new Query(getCtx(), MHRMovement.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{getHR_Process_ID(), C_PBartner_ID}) - .list(); - for (MHRMovement mvm : list) - { - if(movements.containsKey(mvm.getHR_Concept_ID())) - { - MHRMovement lastM = movements.get(mvm.getHR_Concept_ID()); - String columntype = lastM.getColumnType(); - if (columntype.equals(MHRConcept.COLUMNTYPE_Amount)) - { - mvm.addAmount(lastM.getAmount()); - } - else if (columntype.equals(MHRConcept.COLUMNTYPE_Quantity)) - { - mvm.addQty(lastM.getQty()); - } - } - movements.put(mvm.getHR_Concept_ID(), mvm); - } - } - - /** - * Execute the script - * @param scriptCtx - * @param AD_Rule_ID - * @return - */ - private Object executeScript(HashMap scriptCtx, int AD_Rule_ID) - { - MRule rulee = MRule.get(getCtx(), AD_Rule_ID); - Object result = null; - try - { - String text = ""; - if(rulee.getScript() != null) - { - text = rulee.getScript().trim().replace("get", "org.eevolution.model.MHRProcess.get"); - text = rulee.getScript().trim().replace("get", "process.get"); - } - final String script = - " import org.eevolution.model.*;" - +" import ro.arhipac.adempiere.hr.util.Util;" - +" import org.compiere.util.DB;" - +" import java.math.*;" - +" import java.sql.*;" - +" double result = 0;" - + text; - Scriptlet engine = new Scriptlet (Scriptlet.VARIABLE, script, scriptCtx); - Exception ex = engine.execute(); - if (ex != null) - { - throw ex; - } - result = engine.getResult(false); - } - catch (Exception e) - { - throw new AdempiereException("Execution error - @AD_Rule_ID@="+rulee.getValue()); - } - return result; - } - - - // Helper methods ------------------------------------------------------------------------------- - - /** - * Helper Method : get the value of the concept - * @param pconcept - * @return - */ - public double getConcept (String pconcept) - { - MHRConcept concept = MHRConcept.forValue(getCtx(), pconcept.trim()); - - if (concept == null) - { - return 0; // TODO throw exception ? - } - - MHRMovement m = m_movement.get(concept.get_ID()); - if (m == null) - { - return 0; // TODO throw exception ? - } - - String type = m.getColumnType(); - if (MHRMovement.COLUMNTYPE_Amount.equals(type)) - { - return m.getAmount().doubleValue(); - } - else if (MHRMovement.COLUMNTYPE_Quantity.equals(type)) - { - return m.getQty().doubleValue(); - } - else - { - // TODO: throw exception ? - return 0; - } - } - - /** - * Helper Method : sets the value of a concept - * @param conceptValue - * @param value - */ - public void setConcept (String conceptValue, long value) - { - try - { - MHRConcept c = MHRConcept.forValue(getCtx(), conceptValue); - if (c == null) - { - return; // TODO throw exception - } - MHRMovement m = new MHRMovement(getCtx(), 0, null); - m.setColumnType(c.getColumnType()); - m.setColumnValue(BigDecimal.valueOf(value)); - - m.setHR_Process_ID(getHR_Process_ID()); - m.setHR_Concept_ID(m_HR_Concept_ID); - m.setC_BPartner_ID(m_C_BPartner_ID); - m.setDescription("Added From Rule"); // TODO: translate - m.setValidFrom(m_dateTo); - m.setValidTo(m_dateTo); - m.saveEx(); - } - catch(Exception e) - { - s_log.warning(e.getMessage()); - } - } - - /** - * Helper Method : get the sum of the concept values, grouped by the Category - * @param pconcept - * @return - */ - public double getConceptGroup (String pconcept) - { - final MHRConceptCategory category = MHRConceptCategory.forValue(getCtx(), pconcept); - if (category == null) - { - return 0.0; // TODO: need to throw exception ? - } - // - double value = 0.0; - for(MHRPayrollConcept pc : linesConcept) - { - MHRConcept con = MHRConcept.get(getCtx(), pc.getHR_Concept_ID()); - if(con.getHR_Concept_Category_ID() == category.get_ID()) - { - MHRMovement movement = m_movement.get(pc.getHR_Concept_ID()); - String columnType = movement.getColumnType(); - if(MHRConcept.COLUMNTYPE_Amount.equals(columnType)) - { - value += movement.getAmount().doubleValue(); - } - else if (MHRConcept.COLUMNTYPE_Quantity.equals(columnType)) - { - value += movement.getQty().doubleValue(); - } - } - } - return value; - } - - - /** - * Helper Method : Get Concept [get concept to search key ] - * @param pList Value List - * @param amount Amount to search - * @param column Number of column to return (1.......8) - * @return The amount corresponding to the designated column 'column' - */ - public double getList (String pList, double amount, String column) - { - BigDecimal value = Env.ZERO; - if (m_columnType.equals(MHRConcept.COLUMNTYPE_Amount)) - { - column = column.toString().length() == 1 ? "Col_"+column : "Amount"+column; - ArrayList params = new ArrayList(); - String sqlList = "SELECT (SELECT " +column+ " FROM HR_ListLine ll WHERE ll.HR_ListVersion_ID=lv.HR_ListVersion_ID AND " - + " ( " +amount+ " BETWEEN ll.MinValue AND ll.MaxValue) ) " - + " FROM HR_List l " - + " INNER JOIN HR_ListVersion lv ON (lv.HR_List_ID=l.HR_List_ID)" - + " WHERE l.Value = ? AND l.AD_Client_ID = ?" - +" AND (? BETWEEN lv.ValidFrom AND lv.ValidTo ) "; - params.add(pList); - params.add(getAD_Client_ID()); - params.add(m_dateFrom); - - value = DB.getSQLValueBDEx(get_TrxName(),sqlList,params); - } - // - if (value == null) - { - throw new IllegalStateException("getList Out of Range"); - } - return value.doubleValue(); - } // getList - - - /** - * Helper Method : Get Attribute [get Attribute to search key concept ] - * @param pConcept - Value to Concept - * @return Amount of concept, applying to employee - */ - public double getAttribute (String pConcept) - { - MHRConcept concept = MHRConcept.forValue(getCtx(), pConcept); - if (concept == null) - return 0; - - ArrayList params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - // check ValidFrom: - whereClause.append(MHRAttribute.COLUMNNAME_ValidFrom + "<=?"); - params.add(m_dateFrom); - //check client - whereClause.append(" AND AD_Client_ID = ?"); - params.add(getAD_Client_ID()); - //check concept - whereClause.append(" AND EXISTS (SELECT 1 FROM HR_Concept c WHERE c.HR_Concept_ID=HR_Attribute.HR_Concept_ID" - + " AND c.Value = ?)"); - params.add(pConcept); - // - if (!concept.getType().equals(MHRConcept.TYPE_Information)) - { - whereClause.append(" AND " + MHRAttribute.COLUMNNAME_C_BPartner_ID + " = ?"); - params.add(m_C_BPartner_ID); - } - - MHRAttribute attribute = new Query(getCtx(), MHRAttribute.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(params) - .setOrderBy(MHRAttribute.COLUMNNAME_ValidFrom + " DESC") - .first(); - if (attribute == null) - return 0.0; - - // if column type is Quantity return quantity - if (concept.getColumnType().equals(MHRConcept.COLUMNTYPE_Quantity)) - return attribute.getQty().doubleValue(); - - // if column type is Amount return amount - if (concept.getColumnType().equals(MHRConcept.COLUMNTYPE_Amount)) - return attribute.getAmount().doubleValue(); - - //something else - return 0.0; //TODO throw exception ?? - } // getAttribute - - - /** - * Helper Method : Get Attribute [get Attribute to search key concept ] - * @param conceptValue - * @return ServiceDate - */ - public Timestamp getAttributeDate (String conceptValue) - { - MHRConcept concept = MHRConcept.forValue(getCtx(), conceptValue); - if (concept == null) - return null; - - ArrayList params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - //check client - whereClause.append("AD_Client_ID = ?"); - params.add(getAD_Client_ID()); - //check concept - whereClause.append(" AND EXISTS (SELECT 1 FROM HR_Concept c WHERE c.HR_Concept_ID=HR_Attribute.HR_Concept_ID" - + " AND c.Value = ?)"); - params.add(conceptValue); - // - if (!concept.getType().equals(MHRConcept.TYPE_Information)) - { - whereClause.append(" AND " + MHRAttribute.COLUMNNAME_C_BPartner_ID + " = ?"); - params.add(m_C_BPartner_ID); - } - - MHRAttribute attribute = new Query(getCtx(), MHRAttribute.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(params) - .setOrderBy(MHRAttribute.COLUMNNAME_ValidFrom + " DESC") - .first(); - if (attribute == null) - return null; - - return attribute.getServiceDate(); - } - - /** - * Helper Method : Get the number of days between start and end, in Timestamp format - * @param date1 - * @param date2 - * @return no. of days - */ - public int getDays (Timestamp date1, Timestamp date2) - { - // adds one for the last day - return org.compiere.util.TimeUtil.getDaysBetween(date1,date2) + 1; - } - - - /** - * Helper Method : Get the number of days between start and end, in String format - * @param date1 - * @param date2 - * @return no. of days - */ - public int getDays (String date1, String date2) - { - Timestamp dat1 = Timestamp.valueOf(date1); - Timestamp dat2 = Timestamp.valueOf(date2); - return getDays(dat1, dat2); - } - - /** - * Helper Method : Get Months, Date in Format Timestamp - * @param start - * @param end - * @return no. of month between two dates - */ - public int getMonths(Timestamp start,Timestamp end) - { - boolean negative = false; - if (end.before(start)) - { - negative = true; - Timestamp temp = start; - start = end; - end = temp; - } - - GregorianCalendar cal = new GregorianCalendar(); - cal.setTime(start); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); - GregorianCalendar calEnd = new GregorianCalendar(); - - calEnd.setTime(end); - calEnd.set(Calendar.HOUR_OF_DAY, 0); - calEnd.set(Calendar.MINUTE, 0); - calEnd.set(Calendar.SECOND, 0); - calEnd.set(Calendar.MILLISECOND, 0); - - if (cal.get(Calendar.YEAR) == calEnd.get(Calendar.YEAR)) - { - if (negative) - return (calEnd.get(Calendar.MONTH) - cal.get(Calendar.MONTH)) * -1; - return calEnd.get(Calendar.MONTH) - cal.get(Calendar.MONTH); - } - - // not very efficient, but correct - int counter = 0; - while (calEnd.after(cal)) - { - cal.add (Calendar.MONTH, 1); - counter++; - } - if (negative) - return counter * -1; - return counter; - } - - - /** - * Helper Method : Concept for a range from-to in periods. - * Periods with values of 0 -1 1, etc. actual previous one period, next period - * 0 corresponds to actual period. - * @param conceptValue concept key(value) - * @param periodFrom the search is done by the period value, it helps to search from previous years - * @param periodTo - */ - public double getConcept (String conceptValue, int periodFrom, int periodTo) - { - return getConcept(conceptValue, null, periodFrom,periodTo); - } - - /** - * Helper Method : Concept by range from-to in periods from a different payroll - * periods with values 0 -1 1, etc. actual previous one period, next period - * 0 corresponds to actual period - * @param conceptValue - * @param pFrom - * @param pTo the search is done by the period value, it helps to search from previous years - * @param payrollValue is the value of the payroll. - */ - public double getConcept(String conceptValue, String payrollValue,int periodFrom,int periodTo) - { - int payroll_id; - if (payrollValue == null) - { - payroll_id = getHR_Payroll_ID(); - } - else - { - payroll_id = MHRPayroll.forValue(getCtx(), payrollValue).get_ID(); - } - - MHRConcept concept = MHRConcept.forValue(getCtx(), conceptValue); - if (concept == null) - return 0.0; - // - // Detect field name - final String fieldName; - if (MHRConcept.COLUMNTYPE_Quantity.equals(concept.getColumnType())) - { - fieldName = MHRMovement.COLUMNNAME_Qty; - } - else if (MHRConcept.COLUMNTYPE_Amount.equals(concept.getColumnType())) - { - fieldName = MHRMovement.COLUMNNAME_Amount; - } - else - { - return 0; // TODO: throw exception? - } - // - MHRPeriod p = MHRPeriod.get(getCtx(), getHR_Period_ID()); - ArrayList params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - //check client - whereClause.append("AD_Client_ID = ?"); - params.add(getAD_Client_ID()); - //check concept - whereClause.append(" AND " + MHRMovement.COLUMNNAME_HR_Concept_ID + "=?"); - params.add(m_HR_Concept_ID); - //check partner - whereClause.append(" AND " + MHRMovement.COLUMNNAME_C_BPartner_ID + "=?"); - params.add(m_C_BPartner_ID); - // - //check process and payroll - whereClause.append(" AND EXISTS (SELECT 1 FROM HR_Process p" - +" INNER JOIN HR_Period pr ON (pr.HR_Period_id=p.HR_Period_ID)" - +" WHERE HR_Movement.HR_Process_ID = p.HR_Process_ID" - +" AND p.HR_Payroll_ID=?"); - - params.add(payroll_id); - if (periodFrom < 0) - { - whereClause.append(" AND pr.PeriodNo >= ?"); - params.add(p.getPeriodNo() +periodFrom); - } - if (periodTo > 0) - { - whereClause.append(" AND pr.PeriodNo >= ?"); - params.add(p.getPeriodNo() +periodTo); - } - whereClause.append(")"); - // - StringBuffer sql = new StringBuffer("SELECT COALESCE(SUM(").append(fieldName).append("),0) FROM ").append(MHRMovement.Table_Name) - .append(" WHERE ").append(whereClause); - BigDecimal value = DB.getSQLValueBDEx(get_TrxName(), sql.toString(), params); - return value.doubleValue(); - - } // getConcept - - /** - * Helper Method : Attribute that had from some date to another to date, - * if it finds just one period it's seen for the attribute of such period - * if there are two or more attributes based on the days - * @param ctx - * @param vAttribute - * @param dateFrom - * @param dateTo - * @return attribute value - */ - public double getAttribute (Properties ctx, String vAttribute, Timestamp dateFrom, Timestamp dateTo) - { - // TODO ??? - return 0; - } - - /** - * Helper Method : Attribute that had from some period to another to period, - * periods with values 0 -1 1, etc. actual previous one period, next period - * 0 corresponds to actual period - * Value of HR_Attribute - * if it finds just one period it's seen for the attribute of such period - * if there are two or more attributes - * pFrom and pTo the search is done by the period value, it helps to search - * from previous year based on the days - * @param ctx - * @param vAttribute - * @param periodFrom - * @param periodTo - * @param pFrom - * @param pTo - * @return attribute value - */ - public double getAttribute (Properties ctx, String vAttribute, int periodFrom,int periodTo, - String pFrom,String pTo) - { - // TODO ??? - return 0; - } - - /** - * Helper Method : get days from specific period - * @param period - * @return no. of days - */ - public double getDays (int period) - { - return Env.getContextAsInt(getCtx(), "_DaysPeriod") + 1; - } -} // MHRProcess diff --git a/base/src/org/eevolution/model/MHRYear.java b/base/src/org/eevolution/model/MHRYear.java deleted file mode 100644 index ddeaf2658e..0000000000 --- a/base/src/org/eevolution/model/MHRYear.java +++ /dev/null @@ -1,128 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2008 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Oscar Gómez www.e-evolution.com * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.Properties; - -import org.compiere.model.MCalendar; -import org.compiere.model.MPeriod; -import org.compiere.util.DB; -import org.compiere.util.Msg; -import org.compiere.util.TimeUtil; - -/** - * MHRYear Year for a Payroll - * - * @author oscar.gomez@e-evolution.com, e-Evolution http://www.e-evolution.com - *
  • Original contributor of Payroll Functionality - * @author victor.perez@e-evolution.com, e-Evolution http://www.e-evolution.com - *
  • FR [ 2520591 ] Support multiples calendar for Org - * @see http://sourceforge.net/tracker2/?func=detail&atid=879335&aid=2520591&group_id=176962 - - */ -public class MHRYear extends X_HR_Year -{ - /** - * - */ - private static final long serialVersionUID = -7789699154024839462L; - - /** - * Standard Constructor - * @param ctx context - * @param HR_Payroll_ID id - */ - public MHRYear (Properties ctx, int HR_Year_ID, String trxName) - { - super (ctx, HR_Year_ID, trxName); - if (HR_Year_ID == 0) - { - setProcessing (false); // N - } - } // HRYear - - /** - * Load Constructor - * @param ctx context - * @param rs result set - */ - public MHRYear (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - /** - * Parent Constructor - * @param parent parent - */ - public MHRYear (MCalendar calendar) - { - this (calendar.getCtx(), 0, calendar.get_TrxName()); - setClientOrg(calendar); - } - - - /** - * CreatePeriods. - * Creates also Period - * @param HR_Payroll_ID - * @return true if created - */ - public boolean createPeriods() - { - int sumDays = 0; - int C_Calendar_ID = DB.getSQLValueEx(get_TrxName(), "SELECT C_Calendar_ID FROM C_Year WHERE C_Year_ID = ?", getC_Year_ID()); - if (C_Calendar_ID <= 0) - return false; - - MHRPayroll payroll = new MHRPayroll(getCtx(), getHR_Payroll_ID(), get_TrxName()); - for (int period = 1; period <= getQty(); period++) - { - sumDays = period != 1 ? (period-1) * (getNetDays()) : 0; - Timestamp StartDate = TimeUtil.addDays(getStartDate(),sumDays); - Timestamp EndDate = TimeUtil.addDays(StartDate,getNetDays()-1); - int C_Period_ID = DB.getSQLValueEx(get_TrxName(), - "SELECT C_Period_ID FROM C_Period p " - + " INNER JOIN C_Year y ON (p.C_Year_ID=y.C_Year_ID) " - + " WHERE " - + " ? BETWEEN p.startdate AND p.endDate" - + " AND y.C_Calendar_ID=?", - EndDate, C_Calendar_ID); - if(C_Period_ID <= 0) - return false; - - MPeriod m_period = MPeriod.get(getCtx(), C_Period_ID); - MHRPeriod HR_Period = new MHRPeriod(getCtx(), 0, get_TrxName()); - HR_Period.setAD_Org_ID(getAD_Org_ID()); - HR_Period.setHR_Year_ID(getHR_Year_ID()); - HR_Period.setHR_Payroll_ID(getHR_Payroll_ID()); - HR_Period.setName(StartDate.toString().substring(0, 10)+" "+Msg.translate(getCtx(), "To")+" "+EndDate.toString().substring(0, 10) ); - HR_Period.setDescription(Msg.translate(getCtx(), "HR_Payroll_ID")+" "+payroll.getName().trim()+" "+Msg.translate(getCtx(), "From")+ " "+period+" " +Msg.translate(getCtx(), "To")+" "+ StartDate.toString().substring(0, 10)+" al "+EndDate.toString().substring(0, 10)); - HR_Period.setPeriodNo(period); - HR_Period.setC_Period_ID(C_Period_ID); - HR_Period.setC_Year_ID(m_period.getC_Year_ID()); - HR_Period.setStartDate(StartDate); - HR_Period.setEndDate(EndDate); - HR_Period.setDateAcct(EndDate); - HR_Period.setIsActive(true); - HR_Period.saveEx(); - } - return true; - } // createPeriods -} // HRYear diff --git a/base/src/org/eevolution/model/MIMPProcessor.java b/base/src/org/eevolution/model/MIMPProcessor.java deleted file mode 100644 index 643fbe23d6..0000000000 --- a/base/src/org/eevolution/model/MIMPProcessor.java +++ /dev/null @@ -1,222 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ -package org.eevolution.model; - -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.Properties; -import java.util.logging.Level; - -import org.compiere.model.AdempiereProcessor; -import org.compiere.model.AdempiereProcessorLog; -import org.compiere.util.CLogger; -import org.compiere.util.DB; - -/** - * @author Trifon Trifonov - */ -public class MIMPProcessor - extends X_IMP_Processor - implements AdempiereProcessor -{ - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger (MIMPProcessor.class); - - public MIMPProcessor(Properties ctx, - int EXP_ReplicationProcessor_ID, String trxName) - { - super(ctx, EXP_ReplicationProcessor_ID, trxName); - if (EXP_ReplicationProcessor_ID == 0) - { - //setValue (/*client.getName() + " - " +*/ "Default Import Processor"); - setName (/*client.getName() + " - " +*/ "Default Import Processor"); - setFrequencyType (FREQUENCYTYPE_Hour); - setFrequency (1); - setKeepLogDays (7); - } - } - - public MIMPProcessor(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - /** - * - */ - public Timestamp getDateNextRun (boolean requery) - { - if (requery) - load(get_TrxName()); - return getDateNextRun(); - } - - - /** - * Get Logs - * @return logs - */ - public AdempiereProcessorLog[] getLogs () - { - ArrayList list = new ArrayList(); - String sql = "SELECT * " - + "FROM " + X_IMP_ProcessorLog.Table_Name + " " - + "WHERE " + X_IMP_Processor.COLUMNNAME_IMP_Processor_ID + "=? " // # 1 - + "ORDER BY Created DESC"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql, get_TrxName()); - pstmt.setInt (1, getIMP_Processor_ID()); - ResultSet rs = pstmt.executeQuery (); - while (rs.next ()) - list.add (new MIMPProcessorLog (getCtx(), rs, get_TrxName())); - rs.close (); - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE, sql, e); - } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } - MIMPProcessorLog[] retValue = new MIMPProcessorLog[list.size ()]; - list.toArray (retValue); - return retValue; - } // getLogs - - /** - * Delete old Request Log - * @return number of records - */ - public int deleteLog() - { - if (getKeepLogDays() < 1) - return 0; - String sql = "DELETE " + X_IMP_ProcessorLog.Table_Name + " " - + "WHERE "+X_IMP_ProcessorLog.COLUMNNAME_IMP_Processor_ID+"=" + getIMP_Processor_ID() - + " AND (Created+" + getKeepLogDays() + ") < SysDate"; - int no = DB.executeUpdate(sql, get_TrxName()); - return no; - } - - public String getServerID() { - return "ReplicationProcessor" + get_ID(); - } - - public X_IMP_ProcessorParameter[] getIMP_ProcessorParameters(String trxName) { - List resultList = new ArrayList(); - - StringBuffer sql = new StringBuffer("SELECT * ") - .append(" FROM ").append(X_IMP_ProcessorParameter.Table_Name) - .append(" WHERE ").append(X_IMP_ProcessorParameter.COLUMNNAME_IMP_Processor_ID).append("=?") // # 1 - .append(" AND IsActive = ?") // # 2 - //.append(" ORDER BY ").append(X_EXP_ProcessorParameter.COLUMNNAME_) - ; - PreparedStatement pstmt = null; - X_IMP_ProcessorParameter processorParameter = null; - try { - pstmt = DB.prepareStatement (sql.toString(), trxName); - pstmt.setInt(1, getIMP_Processor_ID()); - pstmt.setString(2, "Y"); - ResultSet rs = pstmt.executeQuery (); - while ( rs.next() ) { - processorParameter = new X_IMP_ProcessorParameter (getCtx(), rs, trxName); - resultList.add(processorParameter); - } - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } - } - X_IMP_ProcessorParameter[] result = (X_IMP_ProcessorParameter[])resultList.toArray( new X_IMP_ProcessorParameter[0]); - return result; - } - - public static MIMPProcessor[] getActive(Properties ctx) - { - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM "+X_IMP_Processor.Table_Name+" WHERE IsActive='Y'"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); - while (rs.next ()) - list.add (new MIMPProcessor (ctx, rs, null)); - rs.close (); - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - s_log.log (Level.SEVERE, sql, e); - } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } - - MIMPProcessor[] retValue = new MIMPProcessor[list.size()]; - list.toArray(retValue); - return retValue; - } // getActive - -} diff --git a/base/src/org/eevolution/model/MIMPProcessorLog.java b/base/src/org/eevolution/model/MIMPProcessorLog.java deleted file mode 100644 index 823e2eb0c3..0000000000 --- a/base/src/org/eevolution/model/MIMPProcessorLog.java +++ /dev/null @@ -1,83 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -import org.compiere.model.AdempiereProcessorLog; - -/** - * @author Trifon Trifonov - */ -public class MIMPProcessorLog - extends X_IMP_ProcessorLog - implements AdempiereProcessorLog -{ - - /** - * serialVersionUID - */ - private static final long serialVersionUID = 1L; - - /** - * - * @param ctx - * @param EXP_ReplicationProcessorLog_ID - * @param trxName - */ - public MIMPProcessorLog(Properties ctx, int IMP_ProcessorLog_ID, String trxName) { - super(ctx, IMP_ProcessorLog_ID, trxName); - } - - /** - * - * @param ctx - * @param rs - * @param trxName - */ - public MIMPProcessorLog(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - /** - * - * @param parent - * @param summary - */ - public MIMPProcessorLog (MIMPProcessor parent, String summary) - { - this (parent.getCtx(), 0, parent.get_TrxName()); - setClientOrg(parent); - setIMP_Processor_ID(parent.getIMP_Processor_ID()); - setSummary(summary); - } - -} diff --git a/base/src/org/eevolution/model/MPPCostCollector.java b/base/src/org/eevolution/model/MPPCostCollector.java deleted file mode 100644 index 38e660857d..0000000000 --- a/base/src/org/eevolution/model/MPPCostCollector.java +++ /dev/null @@ -1,1002 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - - -import java.io.File; -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; - -import org.adempiere.exceptions.AdempiereException; -import org.adempiere.exceptions.DocTypeNotFoundException; -import org.adempiere.exceptions.FillMandatoryException; -import org.adempiere.exceptions.NoVendorForProductException; -import org.compiere.model.I_C_UOM; -import org.compiere.model.I_M_Product; -import org.compiere.model.MAttributeSetInstance; -import org.compiere.model.MBPartner; -import org.compiere.model.MClient; -import org.compiere.model.MDocType; -import org.compiere.model.MLocator; -import org.compiere.model.MOrder; -import org.compiere.model.MOrderLine; -import org.compiere.model.MPeriod; -import org.compiere.model.MProduct; -import org.compiere.model.MProductPO; -import org.compiere.model.MStorage; -import org.compiere.model.MTransaction; -import org.compiere.model.MUOM; -import org.compiere.model.MWarehouse; -import org.compiere.model.ModelValidationEngine; -import org.compiere.model.ModelValidator; -import org.compiere.model.Query; -import org.compiere.print.ReportEngine; -import org.compiere.process.DocAction; -import org.compiere.process.DocumentEngine; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.compiere.util.TimeUtil; -import org.eevolution.exceptions.ActivityProcessedException; - -/** - * PP Cost Collector Model - * - * @author victor.perez@e-evolution.com, e-Evolution http://www.e-evolution.com - *
  • Original contributor of Manufacturing Standard Cost - *
  • FR [ 2520591 ] Support multiples calendar for Org - * @see http://sourceforge.net/tracker2/?func=detail&atid=879335&aid=2520591&group_id=176962 - * - * @author Teo Sarca, www.arhipac.ro - * @version $Id: MPPCostCollector.java,v 1.1 2004/06/19 02:10:34 vpj-cd Exp $ - */ -public class MPPCostCollector extends X_PP_Cost_Collector implements DocAction -{ - private static final long serialVersionUID = 1L; - - /** - * Create & Complete Cost Collector - * @param pp_order - * @param M_Product_ID - * @param M_Locator_ID - * @param M_AttributeSetInstance_ID - * @param S_Resource_ID - * @param PP_Order_BOMLine_ID - * @param PP_Order_Node_ID - * @param C_DocType_ID - * @param CostCollectorType - * @param movementdate - * @param qty - * @param scrap - * @param reject - * @param durationSetup - * @param duration - * @param trxName - * @return completed cost collector - */ - public static MPPCostCollector createCollector (MPPOrder pp_order, - int M_Product_ID, - int M_Locator_ID, - int M_AttributeSetInstance_ID, - int S_Resource_ID, - int PP_Order_BOMLine_ID, - int PP_Order_Node_ID, - int C_DocType_ID, - String CostCollectorType, - Timestamp movementdate, - BigDecimal qty, - BigDecimal scrap, - BigDecimal reject, - int durationSetup, - int duration, - String trxName - ) - { - MPPCostCollector cc = new MPPCostCollector(pp_order.getCtx(), 0, trxName); - cc.setPP_Order_ID(pp_order.getPP_Order_ID()); - cc.setPP_Order_BOMLine_ID(PP_Order_BOMLine_ID); - cc.setPP_Order_Workflow_ID(pp_order.getMPPOrderWorkflow().getPP_Order_Workflow_ID()); - cc.setPP_Order_Node_ID(PP_Order_Node_ID); - cc.setAD_OrgTrx_ID(pp_order.getAD_OrgTrx_ID()); - cc.setC_Activity_ID(pp_order.getC_Activity_ID()); - cc.setC_Campaign_ID(pp_order.getC_Campaign_ID()); - cc.setC_DocType_ID(C_DocType_ID); - cc.setC_DocTypeTarget_ID(C_DocType_ID); - cc.setCostCollectorType(CostCollectorType); - cc.setC_Project_ID(pp_order.getC_Project_ID()); - cc.setDescription(pp_order.getDescription()); - cc.setDocAction(MPPCostCollector.ACTION_Complete); - cc.setDocStatus(MPPCostCollector.DOCSTATUS_Drafted); - cc.setIsActive(true); - cc.setM_Warehouse_ID(pp_order.getM_Warehouse_ID()); - cc.setM_Locator_ID(M_Locator_ID); - cc.setM_AttributeSetInstance_ID(M_AttributeSetInstance_ID); - cc.setS_Resource_ID(S_Resource_ID); - cc.setMovementDate(movementdate); - cc.setDateAcct(movementdate); - cc.setMovementQty(qty); - cc.setScrappedQty(scrap); - cc.setQtyReject(reject); - cc.setSetupTimeReal(new BigDecimal(durationSetup)); - cc.setDurationReal(new BigDecimal(duration)); - cc.setPosted(false); - cc.setProcessed(false); - cc.setProcessing(false); - cc.setUser1_ID(pp_order.getUser1_ID()); - cc.setUser2_ID(pp_order.getUser2_ID()); - cc.setM_Product_ID(M_Product_ID); - cc.saveEx(); - if (!cc.processIt(MPPCostCollector.DOCACTION_Complete)) - { - throw new AdempiereException(cc.getProcessMsg()); - } - cc.saveEx(); - return cc; - } - - - - /** - * Standard Constructor - * @param ctx context - * @param PP_Cost_Collector id - */ - public MPPCostCollector(Properties ctx, int PP_Cost_Collector_ID, String trxName) - { - super (ctx, PP_Cost_Collector_ID,trxName); - if (PP_Cost_Collector_ID == 0) - { - setC_DocType_ID(0); - setDocStatus (DOCSTATUS_Drafted); // DR - setDocAction (DOCACTION_Complete); // CO - setMovementDate (new Timestamp(System.currentTimeMillis())); // @#Date@ - setIsActive(true); - setPosted (false); - setProcessing (false); - setProcessed (false); - } - } // MPPCostCollector - - /** - * Load Constructor - * @param ctx context - * @param rs result set - */ - public MPPCostCollector(Properties ctx, ResultSet rs,String trxName) - { - super (ctx, rs, trxName); - } // MPPCostCollector - - - /** - * Add to Description - * @param description text - */ - public void addDescription (String description) - { - String desc = getDescription(); - if (desc == null) - setDescription(description); - else - setDescription(desc + " | " + description); - } // addDescription - - - public void setC_DocTypeTarget_ID(String docBaseType) - { - MDocType[] doc = MDocType.getOfDocBaseType(getCtx(), docBaseType); - if(doc == null) - { - throw new DocTypeNotFoundException(docBaseType, ""); - } - else - { - setC_DocTypeTarget_ID(doc[0].get_ID()); - } - } - -// @Override - public void setProcessed (boolean processed) - { - super.setProcessed (processed); - if (get_ID() == 0) - return; - final String sql = "UPDATE PP_Cost_Collector SET Processed=? WHERE PP_Cost_Collector_ID=?"; - int noLine = DB.executeUpdateEx(sql, new Object[]{processed, get_ID()}, get_TrxName()); - log.fine("setProcessed - " + processed + " - Lines=" + noLine); - } // setProcessed - - -// @Override - public boolean processIt (String processAction) - { - m_processMsg = null; - DocumentEngine engine = new DocumentEngine (this, getDocStatus()); - return engine.processIt (processAction, getDocAction()); - } // processIt - - /** Process Message */ - private String m_processMsg = null; - /** Just Prepared Flag */ - private boolean m_justPrepared = false; - - /** Manufacturing Order **/ - private MPPOrder m_pporder = null; - - /** Manufacturing Order Activity **/ - private MPPOrderNode m_orderNode = null; - - /** Manufacturing Order BOM Line **/ - private MPPOrderBOMLine m_bomLine = null; - -// @Override - public boolean unlockIt() - { - log.info("unlockIt - " + toString()); - setProcessing(false); - return true; - } // unlockIt - -// @Override - public boolean invalidateIt() - { - log.info("invalidateIt - " + toString()); - setDocAction(DOCACTION_Prepare); - return true; - } // invalidateIt - -// @Override - public String prepareIt() - { - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE); - if (m_processMsg != null) - { - return DocAction.STATUS_Invalid; - } - - MPeriod.testPeriodOpen(getCtx(), getMovementDate(), getC_DocTypeTarget_ID(), getAD_Org_ID()); - // Convert/Check DocType - setC_DocType_ID(getC_DocTypeTarget_ID()); - - // - // Operation Activity - if(isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl)) - { - MPPOrderNode activity = getPP_Order_Node(); - if(MPPOrderNode.DOCACTION_Complete.equals(activity.getDocStatus())) - { - throw new ActivityProcessedException(activity); - } - - if (activity.isSubcontracting()) - { - if(MPPOrderNode.DOCSTATUS_InProgress.equals(activity.getDocStatus()) - && MPPCostCollector.DOCSTATUS_InProgress.equals(getDocStatus())) - { - return MPPOrderNode.DOCSTATUS_InProgress; - } - else if(MPPOrderNode.DOCSTATUS_InProgress.equals(activity.getDocStatus()) - && MPPCostCollector.DOCSTATUS_Drafted.equals(getDocStatus())) - { - throw new ActivityProcessedException(activity); - } - m_processMsg = createPO(activity); - m_justPrepared = false; - setDocAction(DOCACTION_Complete); - activity.setDocStatus(DOCSTATUS_InProgress); - activity.saveEx(); - return DOCSTATUS_InProgress; - } - - activity.setDocStatus(DOCSTATUS_InProgress); - activity.setQtyDelivered(activity.getQtyDelivered().add(getMovementQty())); - activity.setQtyScrap(activity.getQtyScrap().add(getScrappedQty())); - activity.setQtyReject(activity.getQtyReject().add(getQtyReject())); - activity.setDurationReal(activity.getDurationReal()+getDurationReal().intValue()); - activity.setSetupTimeReal(activity.getSetupTimeReal()+getSetupTimeReal().intValue()); - activity.saveEx(); - - // report all activity previews to milestone activity - if(activity.isMilestone()) - { - MPPOrderWorkflow order_workflow = activity.getMPPOrderWorkflow(); - order_workflow.closeActivities(activity, getMovementDate(), true); - } - } - - - m_justPrepared = true; - setDocAction(DOCACTION_Complete); - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE); - if (m_processMsg != null) - { - return DocAction.STATUS_Invalid; - } - - return DocAction.STATUS_InProgress; - } // prepareIt - -// @Override - public boolean approveIt() - { - log.info("approveIt - " + toString()); - //setIsApproved(true); - return true; - } // approveIt - -// @Override - public boolean rejectIt() - { - log.info("rejectIt - " + toString()); - //setIsApproved(false); - return true; - } // rejectIt - -// @Override - public String completeIt() - { - // Re-Check - if (!m_justPrepared) - { - String status = prepareIt(); - if (!DocAction.STATUS_InProgress.equals(status)) - return status; - } - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE); - if (m_processMsg != null) - return DocAction.STATUS_Invalid; - - BigDecimal QtyIssue = Env.ZERO; - BigDecimal QtyReceipt = Env.ZERO; - BigDecimal Qty = getMovementQty(); - - if (isIssue()) - { - Qty = Qty.negate(); - QtyIssue = Qty; - } - else - { - QtyReceipt = Qty.negate(); - } - - // - // Update Order Line - if(!isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl)) - { - // Stock Movement - MProduct product = MProduct.get(getCtx(), getM_Product_ID()); - if (product != null && product.isStocked()) - { - // Only for Production Issue records - if (isIssue()) - { - checkMaterialPolicy(getPP_Order_BOMLine()); - } - - log.fine("Material Transaction"); - MTransaction mtrx = null; - int reservationAttributeSetInstance_ID = getM_AttributeSetInstance_ID(); - - if (getM_AttributeSetInstance_ID() == 0) - { - for (MPPOrderBOMLineMA ma : MPPOrderBOMLineMA.get(getCtx(), getPP_Order_Node_ID(), get_TrxName())) - { - BigDecimal QtyMA = ma.getMovementQty(); - if (isIssue()) - { - QtyMA = QtyMA.negate(); - QtyIssue = QtyMA; - } - else - { - QtyReceipt = QtyMA.negate(); - } - - if (!MStorage.add(getCtx(), getM_Warehouse_ID(), - getM_Locator_ID(), - getM_Product_ID(), - ma.getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID, - QtyMA, QtyIssue, QtyReceipt, get_TrxName())) - { - throw new AdempiereException(); //Cannot correct Inventory (MA) - } - - // Create Transaction - mtrx = new MTransaction (getCtx(), this.getAD_Org_ID(), - getMovementType(), getM_Locator_ID(), - getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), - QtyMA, getMovementDate(), get_TrxName()); - mtrx.setPP_Cost_Collector_ID(getPP_Cost_Collector_ID()); - mtrx.saveEx(); - } - } - // sLine.getM_AttributeSetInstance_ID() != 0 - if (mtrx == null) - { - // Fallback: Update Storage - - if (!MStorage.add(getCtx(), getM_Warehouse_ID(), - getM_Locator_ID(), - getM_Product_ID(), - getM_AttributeSetInstance_ID(), reservationAttributeSetInstance_ID, - Qty, QtyIssue, QtyReceipt, get_TrxName())) - { - throw new AdempiereException(); // Cannot correct Inventory; - } - // FallBack: Create Transaction - - mtrx = new MTransaction (getCtx(),getAD_Org_ID(), - getMovementType(), getM_Locator_ID(), - getM_Product_ID(), getM_AttributeSetInstance_ID(), - Qty, getMovementDate(), get_TrxName()); - mtrx.setPP_Cost_Collector_ID(getPP_Cost_Collector_ID()); - mtrx.saveEx(); - } - } // stock movement - - - if (isIssue()) - { - // Update PP Order Line - MPPOrderBOMLine obomline = getPP_Order_BOMLine(); - obomline.setQtyDelivered(obomline.getQtyDelivered().add(getMovementQty())); - obomline.setQtyScrap(obomline.getQtyScrap().add(getScrappedQty())); - obomline.setQtyReject(obomline.getQtyReject().add(getQtyReject())); - obomline.setDateDelivered(getMovementDate()); // overwrite=last - obomline.setM_AttributeSetInstance_ID(getM_AttributeSetInstance_ID()); - log.fine("OrderLine - Reserved=" + obomline.getQtyReserved() + ", Delivered=" + obomline.getQtyDelivered()); - obomline.setQtyReserved(obomline.getQtyReserved().subtract(getMovementQty())); - obomline.saveEx(); - log.fine("OrderLine -> Reserved="+obomline.getQtyReserved()+", Delivered="+obomline.getQtyDelivered()); - } - if (isReceipt()) - { - // Update PP Order Qtys - MPPOrder order = getPP_Order(); - order.setQtyDelivered(order.getQtyDelivered().add(getMovementQty())); - order.setQtyScrap(order.getQtyScrap().add(getScrappedQty())); - order.setQtyReject(order.getQtyReject().add(getQtyReject())); - order.setQtyReserved(order.getQtyReserved().subtract(getMovementQty())); - // - // Update PP Order Dates - order.setDateDelivered(getMovementDate()); // overwrite=last - if (order.getDateStart() == null) - { - order.setDateStart(getMovementDate()); - } - if (order.getQtyOpen().signum() <= 0) - { - order.setDateFinish(getMovementDate()); - } - order.saveEx(); - } - } - else if(isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl)) - { - MPPOrderNode activity = getPP_Order_Node(); - if(activity.getDocStatus().equals(MPPOrderNode.DOCSTATUS_Completed)) - { - throw new ActivityProcessedException(activity); - } - - if(isSubcontracting()) - { - String whereClause = MOrderLine.COLUMNNAME_PP_Cost_Collector_ID+"=?"; - Collection olines = new Query(getCtx(), MOrderLine.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{get_ID()}) - .list(); - String DocStatus = MPPOrderNode.DOCSTATUS_Completed; - StringBuffer msg = new StringBuffer("The quantity do not is complete for next Purchase Order : "); - for (MOrderLine oline : olines) - { - if(oline.getQtyDelivered().compareTo(oline.getQtyOrdered()) < 0) - { - DocStatus = MPPOrderNode.DOCSTATUS_InProgress; - } - msg.append(oline.getParent().getDocumentNo()).append(","); - } - - if(MPPOrderNode.DOCSTATUS_InProgress.equals(DocStatus)) - { - m_processMsg = msg.toString(); - return DocStatus; - } - setProcessed(true); - setDocAction(MPPOrderNode.DOCACTION_Close); - setDocStatus(MPPOrderNode.DOCSTATUS_Completed); - activity.setDocStatus(MPPOrderNode.DOCSTATUS_Completed); - activity.setDocAction(MPPOrderNode.DOCACTION_None); - activity.saveEx(); - m_processMsg = Msg.translate(getCtx(), "PP_Order_ID") - +": "+ getPP_Order().getDocumentNo() - +" "+ Msg.translate(getCtx(),"PP_Order_Node_ID") - +": "+getPP_Order_Node().getValue(); - return DocStatus; - } - else - { - if(activity.getQtyDelivered().compareTo(activity.getQtyRequiered()) >= 0) - { - activity.setDocStatus(MPPOrderNode.DOCSTATUS_Completed); - activity.setDocAction(MPPOrderNode.DOCACTION_None); - activity.setAction(MPPOrderNode.ACTION_WaitSleep); - activity.saveEx(); - } - } - } // end Activity Control - // - setProcessed(true); - setDocAction(DOCACTION_Close); - setDocStatus(DOCSTATUS_Completed); - - return DocAction.STATUS_Completed; - } // completeIt - -// @Override - public boolean voidIt() - { - return false; - } // voidIt - -// @Override - public boolean closeIt() - { - log.info("closeIt - " + toString()); - setDocAction(DOCACTION_None); - return true; - } // closeIt - -// @Override - public boolean reverseCorrectIt() - { - return false; - } - -// @Override - public boolean reverseAccrualIt() - { - return false; - } - -// @Override - public boolean reActivateIt() - { - return false; - } - -// @Override - public String getSummary() - { - StringBuffer sb = new StringBuffer(); - sb.append(getDescription()); - return sb.toString(); - } - -// @Override - public String getProcessMsg() - { - return m_processMsg; - } - -// @Override - public int getDoc_User_ID() - { - return getCreatedBy(); - } - -// @Override - public int getC_Currency_ID() - { - return 0; - } - -// @Override - public BigDecimal getApprovalAmt() - { - return Env.ZERO; - } - -// @Override - public File createPDF () - { - try - { - File temp = File.createTempFile(get_TableName()+get_ID()+"_", ".pdf"); - return createPDF (temp); - } - catch (Exception e) - { - log.severe("Could not create PDF - " + e.getMessage()); - } - return null; - } // getPDF - - /** - * Create PDF file - * @param file output file - * @return file if success - */ - public File createPDF (File file) - { - ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.ORDER, getPP_Order_ID()); - if (re == null) - return null; - return re.getPDF(file); - } // createPDF - -// @Override - public String getDocumentInfo() - { - MDocType dt = MDocType.get(getCtx(), getC_DocType_ID()); - return dt.getName() + " " + getDocumentNo(); - } // getDocumentInfo - - @Override - protected boolean beforeSave(boolean newRecord) - { - // Set default locator, if not set and we have the warehouse: - if (getM_Locator_ID() <= 0 && getM_Warehouse_ID() > 0) - { - MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID()); - MLocator loc = wh.getDefaultLocator(); - if (loc != null) - { - setM_Locator_ID(loc.get_ID()); - } - } - // - if (isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl) && getPP_Order_Node_ID() <= 0) - { - throw new FillMandatoryException(COLUMNNAME_PP_Order_Node_ID); - } - // - if (isIssue() && getPP_Order_BOMLine_ID() <= 0) - { - throw new FillMandatoryException(COLUMNNAME_PP_Order_BOMLine_ID); - } - // - return true; - } - - private void closeNew(int PP_Order_ID, int PP_Order_Node_ID) - { - if(isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl)) - { - String whereClause = COLUMNNAME_PP_Order_ID+"=?"; - List list = new Query(getCtx(), Table_Name, whereClause, get_TrxName()) - .setOnlyActiveRecords(true) - .setParameters(new Object[]{PP_Order_ID}) - .list(); - for (MPPCostCollector cc : list) - { - cc.setDocStatus(DOCSTATUS_Closed); - cc.setDocAction(DOCACTION_None); - cc.saveEx(); - } - } - } - - @Deprecated - private void completeNew(int PP_Order_ID) - { - if(isCostCollectorType(COSTCOLLECTORTYPE_ActivityControl)) - { - String whereClause = COLUMNNAME_PP_Order_ID+"=?" - +" AND "+COLUMNNAME_DocStatus+"<>'"+DOCSTATUS_Completed+"'" - +" AND "+COLUMNNAME_DocStatus+"<>'"+DOCSTATUS_Closed+"'"; - List list = new Query(getCtx(), Table_Name, whereClause, get_TrxName()) - .setOnlyActiveRecords(true) - .setParameters(new Object[]{PP_Order_ID}) - .list(); - for (MPPCostCollector cc : list) - { - cc.completeIt(); - cc.saveEx(); - } - } - } - - /** - * Check Material Policy. - * Sets line ASI - */ - private void checkMaterialPolicy(MPPOrderBOMLine line) - { - MPPOrderBOMLineMA.deleteOrderBOMLineMA(line.get_ID(), get_TrxName()); - - // is ASI != 0, MA is not needed - if (line.getM_AttributeSetInstance_ID() != 0) - { - return; - } - - BigDecimal qty = getMovementQty(); - BigDecimal qtyASI = Env.ZERO ; - - // Check Line - MProduct product = MProduct.get(getCtx(), line.getM_Product_ID()); - if (qty.signum() > 0) // Incoming Trx -> Create new ASI - { - MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName()); - asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID()); - asi.saveEx(); - line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID()); - line.saveEx(); - } - else // Outgoing Trx - { - String MMPolicy = product.getMMPolicy(); - MStorage[] storages = MStorage.getAllWithASI(getCtx(), - line.getM_Product_ID(), line.getM_Locator_ID(), - MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName()); - BigDecimal qtyToDeliver = qty.negate(); - - for (MStorage storage : storages) - { - //consume ASI Zero - if (storage.getM_AttributeSetInstance_ID() == 0) - { - qtyASI = qtyASI.add(storage.getQtyOnHand()); - qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand()); - } - else if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0) - { - MPPOrderBOMLineMA ma = new MPPOrderBOMLineMA (line, - storage.getM_AttributeSetInstance_ID(), - qtyToDeliver); - ma.saveEx(); - qtyToDeliver = Env.ZERO; - log.fine( ma + ", QtyToDeliver=" + qtyToDeliver); - break; - } - else - { - MPPOrderBOMLineMA ma = new MPPOrderBOMLineMA (line, - storage.getM_AttributeSetInstance_ID(), - storage.getQtyOnHand()); - ma.saveEx(); - qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand()); - log.fine( ma + ", QtyToDeliver=" + qtyToDeliver); - } - } // for storage - - // No AttributeSetInstance found for remainder - BigDecimal qtyRemaining = qtyToDeliver.add(qtyASI); - if (qtyRemaining.signum() != 0) - { - MPPOrderBOMLineMA ma = new MPPOrderBOMLineMA (line, 0 , qtyRemaining); - ma.saveEx(); - log.fine("##: " + ma); - } - } // outgoing Trx - } // checkMaterialPolicy - - @Override - public MPPOrderNode getPP_Order_Node() - { - int node_id = getPP_Order_Node_ID(); - if (node_id <= 0) - { - m_orderNode = null; - return null; - } - if (m_orderNode == null || m_orderNode.get_ID() != node_id) - { - m_orderNode = new MPPOrderNode(getCtx(), node_id, get_TrxName()); - } - m_orderNode.set_TrxName(get_TrxName()); - return m_orderNode; - } - - @Override - public MPPOrderBOMLine getPP_Order_BOMLine() - { - int id = getPP_Order_BOMLine_ID(); - if (id <= 0) - { - m_bomLine = null; - return null; - } - if (m_bomLine == null || m_bomLine.get_ID() != id) - { - m_bomLine = new MPPOrderBOMLine(getCtx(), id, get_TrxName()); - } - m_bomLine.set_TrxName(get_TrxName()); - return m_bomLine; - } - - @Override - public MPPOrder getPP_Order() - { - int id = getPP_Order_ID(); - if (id <= 0) - { - m_pporder = null; - return null; - } - if (m_pporder == null || m_pporder.get_ID() != id) - { - m_pporder = new MPPOrder(getCtx(), id, get_TrxName()); - } - m_pporder.set_TrxName(get_TrxName()); - return m_pporder; - } - - - /** - * Create Purchase Order (in case of Subcontracting) - * @param activity - */ - private String createPO(MPPOrderNode activity) - { - String msg = ""; - HashMap orders = new HashMap(); - // - String whereClause = MPPOrderNodeProduct.COLUMNNAME_PP_Order_Node_ID+"=?" - +" AND "+MPPOrderNodeProduct.COLUMNNAME_IsSubcontracting+"=?"; - Collection subcontracts = new Query(getCtx(), MPPOrderNodeProduct.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{activity.get_ID(), true}) - .setOnlyActiveRecords(true) - .list(); - - for (MPPOrderNodeProduct subcontract : subcontracts) - { - // - // If Product is not Purchased or is not Service, then it is not a subcontracting candidate [SKIP] - MProduct product = MProduct.get(getCtx(), subcontract.getM_Product_ID()); - if(!product.isPurchased() || !MProduct.PRODUCTTYPE_Service.equals(product.getProductType())) - throw new AdempiereException("The Product: " + product.getName() + " Do not is Purchase or Service Type"); - - // - // Find Vendor and Product PO data - int C_BPartner_ID = activity.getC_BPartner_ID(); - MProductPO product_po = null; - for (MProductPO ppo : MProductPO.getOfProduct(getCtx(), product.get_ID(), null)) - { - if(C_BPartner_ID == ppo.getC_BPartner_ID()) - { - C_BPartner_ID = ppo.getC_BPartner_ID(); - product_po = ppo; - break; - } - if (ppo.isCurrentVendor() && ppo.getC_BPartner_ID() != 0) - { - C_BPartner_ID = ppo.getC_BPartner_ID(); - product_po = ppo; - break; - } - } - if(C_BPartner_ID <= 0 || product_po == null) - { - throw new NoVendorForProductException(product.getName()); - } - // - // Calculate Lead Time - Timestamp today = new Timestamp(System.currentTimeMillis()); - Timestamp datePromised = TimeUtil.addDays(today, product_po.getDeliveryTime_Promised()); - // - // Get/Create Purchase Order Header - MOrder order = orders.get(C_BPartner_ID); - if(order == null) - { - order = new MOrder(getCtx(), 0, get_TrxName()); - MBPartner vendor = MBPartner.get(getCtx(), C_BPartner_ID); - order.setAD_Org_ID(getAD_Org_ID()); - order.setBPartner(vendor); - order.setIsSOTrx(false); - order.setC_DocTypeTarget_ID(); - order.setDatePromised(datePromised); - order.setDescription(Msg.translate(getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) +":"+getPP_Order().getDocumentNo()); - order.setDocStatus(MOrder.DOCSTATUS_Drafted); - order.setDocAction(MOrder.DOCACTION_Complete); - order.setAD_User_ID(getAD_User_ID()); - order.setM_Warehouse_ID(getM_Warehouse_ID()); - //order.setSalesRep_ID(getAD_User_ID()); - order.saveEx(); - addDescription(Msg.translate(getCtx(), "C_Order_ID")+": "+order.getDocumentNo()); - orders.put(C_BPartner_ID, order); - msg = msg + Msg.translate(getCtx(), "C_Order_ID") - +" : "+ order.getDocumentNo() - +" - " - +Msg.translate(getCtx(),"C_BPartner_ID") - +" : "+vendor.getName()+" , "; - } - // - // Create Order Line: - BigDecimal QtyOrdered = getMovementQty().multiply(subcontract.getQty()); - // Check Order Min - if(product_po.getOrder_Min().signum() > 0) - { - QtyOrdered = QtyOrdered.max(product_po.getOrder_Min()); - } - // Check Order Pack - if (product_po.getOrder_Pack().signum() > 0 && QtyOrdered.signum() > 0) - { - QtyOrdered = product_po.getOrder_Pack().multiply(QtyOrdered.divide(product_po.getOrder_Pack(), 0 , BigDecimal.ROUND_UP)); - } - MOrderLine oline = new MOrderLine(order); - oline.setM_Product_ID(product.getM_Product_ID()); - oline.setDescription(activity.getDescription()); - oline.setM_Warehouse_ID(getM_Warehouse_ID()); - oline.setQty(QtyOrdered); - //line.setPrice(m_product_po.getPricePO()); - //oline.setPriceList(m_product_po.getPriceList()); - oline.setPP_Cost_Collector_ID(get_ID()); - oline.setDatePromised(datePromised); - oline.saveEx(); - // - // TODO: Mark this as processed? - setProcessed(true); - } // each subcontracting line - return msg; - } - - @Override - public I_M_Product getM_Product() - { - return MProduct.get(getCtx(), getM_Product_ID()); - } - - @Override - public I_C_UOM getC_UOM() - { - return MUOM.get(getCtx(), getC_UOM_ID()); - } - - public boolean isIssue() - { - return isCostCollectorType(COSTCOLLECTORTYPE_ComponentIssue); - } - - public boolean isReceipt() - { - return isCostCollectorType(COSTCOLLECTORTYPE_MaterialReceipt); - } - - public String getMovementType() - { - if (isCostCollectorType(COSTCOLLECTORTYPE_MaterialReceipt)) - return MTransaction.MOVEMENTTYPE_WorkOrderPlus; - else if(isCostCollectorType(COSTCOLLECTORTYPE_ComponentIssue)) - return MTransaction.MOVEMENTTYPE_WorkOrder_; - else - return null; - } - - /** - * Check if CostCollectorType is equal with any of provided types - * @param types - * @return - */ - public boolean isCostCollectorType(String ... types) - { - String type = getCostCollectorType(); - for (String t : types) - { - if (type.equals(t)) - return true; - } - return false; - } -} // MPPCostCollector diff --git a/base/src/org/eevolution/model/MPPMRP.java b/base/src/org/eevolution/model/MPPMRP.java deleted file mode 100644 index 467f1179a4..0000000000 --- a/base/src/org/eevolution/model/MPPMRP.java +++ /dev/null @@ -1,917 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; - -import org.adempiere.exceptions.AdempiereException; -import org.compiere.model.MDocType; -import org.compiere.model.MForecastLine; -import org.compiere.model.MLocator; -import org.compiere.model.MOrder; -import org.compiere.model.MOrderLine; -import org.compiere.model.MProduct; -import org.compiere.model.MRefList; -import org.compiere.model.MRequisition; -import org.compiere.model.MRequisitionLine; -import org.compiere.model.MResource; -import org.compiere.model.MResourceType; -import org.compiere.model.PO; -import org.compiere.model.Query; -import org.compiere.model.X_M_Forecast; -import org.compiere.process.DocAction; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.compiere.util.TimeUtil; -import org.compiere.util.Util; -import org.compiere.wf.MWorkflow; - - -/** - * PP_MRP - * - * @author Victor Perez www.e-evolution.com - * @version $Id: MPPMRP.java,v 1.4 2004/05/13 06:05:22 vpj-cd Exp $ - * - * @author Teo Sarca, www.arhipac.ro - */ -public class MPPMRP extends X_PP_MRP -{ - private static final long serialVersionUID = 1L; - - private static CLogger s_log = CLogger.getCLogger(MPPMRP.class); - - private static HashMap s_sourceColumnNames = new HashMap(); - static - { - s_sourceColumnNames.put(MOrder.Table_Name, new String[]{ - MOrder.COLUMNNAME_DatePromised, - MOrder.COLUMNNAME_DocStatus, - }); - s_sourceColumnNames.put(MOrderLine.Table_Name, new String[]{ - "AD_Org_ID", - MOrderLine.COLUMNNAME_DateOrdered, - MOrderLine.COLUMNNAME_DatePromised, - MOrderLine.COLUMNNAME_C_BPartner_ID, - MOrderLine.COLUMNNAME_M_Warehouse_ID, - MOrderLine.COLUMNNAME_M_Product_ID, - MOrderLine.COLUMNNAME_QtyOrdered, - MOrderLine.COLUMNNAME_QtyDelivered, - }); - s_sourceColumnNames.put(MRequisition.Table_Name, new String[]{ - MRequisition.COLUMNNAME_DateRequired, - MRequisition.COLUMNNAME_M_Warehouse_ID, - }); - s_sourceColumnNames.put(MRequisitionLine.Table_Name, new String[]{ - "AD_Org_ID", - MRequisitionLine.COLUMNNAME_M_Product_ID, - MRequisitionLine.COLUMNNAME_Qty, - MRequisitionLine.COLUMNNAME_C_OrderLine_ID, // QtyOrdered depends on that - }); - s_sourceColumnNames.put(X_M_Forecast.Table_Name, new String[]{ - }); - s_sourceColumnNames.put(MForecastLine.Table_Name, new String[]{ - "AD_Org_ID", - MForecastLine.COLUMNNAME_DatePromised, - MForecastLine.COLUMNNAME_M_Warehouse_ID, - MForecastLine.COLUMNNAME_M_Product_ID, - MForecastLine.COLUMNNAME_Qty, - }); - s_sourceColumnNames.put(MDDOrderLine.Table_Name, new String[]{ - "AD_Org_ID", - MDDOrderLine.COLUMNNAME_M_Product_ID, - MDDOrderLine.COLUMNNAME_DatePromised, - MDDOrderLine.COLUMNNAME_QtyOrdered, - MDDOrderLine.COLUMNNAME_QtyDelivered, - MDDOrderLine.COLUMNNAME_ConfirmedQty, - MDDOrderLine.COLUMNNAME_M_Locator_ID, - MDDOrderLine.COLUMNNAME_M_LocatorTo_ID, - MDDOrderLine.COLUMNNAME_ConfirmedQty, - }); - s_sourceColumnNames.put(MPPOrder.Table_Name, new String[]{ - "AD_Org_ID", - MPPOrder.COLUMNNAME_M_Product_ID, - MPPOrder.COLUMNNAME_DatePromised, - MPPOrder.COLUMNNAME_QtyOrdered, - MPPOrder.COLUMNNAME_QtyDelivered, - MPPOrder.COLUMNNAME_PP_Product_BOM_ID, - MPPOrder.COLUMNNAME_AD_Workflow_ID, - }); - s_sourceColumnNames.put(MPPOrderBOMLine.Table_Name, new String[]{ - MPPOrderBOMLine.COLUMNNAME_M_Product_ID, - MPPOrderBOMLine.COLUMNNAME_M_Warehouse_ID, - MPPOrderBOMLine.COLUMNNAME_QtyEntered, - MPPOrderBOMLine.COLUMNNAME_QtyDelivered, - }); - } - - /** - * Check if a persistent object is changed, from MRP point of view - * @param po MRP relevant PO (e.g. MOrder, MOrderLine, MPPOrder etc) - * @return true if object changed - */ - public static boolean isChanged(PO po) - { - String[] columnNames = s_sourceColumnNames.get(po.get_TableName()); - if (columnNames == null || columnNames.length == 0) - { - return false; - } - for (String columnName : columnNames) - { - if (po.is_ValueChanged(columnName)) - { - return true; - } - } - return false; - } - - public static void deleteMRP(PO po) - { - String tableName = po.get_TableName(); - int no = DB.executeUpdateEx("DELETE FROM "+Table_Name+" WHERE "+tableName+"_ID=? AND AD_Client_ID=?", - new Object[]{po.get_ID(), po.getAD_Client_ID()}, - po.get_TrxName()); - s_log.finest("Deleted "+tableName+" #"+no); - } - - private static Query getQuery(PO po, String typeMRP, String orderType) - { - ArrayList params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - // - whereClause.append("AD_Client_ID=?"); - params.add(po.getAD_Client_ID()); - // - whereClause.append(" AND ").append(po.get_TableName()).append("_ID=?"); - params.add(po.get_ID()); - // - if (typeMRP != null) - { - whereClause.append(" AND ").append(COLUMNNAME_TypeMRP).append("=?"); - params.add(typeMRP); - } - // - if (orderType != null) - { - whereClause.append(" AND ").append(COLUMNNAME_OrderType).append("=?"); - params.add(orderType); - } - // - return new Query(po.getCtx(), Table_Name, whereClause.toString(), po.get_TrxName()) - .setParameters(params); - } - - /************************************************************************** - * Default Constructor - * @param ctx context - * @param PP_MRP_ID id - * @param trxName Transaction Name - */ - public MPPMRP(Properties ctx, int PP_MRP_ID, String trxName) - { - super(ctx, PP_MRP_ID,trxName); - if (PP_MRP_ID == 0) - { - setDateSimulation(new Timestamp (System.currentTimeMillis())); - } - } // MPPMRP - - /** - * Load Constructor - * @param ctx context - * @param rs result set - */ - public MPPMRP(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs , trxName); - } - - public void setPP_Order(MPPOrder o) - { - setPP_Order_ID(o.getPP_Order_ID()); - setOrderType(ORDERTYPE_ManufacturingOrder); - // - setName(o.getDocumentNo()); - setDescription(o.getDescription()); - setDatePromised(o.getDatePromised()); - setDateOrdered(o.getDateOrdered()); - setDateStartSchedule(o.getDateStartSchedule()); - setDateFinishSchedule(o.getDateFinishSchedule()); - setS_Resource_ID(o.getS_Resource_ID()); - setDocStatus(o.getDocStatus()); - } - - public void setC_Order(MOrder o) - { - setC_Order_ID(o.get_ID()); - setC_BPartner_ID(o.getC_BPartner_ID()); - setDocStatus(o.getDocStatus()); - if (o.isSOTrx()) - { - setOrderType(MPPMRP.ORDERTYPE_SalesOrder); - setTypeMRP(MPPMRP.TYPEMRP_Demand); - } - else - { - setOrderType(MPPMRP.ORDERTYPE_PurchaseOrder); - setTypeMRP(MPPMRP.TYPEMRP_Supply); - } - } - - /** - * Create MRP record based in Forecast Line - * @param MForecastLine Forecast Line - * @param delete Indicate if this record is delete - */ - public static void M_ForecastLine(MForecastLine fl, boolean delete) - { - String trxName = fl.get_TrxName(); - Properties ctx = fl.getCtx(); - - if (delete) - { - deleteMRP(fl); - return; - } - - X_M_Forecast f = new X_M_Forecast(ctx, fl.getM_Forecast_ID(), trxName); - MPPMRP mrp = getQuery(fl, null, null).firstOnly(); - if (mrp == null) - { - mrp = new MPPMRP(ctx, 0, trxName); - mrp.setAD_Org_ID(fl.getAD_Org_ID()); - mrp.setM_Forecast_ID(fl.getM_Forecast_ID()); - mrp.setM_ForecastLine_ID(fl.getM_ForecastLine_ID()); - mrp.setOrderType(MPPMRP.ORDERTYPE_Forecast); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Demand); - } - 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.setM_Warehouse_ID(fl.getM_Warehouse_ID()); - mrp.setDocStatus(DocAction.STATUS_InProgress); - mrp.saveEx(); - } - - /** - * Create MRP record based in Order - * @param MOrder - * @param delete Indicate if this record is delete - * @return - */ - public static void C_Order(MOrder o, boolean delete) - { - if (delete) - { - deleteMRP(o); - return; - } - - MDocType dt = MDocType.get(o.getCtx(), o.getC_DocTypeTarget_ID()); - String DocSubTypeSO = dt.getDocSubTypeSO(); - if(MDocType.DOCSUBTYPESO_StandardOrder.equals(DocSubTypeSO) || !o.isSOTrx()) - { - if((o.getDocStatus().equals(MOrder.DOCSTATUS_InProgress) - || o.getDocStatus().equals(MOrder.DOCSTATUS_Completed)) - || !o.isSOTrx()) - { - for(MOrderLine line : o.getLines()) - { - C_OrderLine(line , false); - } - } - - if (o.is_ValueChanged(MOrder.COLUMNNAME_DocStatus) - || o.is_ValueChanged(MOrder.COLUMNNAME_C_BPartner_ID) - ) - { - List list = getQuery(o, null, null).list(); - for (MPPMRP mrp : list) - { - mrp.setC_Order(o); - mrp.saveEx(); - } - } - } - } - - /** - * 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) - { - if (delete) - { - deleteMRP(ol); - // Delete generated manufacturing order - MPPOrder order = MPPOrder.forC_OrderLine_ID(ol.getCtx(), ol.get_ID(), ol.get_TrxName()); - if (order != null && !order.isProcessed()) - { - order.deleteEx(true); - } - return; - } - - MPPMRP mrp = getQuery(ol, null, null).firstOnly(); - if(mrp == null) - { - mrp = new MPPMRP(ol.getCtx(), 0, ol.get_TrxName()); - mrp.setC_OrderLine_ID(ol.getC_OrderLine_ID()); - } - mrp.setAD_Org_ID(ol.getAD_Org_ID()); - mrp.setC_Order(ol.getParent()); - 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.saveEx(); - - MOrder o = ol.getParent(); - MDocType dt = MDocType.get(o.getCtx(), o.getC_DocTypeTarget_ID()); - String DocSubTypeSO = dt.getDocSubTypeSO(); - if(MDocType.DOCSUBTYPESO_StandardOrder.equals(DocSubTypeSO)) - { - MPPOrder order = MPPOrder.forC_OrderLine_ID(ol.getCtx(), ol.get_ID(), ol.get_TrxName()); - if (order == null) - { - final String whereClause = MPPProductBOM.COLUMNNAME_BOMType+" IN (?,?)" - +" AND "+MPPProductBOM.COLUMNNAME_BOMUse+"=?" - +" AND "+MPPProductBOM.COLUMNNAME_M_Product_ID+"=?"; - MPPProductBOM bom = new Query(ol.getCtx(), MPPProductBOM.Table_Name, whereClause, null) - .setParameters(new Object[]{ - MPPProductBOM.BOMTYPE_Make_To_Order, - MPPProductBOM.BOMTYPE_Make_To_Kit, - MPPProductBOM.BOMUSE_Manufacturing, - ol.getM_Product_ID()}) - .firstOnly(); - - MPPProductPlanning pp = null; - //Validate the BOM based in planning data - if(bom == null) - { - pp = MPPProductPlanning.find(ol.getCtx(), ol.getAD_Org_ID(), 0, 0, ol.getM_Product_ID(), null); - if(pp != null) - { - bom = (MPPProductBOM) pp.getPP_Product_BOM(); - if( bom != null - && !MPPProductBOM.BOMTYPE_Make_To_Order.equals(bom.getBOMType()) - && !MPPProductBOM.BOMTYPE_Make_To_Kit.equals(bom.getBOMType()) ) - { - bom = null; - } - } - } - if (bom != null) - { - final MProduct product = MProduct.get(ol.getCtx(), ol.getM_Product_ID()); - final int plant_id = MPPProductPlanning.getPlantForWarehouse(ol.getM_Warehouse_ID()); - if(plant_id <= 0 ) - { - //TODO: vpj-cd create the msg for error - throw new AdempiereException("Do not exist Resource Plant for this Warehouse"); - } - MWorkflow workflow = MWorkflow.get(ol.getCtx(), MWorkflow.getWorkflowSearchKey(product)); - //Validate the workflow based in planning data - if(workflow == null && pp != null) - { - workflow = pp.getAD_Workflow(); - } - // - if (plant_id > 0 && workflow != null) - { - int duration = MPPMRP.getDays(ol.getCtx(), plant_id, workflow.get_ID(), ol.getQtyOrdered(), ol.get_TrxName()).intValue(); - // - order = new MPPOrder(ol.getCtx(), 0 , ol.get_TrxName()); - //comment for Manufacturing Order - order.setDescription( Msg.translate(ol.getCtx(),MRefList.getListName(ol.getCtx(), MPPOrderBOM.BOMTYPE_AD_Reference_ID, bom.getBOMType())) - + " " - + Msg.translate(ol.getCtx(), MOrder.COLUMNNAME_C_Order_ID) - + " : " - + o.getDocumentNo()); - order.setC_OrderLine_ID(ol.getC_OrderLine_ID()); - order.setS_Resource_ID(plant_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(bom.get_ID()); - order.setAD_Workflow_ID(workflow.get_ID()); - order.setPlanner_ID(ol.getParent().getSalesRep_ID()); - order.setLine(10); - order.setDateOrdered(ol.getDateOrdered()); - order.setDatePromised(ol.getDatePromised()); - order.setDateStartSchedule(TimeUtil.addDays(ol.getDatePromised(), 0 - duration)); - order.setDateFinishSchedule(ol.getDatePromised()); - order.setC_UOM_ID(ol.getC_UOM_ID()); - order.setQty(ol.getQtyOrdered()); - order.setPriorityRule(MPPOrder.PRIORITYRULE_High); - order.saveEx(); - order.setDocStatus(order.prepareIt()); - order.setDocAction(MPPOrder.ACTION_Complete); - order.saveEx(); - //comment for Order Line - ol.setDescription( Msg.translate(ol.getCtx(),MRefList.getListName(ol.getCtx(), MPPOrderBOM.BOMTYPE_AD_Reference_ID, bom.getBOMType())) - + " " - + Msg.translate(ol.getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) - + " : " - + order.getDocumentNo()); - ol.saveEx(); - } - } - } - else - { - if (!order.isProcessed()) - { - //if you chance product in order line the Manufacturing order is void - if(order.getM_Product_ID() != ol.getM_Product_ID()) - { - order.setDescription(""); - order.setQtyEntered(Env.ZERO); - order.setC_OrderLine_ID(0); - order.voidIt(); - order.setDocStatus(MPPOrder.DOCSTATUS_Voided); - order.setDocAction(MPPOrder.ACTION_None); - order.save(); - ol.setDescription(""); - ol.saveEx(); - - } - if(order.getQtyEntered().compareTo(ol.getQtyEntered()) != 0) - { - order.setQty(ol.getQtyEntered()); - order.saveEx(); - } - if(order.getDatePromised().compareTo(ol.getDatePromised()) != 0) - { - order.setDatePromised(ol.getDatePromised()); - order.saveEx(); - } - } - } - } - - 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) - { - Properties ctx = o.getCtx(); - String trxName = o.get_TrxName(); - - if (delete) - { - deleteMRP(o); - return; - } - // - // Supply - MPPMRP mrpSupply = getQuery(o, TYPEMRP_Supply, ORDERTYPE_ManufacturingOrder).firstOnly(); - if(mrpSupply == null) - { - mrpSupply = new MPPMRP(ctx, 0, trxName); - mrpSupply.setAD_Org_ID(o.getAD_Org_ID()); - mrpSupply.setTypeMRP(MPPMRP.TYPEMRP_Supply); - } - mrpSupply.setPP_Order(o); - mrpSupply.setQty(o.getQtyOrdered().subtract(o.getQtyDelivered())); - mrpSupply.setM_Product_ID(o.getM_Product_ID()); - mrpSupply.setM_Warehouse_ID(o.getM_Warehouse_ID()); - mrpSupply.saveEx(); - // - // Demand - List mrpDemandList = getQuery(o, TYPEMRP_Demand, ORDERTYPE_ManufacturingOrder).list(); - for (MPPMRP mrpDemand : mrpDemandList) - { - mrpDemand.setPP_Order(o); - mrpDemand.saveEx(); - } - } - - /** - * 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 trxName = obl.get_TrxName(); - Properties ctx = obl.getCtx(); - if (delete) - { - deleteMRP(obl); - return; - } - // - String typeMRP = MPPMRP.TYPEMRP_Demand; - BigDecimal qty = obl.getQtyRequiered().subtract(obl.getQtyDelivered()); - // - // By-Product support: - if (obl.isComponentType(MPPOrderBOMLine.COMPONENTTYPE_ByProduct)) - { - // TODO: need to evaluate - deleteMRP(obl); - return; -// typeMRP = MPPMRP.TYPEMRP_Supply; -// qty = qty.negate(); - } - // - MPPMRP mrp = getQuery(obl, typeMRP, ORDERTYPE_ManufacturingOrder).firstOnly(); - if(mrp == null) - { - mrp = new MPPMRP(ctx, 0, trxName); - mrp.setPP_Order_BOMLine_ID(obl.getPP_Order_BOMLine_ID()); - } - mrp.setAD_Org_ID(obl.getAD_Org_ID()); - mrp.setTypeMRP(typeMRP); - mrp.setPP_Order(obl.getParent()); - mrp.setQty(qty); - mrp.setM_Product_ID(obl.getM_Product_ID()); - mrp.setM_Warehouse_ID(obl.getM_Warehouse_ID()); - mrp.saveEx(); - } - - /** - * 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) - { - if (delete) - { - deleteMRP(o); - return; - } - } - - /** - * 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 trxName = ol.getParent().get_TrxName(); - Properties m_ctx = ol.getCtx(); - if (delete) - { - deleteMRP(ol); - return; - } - // - MPPMRP mrp = getQuery(ol, TYPEMRP_Demand, ORDERTYPE_DistributionOrder).firstOnly(); - MLocator source = MLocator.get( m_ctx , ol.getM_Locator_ID()); - MLocator target = MLocator.get( m_ctx , ol.getM_LocatorTo_ID()); - 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 - { - 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(); - - } - mrp = getQuery(ol, TYPEMRP_Supply, ORDERTYPE_DistributionOrder).firstOnly(); - 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; - } - - - /** - * 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) - { - if (delete) - { - deleteMRP(rl); - return; - } - - MPPMRP mrp = getQuery(rl, null, null).firstOnly(); - MRequisition r = rl.getParent(); - if (mrp == null) - { - mrp = new MPPMRP(rl.getCtx(), 0, rl.get_TrxName()); - mrp.setM_Requisition_ID(rl.getM_Requisition_ID()); - mrp.setM_RequisitionLine_ID(rl.getM_RequisitionLine_ID()); - mrp.setOrderType(MPPMRP.ORDERTYPE_MaterialRequisition); - mrp.setTypeMRP(MPPMRP.TYPEMRP_Supply); - mrp.setIsAvailable(true); - } - mrp.setAD_Org_ID(r.getAD_Org_ID()); - mrp.setName("MRP"); - mrp.setDescription(rl.getDescription()); - mrp.setDateOrdered(r.getDateRequired()); - mrp.setDatePromised(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()); - // We create a MRP record only for Not Ordered Qty. The Order will generate a MRP record for Ordered Qty. - mrp.setQty(rl.getQty().subtract(rl.getQtyOrdered())); - // MRP record for a requisition will be ALWAYS Drafted because - // a requisition generates just Planned Orders (which is a wish list) - // and not Scheduled Receipts - mrp.setDocStatus(DocAction.STATUS_Drafted); - mrp.saveEx(); - } - - /** - * Get Qty Onhand - * @param AD_Client_ID - * @param M_Warehouse_ID - * @param M_Product_ID - * @return - */ - public static BigDecimal getQtyOnHand(Properties ctx, int M_Warehouse_ID ,int M_Product_ID,String trxName) - { - final String sql = "SELECT COALESCE(bomQtyOnHand (M_Product_ID,?,0),0) FROM M_Product" - +" WHERE AD_Client_ID=? AND M_Product_ID=?"; - return DB.getSQLValueBDEx(trxName, sql, new Object[]{M_Warehouse_ID,Env.getAD_Client_ID(ctx),M_Product_ID}); - } - - /** - * Get Reserved Quantity for a Warehouse - * @param ctx - * @param M_Warehouse_ID - * @param M_Product_ID - * @param To - * @param trxName - * @return BibDecimal - */ - public static BigDecimal getQtyReserved(Properties ctx, int M_Warehouse_ID ,int M_Product_ID, Timestamp To,String trxName) - { - final String sql = "SELECT SUM(Qty) FROM PP_MRP WHERE " - +" TypeMRP=?" - +" AND DocStatus IN ('IN','CO')" - +" AND OrderType IN ('SOO','MOP','DOO')" - +" AND AD_Client_ID=? AND M_Warehouse_ID =? AND M_Product_ID=?" - +" AND DatePromised <=?"; - BigDecimal qty = DB.getSQLValueBDEx(trxName, sql, new Object[]{ - MPPMRP.TYPEMRP_Demand, - Env.getAD_Client_ID(ctx),M_Warehouse_ID, M_Product_ID, - To, - }); - // SQL may return no rows or null - if (qty == null) - return Env.ZERO; - - return qty; - } - - /** - * Get Reserved Quantity for a Warehouse - * @param ctx - * @param M_Warehouse_ID - * @param M_Product_ID - * @param trxName - * @return BibDecimal - */ - public static BigDecimal getQtyReserved(Properties ctx, int M_Warehouse_ID ,int M_Product_ID,String trxName) - { - return getQtyReserved(ctx, M_Warehouse_ID, M_Product_ID, new Timestamp (System.currentTimeMillis()), trxName); - } - - /** - * Get Reserved Quantity for a Warehouse - * @param ctx - * @param M_Warehouse_ID - * @param M_Product_ID - * @param To - * @param trxName - * @return - */ - public static BigDecimal getQtyOrdered(Properties ctx, int M_Warehouse_ID ,int M_Product_ID, Timestamp To,String trxName) - { - StringBuffer sql = new StringBuffer("SELECT SUM(Qty) FROM PP_MRP WHERE TypeMRP='S' AND DocStatus IN ('IN','CO')"); - sql.append(" AND OrderType IN ('POO','MOP','DOO') AND AD_Client_ID= ? AND DatePromised <=? AND M_Warehouse_ID =? AND M_Product_ID=?"); - BigDecimal qty = DB.getSQLValueBDEx(trxName, sql.toString(), new Object[]{Env.getAD_Client_ID(ctx), To , M_Warehouse_ID, M_Product_ID}); - // SQL may return no rows or null - if (qty == null) - return Env.ZERO; - - return qty; - } - - /** - * Set Order Reserved Quantity for a Warehouse - * @param AD_Client_ID - * @param M_Warehouse_ID - * @param M_Product_ID - * @param trxName - * @return - */ - public static BigDecimal getQtyOrdered(Properties ctx, int M_Warehouse_ID ,int M_Product_ID,String trxName) - { - return getQtyOrdered(ctx, M_Warehouse_ID, M_Product_ID, new Timestamp (System.currentTimeMillis()), trxName); - } - - /** - * Maximum Low Level Code - * @param ctx - * @param trxName - * @return maximum low level - */ - public static int getMaxLowLevel(Properties ctx, String trxName) - { - int AD_Client_ID = Env.getAD_Client_ID(ctx); - // - final String sql = "SELECT MAX("+MProduct.COLUMNNAME_LowLevel+") FROM M_Product" - +" WHERE AD_Client_ID=? AND "+MProduct.COLUMNNAME_LowLevel+" IS NOT NULL"; - int LowLevel = DB.getSQLValueEx(trxName, sql, AD_Client_ID); - return LowLevel + 1; - } - - /** - * Calculated duration of given workflow, considering resource's available days and timeslot. - * @param ctx - * @param S_Resource_ID - * @param AD_Workflow_ID - * @param QtyOrdered - * @param trxName - * @return duration [days] - */ - 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(ctx, S_Resource_ID); - MResourceType S_ResourceType = MResourceType.get(ctx, S_Resource.getS_ResourceType_ID()); - - BigDecimal AvailableDayTime = Env.ZERO; - if (S_ResourceType.isTimeSlot()) - AvailableDayTime = BigDecimal.valueOf(getHoursAvailable(S_ResourceType.getTimeSlotStart(),S_ResourceType.getTimeSlotEnd())); - else - AvailableDayTime = BigDecimal.valueOf(24); - - int AvailableDays = 0; - if (S_ResourceType.isDateSlot()) { - if (S_ResourceType.isOnMonday()) - AvailableDays += 1; - if (S_ResourceType.isOnTuesday()) - AvailableDays += 1; - if (S_ResourceType.isOnThursday()) - AvailableDays += 1; - if (S_ResourceType.isOnWednesday()) - AvailableDays += 1; - if (S_ResourceType.isOnFriday()) - AvailableDays += 1; - if (S_ResourceType.isOnSaturday()) - AvailableDays += 1; - if (S_ResourceType.isOnSunday()) - AvailableDays += 1; - } - else { - AvailableDays = 7; - } - - MWorkflow wf = MWorkflow.get(ctx, AD_Workflow_ID); - - BigDecimal RequiredTime = BigDecimal.valueOf ( - ( wf.getQueuingTime() - + wf.getSetupTime() - + (wf.getDuration() * QtyOrdered.doubleValue()) - + wf.getWaitingTime() - + wf.getMovingTime() - ) - * ( (double)wf.getDurationBaseSec() / 60 / 60 ) // convert to hours - ); - // TODO: implement here, Victor's suggestion - https://sourceforge.net/forum/message.php?msg_id=5179460 - - // Weekly Factor - BigDecimal WeeklyFactor = BigDecimal.valueOf(7).divide(BigDecimal.valueOf(AvailableDays), 8, BigDecimal.ROUND_UP); - - return (RequiredTime.multiply(WeeklyFactor)).divide(AvailableDayTime, 0, BigDecimal.ROUND_UP); - } - - /** - * Return hours between time1 and time2. - * Minutes, secords and millis are discarded. - * @param time1 Time Start - * @param time2 Time End - * @return hours between time1 and time2 - */ - public static long getHoursAvailable (Timestamp time1, Timestamp time2) - { - return (time2.getTime() - time1.getTime()) / (60 * 60 * 1000); - } - - public static String getDocumentNo(int PP_MRP_ID) - { - return DB.getSQLValueStringEx(null, "SELECT documentNo(PP_MRP_ID) AS DocumentNo FROM PP_MRP WHERE PP_MRP_ID = ?", PP_MRP_ID); - } - - public String toString() - { - String description = getDescription(); - return getClass().getSimpleName()+"[" - +", TypeMRP="+getTypeMRP() - +", DocStatus="+getDocStatus() - +", Qty="+getQty() - +", DatePromised="+getDatePromised() - +", Schedule="+getDateStartSchedule()+"/"+getDateFinishSchedule() - +(!Util.isEmpty(description, true) ? ", Description="+description : "") - +", ID="+get_ID() - +"]"; - } - -} // MPPMRP diff --git a/base/src/org/eevolution/model/MPPOrder.java b/base/src/org/eevolution/model/MPPOrder.java deleted file mode 100644 index 057c8a33a2..0000000000 --- a/base/src/org/eevolution/model/MPPOrder.java +++ /dev/null @@ -1,1330 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.io.File; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Properties; - -import org.adempiere.exceptions.AdempiereException; -import org.adempiere.exceptions.DocTypeNotFoundException; -import org.compiere.model.MAcctSchema; -import org.compiere.model.MClient; -import org.compiere.model.MCost; -import org.compiere.model.MDocType; -import org.compiere.model.MProduct; -import org.compiere.model.MProject; -import org.compiere.model.MResource; -import org.compiere.model.MStorage; -import org.compiere.model.MTable; -import org.compiere.model.MUOM; -import org.compiere.model.MWarehouse; -import org.compiere.model.ModelValidationEngine; -import org.compiere.model.ModelValidator; -import org.compiere.model.PO; -import org.compiere.model.POResultSet; -import org.compiere.model.Query; -import org.compiere.print.ReportEngine; -import org.compiere.process.DocAction; -import org.compiere.process.DocumentEngine; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.wf.MWFNode; -import org.compiere.wf.MWFNodeNext; -import org.compiere.wf.MWorkflow; - -/** - * PP Order Model. - * - * @author Victor Perez www.e-evolution.com - * @author Teo Sarca, www.arhipac.ro - */ -public class MPPOrder extends X_PP_Order implements DocAction -{ - private static final long serialVersionUID = 1L; - - public static MPPOrder forC_OrderLine_ID(Properties ctx, int C_OrderLine_ID, String trxName) - { - return new Query(ctx, MPPOrder.Table_Name, COLUMNNAME_C_OrderLine_ID+"=?", trxName) - .setParameters(new Object[]{C_OrderLine_ID}) - .firstOnly(); - } - - - /************************************************************************** - * Default Constructor - * @param ctx context - * @param C_Order_ID order to load, (0 create new order) - */ - public MPPOrder(Properties ctx, int PP_Order_ID, String trxName) - { - super(ctx, PP_Order_ID, trxName); - // New - if (PP_Order_ID == 0) - { - setQtyDelivered(Env.ZERO); - setQtyReject(Env.ZERO); - setQtyScrap(Env.ZERO); - setIsSelected(false); - setIsSOTrx(false); - setIsApproved(false); - setIsPrinted(false); - setProcessed(false); - setProcessing(false); - setPosted(false); - // - setC_DocType_ID(0); - setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_ManufacturingOrder); - // - //set_ValueNoCheck("DocumentNo", null); - setDocStatus(DOCSTATUS_Drafted); - setDocAction(DOCACTION_Prepare); - } - } // PP_Order - - /************************************************************************** - * Project Constructor - * @param project Project to create Order from - * @param DocSubTypeSO if SO DocType Target (default DocSubTypeSO_OnCredit) - */ - public MPPOrder(MProject project, int PP_Product_BOM_ID, int AD_Workflow_ID) - { - this(project.getCtx(), 0, project.get_TrxName()); - setAD_Client_ID(project.getAD_Client_ID()); - setAD_Org_ID(project.getAD_Org_ID()); - setC_Campaign_ID(project.getC_Campaign_ID()); - setC_Project_ID(project.getC_Project_ID()); - setDescription(project.getName()); - setLine(10); - setPriorityRule(MPPOrder.PRIORITYRULE_Medium); - if (project.getDateContract() == null) - throw new IllegalStateException("Date Contract is mandatory for Manufacturing Order."); - if (project.getDateFinish() == null) - throw new IllegalStateException("Date Finish is mandatory for Manufacturing Order."); - - Timestamp ts = project.getDateContract(); - Timestamp df= project.getDateContract(); - - if (ts != null) setDateOrdered(ts); - if (ts != null) this.setDateStartSchedule(ts); - ts = project.getDateFinish(); - if (df != null) setDatePromised(df); - setM_Warehouse_ID(project.getM_Warehouse_ID()); - setPP_Product_BOM_ID(PP_Product_BOM_ID); - setAD_Workflow_ID(AD_Workflow_ID); - setQtyEntered(Env.ONE); - setQtyOrdered(Env.ONE); - MPPProductBOM bom = new MPPProductBOM(project.getCtx(), PP_Product_BOM_ID, project.get_TrxName()); - MProduct product = MProduct.get(project.getCtx(), bom.getM_Product_ID()); - setC_UOM_ID(product.getC_UOM_ID()); - - setM_Product_ID(bom.getM_Product_ID()); - - String where = MResource.COLUMNNAME_IsManufacturingResource +" = 'Y' AND "+ - MResource.COLUMNNAME_ManufacturingResourceType +" = '" + MResource.MANUFACTURINGRESOURCETYPE_Plant + "' AND " + - MResource.COLUMNNAME_M_Warehouse_ID + " = " + project.getM_Warehouse_ID(); - MResource resoruce = (MResource) MTable.get(project.getCtx(), MResource.Table_ID).getPO( where , project.get_TrxName()); - if (resoruce == null) - throw new IllegalStateException("Resource is mandatory."); - setS_Resource_ID(resoruce.getS_Resource_ID()); - } // MOrder - - /** - * Load Constructor - * @param ctx context - * @param rs result set record - */ - public MPPOrder(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } // MOrder - - /** - * @return Open Qty (Ordered - Delivered - Scrap) - */ - public BigDecimal getQtyOpen() - { - return getQtyOrdered().subtract(getQtyDelivered()).subtract(getQtyScrap()); - } - - /** - * Get BOM Lines of PP Order - * @param requery - * @return Order BOM Lines - */ - public MPPOrderBOMLine[] getLines(boolean requery) - { - if (m_lines != null && !requery) - { - set_TrxName(m_lines, get_TrxName()); - return m_lines; - } - String whereClause = MPPOrderBOMLine.COLUMNNAME_PP_Order_ID+"=?"; - List list = new Query(getCtx(), MPPOrderBOMLine.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{getPP_Order_ID()}) - .setOrderBy(MPPOrderBOMLine.COLUMNNAME_Line) - .list(); - m_lines = list.toArray(new MPPOrderBOMLine[list.size()]); - return m_lines; - } - private MPPOrderBOMLine[] m_lines = null; - - /** - * Get BOM Lines of PP Order - * @return Order BOM Lines - */ - public MPPOrderBOMLine[] getLines() - { - return getLines(true); - } - - public void setC_DocTypeTarget_ID(String docBaseType) - { - MDocType[] doc = MDocType.getOfDocBaseType(getCtx(), docBaseType); - if(doc == null) - { - throw new DocTypeNotFoundException(docBaseType, ""); - } - else - { - setC_DocTypeTarget_ID(doc[0].get_ID()); - } - } - - @Override - public void setProcessed(boolean processed) - { - super.setProcessed(processed); - - // Update DB: - if (get_ID() <= 0) - return; - final String sql = "UPDATE PP_Order SET Processed=? WHERE PP_Order_ID=?"; - DB.executeUpdateEx(sql, new Object[]{processed, get_ID()}, get_TrxName()); - } // setProcessed - - @Override - protected boolean beforeSave(boolean newRecord) - { - if (getAD_Client_ID() == 0) - { - m_processMsg = "AD_Client_ID = 0"; - return false; - } - if (getAD_Org_ID() == 0) - { - int context_AD_Org_ID = Env.getAD_Org_ID(getCtx()); - if (context_AD_Org_ID == 0) { - m_processMsg = "AD_Org_ID = 0"; - return false; - } - setAD_Org_ID(context_AD_Org_ID); - log.warning("beforeSave - Changed Org to Context=" + context_AD_Org_ID); - } - if (getM_Warehouse_ID() == 0) - { - int ii = Env.getContextAsInt(getCtx(), "#M_Warehouse_ID"); - if (ii != 0) - { - setM_Warehouse_ID(ii); - } - } - // If DateFinishSchedule is not filled, use DatePromised - if (getDateFinishSchedule() == null) - { - setDateFinishSchedule(getDatePromised()); - } - - return true; - } - - @Override - protected boolean afterSave(boolean newRecord, boolean success) - { - if (!success) - { - return false; - } - - boolean explotion = DocAction.STATUS_Drafted.equals(getDocStatus()) - || DocAction.STATUS_InProgress.equals(getDocStatus()); - - if( is_ValueChanged(MPPOrder.COLUMNNAME_QtyEntered) && explotion) - { - deleteWorkflowAndBOM(); - explotion(); - } - if( is_ValueChanged(MPPOrder.COLUMNNAME_QtyEntered) && !explotion) - { - throw new AdempiereException("Cannot Change Quantity, Only is allow with Draft or In Process Status"); // TODO: Create Message for Translation - } - - if (!newRecord) - { - return success; - } - - explotion(); - return true; - } // beforeSave - - @Override - protected boolean beforeDelete() - { - // OrderBOMLine - if (getDocStatus().equals(DOCSTATUS_Drafted) || getDocStatus().equals(DOCSTATUS_InProgress)) - { - String whereClause = "PP_Order_ID=? AND AD_Client_ID=?"; - Object[] params = new Object[]{get_ID(), getAD_Client_ID()}; - // - deletePO(MPPOrderCost.Table_Name, whereClause, params); - deleteWorkflowAndBOM(); - } - return true; - } // beforeDelete - - private void deleteWorkflowAndBOM() - { - // New record, nothing to do - if (get_ID() <= 0) - { - return; - } - // - String whereClause = "PP_Order_ID=? AND AD_Client_ID=?"; - Object[] params = new Object[]{get_ID(), getAD_Client_ID()}; - // Reset workflow start node - DB.executeUpdateEx("UPDATE PP_Order_Workflow SET PP_Order_Node_ID=NULL WHERE "+whereClause, params, get_TrxName()); - // Delete workflow: - deletePO(X_PP_Order_Node_Asset.Table_Name, whereClause, params); - deletePO(X_PP_Order_Node_Product.Table_Name, whereClause, params); - deletePO(MPPOrderNodeNext.Table_Name, whereClause, params); - deletePO(MPPOrderNode.Table_Name, whereClause, params); - deletePO(MPPOrderWorkflow.Table_Name, whereClause, params); - // Delete BOM: - deletePO(MPPOrderBOMLine.Table_Name, whereClause, params); - deletePO(MPPOrderBOM.Table_Name, whereClause, params); - - } - - public boolean processIt(String processAction) - { - m_processMsg = null; - DocumentEngine engine = new DocumentEngine(this, getDocStatus()); - return engine.processIt(processAction, getDocAction()); - } // processIt - - /** Process Message */ - private String m_processMsg = null; - /** Just Prepared Flag */ - private boolean m_justPrepared = false; - - public boolean unlockIt() - { - log.info("unlockIt - " + toString()); - setProcessing(false); - return true; - } // unlockIt - - public boolean invalidateIt() - { - log.info("invalidateIt - " + toString()); - setDocAction(DOCACTION_Prepare); - return true; - } // invalidateIt - - public String prepareIt() - { - log.info("prepareIt - " + toString()); - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE); - if (m_processMsg != null) - return DocAction.STATUS_Invalid; - - // Lines - MPPOrderBOMLine[] lines = getLines(); - if (lines.length == 0) - { - m_processMsg = "@NoLines@"; - return DocAction.STATUS_Invalid; - } - - // Cannot change Std to anything else if different warehouses - if (getC_DocType_ID() != 0) - { - for (int i = 0; i < lines.length; i++) - { - if (lines[i].getM_Warehouse_ID() != getM_Warehouse_ID()) - { - log.warning("different Warehouse " + lines[i]); - m_processMsg = "@CannotChangeDocType@"; - return DocAction.STATUS_Invalid; - } - } - } - - // New or in Progress/Invalid - if (DOCSTATUS_Drafted.equals(getDocStatus()) - || DOCSTATUS_InProgress.equals(getDocStatus()) - || DOCSTATUS_Invalid.equals(getDocStatus()) - || getC_DocType_ID() == 0) - { - setC_DocType_ID(getC_DocTypeTarget_ID()); - } - - String docBaseType = MDocType.get(getCtx(), getC_DocType_ID()).getDocBaseType(); - if (MDocType.DOCBASETYPE_QualityOrder.equals(docBaseType)) - { - ; // nothing - } - // ManufacturingOrder, MaintenanceOrder - else - { - reserveStock(lines); - orderStock(); - } - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE); - if (m_processMsg != null) - return DocAction.STATUS_Invalid; - - m_justPrepared = true; - return DocAction.STATUS_InProgress; - } // prepareIt - - private void orderStock() - { - MProduct product = getM_Product(); - if (product.isStocked()) - { - BigDecimal target = getQtyOrdered(); - BigDecimal difference = target.subtract(getQtyReserved()).subtract(getQtyDelivered()); - if (difference.signum() == 0) - return ; - BigDecimal ordered = difference; - - int M_Locator_ID = getM_Locator_ID(ordered); - // Necessary to clear order quantities when called from closeIt - 4Layers - if (DOCACTION_Close.equals(getDocAction())) - { - if (!MStorage.add(getCtx(), getM_Warehouse_ID(), M_Locator_ID, - getM_Product_ID(), getM_AttributeSetInstance_ID(), - getM_AttributeSetInstance_ID(), Env.ZERO, Env.ZERO, ordered, get_TrxName())) - { - throw new AdempiereException(); - } - } - else - { - // Update Storage - if (!MStorage.add(getCtx(), getM_Warehouse_ID(), M_Locator_ID, - getM_Product_ID(), getM_AttributeSetInstance_ID(), - getM_AttributeSetInstance_ID(), Env.ZERO, Env.ZERO, ordered, get_TrxName())) - { - throw new AdempiereException(); - } - } - - setQtyReserved(getQtyReserved().add(difference)); - saveEx(get_TrxName()); - } - } - - /** - * Reserve Inventory. - * @param lines order lines (ordered by M_Product_ID for deadlock prevention) - * @return true if (un) reserved - */ - private void reserveStock(MPPOrderBOMLine[] lines) - { - final int header_M_Warehouse_ID = getM_Warehouse_ID(); - - // Always check and (un) Reserve Inventory - for (MPPOrderBOMLine line : lines) - { - // Check/set WH/Org - if (header_M_Warehouse_ID != 0) // enforce WH - { - if (header_M_Warehouse_ID != line.getM_Warehouse_ID()) - line.setM_Warehouse_ID(header_M_Warehouse_ID); - if (getAD_Org_ID() != line.getAD_Org_ID()) - line.setAD_Org_ID(getAD_Org_ID()); - } - // - final BigDecimal target = line.getQtyRequiered(); - final BigDecimal difference = target.subtract(line.getQtyReserved()).subtract(line.getQtyDelivered()); - if (difference.signum() == 0) - { - continue; - } - log.fine("Line=" + line.getLine() + " - Target=" + target + ",Difference=" + difference + " - Requiered=" + line.getQtyRequiered() - + ",Reserved=" + line.getQtyReserved() + ",Delivered=" + line.getQtyDelivered()); - - // Check Product - Stocked and Item - MProduct product = line.getM_Product(); - if (!product.isStocked()) - { - continue; - } - BigDecimal ordered = Env.ZERO; - BigDecimal reserved = difference; - int M_Locator_ID = getM_Locator_ID(ordered); - // Update Storage - if (!MStorage.add(getCtx(), line.getM_Warehouse_ID(), M_Locator_ID, - line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), - line.getM_AttributeSetInstance_ID(), Env.ZERO, reserved, ordered, get_TrxName())) - { - throw new AdempiereException(); - } - // update line - line.setQtyReserved(line.getQtyReserved().add(difference)); - line.saveEx(get_TrxName()); - } - } // reserveStock - - public boolean approveIt() - { - log.info("approveIt - " + toString()); - MDocType doc = MDocType.get(getCtx(), getC_DocType_ID()); - if (doc.getDocBaseType().equals(MDocType.DOCBASETYPE_QualityOrder)) - { - String whereClause = COLUMNNAME_PP_Product_BOM_ID+"=? AND "+COLUMNNAME_AD_Workflow_ID+"=?"; - MQMSpecification qms = new Query(getCtx(), MQMSpecification.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{getPP_Product_BOM_ID(), getAD_Workflow_ID()}) - .first(); - return qms != null ? qms.isValid(getM_AttributeSetInstance_ID()) : true; - } - else - { - setIsApproved(true); - } - - return true; - } // approveIt - - public boolean rejectIt() - { - log.info("rejectIt - " + toString()); - setIsApproved(false); - return true; - } // rejectIt - - public String completeIt() - { - // Just prepare - if (DOCACTION_Prepare.equals(getDocAction())) - { - setProcessed(false); - return DocAction.STATUS_InProgress; - } - - // Re-Check - if (!m_justPrepared) - { - String status = prepareIt(); - if (!DocAction.STATUS_InProgress.equals(status)) - return status; - } - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE); - if (m_processMsg != null) - { - return DocAction.STATUS_Invalid; - } - - // Implicit Approval - if (!isApproved()) - { - approveIt(); - } - - MAcctSchema as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema(); - log.info("Cost_Group_ID" + as.getM_CostType_ID()); - - // - // Create Standard Costs for Order - Collection costs = MCost.getByCostType(getM_Product(), as, as.getM_CostType_ID(), - getAD_Org_ID(), getM_AttributeSetInstance_ID()); - - for (MCost cost : costs) - { - MPPOrderCost PP_Order_Cost = new MPPOrderCost(cost, get_ID(), get_TrxName()); - PP_Order_Cost.saveEx(); - } - - // - // Create Standard Costs for Order BOM Line - for (MPPOrderBOMLine line : getLines()) - { - costs = MCost.getByCostType(line.getM_Product(), as, as.getM_CostType_ID(), - getAD_Org_ID(), getM_AttributeSetInstance_ID()); - - for (MCost cost : costs) - { - MPPOrderCost PP_Order_Cost = new MPPOrderCost(cost, get_ID(), get_TrxName()); - PP_Order_Cost.saveEx(); - } - } - - MPPOrderBOM obom = (MPPOrderBOM)getMPPOrderBOM(); - - // Auto receipt and issue for kit - if (MPPOrderBOM.BOMTYPE_Make_To_Kit.equals(obom.getBOMType()) && MPPOrderBOM.BOMUSE_Manufacturing.equals(obom.getBOMUse())) - { - Timestamp today = new Timestamp(System.currentTimeMillis()); - ArrayList[][] issue = new ArrayList[m_lines.length][1]; - - for (int i = 0; i < getLines().length ; i++) - { - MPPOrderBOMLine line = m_lines[i]; - - KeyNamePair id = null; - - if(MPPOrderBOMLine.ISSUEMETHOD_Backflush.equals(line.getIssueMethod())) - { - id = new KeyNamePair(line.get_ID(),"Y"); - } - else - id = new KeyNamePair(line.get_ID(),"N"); - - ArrayList data = new ArrayList(); - - data.add(id); //0 - ASI - data.add(line.isCritical()); //1 - Critical - MProduct product = (MProduct) line.getM_Product(); - data.add(product.getValue()); //2 - Value - KeyNamePair productKey = new KeyNamePair(product.get_ID(),product.getName()); - data.add(productKey); //3 - KeyNamePair Product - data.add(line.getQtyRequiered()); //4 - QtyToDeliver - data.add(Env.ZERO); //5 - QtyScrapComponent - issue[i][0] = data; - - } - - boolean isCompleteQtyDeliver = MPPOrder.isAvailableQty(this, issue ,today); - if (!isCompleteQtyDeliver) - { - throw new AdempiereException("@NoQtyAvailable@"); - } - - for(int i = 0; i < issue.length; i++ ) - { - KeyNamePair key = (KeyNamePair) issue[i][0].get(0); - Boolean isCritical = (Boolean) issue[i][0].get(1); - String value = (String)issue[i][0].get(2); - KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3); - int M_Product_ID = productkey.getKey(); - BigDecimal qtyToDeliver = (BigDecimal)issue[i][0].get(4); - BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5); - - MStorage[] storages = MPPOrder.getStorages(getCtx(), - M_Product_ID, - getM_Warehouse_ID(), - 0, - getM_AttributeSetInstance_ID(), - 1, today); - - MPPOrder.createIssue( - this, - key.getKey(), - today, qtyToDeliver, - qtyScrapComponent, - Env.ZERO, - storages, - get_TrxName()); - } - MPPOrder.createReceipt( - this, - today , - getQtyDelivered(), - getQtyOpen(), - getQtyScrap(), - getQtyReject(), - getM_Locator_ID(), - getM_AttributeSetInstance_ID(), false, get_TrxName()); - setQtyDelivered(getQtyOpen()); - return DOCSTATUS_Closed; - } - - setProcessed(true); - setDocAction(DOCACTION_Close); - - String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE); - if (valid != null) - { - m_processMsg = valid; - return DocAction.STATUS_Invalid; - } - return DocAction.STATUS_Completed; - } // completeIt - - /** - * Check if the Quantity from all BOM Lines is available (QtyOnHand >= QtyRequired) - * @return true if entire Qty is available for this Order - */ - public boolean isAvailable() - { - String whereClause = "QtyOnHand >= QtyRequiered AND PP_Order_ID=?"; - boolean available = new Query(getCtx(), "RV_PP_Order_Storage", whereClause, get_TrxName()) - .setParameters(new Object[]{get_ID()}) - .match(); - return available; - } - - public boolean voidIt() - { - log.info(toString()); - // Before Void - m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_VOID); - if (m_processMsg != null) - return false; - - // TODO: not implemented - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_VOID); - if (m_processMsg != null) - return false; - - setProcessed(true); - setDocAction(DOCACTION_None); - return false; - } // voidIt - - public boolean closeIt() - { - log.info(toString()); - // Before Close - m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_CLOSE); - if (m_processMsg != null) - return false; - - if(MPPOrder.DOCSTATUS_Closed.equals(getDocStatus())) - return true; - - if(!MPPOrder.DOCSTATUS_Completed.equals(getDocStatus())) - { - String DocStatus = completeIt(); - setDocStatus(DocStatus); - setDocAction(MPPOrder.ACTION_None); - } - - BigDecimal qtyReported = getQtyDelivered().add(getQtyReject().add(getQtyScrap())); - if(qtyReported.signum() > 0) - { - //Close all the activity do not reported - MPPOrderWorkflow m_order_wf = getMPPOrderWorkflow(); - m_order_wf.closeActivities(m_order_wf.getLastNode(getAD_Client_ID()), getUpdated(),false); - } - - orderStock(); // Clear Ordered Quantities - reserveStock(getLines()); // Clear Reservations - - m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_CLOSE); - if (m_processMsg != null) - return false; - - setProcessed(true); - setDocAction(DOCACTION_None); - return true; - } // closeIt - - public boolean reverseCorrectIt() - { - log.info("reverseCorrectIt - " + toString()); - return voidIt(); - } // reverseCorrectionIt - - public boolean reverseAccrualIt() - { - log.info("reverseAccrualIt - " + toString()); - return false; - } // reverseAccrualIt - - public boolean reActivateIt() - { - // After reActivate - m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_REACTIVATE); - if (m_processMsg != null) - return false; - - setDocAction(DOCACTION_Complete); - setProcessed(false); - return true; - } // reActivateIt - - public int getDoc_User_ID() - { - return getPlanner_ID(); - } // getDoc_User_ID - - public BigDecimal getApprovalAmt() - { - return Env.ZERO; - } // getApprovalAmt - - public int getC_Currency_ID() - { - return 0; - } - - public String getProcessMsg() - { - return m_processMsg; - } - - public String getSummary() - { - return "" + getDocumentNo() + "/" + getDatePromised(); - } - - public File createPDF() - { - try { - File temp = File.createTempFile(get_TableName() + get_ID() + "_", ".pdf"); - return createPDF(temp); - } - catch (Exception e) { - log.severe("Could not create PDF - " + e.getMessage()); - } - return null; - } // getPDF - - /** - * Create PDF file - * @param file output file - * @return file if success - */ - public File createPDF(File file) - { - ReportEngine re = ReportEngine.get(getCtx(), ReportEngine.MANUFACTURING_ORDER, getPP_Order_ID()); - if (re == null) - return null; - return re.getPDF(file); - } // createPDF - - /** - * Get Document Info - * @return document info (untranslated) - */ - public String getDocumentInfo() - { - MDocType dt = MDocType.get(getCtx(), getC_DocType_ID()); - return dt.getName() + " " + getDocumentNo(); - } // getDocumentInfo - - private void deletePO(String tableName, String whereClause, Object[] params) - { - // TODO: refactor this method and move it to org.compiere.model.Query class - POResultSet rs = new Query(getCtx(), tableName, whereClause, get_TrxName()) - .setParameters(params) - .scroll(); - try - { - while(rs.hasNext()) - { - rs.next().deleteEx(true); - } - } - finally - { - rs.close(); - } - } - - /** - * Set Qty Entered/Ordered. - * Use this Method if the Line UOM is the Product UOM - * @param Qty QtyOrdered/Entered - */ - public void setQty (BigDecimal Qty) - { - super.setQtyEntered (Qty); - super.setQtyOrdered (getQtyEntered()); - } // setQty - - /** - * Set Qty Entered - enforce entered UOM - * @param QtyEntered - */ - public void setQtyEntered (BigDecimal QtyEntered) - { - if (QtyEntered != null && getC_UOM_ID() != 0) - { - int precision = MUOM.getPrecision(getCtx(), getC_UOM_ID()); - QtyEntered = QtyEntered.setScale(precision, BigDecimal.ROUND_HALF_UP); - } - super.setQtyEntered (QtyEntered); - } // setQtyEntered - - /** - * Set Qty Ordered - enforce Product UOM - * @param QtyOrdered - */ - public void setQtyOrdered (BigDecimal QtyOrdered) - { - if (QtyOrdered != null) - { - int precision = getM_Product().getUOMPrecision(); - QtyOrdered = QtyOrdered.setScale(precision, BigDecimal.ROUND_HALF_UP); - } - super.setQtyOrdered(QtyOrdered); - } // setQtyOrdered - -// @Override - public MProduct getM_Product() - { - return MProduct.get (getCtx(), getM_Product_ID()); - } // getProduct - - public MPPOrderBOM getMPPOrderBOM() - { - final String whereClause = MPPOrderBOM.COLUMNNAME_PP_Order_ID+"=?"; - return new Query(getCtx(), MPPOrderBOM.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{getPP_Order_ID()}) - .firstOnly(); - } - - private MPPOrderWorkflow m_PP_Order_Workflow = null; - public MPPOrderWorkflow getMPPOrderWorkflow() - { - if (m_PP_Order_Workflow != null) - { - return m_PP_Order_Workflow; - } - final String whereClause = MPPOrderWorkflow.COLUMNNAME_PP_Order_ID+"=?"; - m_PP_Order_Workflow = new Query(getCtx(), MPPOrderWorkflow.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{getPP_Order_ID()}) - .firstOnly(); - return m_PP_Order_Workflow; - } - - /** - * Create PP_Order_BOM from PP_Product_BOM. - * Create PP_Order_Workflow from AD_Workflow. - */ - private void explotion() - { - // Create BOM Head - MPPProductBOM PP_Product_BOM = MPPProductBOM.get(getCtx(), getPP_Product_BOM_ID()); - if (PP_Product_BOM.isValidFromTo(getDateStartSchedule())) - { - MPPOrderBOM PP_Order_BOM = new MPPOrderBOM(PP_Product_BOM, getPP_Order_ID(), get_TrxName()); - PP_Order_BOM.setAD_Org_ID(getAD_Org_ID()); - PP_Order_BOM.saveEx(); - - for (MPPProductBOMLine PP_Product_BOMline : PP_Product_BOM.getLines()) - { - if (PP_Product_BOMline.isValidFromTo(getDateStartSchedule())) - { - MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, - getPP_Order_ID(), PP_Order_BOM.get_ID(), - getM_Warehouse_ID(), - get_TrxName()); - PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID()); - PP_Order_BOMLine.setQtyOrdered(getQtyOrdered()); - PP_Order_BOMLine.saveEx(); - } // end if valid From / To - } // end Create Order BOM - - } // end if From / To parent - - // Create Workflow (Routing & Process - MWorkflow AD_Workflow = MWorkflow.get(getCtx(), getAD_Workflow_ID()); - if (AD_Workflow.isValidFromTo(getDateStartSchedule())) - { - MPPOrderWorkflow PP_Order_Workflow = new MPPOrderWorkflow(AD_Workflow, get_ID(), get_TrxName()); - PP_Order_Workflow.setAD_Org_ID(getAD_Org_ID()); - PP_Order_Workflow.saveEx(); - for (MWFNode AD_WF_Node : AD_Workflow.getNodes(false, getAD_Client_ID())) - { - if (AD_WF_Node.isValidFromTo(getDateStartSchedule())) - { - MPPOrderNode PP_Order_Node = new MPPOrderNode(AD_WF_Node, PP_Order_Workflow, - getQtyOrdered(), - get_TrxName()); - PP_Order_Node.setAD_Org_ID(getAD_Org_ID()); - PP_Order_Node.saveEx(); - - for (MWFNodeNext AD_WF_NodeNext : AD_WF_Node.getTransitions(getAD_Client_ID())) - { - MPPOrderNodeNext nodenext = new MPPOrderNodeNext(AD_WF_NodeNext, PP_Order_Node); - nodenext.setAD_Org_ID(getAD_Org_ID()); - nodenext.saveEx(); - }// for NodeNext - - for (MPPWFNodeProduct wfnp : MPPWFNodeProduct.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) - { - MPPOrderNodeProduct nodeorderproduct = new MPPOrderNodeProduct(wfnp, PP_Order_Node); - nodeorderproduct.setAD_Org_ID(getAD_Org_ID()); - nodeorderproduct.saveEx(); - } - - for (MPPWFNodeAsset wfna : MPPWFNodeAsset.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) - { - MPPOrderNodeAsset nodeorderasset = new MPPOrderNodeAsset(wfna, PP_Order_Node); - nodeorderasset.setAD_Org_ID(getAD_Org_ID()); - nodeorderasset.saveEx(); - } - }// for node - - } - // Update transitions nexts and set first node - PP_Order_Workflow.loadNodes(); - for (MPPOrderNode orderNode : PP_Order_Workflow.getNodes(false, getAD_Client_ID())) - { - // set workflow start node - if (PP_Order_Workflow.getAD_WF_Node_ID() == orderNode.getAD_WF_Node_ID()) - { - PP_Order_Workflow.setPP_Order_Node_ID(orderNode.getPP_Order_Node_ID()); - } - // set node next - for (MPPOrderNodeNext next : orderNode.getTransitions(getAD_Client_ID())) - { - next.setPP_Order_Next_ID(); - next.saveEx(); - } - } - PP_Order_Workflow.saveEx(); - - BigDecimal QtyBatchs = null; - BigDecimal QtyBatchSize = PP_Order_Workflow.getQtyBatchSize().setScale(0, RoundingMode.UP); - - if (QtyBatchSize.signum()==0) - QtyBatchs = Env.ONE; - else - QtyBatchs = getQtyOrdered().divide(QtyBatchSize , 0, BigDecimal.ROUND_UP); - - setQtyBatchs(QtyBatchs); - setQtyBatchSize(QtyBatchSize); - - } // workflow valid from/to - } - - /** - * Create Receipt Finish Good - * @param order - * @param movementDate - * @param qtyDelivered - * @param qtyToDeliver - * @param qtyScrap - * @param qtyReject - * @param M_Locator_ID - * @param M_AttributeSetInstance_ID - * @param IsCloseDocument - * @param trxName - */ - static public void createReceipt(MPPOrder order, - Timestamp movementDate, - BigDecimal qtyDelivered, - BigDecimal qtyToDeliver, - BigDecimal qtyScrap, - BigDecimal qtyReject, - int M_Locator_ID, - int M_AttributeSetInstance_ID, - boolean IsCloseDocument, - String trxName) - { - - if (qtyToDeliver.signum() != 0 || qtyScrap.signum() != 0 || qtyReject.signum() != 0) - { - MPPCostCollector.createCollector( - order, //MPPOrder - order.getM_Product_ID(), //M_Product_ID - M_Locator_ID, //M_Locator_ID - M_AttributeSetInstance_ID, //M_AttributeSetInstance_ID - order.getS_Resource_ID(), //S_Resource_ID - 0, //PP_Order_BOMLine_ID - 0, //PP_Order_Node_ID - MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder), //C_DocType_ID - MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt, //Production "+" - movementDate, //MovementDate - qtyToDeliver, qtyScrap, qtyReject, //qty,scrap,reject - 0,0, //durationSetup,duration - trxName); - } - - if (IsCloseDocument) - { - order.setDateFinish(movementDate); - order.closeIt(); - order.saveEx(); - } - - order.setDateDelivered(movementDate); - if (order.getDateStart() == null) - { - order.setDateStart(movementDate); - } - - BigDecimal DQ = qtyDelivered; - BigDecimal SQ = qtyScrap; - BigDecimal OQ = qtyToDeliver; - if (DQ.add(SQ).compareTo(OQ) >= 0) - { - order.setDateFinish(movementDate); - } - - order.saveEx(trxName); - - } - - /** - * Create Issue - * @param PP_OrderBOMLine_ID - * @param movementdate - * @param qty - * @param qtyScrap - * @param qtyReject - * @param storages - */ - public static void createIssue(MPPOrder order, int PP_OrderBOMLine_ID, - Timestamp movementdate, - BigDecimal qty, BigDecimal qtyScrap, BigDecimal qtyReject, - MStorage[] storages, - String trxName) - { - if (qty.signum() == 0) - return; - - BigDecimal toIssue = qty.add(qtyScrap); - for (MStorage storage : storages) - { - // TODO Selection of ASI - - if (storage.getQtyOnHand().signum() == 0) - continue; - - BigDecimal qtyIssue = toIssue.min(storage.getQtyOnHand()); - //log.fine("ToIssue: " + issue); - MPPOrderBOMLine PP_orderbomLine = new MPPOrderBOMLine(order.getCtx(), PP_OrderBOMLine_ID, trxName); - //create record for negative and positive transaction - if (qtyIssue.signum() != 0 || qtyScrap.signum() != 0 || qtyReject.signum() != 0) - { - String CostCollectorType = MPPCostCollector.COSTCOLLECTORTYPE_ComponentIssue; - // Method Variance - if (PP_orderbomLine.getQtyBatch().signum() == 0 - && PP_orderbomLine.getQtyBOM().signum() == 0) - { - CostCollectorType = MPPCostCollector.COSTCOLLECTORTYPE_MethodChangeVariance; - } - // - MPPCostCollector.createCollector ( - order, //MPPOrder - PP_orderbomLine.getM_Product_ID(), //M_Product_ID - storage.getM_Locator_ID(), //M_Locator_ID - storage.getM_AttributeSetInstance_ID(), //M_AttributeSetInstance_ID - order.getS_Resource_ID(), //S_Resource_ID - PP_OrderBOMLine_ID, //PP_Order_BOMLine_ID - 0, //PP_Order_Node_ID - MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder), //C_DocType_ID, - CostCollectorType, //Production "-" - movementdate, //MovementDate - qtyIssue, qtyScrap, qtyReject, //qty,scrap,reject - 0,0, //durationSetup,duration - trxName //trxName - ); - - } - - toIssue = toIssue.subtract(qtyIssue); - if (toIssue.signum() == 0) - break; - } - // - if (toIssue.signum() != 0) - { - // should not happen because we validate Qty On Hand on start of this process - throw new AdempiereException("Should not happen toIssue="+toIssue); - } - } - - public static boolean isAvailableQty(MPPOrder order, I_PP_Order_BOMLine line) - { - MProduct product = MProduct.get(order.getCtx(), line.getM_Product_ID()); - if (product == null || !product.isStocked()) - { - return true; - } - - BigDecimal qtyToDeliver = line.getQtyRequiered(); - BigDecimal qtyScrap = line.getQtyScrap(); - BigDecimal qtyRequired = qtyToDeliver.add(qtyScrap); - BigDecimal qtyAvailable = MStorage.getQtyAvailable(order.getM_Warehouse_ID(), 0, - line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), - order.get_TrxName()); - return qtyAvailable.compareTo(qtyRequired) >= 0; - } - - /** - * get if Component is Available - * @param MPPOrdrt Manufacturing order - * @param ArrayList Issues - * @param minGuaranteeDate Guarantee Date - * @return true when the qty available is enough - */ - public static boolean isAvailableQty(MPPOrder order ,ArrayList[][] issue,Timestamp minGuaranteeDate) - { - boolean isCompleteQtyDeliver = false; - int ANY_ASI = 1; - - for(int i = 0; i < issue.length; i++ ) - { - KeyNamePair key = (KeyNamePair) issue[i][0].get(0); - boolean isSelected = key.getName().equals("Y"); - if (key == null || !isSelected) - { - continue; - } - - String value = (String)issue[i][0].get(2); - KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3); - int M_Product_ID = productkey.getKey(); - BigDecimal qtyToDeliver = (BigDecimal)issue[i][0].get(4); - BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5); - - MProduct product = MProduct.get(order.getCtx(), M_Product_ID); - if (product != null && product.isStocked()) - { - int M_AttributeSetInstance_ID = ANY_ASI; - if (value == null && isSelected) - { - M_AttributeSetInstance_ID = (Integer)key.getKey(); - } - - MStorage[] storages = MPPOrder.getStorages(order.getCtx(), - M_Product_ID, - order.getM_Warehouse_ID(), - M_AttributeSetInstance_ID, - order.getM_AttributeSetInstance_ID(), - ANY_ASI, - minGuaranteeDate); - - if (M_AttributeSetInstance_ID == ANY_ASI) - { - BigDecimal toIssue = qtyToDeliver.add(qtyScrapComponent); - for (MStorage storage : storages) - { - // TODO Selection of ASI - if (storage.getQtyOnHand().signum() == 0) - continue; - BigDecimal issueActual = toIssue.min(storage.getQtyOnHand()); - toIssue = toIssue.subtract(issueActual); - if (toIssue.signum() <= 0) - break; - } - } - else - { - BigDecimal qtydelivered = qtyToDeliver; - qtydelivered.setScale(4, BigDecimal.ROUND_HALF_UP); - qtydelivered = Env.ZERO; - } - - BigDecimal onHand = Env.ZERO; - for (MStorage storage : storages) - { - onHand = onHand.add(storage.getQtyOnHand()); - } - - isCompleteQtyDeliver = onHand.compareTo(qtyToDeliver.add(qtyScrapComponent)) >= 0; - if (!isCompleteQtyDeliver) - break; - - } - } // for each line - - return isCompleteQtyDeliver; - } - - public static MStorage[] getStorages( - Properties ctx, - int M_Product_ID, - int M_Warehouse_ID, - int M_ASI_ID, - int O_ASI_ID, - int ANY_ASI, - Timestamp minGuaranteeDate) - { - MProduct product = MProduct.get(ctx, M_Product_ID); - if (product != null && product.isStocked()) - { - String MMPolicy = product.getMMPolicy(); - return MStorage.getWarehouse(ctx, - M_Warehouse_ID, - M_Product_ID, - M_ASI_ID == ANY_ASI ? O_ASI_ID : M_ASI_ID, - product.getM_AttributeSet_ID(), - true, // all attribute set instances - minGuaranteeDate, - MClient.MMPOLICY_FiFo.equals(MMPolicy), - null // no trx - ); - } - else - { - return new MStorage[0]; - } - } - - /** - * @return Default Locator for current Warehouse - */ - public int getM_Locator_ID() - { - MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID()); - return wh.getDefaultLocator().getM_Locator_ID(); - } - - /** - * @param qty - * @return Storage locator for current product/asi/warehouse and qty - * @see MStorage#getM_Locator_ID(int, int, int, BigDecimal, String) - */ - private int getM_Locator_ID(BigDecimal qty) - { - int M_Locator_ID = 0; - int M_ASI_ID = getM_AttributeSetInstance_ID(); - // Get existing Locator - if (M_ASI_ID != 0) - { - M_Locator_ID = MStorage.getM_Locator_ID(getM_Warehouse_ID(), getM_Product_ID(), M_ASI_ID, qty, get_TrxName()); - } - // Get Default - if (M_Locator_ID == 0) - { - M_Locator_ID = getM_Locator_ID(); - } - return M_Locator_ID; - } - - public String toString() - { - StringBuffer sb = new StringBuffer("MPPOrder[").append(get_ID()) - .append("-").append(getDocumentNo()) - .append(",IsSOTrx=").append(isSOTrx()) - .append(",C_DocType_ID=").append(getC_DocType_ID()) - .append("]"); - return sb.toString(); - } // toString -} // MPPOrder diff --git a/base/src/org/eevolution/model/MPPOrderBOM.java b/base/src/org/eevolution/model/MPPOrderBOM.java deleted file mode 100644 index 4367c72b91..0000000000 --- a/base/src/org/eevolution/model/MPPOrderBOM.java +++ /dev/null @@ -1,101 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -//package org.compiere.mfg.model; -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -/** - * Order BOM Model. - * - * @author Victor Perez www.e-evolution.com - * @version $Id: MOrder.java,v 1.40 2004/04/13 04:19:30 vpj-cd Exp $ - * - * @author Teo Sarca, www.arhipac.ro - */ -public class MPPOrderBOM extends X_PP_Order_BOM -{ - private static final long serialVersionUID = 1L; - - /** - * Default Constructor - * @param ctx context - * @param C_Order_ID order to load, (0 create new order) - */ - public MPPOrderBOM(Properties ctx, int PP_Order_BOM_ID,String trxName) - { - super (ctx, PP_Order_BOM_ID,trxName); - // New - if ( PP_Order_BOM_ID == 0) - { - setProcessing(false); - } - } // MOrder - - /** - * Load Constructor - * @param ctx context - * @param rs result set record - */ - public MPPOrderBOM(Properties ctx, ResultSet rs,String trxName) - { - super (ctx, rs, trxName); - } // MOrder - - /** - * Peer constructor - * @param bom - * @param PP_Order_ID - * @param trxName - */ - public MPPOrderBOM(MPPProductBOM bom, int PP_Order_ID, String trxName) - { - this(bom.getCtx(), 0, trxName); - // - setBOMType(bom.getBOMType()); - setBOMUse(bom.getBOMUse()); - setM_ChangeNotice_ID(bom.getM_ChangeNotice_ID()); - setHelp(bom.getHelp()); - //setCopyFrom(bom.getCopyFrom()); - setProcessing(bom.isProcessing()); - setHelp(bom.getHelp()); - setDescription(bom.getDescription()); - setM_AttributeSetInstance_ID(bom.getM_AttributeSetInstance_ID()); - setM_Product_ID(bom.getM_Product_ID()); - setName(bom.getName()); - setRevision(bom.getRevision()); - setValidFrom(bom.getValidFrom()); - setValidTo(bom.getValidTo()); - setValue(bom.getValue()); - setDocumentNo(bom.getDocumentNo()); - setC_UOM_ID(bom.getC_UOM_ID()); - // - setPP_Order_ID(PP_Order_ID); - } - - /** - * String Representation - * @return info - */ - public String toString () - { - StringBuffer sb = new StringBuffer ("MPPOrderBOM[") - .append(get_ID()).append("-").append(getDocumentNo()) - .append ("]"); - return sb.toString (); - } // toString -} // MPPOrderBOM diff --git a/base/src/org/eevolution/model/MPPOrderBOMLine.java b/base/src/org/eevolution/model/MPPOrderBOMLine.java deleted file mode 100644 index 4af3019fd8..0000000000 --- a/base/src/org/eevolution/model/MPPOrderBOMLine.java +++ /dev/null @@ -1,344 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Properties; - -import org.adempiere.exceptions.AdempiereException; -import org.adempiere.exceptions.DBException; -import org.compiere.model.MProduct; -import org.compiere.model.MUOM; -import org.compiere.model.MWarehouse; -import org.compiere.model.Query; -import org.compiere.util.DB; -import org.compiere.util.Env; - -/** - * PP Order BOM Line Model. - * - * @author Victor Perez www.e-evolution.com - * @author Teo Sarca, www.arhipac.ro - */ -public class MPPOrderBOMLine extends X_PP_Order_BOMLine -{ - private static final long serialVersionUID = 1L; - - public static MPPOrderBOMLine forM_Product_ID(Properties ctx, int PP_Order_ID, int M_Product_ID, String trxName) - { - final String whereClause = COLUMNNAME_PP_Order_ID+"=? AND "+COLUMNNAME_M_Product_ID+"=?"; - return new Query(ctx, Table_Name, whereClause, trxName) - .setParameters(new Object[]{PP_Order_ID, M_Product_ID}) - .firstOnly(); - } - - public MPPOrderBOMLine(Properties ctx, int PP_Order_BOMLine_ID, String trxName) - { - super (ctx, PP_Order_BOMLine_ID, trxName); - if (PP_Order_BOMLine_ID == 0) - { - setQtyDelivered(Env.ZERO); - setQtyPost(Env.ZERO); - setQtyReject(Env.ZERO); - setQtyRequiered(Env.ZERO); - setQtyReserved(Env.ZERO); - setQtyScrap(Env.ZERO); - } - } // PP_Order_BOMLine_ID - - - public MPPOrderBOMLine(Properties ctx, ResultSet rs,String trxName) - { - super (ctx, rs,trxName); - } // MOrderLine - - /** - * Peer constructor - * @param bomLine - * @param PP_Order_ID - * @param PP_Order_BOM_ID - * @param M_Warehouse_ID - * @param trxName - */ - public MPPOrderBOMLine(MPPProductBOMLine bomLine, - int PP_Order_ID, int PP_Order_BOM_ID, int M_Warehouse_ID, - String trxName) - { - this(bomLine.getCtx(), 0, trxName); - - setPP_Order_BOM_ID(PP_Order_BOM_ID); - setPP_Order_ID(PP_Order_ID); - setM_Warehouse_ID(M_Warehouse_ID); - // - setM_ChangeNotice_ID(bomLine.getM_ChangeNotice_ID()); - setDescription(bomLine.getDescription()); - setHelp(bomLine.getHelp()); - setAssay(bomLine.getAssay()); - setQtyBatch(bomLine.getQtyBatch()); - setQtyBOM(bomLine.getQtyBOM()); - setIsQtyPercentage(bomLine.isQtyPercentage()); - setComponentType(bomLine.getComponentType()); - setC_UOM_ID(bomLine.getC_UOM_ID()); - setForecast(bomLine.getForecast()); - setIsCritical(bomLine.isCritical()); - setIssueMethod(bomLine.getIssueMethod()); - setLeadTimeOffset(bomLine.getLeadTimeOffset()); - setM_AttributeSetInstance_ID(bomLine.getM_AttributeSetInstance_ID()); - setM_Product_ID(bomLine.getM_Product_ID()); - setScrap(bomLine.getScrap()); - setValidFrom(bomLine.getValidFrom()); - setValidTo(bomLine.getValidTo()); - setBackflushGroup(bomLine.getBackflushGroup()); - } - - /** - * Parent (PP_Order) - */ - private MPPOrder m_parent = null; - - /** - * Qty used for exploding this BOM Line. - * When ComponentType is Phantom, it is set on beforeSave as QtyRequired and reset on afterSave. - */ - private BigDecimal m_qtyToExplode = null; - - - @Override - protected boolean beforeSave(boolean newRecord) - { - // Get Line No - if (getLine() == 0) - { - String sql = "SELECT COALESCE(MAX("+COLUMNNAME_Line+"),0)+10 FROM "+Table_Name - +" WHERE "+COLUMNNAME_PP_Order_ID+"=?"; - int ii = DB.getSQLValueEx (get_TrxName(), sql, getPP_Order_ID()); - setLine (ii); - } - - // If Phantom, we need to explode this line (see afterSave): - if(newRecord && COMPONENTTYPE_Phantom.equals(getComponentType())) - { - m_qtyToExplode = getQtyRequiered(); - setQtyRequiered(Env.ZERO); - } - - - return true; - } - - @Override - protected boolean afterSave(boolean newRecord, boolean success) - { - if (!success) - return false; - log.fine(" Parent Product" + getM_Product_ID() + " getQtyBatch" + getQtyBatch() + " getQtyRequiered" + getQtyRequiered() + " QtyScrap" + getQtyScrap()); - // - // Explode Phantom Items - if(m_qtyToExplode != null) - { - MProduct parent = MProduct.get(getCtx(), getM_Product_ID()); - int PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(parent); - if (PP_Product_BOM_ID <= 0) - { - return true; - } - MPPProductBOM bom = MPPProductBOM.get(getCtx(), PP_Product_BOM_ID); - if (bom != null) - { - for(MPPProductBOMLine PP_Product_BOMline : bom.getLines()) - { - MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, - getPP_Order_ID(), getPP_Order_BOM_ID(), - getM_Warehouse_ID(), - get_TrxName()); - PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID()); - PP_Order_BOMLine.setQtyOrdered(m_qtyToExplode); - PP_Order_BOMLine.saveEx(); - } - } - m_qtyToExplode = null; - } - return true; - - } - - @Override - public MProduct getM_Product() - { - return MProduct.get(getCtx(), getM_Product_ID()); - } - - @Override - public MUOM getC_UOM() - { - return MUOM.get(getCtx(), getC_UOM_ID()); - } - - @Override - public MWarehouse getM_Warehouse() - { - return MWarehouse.get(getCtx(), getM_Warehouse_ID()); - } - - /** - * Get Parent - * @return PP_Order - */ - public MPPOrder getParent() - { - int id = getPP_Order_ID(); - if (id <= 0) - { - m_parent = null; - return null; - } - if (m_parent == null || m_parent.get_ID() != id) - { - m_parent = new MPPOrder(getCtx(), id, get_TrxName()); - } - return m_parent; - } // getParent - - public void setQtyOrdered(BigDecimal QtyOrdered) - { - BigDecimal multiplier = Env.ZERO; - if (isQtyPercentage()) - { - multiplier = getQtyBatch().divide(Env.ONEHUNDRED, 8, RoundingMode.UP); - } - else - { - multiplier = getQtyBOM(); - } - BigDecimal qty = QtyOrdered.multiply(multiplier).setScale(8, RoundingMode.UP); - - if (isComponentType(COMPONENTTYPE_Component,COMPONENTTYPE_Phantom - ,COMPONENTTYPE_Packing - ,COMPONENTTYPE_ByProduct)) - { - setQtyRequiered(qty); - } - else if (isComponentType(COMPONENTTYPE_Tools)) - { - setQtyRequiered(multiplier); - } - else - { - throw new AdempiereException("@NotSupported@ @ComponentType@ "+getComponentType()); - } - // - // Set Scrap of Component - BigDecimal Scrap = getScrap(); - if (Scrap.signum() != 0) - { - Scrap = Scrap.divide(Env.ONEHUNDRED, 8, BigDecimal.ROUND_UP); - setQtyRequiered(getQtyRequiered().divide(Env.ONE.subtract(Scrap), 8, BigDecimal.ROUND_HALF_UP)); - } - } - - /** - * @return Qty Open (Requiered - Delivered) - */ - public BigDecimal getQtyOpen() - { - return getQtyRequiered().subtract(getQtyDelivered()); - } - - /** Storage Qty On Hand */ - private BigDecimal m_qtyOnHand = null; - /** Storage Qty Available */ - private BigDecimal m_qtyAvailable = null; - - /** - * Load Storage Info - * @param reload - */ - private void loadStorage(boolean reload) - { - if (!reload && m_qtyOnHand != null && m_qtyAvailable != null) - { - return; - } - // - final String sql = "SELECT " - +" bomQtyAvailable("+COLUMNNAME_M_Product_ID+", "+COLUMNNAME_M_Warehouse_ID+", 0)" - +",bomQtyOnHand("+COLUMNNAME_M_Product_ID+", "+COLUMNNAME_M_Warehouse_ID+", 0)" - +" FROM "+Table_Name - +" WHERE "+COLUMNNAME_PP_Order_BOMLine_ID+"=?"; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql, get_TrxName()); - DB.setParameters(pstmt, new Object[]{get_ID()}); - rs = pstmt.executeQuery(); - if (rs.next()) - { - m_qtyAvailable = rs.getBigDecimal(1); - m_qtyOnHand = rs.getBigDecimal(2); - } - } - catch (SQLException e) - { - throw new DBException(e, sql); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - } - - /** - * @return storage Available Qty - */ - public BigDecimal getQtyAvailable() - { - loadStorage(false); - return m_qtyAvailable; - } - - /** - * @return storage Qty On Hand - */ - public BigDecimal getQtyOnHand() - { - loadStorage(false); - return m_qtyOnHand; - } - - /** - * @param componentTypes one or more component types - * @return true of Component Type is any of following types - */ - public boolean isComponentType(String ... componentTypes) - { - String currentType = getComponentType(); - for (String type : componentTypes) - { - if (currentType.equals(type)) - { - return true; - } - } - return false; - } -} diff --git a/base/src/org/eevolution/model/MPPOrderBOMLineMA.java b/base/src/org/eevolution/model/MPPOrderBOMLineMA.java deleted file mode 100644 index 3fd2f809e3..0000000000 --- a/base/src/org/eevolution/model/MPPOrderBOMLineMA.java +++ /dev/null @@ -1,127 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, http://www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.util.List; -import java.util.Properties; - -import org.compiere.model.Query; -import org.compiere.util.CLogger; -import org.compiere.util.DB; - -/** - * Cost Collector Material Allocation - * - * @author Victor Perez www.e-evolution.com - * @author Teo Sarca, http://www.arhipac.ro - */ -public class MPPOrderBOMLineMA extends X_PP_Order_BOMLineMA -{ - private static final long serialVersionUID = 1L; - - /** - * Get Material Allocations for Line - * @param ctx context - * @param PP_Order_BOMLine_ID line - * @param trxName trx - * @return allocations - */ - public static MPPOrderBOMLineMA[] get (Properties ctx, int PP_Order_BOMLine_ID, String trxName) - { - final String whereClause = COLUMNNAME_PP_Order_BOMLine_ID+"=?"; - List list = new Query(ctx, Table_Name, whereClause, trxName) - .setParameters(new Object[]{PP_Order_BOMLine_ID}) - .setOrderBy(COLUMNNAME_PP_Order_BOMLineMA_ID) - .list(); - return list.toArray(new MPPOrderBOMLineMA[list.size()]); - } - - /** - * Delete all Material Allocation for PP order component - * @param PP_Order_BOMLine_ID PP order component line - * @return number of rows deleted - */ - public static int deleteOrderBOMLineMA (int PP_Order_BOMLine_ID, String trxName) - { - final String sql = "DELETE FROM "+Table_Name+" WHERE "+COLUMNNAME_PP_Order_BOMLine_ID+"=?"; - int no = DB.executeUpdateEx(sql, new Object[]{PP_Order_BOMLine_ID}, trxName); - - s_log.config("Delete old #" + no); - return no; - } - - /** Logger */ - private static CLogger s_log = CLogger.getCLogger (MPPOrderBOMLineMA.class); - - /** - * Standard Constructor - * @param ctx context - * @param M_InOutLineMA_ID ignored - * @param trxName trx - */ - public MPPOrderBOMLineMA (Properties ctx, int PP_Order_BOMLineMA_ID, String trxName) - { - super (ctx, PP_Order_BOMLineMA_ID, trxName); - if (PP_Order_BOMLineMA_ID != 0) - throw new IllegalArgumentException("Multi-Key"); - } // MInOutLineMA - - /** - * Load Cosntructor - * @param ctx context - * @param rs result set - * @param trxName trx - */ - public MPPOrderBOMLineMA (Properties ctx, ResultSet rs, String trxName) - { - super (ctx, rs, trxName); - } // MInOutLineMA - - /** - * Parent Constructor - * @param parent parent - * @param M_AttributeSetInstance_ID asi - * @param MovementQty qty - */ - public MPPOrderBOMLineMA (MPPOrderBOMLine parent, int M_AttributeSetInstance_ID, BigDecimal MovementQty) - { - this (parent.getCtx(), 0, parent.get_TrxName()); - setClientOrg(parent); - setPP_Order_BOMLine_ID(parent.getPP_Order_BOMLine_ID()); - // - setM_AttributeSetInstance_ID(M_AttributeSetInstance_ID); - setMovementQty(MovementQty); - } // MInOutLineMA - - - /** - * String Representation - * @return info - */ - public String toString () - { - StringBuffer sb = new StringBuffer ("MPPOrderBOMLineMA["); - sb.append("PP_Order_BOMLine_ID=").append(getPP_Order_BOMLine_ID()) - .append(",M_AttributeSetInstance_ID=").append(getM_AttributeSetInstance_ID()) - .append(", Qty=").append(getMovementQty()) - .append ("]"); - return sb.toString (); - } // toString - -} // PP_Order_BOMLineMA diff --git a/base/src/org/eevolution/model/MPPOrderCost.java b/base/src/org/eevolution/model/MPPOrderCost.java deleted file mode 100644 index 23fb1b2046..0000000000 --- a/base/src/org/eevolution/model/MPPOrderCost.java +++ /dev/null @@ -1,76 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ - -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -import org.compiere.model.MCost; - -/** - * PP Order Cost Model. - * - * @author Victor Perez www.e-evolution.com - * @version $Id: MOrder.java,v 1.40 2004/04/13 04:19:30 vpj-cd Exp $ - * - * @author Teo Sarca, www.arhipac.ro - */ -public class MPPOrderCost extends X_PP_Order_Cost -{ - private static final long serialVersionUID = 1L; - - /** - * Default Constructor - * @param ctx context - * @param C_Order_ID order to load, (0 create new order) - */ - public MPPOrderCost(Properties ctx, int PP_Order_Cost_ID,String trxName) - { - super (ctx, PP_Order_Cost_ID, trxName); - } // MOrder - - /** - * Peer constructor - * @param cost - * @param PP_Order_ID - */ - public MPPOrderCost(MCost cost, int PP_Order_ID, String trxName) - { - this(cost.getCtx(), 0, trxName); - - setPP_Order_ID(PP_Order_ID); - setC_AcctSchema_ID(cost.getC_AcctSchema_ID()); - setCumulatedAmt(cost.getCumulatedAmt()); - setCumulatedQty(cost.getCumulatedQty()); - setCurrentCostPriceLL(cost.getCurrentCostPriceLL()); - setCurrentCostPrice(cost.getCurrentCostPrice()); - setM_Product_ID(cost.getM_Product_ID()); - setM_AttributeSetInstance_ID(cost.getM_AttributeSetInstance_ID()); - setM_CostElement_ID(cost.getM_CostElement_ID()); - } - - /** - * Load Constructor - * @param ctx context - * @param rs result set record - */ - public MPPOrderCost(Properties ctx, ResultSet rs, String trxName) - { - super (ctx, rs, trxName); - } // MOrder -} diff --git a/base/src/org/eevolution/model/MPPOrderNode.java b/base/src/org/eevolution/model/MPPOrderNode.java deleted file mode 100644 index 5559d59e47..0000000000 --- a/base/src/org/eevolution/model/MPPOrderNode.java +++ /dev/null @@ -1,367 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.eevolution.model; - -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.adempiere.exceptions.AdempiereException; -import org.compiere.model.MResource; -import org.compiere.model.MUOM; -import org.compiere.model.Query; -import org.compiere.util.CCache; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.wf.MWFNode; - -/** - * PP Order Workflow Node Model - * - * @author Victor Perez, e-Evolution, S.C. - * @author Teo Sarca, http://www.arhipac.ro - */ -public class MPPOrderNode extends X_PP_Order_Node -{ - private static final long serialVersionUID = 1L; - - - /** - * Get WF Node from Cache - * @param ctx context - * @param PP_Order_Node_ID id - * @return MPPOrderNode - */ - public static MPPOrderNode get (Properties ctx, int PP_Order_Node_ID) - { - MPPOrderNode retValue = s_cache.get (PP_Order_Node_ID); - if (retValue != null) - return retValue; - retValue = new MPPOrderNode (ctx, PP_Order_Node_ID, null); - if (retValue.get_ID () != 0) - s_cache.put (PP_Order_Node_ID, retValue); - return retValue; - } // get - - - /** - * @return true if this is last node - */ - public static boolean isLastNode(Properties ctx, int PP_Order_Node_ID, String trxName) - { - String whereClause = MPPOrderNodeNext.COLUMNNAME_PP_Order_Node_ID+"=?"; - return false == new Query(ctx, MPPOrderNodeNext.Table_Name, whereClause, trxName) - .setOnlyActiveRecords(true) - .setParameters(new Object[]{PP_Order_Node_ID}) - .match(); - } - - /** Cache */ - private static CCache s_cache = new CCache (Table_Name, 50); - /** MPPOrderWorkflow */ - MPPOrderWorkflow m_order_wf = null; - - /************************************************************************** - * Standard Constructor - save to cache - * @param ctx context - * @param PP_Order_Node_ID id - * @param trxName transaction - */ - public MPPOrderNode (Properties ctx, int PP_Order_Node_ID, String trxName) - { - super (ctx, PP_Order_Node_ID, trxName); - if (PP_Order_Node_ID == 0) - { - // setPP_Order_Node_ID (0); - // setPP_Order_Workflow_ID (0); - // setValue (null); - // setName (null); - setAction (ACTION_WaitSleep); - setCost (Env.ZERO); - setDuration (0); - setEntityType (ENTITYTYPE_UserMaintained); // U - setIsCentrallyMaintained (true); // Y - setJoinElement (JOINELEMENT_XOR); // X - setLimit (0); - setSplitElement (SPLITELEMENT_XOR); // X - setWaitingTime (0); - setXPosition (0); - setYPosition (0); - setDocStatus(MPPOrderNode.DOCSTATUS_Drafted); - } - // Save to Cache - if (get_ID() != 0) - s_cache.put (getPP_Order_Node_ID(), this); - } // MPPOrderNode - - /** - * Parent Constructor - * @param wf workflow (parent) - * @param Value value - * @param Name name - */ - public MPPOrderNode (MPPOrderWorkflow wf, String Value, String Name) - { - this (wf.getCtx(), 0, wf.get_TrxName()); - setClientOrg(wf); - setPP_Order_Workflow_ID (wf.getPP_Order_Workflow_ID()); - setValue (Value); - setName (Name); - m_durationBaseMS = wf.getDurationBaseSec() * 1000; - } // MPPOrderNode - - /** - * Peer constructor - * @param wfNode - * @param PP_Order_Workflow - * @param qtyOrdered - * @param trxName - */ - public MPPOrderNode (MWFNode wfNode, MPPOrderWorkflow PP_Order_Workflow, - BigDecimal qtyOrdered, - String trxName) - { - this(wfNode.getCtx(), 0, trxName); - setPP_Order_ID(PP_Order_Workflow.getPP_Order_ID()); - setPP_Order_Workflow_ID(PP_Order_Workflow.getPP_Order_Workflow_ID()); - // - setAction(wfNode.getAction()); - setAD_WF_Node_ID(wfNode.getAD_WF_Node_ID()); - setAD_WF_Responsible_ID(wfNode.getAD_WF_Responsible_ID()); - setAD_Workflow_ID(wfNode.getAD_Workflow_ID()); - setIsSubcontracting(wfNode.isSubcontracting()); - setC_BPartner_ID(wfNode.getC_BPartner_ID()); - setCost(wfNode.getCost()); - setDuration(wfNode.getDuration()); - setEntityType(wfNode.getEntityType()); - setIsCentrallyMaintained(wfNode.isCentrallyMaintained()); - setJoinElement(wfNode.getJoinElement()); // X - setLimit(wfNode.getLimit()); - setName(wfNode.getName()); - setPriority(wfNode.getPriority()); - setSplitElement(wfNode.getSplitElement()); // X - setSubflowExecution(wfNode.getSubflowExecution()); - setValue(wfNode.getValue()); - setS_Resource_ID(wfNode.getS_Resource_ID()); - setSetupTime(wfNode.getSetupTime()); - setSetupTimeRequiered(wfNode.getSetupTime()); - setMovingTime(wfNode.getMovingTime()); - setWaitingTime(wfNode.getWaitingTime()); - setWorkingTime(wfNode.getWorkingTime()); - setQueuingTime(wfNode.getQueuingTime()); - setXPosition(wfNode.getXPosition()); - setYPosition(wfNode.getYPosition()); - setDocAction(wfNode.getDocAction()); - setAD_Column_ID(wfNode.getAD_Column_ID()); - setAD_Form_ID(wfNode.getAD_Form_ID()); - setAD_Image_ID(wfNode.getAD_Image_ID()); - setAD_Window_ID(wfNode.getAD_Window_ID()); - setAD_Process_ID(wfNode.getAD_Process_ID()); - setAttributeName(wfNode.getAttributeName()); - setAttributeValue(wfNode.getAttributeValue()); - setC_BPartner_ID(wfNode.getC_BPartner_ID()); - setStartMode(wfNode.getStartMode()); - setFinishMode(wfNode.getFinishMode()); - setValidFrom(wfNode.getValidFrom()); - setValidTo(wfNode.getValidTo()); - // - setQtyOrdered(qtyOrdered); - setDocStatus(MPPOrderNode.DOCSTATUS_Drafted); - } - - /** - * Load Constructor - save to cache - * @param ctx context - * @param rs result set to load info from - * @param trxName transaction - */ - public MPPOrderNode (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - loadNext(); - // Save to Cache - s_cache.put (getPP_Order_Node_ID(), this); - } // MPPOrderNode - - - /** Next Modes */ - private List m_next = new ArrayList(); - /** Duration Base MS */ - private long m_durationBaseMS = -1; - /** Workflow Order */ - private MPPOrder m_workflow = null; - - /** - * Load Next - */ - private void loadNext() - { - boolean splitAnd = SPLITELEMENT_AND.equals(getSplitElement()); - String whereClause = MPPOrderNodeNext.COLUMNNAME_PP_Order_Node_ID+"=?"; - m_next = new Query(getCtx(), MPPOrderNodeNext.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{get_ID()}) - .setOnlyActiveRecords(true) - .setOrderBy(MPPOrderNodeNext.COLUMNNAME_SeqNo) - .list(); - for (MPPOrderNodeNext next : m_next) - { - next.setFromSplitAnd(splitAnd); - } - log.fine("#" + m_next.size()); - } // loadNext - - /** - * Set Qty Required and DurationRequired (Duration * qtyOrdered) - * @param qtyOrdered - */ - public void setQtyOrdered(BigDecimal qtyOrdered) - { - setQtyRequiered(qtyOrdered); - BigDecimal time = BigDecimal.valueOf(getDuration()).multiply(qtyOrdered); - setDurationRequiered(time.intValue()); - } - - /** - * Get Number of Next Nodes - * @return number of next nodes - */ - public int getNextNodeCount() - { - return m_next.size(); - } // getNextNodeCount - - /** - * Get the transitions - * @param AD_Client_ID for client - * @return array of next nodes - */ - public MPPOrderNodeNext[] getTransitions(int AD_Client_ID) - { - ArrayList list = new ArrayList(); - for (MPPOrderNodeNext next : m_next) - { - if (next.getAD_Client_ID() == 0 || next.getAD_Client_ID() == AD_Client_ID) - { - list.add(next); - } - } - return list.toArray(new MPPOrderNodeNext [list.size()]); - } // getNextNodes - - /** - * Get Duration in ms - * @return duration in ms - */ - public long getDurationMS () - { - long duration = super.getDuration (); - if (duration == 0) - return 0; - if (m_durationBaseMS == -1) - m_durationBaseMS = getMPPOrderWorkflow().getDurationBaseSec() * 1000; - return duration * m_durationBaseMS; - } // getDurationMS - - /** - * Get Duration Limit in ms - * @return duration limit in ms - */ - public long getLimitMS () - { - long limit = super.getLimit (); - if (limit == 0) - return 0; - if (m_durationBaseMS == -1) - m_durationBaseMS = getMPPOrderWorkflow().getDurationBaseSec() * 1000; - return limit * m_durationBaseMS; - } // getLimitMS - - /** - * Get Duration CalendarField - * @return Calendar.MINUTE, etc. - */ - public int getDurationCalendarField() - { - return getMPPOrderWorkflow().getDurationCalendarField(); - } // getDurationCalendarField - - /** - * String Representation - * @return info - */ - public String toString () - { - StringBuffer sb = new StringBuffer ("MPPOrderNode["); - sb.append(get_ID()) - .append("-").append(getName()) - .append ("]"); - return sb.toString (); - } // toString - - /** - * Calculate the cost for this Activity using the Cost Element Type - * @param CostElementType Cost Element Type (Labor or Burden) - * @param C_AcctSchema_ID AcctSchema - * @param M_CostType_ID Cost Type - * @param AD_Org_ID Organization - * @param setuptime Setup Time - * @param duration Duration - * @return cost for this Cost Element Type (Labor or Burden) - * @throws Exception when the UOM do not is Hours - */ - public BigDecimal getCostForCostElementType(String CostElementType, int C_AcctSchema_ID,int M_CostType_ID,int AD_Org_ID,int setuptime, int duration) - { - MResource resource = (MResource) getS_Resource(); - //get the rate for this cost type element (Rsource, Burden) - MPPOrderWorkflow workflow = getMPPOrderWorkflow(); - double rate = resource.getResouceRate(C_AcctSchema_ID, M_CostType_ID,CostElementType, AD_Org_ID); - BigDecimal cost = Env.ZERO; - if (rate == 0) - { - return Env.ZERO; - } - - int C_UOM_ID = DB.getSQLValueEx(get_TrxName(),"SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? " , getS_Resource_ID()); - MUOM uom = MUOM.get(getCtx(), C_UOM_ID); - if (uom.isHour()) - { - double hours = (setuptime / workflow.getQtyBatchSize().doubleValue() + duration) - * workflow.getDurationBaseSec() / 3600; - double nodeCost = rate * hours; - cost = cost.add(new BigDecimal(nodeCost)); - log.info("Activity: " + getName() + " Resouce: " + resource.getName() +" CostElementType: " + CostElementType + " Time Base: "+workflow.getDurationUnit() +" Duration (H): " + hours + " Rate: " + rate + " Activity Cost: " + nodeCost +" =>Cost: "+cost); - } - else - { - throw new AdempiereException("@NotSupported@ @C_UOM_ID@="+uom.getName()); - } - return cost; - } - - /** - * Get Parent - * @return MPPOrderWorkflow - */ - public MPPOrderWorkflow getMPPOrderWorkflow() - { - if (m_order_wf == null) - m_order_wf = new MPPOrderWorkflow(getCtx(), getPP_Order_Workflow_ID(), get_TrxName()); - return m_order_wf; - } // getParent -} diff --git a/base/src/org/eevolution/model/MPPOrderNodeAsset.java b/base/src/org/eevolution/model/MPPOrderNodeAsset.java deleted file mode 100644 index 22052d5bab..0000000000 --- a/base/src/org/eevolution/model/MPPOrderNodeAsset.java +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -/** - * Order Node Asset Model - * - * @author Victor Perez www.e-evolution.com - * @author Teo Sarca, www.arhipac.ro - */ -public class MPPOrderNodeAsset extends X_PP_Order_Node_Asset -{ - private static final long serialVersionUID = 1L; - - public MPPOrderNodeAsset (Properties ctx, int PP_Order_Node_Asset_ID, String trxName) - { - super (ctx, PP_Order_Node_Asset_ID, trxName); - if (PP_Order_Node_Asset_ID == 0) - { - } - } - - public MPPOrderNodeAsset (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - /** - * Create a new MPPOrderNodeAsset based in MPPWFNodeProduct - * @param na - * @param PP_Order_Node - */ - public MPPOrderNodeAsset (MPPWFNodeAsset na, MPPOrderNode PP_Order_Node) - { - this(PP_Order_Node.getCtx(), 0, PP_Order_Node.get_TrxName()); - setClientOrg(PP_Order_Node); - //setSeqNo(na.getSeqNo()); - setA_Asset_ID(na.getA_Asset_ID()); - // - setPP_Order_ID(PP_Order_Node.getPP_Order_ID()); - setPP_Order_Workflow_ID(PP_Order_Node.getPP_Order_Workflow_ID()); - setPP_Order_Node_ID(PP_Order_Node.get_ID()); - } -} diff --git a/base/src/org/eevolution/model/MPPOrderNodeNext.java b/base/src/org/eevolution/model/MPPOrderNodeNext.java deleted file mode 100644 index 6dca8e5bf3..0000000000 --- a/base/src/org/eevolution/model/MPPOrderNodeNext.java +++ /dev/null @@ -1,170 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -import org.compiere.util.DB; -import org.compiere.wf.MWFNodeNext; - -/** - * PP Order Workflow Node Next - Transition - * - * @author Victor Perez www.e-evolution.com - * @author Teo Sarca, http://www.arhipac.ro - */ -public class MPPOrderNodeNext extends X_PP_Order_NodeNext -{ - private static final long serialVersionUID = 1L; - - /** - * Standard Costructor - * @param ctx context - * @param PP_OrderNodeNext_ID id - * @param trxName transaction - */ - public MPPOrderNodeNext (Properties ctx, int PP_OrderNodeNext_ID, String trxName) - { - super (ctx, PP_OrderNodeNext_ID, trxName); - if (PP_OrderNodeNext_ID == 0) - { - // setPP_OrderNext_ID (0); - // setPP_OrderNode_ID (0); - setEntityType (ENTITYTYPE_UserMaintained); // U - setIsStdUserWorkflow (false); - setSeqNo (10); // 10 - } - } // MPPOrderNodeNext - - /** - * Default Constructor - * @param ctx context - * @param rs result set to load info from - * @param trxName transaction - */ - public MPPOrderNodeNext (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } // MPPOrderNodeNext - - /** - * Parent constructor - * @param parent patent - * @param PP_OrderNext_ID Next - */ - public MPPOrderNodeNext (MPPOrderNode parent, int PP_Order_Next_ID) - { - this(parent.getCtx(), 0, parent.get_TrxName()); - setClientOrg(parent); - setPP_Order_ID(parent.getPP_Order_ID()); - setPP_Order_Node_ID(parent.get_ID()); - setPP_Order_Next_ID(PP_Order_Next_ID); - } // MPPOrderNodeNext - - /** - * Peer constructor - * @param wfNodeNext - * @param parent - * @param trxName - */ - public MPPOrderNodeNext (MWFNodeNext wfNodeNext, MPPOrderNode parent) - { - this(parent, 0); - // - setAD_WF_Node_ID(wfNodeNext.getAD_WF_Node_ID()); - setAD_WF_Next_ID(wfNodeNext.getAD_WF_Next_ID()); - setDescription(wfNodeNext.getDescription()); - setEntityType(wfNodeNext.getEntityType()); - setIsStdUserWorkflow(wfNodeNext.isStdUserWorkflow()); - setSeqNo(wfNodeNext.getSeqNo()); - setTransitionCode(wfNodeNext.getTransitionCode()); - } - - /** From (Split Eleemnt) is AND */ - public Boolean m_fromSplitAnd = null; - /** To (Join Element) is AND */ - public Boolean m_toJoinAnd = null; - - @Override - public String toString() - { - StringBuffer sb = new StringBuffer ("MPPOrderNodeNext["); - sb.append(getSeqNo()) - .append(":Node=").append(getPP_Order_Node_ID()).append("->Next=").append(getPP_Order_Next_ID()); - //if (m_conditions != null) - // sb.append(",#").append(m_conditions.length); - if (getDescription() != null && getDescription().length() > 0) - sb.append(",").append(getDescription()); - sb.append ("]"); - return sb.toString (); - } // toString - - /** - * Split Element is AND - * @return Returns the from Split And. - */ - public boolean isFromSplitAnd() - { - if (m_fromSplitAnd != null) - return m_fromSplitAnd.booleanValue(); - return false; - } // getFromSplitAnd - - /** - * Split Element is AND. - * Set by MPPOrderNode.loadNodes - * @param fromSplitAnd The from Split And - */ - public void setFromSplitAnd (boolean fromSplitAnd) - { - m_fromSplitAnd = new Boolean(fromSplitAnd); - } // setFromSplitAnd - - /** - * Join Element is AND - * @return Returns the to Join And. - */ - public boolean isToJoinAnd () - { - if (m_toJoinAnd == null && getPP_Order_Next_ID() != 0) - { - MPPOrderNode next = MPPOrderNode.get(getCtx(), getPP_Order_Next_ID()); - setToJoinAnd(MPPOrderNode.JOINELEMENT_AND.equals(next.getJoinElement())); - } - if (m_toJoinAnd != null) - return m_toJoinAnd.booleanValue(); - return false; - } // getToJoinAnd - - /** - * Join Element is AND. - * @param toJoinAnd The to Join And to set. - */ - private void setToJoinAnd (boolean toJoinAnd) - { - m_toJoinAnd = new Boolean(toJoinAnd); - } // setToJoinAnd - - public void setPP_Order_Next_ID() - { - final String sql = "SELECT PP_Order_Node_ID FROM PP_Order_Node " - + " WHERE PP_Order_ID=? AND AD_WF_Node_ID=? AND AD_Client_ID=?"; - int id = DB.getSQLValueEx(get_TrxName(), sql, getPP_Order_ID(), getAD_WF_Next_ID(), getAD_Client_ID()); - setPP_Order_Next_ID(id > 0 ? id : 0); - } -} // MPPOrderNodeNext diff --git a/base/src/org/eevolution/model/MPPOrderNodeProduct.java b/base/src/org/eevolution/model/MPPOrderNodeProduct.java deleted file mode 100644 index df91d68de5..0000000000 --- a/base/src/org/eevolution/model/MPPOrderNodeProduct.java +++ /dev/null @@ -1,81 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Properties; - -import org.adempiere.exceptions.AdempiereException; -import org.compiere.util.DB; -import org.compiere.util.Env; - -/** - * Order Node Product Model - * - * @author Victor Perez www.e-evolution.com - * @author Teo Sarca, www.arhipac.ro - */ -public class MPPOrderNodeProduct extends X_PP_Order_Node_Product -{ - private static final long serialVersionUID = 1L; - - public MPPOrderNodeProduct (Properties ctx, int PP_WF_Order_Product_ID, String trxName) - { - super (ctx, PP_WF_Order_Product_ID, trxName); - if (PP_WF_Order_Product_ID == 0) - { - } - } - - public MPPOrderNodeProduct (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - /** - * Create a new MPPOrderNodeProduct based in MPPWFNodeProduct - * @param np - * @param PP_Order_Node order node - */ - public MPPOrderNodeProduct (MPPWFNodeProduct np, MPPOrderNode PP_Order_Node) - { - this(PP_Order_Node.getCtx(), 0, PP_Order_Node.get_TrxName()); - setClientOrg(PP_Order_Node); - setSeqNo(np.getSeqNo()); - setIsActive(np.isActive()); - setM_Product_ID(np.getM_Product_ID()); - setQty(np.getQty()); - setIsSubcontracting(np.isSubcontracting()); - setYield(np.getYield()); - // - setPP_Order_ID(PP_Order_Node.getPP_Order_ID()); - setPP_Order_Workflow_ID(PP_Order_Node.getPP_Order_Workflow_ID()); - setPP_Order_Node_ID(PP_Order_Node.get_ID()); - } - - @Override - protected boolean beforeSave(boolean newRecord) - { - if(getQty().equals(Env.ZERO) && isSubcontracting()) - { - setQty(Env.ONE); - } - - // - return true; - } -} diff --git a/base/src/org/eevolution/model/MPPOrderWorkflow.java b/base/src/org/eevolution/model/MPPOrderWorkflow.java deleted file mode 100644 index 04dc81363c..0000000000 --- a/base/src/org/eevolution/model/MPPOrderWorkflow.java +++ /dev/null @@ -1,593 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.model.MClient; -import org.compiere.model.MDocType; -import org.compiere.model.MOrder; -import org.compiere.model.Query; -import org.compiere.util.CCache; -import org.compiere.util.Env; -import org.compiere.wf.MWorkflow; - -/** - * PP Order WorkFlow Model - * - * @author Jorg Janke - * @version $Id: MPPOrderWorkflow.java,v 1.4 2006/07/30 00:51:05 jjanke Exp $ - * - * @author Teo Sarca, http://www.arhipac.ro - */ -public class MPPOrderWorkflow extends X_PP_Order_Workflow -{ - private static final long serialVersionUID = 1L; - - /** - * Get Workflow from Cache - * @param ctx context - * @param AD_Workflow_ID id - * @return workflow - */ - public static MPPOrderWorkflow get (Properties ctx, int PP_Order_Workflow_ID) - { - Integer key = new Integer (PP_Order_Workflow_ID); - MPPOrderWorkflow retValue = (MPPOrderWorkflow)s_cache.get(key); - if (retValue != null) - return retValue; - retValue = new MPPOrderWorkflow (ctx, PP_Order_Workflow_ID, null); - if (retValue.get_ID() != 0) - s_cache.put(key, retValue); - return retValue; - } // get - - /** Single Cache */ - private static CCache s_cache = new CCache(Table_Name, 20); - - /************************************************************************** - * Create/Load Workflow - * @param ctx Context - * @param PP_Order_Workflow_ID ID - * @param trxName transaction - */ - public MPPOrderWorkflow (Properties ctx, int PP_Order_Workflow_ID, String trxName) - { - super (ctx, PP_Order_Workflow_ID, trxName); - if (PP_Order_Workflow_ID == 0) - { - // setPP_Order_Workflow_ID (0); - // setValue (null); - // setName (null); - setAccessLevel (ACCESSLEVEL_Organization); - setAuthor (MClient.get(ctx).getName()); - setDurationUnit(DURATIONUNIT_Day); - setDuration (1); - setEntityType (ENTITYTYPE_UserMaintained); // U - setIsDefault (false); - setPublishStatus (PUBLISHSTATUS_UnderRevision); // U - setVersion (0); - setCost (Env.ZERO); - setWaitingTime (0); - setWorkingTime (0); - } - loadNodes(); - } // MPPOrderWorkflow - - /** - * Load Constructor - * @param ctx context - * @param rs result set - * @param trxName transaction - */ - public MPPOrderWorkflow (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - loadNodes(); - } // Workflow - - /** - * Peer constructor - * @param workflow - * @param PP_Order_ID - * @param trxName - */ - public MPPOrderWorkflow (MWorkflow workflow, int PP_Order_ID, String trxName) - { - this(workflow.getCtx(), 0, trxName); - setPP_Order_ID(PP_Order_ID); - // - setValue(workflow.getValue()); - setWorkflowType(workflow.getWorkflowType()); - setQtyBatchSize(workflow.getQtyBatchSize()); - setName(workflow.getName()); - setAccessLevel(workflow.getAccessLevel()); - setAuthor(workflow.getAuthor()); - setDurationUnit(workflow.getDurationUnit()); - setDuration(workflow.getDuration()); - setEntityType(workflow.getEntityType()); - setIsDefault(workflow.isDefault()); - setPublishStatus(workflow.getPublishStatus()); - setVersion(workflow.getVersion()); - setCost(workflow.getCost()); - setWaitingTime(workflow.getWaitingTime()); - setWorkingTime(workflow.getWorkingTime()); - setAD_WF_Responsible_ID(workflow.getAD_WF_Responsible_ID()); - setAD_Workflow_ID(workflow.getAD_Workflow_ID()); - setLimit(workflow.getLimit()); - setPriority(workflow.getPriority()); - setValidateWorkflow(workflow.getValidateWorkflow()); - setS_Resource_ID(workflow.getS_Resource_ID()); - setQueuingTime(workflow.getQueuingTime()); - setSetupTime(workflow.getSetupTime()); - setMovingTime(workflow.getMovingTime()); - setProcessType(workflow.getProcessType()); - setAD_Table_ID(workflow.getAD_Table_ID()); - setAD_WF_Node_ID(workflow.getAD_WF_Node_ID()); - setAD_WorkflowProcessor_ID(workflow.getAD_WorkflowProcessor_ID()); - setDescription(workflow.getDescription()); - setValidFrom(workflow.getValidFrom()); - setValidTo(workflow.getValidTo()); - } - - /** WF Nodes */ - private List m_nodes = null; - /** Manufacturing Order */ - private MPPOrder m_order = null; - - /** - * Load All Nodes - */ - protected void loadNodes() - { - final String whereClause = MPPOrderNode.COLUMNNAME_PP_Order_Workflow_ID+"=?"; - m_nodes = new Query(getCtx(), MPPOrderNode.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{get_ID()}) - .setOnlyActiveRecords(true) - .list(); - log.fine("#" + m_nodes.size()); - } // loadNodes - - /** - * Get Number of Nodes - * @return number of nodes - */ - public int getNodeCount() - { - return m_nodes.size(); - } // getNextNodeCount - - /** - * Get the nodes - * @param ordered ordered array - * @param AD_Client_ID for client - * @return array of nodes - */ - public MPPOrderNode[] getNodes(boolean ordered, int AD_Client_ID) - { - if (ordered) - { - return getNodesInOrder(AD_Client_ID); - } - // - ArrayList list = new ArrayList(); - for (MPPOrderNode node : m_nodes) - { - if (node.getAD_Client_ID() == 0 || node.getAD_Client_ID() == AD_Client_ID) - { - list.add(node); - } - } - return list.toArray(new MPPOrderNode [list.size()]); - } // getNodes - - /** - * Get the first node - * @return array of next nodes - */ - public MPPOrderNode getFirstNode() - { - return getNode (getPP_Order_Node_ID()); - } // getFirstNode - - /** - * Get Node with given ID - * @param PP_Order_Node_ID ID - * @return node or null - */ - public MPPOrderNode getNode (int PP_Order_Node_ID) - { - for (MPPOrderNode node : m_nodes) - { - if (node.getPP_Order_Node_ID() == PP_Order_Node_ID) - { - return node; - } - } - return null; - } // getNode - - /** - * Get the next nodes - * @param PP_Order_Node_ID ID - * @param AD_Client_ID for client - * @return array of next nodes or null - */ - public MPPOrderNode[] getNextNodes (int PP_Order_Node_ID, int AD_Client_ID) - { - MPPOrderNode node = getNode(PP_Order_Node_ID); - if (node == null || node.getNextNodeCount() == 0) - { - return null; - } - // - ArrayList list = new ArrayList(); - for (MPPOrderNodeNext nextTr : node.getTransitions(AD_Client_ID)) - { - MPPOrderNode next = getNode (nextTr.getPP_Order_Next_ID()); - if (next != null) - { - list.add(next); - } - } - - // Return Nodes - return list.toArray(new MPPOrderNode [list.size()]); - } // getNextNodes - - /** - * Get The Nodes in Sequence Order - * @param AD_Client_ID client - * @return Nodes in sequence - */ - private MPPOrderNode[] getNodesInOrder(int AD_Client_ID) - { - ArrayList list = new ArrayList(); - addNodesSF (list, getPP_Order_Node_ID(), AD_Client_ID); // start with first - // Remaining Nodes - if (m_nodes.size() != list.size()) - { - // Add Stand alone - for (int n = 0; n < m_nodes.size(); n++) - { - MPPOrderNode node = (MPPOrderNode)m_nodes.get(n); - if (node.getAD_Client_ID() == 0 || node.getAD_Client_ID() == AD_Client_ID) - { - boolean found = false; - for (int i = 0; i < list.size(); i++) - { - MPPOrderNode existing = (MPPOrderNode)list.get(i); - if (existing.getPP_Order_Node_ID() == node.getPP_Order_Node_ID()) - { - found = true; - break; - } - } - if (!found) - { - log.log(Level.WARNING, "Added Node w/o transition: " + node); - list.add(node); - } - } - } - } - // - MPPOrderNode[] nodeArray = new MPPOrderNode [list.size()]; - list.toArray(nodeArray); - return nodeArray; - } // getNodesInOrder - - /** - * Add Nodes recursively (depth first) to Ordered List - * @param list list to add to - * @param PP_Order_Node_ID start node id - * @param AD_Client_ID for client - */ - private void addNodesDF (ArrayList list, int PP_Order_Node_ID, int AD_Client_ID) - { - MPPOrderNode node = getNode (PP_Order_Node_ID); - if (node != null && !list.contains(node)) - { - list.add(node); - // Get Dependent - MPPOrderNodeNext[] nexts = node.getTransitions(AD_Client_ID); - for (int i = 0; i < nexts.length; i++) - addNodesDF (list, nexts[i].getPP_Order_Next_ID(), AD_Client_ID); - } - } // addNodesDF - - /** - * Add Nodes recursively (sibling first) to Ordered List - * @param list list to add to - * @param PP_Order_Node_ID start node id - * @param AD_Client_ID for client - */ - private void addNodesSF (ArrayList list, int PP_Order_Node_ID, int AD_Client_ID) - { - MPPOrderNode node = getNode (PP_Order_Node_ID); - if (node != null - && (node.getAD_Client_ID() == 0 || node.getAD_Client_ID() == AD_Client_ID)) - { - if (!list.contains(node)) - list.add(node); - MPPOrderNodeNext[] nexts = node.getTransitions(AD_Client_ID); - for (int i = 0; i < nexts.length; i++) - { - MPPOrderNode child = getNode (nexts[i].getPP_Order_Next_ID()); - if (child.getAD_Client_ID() == 0 - || child.getAD_Client_ID() == AD_Client_ID) - { - if (!list.contains(child)) - list.add(child); - } - } - // Remainder Nodes not conncetd - for (int i = 0; i < nexts.length; i++) - addNodesSF (list, nexts[i].getPP_Order_Next_ID(), AD_Client_ID); - } - } // addNodesSF - - /************************************************************************** - * Get first transition (Next Node) of ID - * @param PP_Order_Node_ID id - * @param AD_Client_ID for client - * @return next PP_Order_Node_ID or 0 - */ - public int getNext (int PP_Order_Node_ID, int AD_Client_ID) - { - MPPOrderNode[] nodes = getNodesInOrder(AD_Client_ID); - for (int i = 0; i < nodes.length; i++) - { - if (nodes[i].getPP_Order_Node_ID() == PP_Order_Node_ID) - { - MPPOrderNodeNext[] nexts = nodes[i].getTransitions(AD_Client_ID); - if (nexts.length > 0) - { - return nexts[0].getPP_Order_Next_ID(); - } - return 0; - } - } - return 0; - } // getNext - - /** - * Get Transitions (NodeNext) of ID - * @param PP_Order_Node_ID id - * @param AD_Client_ID for client - * @return array of next nodes - */ - public MPPOrderNodeNext[] getNodeNexts (int PP_Order_Node_ID, int AD_Client_ID) - { - MPPOrderNode[] nodes = getNodesInOrder(AD_Client_ID); - for (int i = 0; i < nodes.length; i++) - { - if (nodes[i].getPP_Order_Node_ID() == PP_Order_Node_ID) - { - return nodes[i].getTransitions(AD_Client_ID); - } - } - return null; - } // getNext - - /** - * Get (first) Previous Node of ID - * @param PP_Order_Node_ID id - * @param AD_Client_ID for client - * @return next PP_Order_Node_ID or 0 - */ - public int getPrevious (int PP_Order_Node_ID, int AD_Client_ID) - { - MPPOrderNode[] nodes = getNodesInOrder(AD_Client_ID); - for (int i = 0; i < nodes.length; i++) - { - if (nodes[i].getPP_Order_Node_ID() == PP_Order_Node_ID) - { - if (i > 0) - return nodes[i-1].getPP_Order_Node_ID(); - return 0; - } - } - return 0; - } // getPrevious - - /** - * Get very Last Node - * @param AD_Client_ID for client - * @return next PP_Order_Node_ID or 0 - */ - public int getNodeLastID (int AD_Client_ID) - { - MPPOrderNode[] nodes = getNodesInOrder(AD_Client_ID); - if (nodes.length > 0) - { - return nodes[nodes.length-1].getPP_Order_Node_ID(); - } - return 0; - } // getLast - - /** - * Get very Last Node - * @param AD_Client_ID for client - * @return next PP_Order_Node_ID or 0 - */ - public MPPOrderNode getLastNode (int AD_Client_ID) - { - MPPOrderNode[] nodes = getNodesInOrder(AD_Client_ID); - if (nodes.length > 0) - { - return nodes[nodes.length-1]; - } - return null; - } // getLast - - /** - * Is this the first Node - * @param PP_Order_Node_ID id - * @param AD_Client_ID for client - * @return true if first node - */ - public boolean isFirst (int PP_Order_Node_ID, int AD_Client_ID) - { - return PP_Order_Node_ID == getPP_Order_Node_ID(); - } // isFirst - - /** - * Is this the last Node - * @param PP_Order_Node_ID id - * @param AD_Client_ID for client - * @return true if last node - */ - public boolean isLast (int PP_Order_Node_ID, int AD_Client_ID) - { - MPPOrderNode[] nodes = getNodesInOrder(AD_Client_ID); - return PP_Order_Node_ID == nodes[nodes.length-1].getPP_Order_Node_ID(); - } // isLast - - /** - * String Representation - * @return info - */ - public String toString () - { - StringBuffer sb = new StringBuffer ("MPPOrderWorkflow["); - sb.append(get_ID()).append("-").append(getName()) - .append ("]"); - return sb.toString (); - } // toString - - @Override - protected boolean afterSave (boolean newRecord, boolean success) - { - log.fine("Success=" + success); - if (success && newRecord) - { - // save all nodes -- Creating new Workflow - MPPOrderNode[] nodes = getNodesInOrder(0); - for (int i = 0; i < nodes.length; i++) - nodes[i].saveEx(get_TrxName()); - } - - return success; - } // afterSave - - /** - * Get Duration Base in Seconds - * @return duration unit in seconds - */ - public long getDurationBaseSec () - { - if (getDurationUnit() == null) - return 0; - else if (DURATIONUNIT_Second.equals(getDurationUnit())) - return 1; - else if (DURATIONUNIT_Minute.equals(getDurationUnit())) - return 60; - else if (DURATIONUNIT_Hour.equals(getDurationUnit())) - return 3600; - else if (DURATIONUNIT_Day.equals(getDurationUnit())) - return 86400; - else if (DURATIONUNIT_Month.equals(getDurationUnit())) - return 2592000; - else if (DURATIONUNIT_Year.equals(getDurationUnit())) - return 31536000; - return 0; - } // getDurationBaseSec - - /** - * Get Duration CalendarField - * @return Calendar.MINUTE, etc. - */ - public int getDurationCalendarField() - { - if (getDurationUnit() == null) - return Calendar.MINUTE; - else if (DURATIONUNIT_Second.equals(getDurationUnit())) - return Calendar.SECOND; - else if (DURATIONUNIT_Minute.equals(getDurationUnit())) - return Calendar.MINUTE; - else if (DURATIONUNIT_Hour.equals(getDurationUnit())) - return Calendar.HOUR; - else if (DURATIONUNIT_Day.equals(getDurationUnit())) - return Calendar.DAY_OF_YEAR; - else if (DURATIONUNIT_Month.equals(getDurationUnit())) - return Calendar.MONTH; - else if (DURATIONUNIT_Year.equals(getDurationUnit())) - return Calendar.YEAR; - return Calendar.MINUTE; - } // getDurationCalendarField - - - /** - * Complete Activities - * @param activity - * @param movementdate - */ - public void closeActivities(MPPOrderNode activity, Timestamp movementdate, boolean milestone) - { - - MPPOrderWorkflow order_workflow = activity.getMPPOrderWorkflow(); - MPPOrder order = order_workflow.getMPPOrder(); - int nodeId = activity.get_ID(); - while(nodeId != 0) - { - MPPOrderNode node = MPPOrderNode.get(getCtx(), nodeId); - //break the cycle - if(node.isMilestone() && milestone) - return; - if(!MPPOrderNode.DOCSTATUS_Closed.equals(node.getDocStatus())) - { - - MPPCostCollector.createCollector ( - order, //MPPOrder - order.getM_Product_ID(), //M_Product_ID - order.getM_Locator_ID(), //M_Locator_ID - order.getM_AttributeSetInstance_ID(), //M_AttributeSetInstance_ID - order.getS_Resource_ID(), //S_Resource_ID - 0, //PP_Order_BOMLine_ID - node.get_ID(), //PP_Order_Node_ID - MDocType.getDocType(MDocType.DOCBASETYPE_ManufacturingOrder), //C_DocType_ID, - MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl, //Activity Control - movementdate, //MovementDate - order.getQtyOrdered(), Env.ZERO, Env.ZERO, //qty,scrap,reject - node.getSetupTimeReal(),node.getDurationReal(), //durationSetup,duration - get_TrxName() //trxName - ); - } - nodeId = order_workflow.getPrevious(node.get_ID(), order_workflow.getAD_Client_ID()); - } - } - - /** - * Get Parent - * @return MPPOrder - */ - public MPPOrder getMPPOrder() - { - if (m_order == null) - m_order = new MPPOrder(getCtx(), getPP_Order_ID(), get_TrxName()); - return m_order; - } // getParent - - -} // MPPOrderWorkflow_ID diff --git a/base/src/org/eevolution/model/MPPProductPlanning.java b/base/src/org/eevolution/model/MPPProductPlanning.java index bf7ef3df90..c65b9438b2 100644 --- a/base/src/org/eevolution/model/MPPProductPlanning.java +++ b/base/src/org/eevolution/model/MPPProductPlanning.java @@ -169,14 +169,6 @@ public class MPPProductPlanning extends X_PP_Product_Planning return plant_id; } - /** - * @return Qty On Hand - */ - public BigDecimal getQtyOnHand() - { - return MPPMRP.getQtyOnHand(getCtx(), getM_Warehouse_ID(), getM_Product_ID(), get_TrxName()); - } - @Override protected boolean beforeSave(boolean newRecord) { diff --git a/base/src/org/eevolution/model/MPPWFNodeAsset.java b/base/src/org/eevolution/model/MPPWFNodeAsset.java deleted file mode 100644 index 73ffc66975..0000000000 --- a/base/src/org/eevolution/model/MPPWFNodeAsset.java +++ /dev/null @@ -1,73 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Collection; -import java.util.Properties; - -import org.compiere.model.Query; -import org.compiere.util.CCache; - -/** - * Workflow Node Asset Model - * - * @author Victor Perez www.e-evolution.com - * @author Teo Sarca, www.arhipac.ro - */ -public class MPPWFNodeAsset extends X_PP_WF_Node_Asset -{ - private static final long serialVersionUID = 1L; - - /** Cache */ - private static CCache> - s_cache = new CCache>(Table_Name, 20); - - /** - * @return array of node assets - */ - public static Collection forAD_WF_Node_ID(Properties ctx, int AD_WF_Node_ID) - { - Collection lines = s_cache.get(AD_WF_Node_ID); - if (lines != null) - { - return lines; - } - - final String whereClause = COLUMNNAME_AD_WF_Node_ID+"=?"; - lines = new Query(ctx, Table_Name, whereClause, null) - .setParameters(new Object[]{AD_WF_Node_ID}) - .setOnlyActiveRecords(true) - .setOrderBy(COLUMNNAME_SeqNo) - .list(); - s_cache.put(AD_WF_Node_ID, lines); - return lines; - } - - public MPPWFNodeAsset (Properties ctx, int PP_WF_Node_Asset_ID, String trxName) - { - super (ctx, PP_WF_Node_Asset_ID, trxName); - if (PP_WF_Node_Asset_ID == 0) - { - } - } - - public MPPWFNodeAsset (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } -} diff --git a/base/src/org/eevolution/model/MPPWFNodeProduct.java b/base/src/org/eevolution/model/MPPWFNodeProduct.java deleted file mode 100644 index 5f8405f493..0000000000 --- a/base/src/org/eevolution/model/MPPWFNodeProduct.java +++ /dev/null @@ -1,95 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.model; - -import java.sql.ResultSet; -import java.util.Collection; -import java.util.Properties; - -import org.compiere.model.Query; -import org.compiere.util.CCache; -import org.compiere.util.DB; -import org.compiere.util.Env; - -/** - * Workflow Node Product Model - * - * @author Victor Perez www.e-evolution.com - * @author Teo Sarca, www.arhipac.ro - */ -public class MPPWFNodeProduct extends X_PP_WF_Node_Product -{ - private static final long serialVersionUID = 1L; - - /** Cache */ - private static CCache> - s_cache = new CCache>(Table_Name, 20); - - /** - * @return array of node products - */ - public static Collection forAD_WF_Node_ID(Properties ctx, int AD_WF_Node_ID) - { - Collection lines = s_cache.get(AD_WF_Node_ID); - if (lines != null) - { - return lines; - } - - final String whereClause = COLUMNNAME_AD_WF_Node_ID+"=?"; - lines = new Query(ctx, Table_Name, whereClause, null) - .setParameters(new Object[]{AD_WF_Node_ID}) - .setOnlyActiveRecords(true) - .setOrderBy(COLUMNNAME_SeqNo) - .list(); - s_cache.put(AD_WF_Node_ID, lines); - return lines; - } - - public MPPWFNodeProduct (Properties ctx, int PP_WF_Node_Product_ID, String trxName) - { - super (ctx, PP_WF_Node_Product_ID, trxName); - if (PP_WF_Node_Product_ID == 0) - { - } - } - - public MPPWFNodeProduct (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } - - @Override - protected boolean beforeSave(boolean newRecord) - { - if (getSeqNo() == 0) - { - final String sql = "SELECT COALESCE(MAX("+COLUMNNAME_SeqNo+"),0)+10 FROM "+Table_Name+" WHERE " - +" "+COLUMNNAME_AD_WF_Node_ID+"=?" - +" AND "+COLUMNNAME_PP_WF_Node_Product_ID+"<>?"; - int seqNo = DB.getSQLValueEx(get_TrxName(), sql, getAD_WF_Node_ID(), get_ID()); - setSeqNo(seqNo); - } - if(getQty().equals(Env.ZERO) && isSubcontracting()) - { - setQty(Env.ONE); - } - - // - return true; - } -} // MPPWFNodeProduct diff --git a/base/src/org/eevolution/model/MQMSpecification.java b/base/src/org/eevolution/model/MQMSpecification.java deleted file mode 100644 index e130d44be8..0000000000 --- a/base/src/org/eevolution/model/MQMSpecification.java +++ /dev/null @@ -1,144 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.model.MAttribute; -import org.compiere.model.MAttributeInstance; -import org.compiere.model.MAttributeSet; -import org.compiere.model.MAttributeSetInstance; -import org.compiere.util.DB; - -/** - * Forcast Line Model - * - * @author Victor Perez www.e-evolution.com - * @version $Id: MQMSpecification.java,v 1.11 2005/05/17 05:29:52 vpj-cd vpj-cd $ - */ -public class MQMSpecification extends X_QM_Specification -{ - /** - * Standard Constructor - * @param ctx context - * @param M_ForecastLine_ID id - */ - public MQMSpecification (Properties ctx, int QM_Specification_ID, String trxName) - { - super (ctx, QM_Specification_ID, trxName); - if (QM_Specification_ID == 0) - { - } - - } // MQMSpecification - - /** - * Load Constructor - * @param ctx context - * @param rs result set - */ - public MQMSpecification (Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } // MQMSpecification - - /** Lines */ - private MQMSpecificationLine[] m_lines = null; - - /** - * Get Lines - * @return array of lines - */ - public MQMSpecificationLine[] getLines(String where) - { - if (m_lines != null) - return m_lines; - - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM QM_SpecificationLine WHERE QM_SpecificationLine_ID=? AND "+ where +" ORDER BY Line"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql, get_TrxName()); - pstmt.setInt (1, getQM_Specification_ID()); - ResultSet rs = pstmt.executeQuery (); - while (rs.next ()) - list.add (new MQMSpecificationLine(getCtx(), rs, get_TrxName())); - rs.close (); - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE, "getLines", e); - } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } - m_lines = new MQMSpecificationLine[list.size ()]; - list.toArray (m_lines); - return m_lines; - } // getLines - - public boolean isValid(int M_AttributeSetInstance_ID) - { - //MAttributeSet mas = MAttributeSet.get(getCtx(), getM_AttributeSet_ID()); - -// Save Instance Attributes - - MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(),M_AttributeSetInstance_ID, get_TrxName()); - MAttributeSet as = MAttributeSet.get(getCtx(),asi.getM_AttributeSet_ID()); - MAttribute[] attributes = as.getMAttributes(false); - for (int i = 0; i < attributes.length; i++) - { - - //MAttribute attribute = new MAttribute(getCtx(),0,null); - MAttributeInstance instance = attributes[i].getMAttributeInstance (M_AttributeSetInstance_ID); - MQMSpecificationLine[] lines = getLines(" M_Attribute_ID="+attributes[i].getM_Attribute_ID()); - for (int s = 0; s < lines.length; i++) - { - MQMSpecificationLine line = lines[s]; - if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributes[i].getAttributeValueType())) - { - BigDecimal objValue = instance.getValueNumber(); - if(!line.evaluate(objValue,instance.getValue())); - return false; - } - else - { - String objValue = instance.getValue(); - if(!line.evaluate(objValue,instance.getValue())) - return false; - } - //if(line.evaluate(mas.getValueNumber()) - } - } // for all attributes - return true; - } - -} // MQMSpecification diff --git a/base/src/org/eevolution/model/MQMSpecificationLine.java b/base/src/org/eevolution/model/MQMSpecificationLine.java deleted file mode 100644 index f549f3f957..0000000000 --- a/base/src/org/eevolution/model/MQMSpecificationLine.java +++ /dev/null @@ -1,209 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.model; - -import java.math.BigDecimal; -import java.sql.ResultSet; -import java.util.Properties; - -/** - * Forcast Line Model - * - * @author Victor Perez www.e-evolution.com - * @version $Id: MQMSpecificationLine.java,v 1.11 2005/05/17 05:29:52 vpj-cd Exp $ - */ -public class MQMSpecificationLine extends X_QM_SpecificationLine -{ - /** - * Standard Constructor - * @param ctx context - * @param M_ForecastLine_ID id - */ - public MQMSpecificationLine (Properties ctx, int QM_SpecificationLine_ID, String trxName) - { - super (ctx, QM_SpecificationLine_ID, trxName); - if (QM_SpecificationLine_ID == 0) - { - } - - } // MQMSpecification - - - /** - * Load Constructor - * @param ctx context - * @param rs result set - */ - public MQMSpecificationLine(Properties ctx, ResultSet rs, String trxName) - { - super(ctx, rs, trxName); - } // MQMSpecification - - - /** - * Evaluate Condition - * @return true if true - */ - public boolean evaluate (Object valueObj,String value1) - { - /*if (getAD_Column_ID() == 0) - throw new IllegalStateException("No Column defined - " + this); - - PO po = activity.getPO(); - if (po == null || po.get_ID() == 0) - throw new IllegalStateException("Could not evaluate " + po + " - " + this); - // - Object valueObj = po.get_ValueOfColumn(getAD_Column_ID()); - if (valueObj == null) - valueObj = ""; - String value1 = getValue(); - if (value1 == null) - value1 = ""; - String value2 = getValue2(); - if (value2 == null) - value2 = ""; - - String resultStr = "PO:{" + valueObj + "} " + getOperation() + " Condition:{" + value1 + "}"; - if (getOperation().equals(OPERATION_Sql)) - throw new IllegalArgumentException("SQL Operator not implemented yet: " + resultStr); - if (getOperation().equals(OPERATION_X)) - resultStr += "{" + value2 + "}";*/ - - boolean result = false; - if (valueObj instanceof Number) - result = compareNumber ((Number)valueObj, value1, getValue()); - else - result = compareString(valueObj, value1, getValue()); - // - //log.fine(resultStr + " -> " + result - // + (m_numeric ? " (#)" : " ($)")); - return result; - } // evaluate - - /** - * Compare Number - * @param valueObj comparator - * @return true if operation - */ - private boolean compareNumber (Number valueObj, String value1, String value2) - { - BigDecimal valueObjB = null; - BigDecimal value1B = null; - BigDecimal value2B = null; - try - { - if (valueObj instanceof BigDecimal) - valueObjB = (BigDecimal)valueObj; - else if (valueObj instanceof Integer) - valueObjB = new BigDecimal (((Integer)valueObj).intValue()); - else - valueObjB = new BigDecimal (String.valueOf(valueObj)); - } - catch (Exception e) - { - log.fine("compareNumber - valueObj=" + valueObj + " - " + e.toString()); - return compareString(valueObj, value1, value2); - } - try - { - value1B = new BigDecimal (value1); - } - catch (Exception e) - { - log.fine("compareNumber - value1=" + value1 + " - " + e.toString()); - return compareString(valueObj, value1, value2); - } - - String op = getOperation(); - if (OPERATION_Eq.equals(op)) - return valueObjB.compareTo(value1B) == 0; - else if (OPERATION_Gt.equals(op)) - return valueObjB.compareTo(value1B) > 0; - else if (OPERATION_GtEq.equals(op)) - return valueObjB.compareTo(value1B) >= 0; - else if (OPERATION_Le.equals(op)) - return valueObjB.compareTo(value1B) < 0; - else if (OPERATION_LeEq.equals(op)) - return valueObjB.compareTo(value1B) <= 0; - else if (OPERATION_Like.equals(op)) - return valueObjB.compareTo(value1B) == 0; - else if (OPERATION_NotEq.equals(op)) - return valueObjB.compareTo(value1B) != 0; - // - else if (OPERATION_Sql.equals(op)) - throw new IllegalArgumentException("SQL not Implemented"); - // - else if (OPERATION_X.equals(op)) - { - if (valueObjB.compareTo(value1B) < 0) - return false; - // To - try - { - value2B = new BigDecimal (String.valueOf(value2)); - return valueObjB.compareTo(value2B) <= 0; - } - catch (Exception e) - { - log.fine("compareNumber - value2=" + value2 + " - " + e.toString()); - return false; - } - } - // - throw new IllegalArgumentException("Unknown Operation=" + op); - } // compareNumber - - /** - * Compare String - * @param valueObj comparator - * @return true if operation - */ - private boolean compareString (Object valueObj, String value1S, String value2S) - { - //m_numeric = false; - String valueObjS = String.valueOf(valueObj); - // - String op = getOperation(); - if (OPERATION_Eq.equals(op)) - return valueObjS.compareTo(value1S) == 0; - else if (OPERATION_Gt.equals(op)) - return valueObjS.compareTo(value1S) > 0; - else if (OPERATION_GtEq.equals(op)) - return valueObjS.compareTo(value1S) >= 0; - else if (OPERATION_Le.equals(op)) - return valueObjS.compareTo(value1S) < 0; - else if (OPERATION_LeEq.equals(op)) - return valueObjS.compareTo(value1S) <= 0; - else if (OPERATION_Like.equals(op)) - return valueObjS.compareTo(value1S) == 0; - else if (OPERATION_NotEq.equals(op)) - return valueObjS.compareTo(value1S) != 0; - // - else if (OPERATION_Sql.equals(op)) - throw new IllegalArgumentException("SQL not Implemented"); - // - else if (OPERATION_X.equals(op)) - { - if (valueObjS.compareTo(value1S) < 0) - return false; - // To - return valueObjS.compareTo(value2S) <= 0; - } - // - throw new IllegalArgumentException("Unknown Operation=" + op); - } // compareString - -} // MForcastLine diff --git a/base/src/org/eevolution/model/reasoner/CRPReasoner.java b/base/src/org/eevolution/model/reasoner/CRPReasoner.java deleted file mode 100644 index 69df996944..0000000000 --- a/base/src/org/eevolution/model/reasoner/CRPReasoner.java +++ /dev/null @@ -1,254 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ - -package org.eevolution.model.reasoner; - -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.compiere.model.MResource; -import org.compiere.model.MResourceType; -import org.compiere.model.MResourceUnAvailable; -import org.compiere.model.POResultSet; -import org.compiere.model.Query; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.TimeUtil; -import org.eevolution.model.MPPOrder; -import org.eevolution.model.MPPOrderNode; - - -/** - * @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany - * @version 1.0, October 14th 2005 - * - * @author Teo Sarca, http://www.arhipac.ro - */ -public class CRPReasoner -{ - public Properties getCtx() - { - return Env.getCtx(); - } - - private String getSQLDayRestriction(Timestamp dateTime, MResource r, List params) - { - Timestamp dayStart = r.getResourceType().getDayStart(dateTime); - Timestamp dayEnd = r.getResourceType().getDayEnd(dateTime); - - String whereClause; - - // - // Case 1: The time dependent process has already begun and ends at this day. - whereClause = "(DateStartSchedule<=? AND DateFinishSchedule>=? AND DateFinishSchedule<=?)"; - params.add(dayStart); - params.add(dayStart); - params.add(dayEnd); - - // - // Case 2: The time dependent process begins and ends at this day. - whereClause += " OR (DateStartSchedule>=? AND DateStartSchedule<=?" - +" AND DateFinishSchedule>=? AND DateFinishSchedule<=?)"; - params.add(dayStart); - params.add(dayEnd); - params.add(dayStart); - params.add(dayEnd); - - // - // Case 3: The time dependent process begins at this day and ends few days later. - whereClause += " OR (DateStartSchedule>=? AND DateStartSchedule<=? AND DateFinishSchedule>=?)"; - params.add(dayStart); - params.add(dayEnd); - params.add(dayEnd); - - // - // Case 4: The time dependent process has already begun and ends few days later. - whereClause += " OR (DateStartSchedule<=? AND DateFinishSchedule>=?)"; - params.add(dayStart); - params.add(dayEnd); - - return "("+whereClause+")"; - } - - public Query getPPOrdersNotCompletedQuery(int S_Resource_ID, String trxName) - { - ArrayList params = new ArrayList(); - - StringBuffer whereClause = new StringBuffer(); - - // For current AD_Client_ID (security) - whereClause.append("AD_Client_ID=?"); - params.add(Env.getAD_Client_ID(getCtx())); - - // Skip voided, reversed and closed orders: - whereClause.append(" AND ").append(MPPOrder.COLUMNNAME_DocStatus).append(" NOT IN (?,?,?)"); - params.add(MPPOrder.DOCSTATUS_Voided); - params.add(MPPOrder.DOCSTATUS_Reversed); - params.add(MPPOrder.DOCSTATUS_Closed); - - - // For given resource (if any) - if (S_Resource_ID > 0) - { - whereClause.append(" AND ").append(MPPOrder.COLUMNNAME_S_Resource_ID).append("=?"); - params.add(S_Resource_ID); - } - - return new Query(getCtx(), MPPOrder.Table_Name, whereClause.toString(), trxName) - .setParameters(params) - .setOnlyActiveRecords(true) - .setOrderBy(MPPOrder.COLUMNNAME_DatePromised); - } - - public MPPOrder[] getPPOrders(Timestamp dateTime, MResource r) - { - if(!isAvailable(r, dateTime)) - { - return new MPPOrder[0]; - } - - ArrayList params = new ArrayList(); - params.add(r.get_ID()); - final String whereClause = - // Checks the requested resource id directly on order node, not on resource id of the order - "EXISTS (SELECT 1 FROM PP_Order_Node WHERE " - +" PP_Order_Node.PP_Order_ID=PP_Order.PP_Order_ID" - +" AND S_Resource_ID=?" - // ... and only the orders running on given day - +" AND "+getSQLDayRestriction(dateTime, r, params) - +")" - + " AND AD_Client_ID=?"; - params.add(r.getAD_Client_ID()); - - List list = new Query(r.getCtx(), MPPOrder.Table_Name, whereClause, null) - .setParameters(params) - .list(); - return list.toArray(new MPPOrder[list.size()]); - } - - public MPPOrderNode[] getPPOrderNodes(Timestamp dateTime, MResource r) - { - if(!isAvailable(r, dateTime)) - { - return new MPPOrderNode[0]; - } - - ArrayList params = new ArrayList(); - String whereClause = MPPOrderNode.COLUMNNAME_S_Resource_ID+"=? AND AD_Client_ID=?"; - params.add(r.get_ID()); - params.add(r.getAD_Client_ID()); - - whereClause += " AND "+getSQLDayRestriction(dateTime, r, params); - - List list = new Query(r.getCtx(), MPPOrderNode.Table_Name, whereClause, null) - .setParameters(params) - .list(); - return list.toArray(new MPPOrderNode[list.size()]); - } - - public boolean isAvailable(MResource r, Timestamp dateTime) - { - MResourceType t = MResourceType.get(Env.getCtx(), r.getS_ResourceType_ID()); - return t.isDayAvailable(dateTime) && !MResourceUnAvailable.isUnAvailable(r, dateTime); - } - - public boolean isAvailable(MResource r) - { - return r.getResourceType().isAvailable(); - } - - /** - * Get Next/Previous Available Date - * @param t - * @param dateTime - * @param isScheduleBackward - * @return - */ - private Timestamp getAvailableDate(MResourceType t, Timestamp dateTime, boolean isScheduleBackward) - { - Timestamp date = dateTime; - int direction = isScheduleBackward ? -1 : +1; - for (int i = 0; i <= 7; i++) - { - date = TimeUtil.addDays(date, i * direction); - if (t.isDayAvailable(date)) - { - break; - } - } - return date; - } - - /** - * @param r resource - * @param dateTime - * @return next available date - */ - public Timestamp getAvailableDate(MResource r, Timestamp dateTime, boolean isScheduleBackward) - { - MResourceType t = r.getResourceType(); - Timestamp date = dateTime; - ArrayList params = new ArrayList(); - String whereClause; - String orderByClause; - int direction; - if (isScheduleBackward) - { - whereClause = MResourceUnAvailable.COLUMNNAME_DateFrom+" <= ?"; - params.add(date); - orderByClause = MResourceUnAvailable.COLUMNNAME_DateFrom+" DESC"; - direction = 1; - } - else - { - whereClause = MResourceUnAvailable.COLUMNNAME_DateTo+" >= ?"; - params.add(date); - orderByClause = MResourceUnAvailable.COLUMNNAME_DateTo; - direction = -1; - } - - whereClause += " AND "+MResourceUnAvailable.COLUMNNAME_S_Resource_ID+"=? AND AD_Client_ID=?"; - params.add(r.get_ID()); - params.add(r.getAD_Client_ID()); - - POResultSet rs = new Query(r.getCtx(), MResourceUnAvailable.Table_Name, whereClause, null) - .setOrderBy(orderByClause) - .setParameters(params) - .scroll(); - try - { - while(rs.hasNext()) - { - MResourceUnAvailable rua = rs.next(); - if (rua.isUnAvailable(date)) - { - date = TimeUtil.addDays(rua.getDateTo(), 1 * direction); - } - date = getAvailableDate(t, dateTime, isScheduleBackward); - } - } - finally - { - DB.close(rs); - } - // - date = getAvailableDate(t, dateTime, isScheduleBackward); - return date; - } -} diff --git a/base/src/org/eevolution/model/reasoner/StorageReasoner.java b/base/src/org/eevolution/model/reasoner/StorageReasoner.java deleted file mode 100644 index d8dd6c9412..0000000000 --- a/base/src/org/eevolution/model/reasoner/StorageReasoner.java +++ /dev/null @@ -1,221 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.model.reasoner; - -import java.math.BigDecimal; - -import org.compiere.model.MAttribute; -import org.compiere.model.MAttributeInstance; -import org.compiere.model.MAttributeSet; -import org.compiere.model.MAttributeSetInstance; -import org.compiere.model.MLocator; -import org.compiere.model.MProduct; -import org.compiere.model.MStorage; -import org.compiere.model.PO; -import org.compiere.util.Env; -import org.eevolution.model.MPPOrder; -import org.eevolution.model.MPPOrderWorkflow; -import org.eevolution.model.wrapper.BOMLineWrapper; - -/** - * @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany - * @version 1.0, October 14th 2005 - */ -public class StorageReasoner { - - public StorageReasoner() { - } - - public MPPOrderWorkflow getPPOrderWorkflow(MPPOrder order) { - - int[] ids = PO.getAllIDs("PP_Order_Workflow", "PP_Order_ID = "+order.get_ID(), null); - if(ids.length != 1) { - - return null; - } - - return new MPPOrderWorkflow(Env.getCtx(), ids[0], null); - } - - public boolean equalAttributeInstanceValue(MAttributeInstance ai1, MAttributeInstance ai2) { - - if(ai1.getM_Attribute_ID() != ai2.getM_Attribute_ID()) { - - return false; - } - - boolean equal = true; - - - MAttribute a = new MAttribute(Env.getCtx(), ai1.getM_Attribute_ID(), null); - if(MAttribute.ATTRIBUTEVALUETYPE_Number.equals(a.getAttributeValueType())) { - - if(ai1.getValue() == null) { - - equal = ai2.getValueNumber() == null; - } - else { - - equal = ai1.getValueNumber().compareTo(ai2.getValueNumber()) == 0; - } - } - else if(MAttribute.ATTRIBUTEVALUETYPE_StringMax40.equals(a.getAttributeValueType())) { - - if(ai1.getValue() == null) { - - equal = ai2.getValue() == null; - } - else { - - equal = ai1.getValue().equals(ai2.getValue()); - } - } - else if(MAttribute.ATTRIBUTEVALUETYPE_List.equals(a.getAttributeValueType())) { - - equal = ai1.getM_AttributeValue_ID() == ai2.getM_AttributeValue_ID(); - } - - return equal; - } - - public int[] getAttributeIDs(MAttributeSetInstance asi) { - - MAttributeSet as = new MAttributeSet(Env.getCtx(), asi.getM_AttributeSet_ID(), null); - return getPOIDs(MAttribute.Table_Name, "M_Attribute_ID IN (SELECT M_Attribute_ID FROM M_AttributeUse WHERE M_AttributeSet_ID = "+as.get_ID()+")", null); - } - - public BigDecimal getSumQtyAvailable(MProduct p, MAttributeSetInstance asi) { - - int[] ids = getPOIDs(MLocator.Table_Name, null, null); - - MStorage storage = null; - Object[] obj = null; - - BigDecimal sumQtyAvailable = BigDecimal.ZERO; - - int count = 0; - for(int i = 0; i < ids.length; i++) { - - storage = MStorage.get(Env.getCtx(), ids[i], p.get_ID(), asi.get_ID(), null); - if(storage == null) { - - continue; - } - count++; - - sumQtyAvailable = sumQtyAvailable.add(storage.getQtyOnHand().subtract(storage.getQtyReserved())); - } - - return sumQtyAvailable; - } - - public BigDecimal getSumQtyRequired(BOMLineWrapper line) { - - MProduct p = new MProduct(Env.getCtx(), line.getM_Product_ID(), null); - MAttributeSetInstance asi = new MAttributeSetInstance(Env.getCtx(), line.getM_AttributeSetInstance_ID(), null); - - return getSumQtyAvailable(p, asi).subtract(line.getQtyBOM()).negate(); - } - - public MStorage getAvailableQtyLocator(MProduct p, MAttributeSetInstance asi, BigDecimal qtyRequired) { - - int[] ids = getPOIDs(MLocator.Table_Name, null, null); - - MStorage storage = null; - - BigDecimal qtyAvailable = BigDecimal.ZERO; - BigDecimal qtyOnHand = BigDecimal.ZERO; - BigDecimal qtyReserved = BigDecimal.ZERO; - - for(int i = 0; i < ids.length; i++) { - - storage = MStorage.get(Env.getCtx(), ids[i], p.get_ID(), asi.get_ID(), null); - if(storage != null) { - - qtyOnHand = (storage.getQtyOnHand() == null) ? BigDecimal.ZERO : storage.getQtyOnHand(); - qtyReserved = (storage.getQtyReserved () == null) ? BigDecimal.ZERO : storage.getQtyReserved (); - - qtyAvailable = qtyOnHand.subtract(qtyReserved); - if(qtyRequired.compareTo(qtyAvailable) <= 0 && qtyOnHand.compareTo(BigDecimal.ZERO) > 0) { - - break; - } - else { - - storage = null; - } - } - } - - return storage; - } - - public boolean isQtyAvailable(BOMLineWrapper line) { - - MProduct p = new MProduct(Env.getCtx(), line.getM_Product_ID(), null); - MAttributeSetInstance asi = new MAttributeSetInstance(Env.getCtx(), line.getM_AttributeSetInstance_ID(), null); - - return isQtyAvailable(p, asi); - } - - public boolean isQtyAvailable(MProduct p, MAttributeSetInstance asi) { - - int[] ids = getPOIDs(MLocator.Table_Name, null, null); - - MStorage storage = null; - - BigDecimal sumQtyOnHand = BigDecimal.ZERO; - BigDecimal sumQtyReserved = BigDecimal.ZERO; - - int count = 0; - for(int i = 0; i < ids.length; i++) { - - storage = MStorage.get(Env.getCtx(), ids[i], p.get_ID(), asi.get_ID(), null); - if(storage == null) { - - continue; - } - count++; - - sumQtyOnHand = sumQtyOnHand.add(storage.getQtyOnHand()); - sumQtyReserved = sumQtyReserved.add(storage.getQtyReserved()); - } - - double available = sumQtyOnHand.subtract(sumQtyReserved).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - if(count == 0 || (available <= 0.00d)) { - - return false; - } - - return true; - } - - public int[] getPOIDs(String from, String where, String trx) { - - String client = "AD_Client_ID = "+Env.getAD_Client_ID(Env.getCtx()); - String w = null; - if(where == null || where.length() == 0) { - - w = client; - } - else { - - w = where+" AND "+client; - } - return PO.getAllIDs(from, w, trx); - } -} diff --git a/base/src/org/eevolution/model/wrapper/AbstractPOWrapper.java b/base/src/org/eevolution/model/wrapper/AbstractPOWrapper.java deleted file mode 100644 index 5256bdf827..0000000000 --- a/base/src/org/eevolution/model/wrapper/AbstractPOWrapper.java +++ /dev/null @@ -1,508 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.model.wrapper; - -import java.sql.Timestamp; -import java.util.Properties; - -import org.compiere.model.MAttachment; -import org.compiere.model.PO; - -/** - * @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany - * @version 1.0, October 14th 2005 - */ -public abstract class AbstractPOWrapper { - - protected abstract PO receivePO(Properties ctx, int id, String trxName, String type); - - public AbstractPOWrapper(Properties ctx, int id, String trxName, String type) { - - po = receivePO(ctx, id, trxName, type); - } - - protected PO po; - - public PO get() { - - return po; - } - - /** - * String representation - * @return String representation - */ - public String toString() { - - return po.toString(); // toString - } - - /** - * Equals based on ID - * @param cmp comparator - * @return true if ID the same - */ - public boolean equals(Object cmp) { - - return po.equals(cmp); // equals - } - - /** - * Compare based on DocumentNo, Value, Name, Description - * @param o1 Object 1 - * @param o2 Object 2 - * @return -1 if o1 < o2 - */ - public int compare(Object o1, Object o2) { - - return po.compare(o1, o2); // compare - } - - /** - * Get TableName. - * @return table name - */ - public String get_TableName() { - - return po.get_TableName(); // getTableName - } - - /** - * Return Single Key Record ID - * @return ID or 0 - */ - public int getID() { - - return po.get_ID(); // getID - } - - /** - * Return Deleted Single Key Record ID - * @return ID or 0 - */ - public int getIDOld() { - - return po.get_IDOld(); // getID - } - - /** - * Get Context - * @return context - */ - public Properties getCtx() { - - return po.getCtx(); // getCtx - } - - /************************************************************************** - * Get Value - * @param index index - * @return value - */ - public Object get_Value(int index) { - - return po.get_Value(index); // get_Value - } - - /** - * Get Value - * @param columnName column name - * @return value or null - */ - public Object get_Value(String columnName) { - - return po.get_Value(columnName); // get_Value - } - - /** - * Get Column Value - * @param variableName name - * @return value or "" - */ - public String get_ValueAsString(String variableName) { - - return po.get_ValueAsString(variableName); // get_ValueAsString - } - - /** - * Get Value of Column - * @param AD_Column_ID column - * @return value or null - */ - public Object get_ValueOfColumn(int AD_Column_ID) { - - return po.get_ValueOfColumn(AD_Column_ID); // get_ValueOfColumn - } - - /** - * Get Old Value - * @param index index - * @return value - */ - public Object get_ValueOld(int index) { - - return po.get_ValueOld(index); // get_ValueOld - } - - /** - * Get Old Value - * @param columnName column name - * @return value or null - */ - public Object get_ValueOld(String columnName) { - - return po.get_ValueOld(columnName); // get_ValueOld - } - - /** - * Is Value Changed - * @param index index - * @return true if changed - */ - public boolean is_ValueChanged(int index) { - - return po.is_ValueChanged(index); // is_ValueChanged - } - - /** - * Is Value Changed - * @param columnName column name - * @return true if changed - */ - public boolean is_ValueChanged(String columnName) { - - return po.is_ValueChanged(columnName); // is_ValueChanged - } - - /** - * Return new - old. - * - New Value if Old Value is null - * - New Value - Old Value if Number - * - otherwise null - * @param index index - * @return new - old or null if not appropriate or not changed - */ - public Object get_ValueDifference(int index) { - - return po.get_ValueDifference(index); // get_ValueDifference - } - - /** - * Return new - old. - * - New Value if Old Value is null - * - New Value - Old Value if Number - * - otherwise null - * @param columnName column name - * @return new - old or null if not appropriate or not changed - */ - public Object get_ValueDifference(String columnName) { - - return po.get_ValueDifference(columnName); // get_ValueDifference - } - - /** - * Set Value of Column - * @param AD_Column_ID column - * @param value value - */ - public void set_ValueOfColumn(int AD_Column_ID, Object value) { - - po.set_ValueOfColumn(AD_Column_ID, value); // setValueOfColumn - } - - /** - * Set Custom Column - * @param columnName column - * @param value value - */ - public void set_CustomColumn(String columnName, Object value) { - - po.set_CustomColumn(columnName, value); // set_CustomColumn - } - - /** - * Get Column Index - * @param columnName column name - * @return index of column with ColumnName or -1 if not found - */ - public int get_ColumnIndex(String columnName) { - - return po.get_ColumnIndex(columnName); // getColumnIndex - } - - /** - * (re)Load record with m_ID[*] - */ - public boolean load(String trxName) { - - return po.load(trxName); // load - } - - /** - * Get AD_Client - * @return AD_Client_ID - */ - public int getAD_Client_ID() { - - return po.getAD_Client_ID(); // getAD_Client_ID - } - - /** - * Get AD_Org - * @return AD_Org_ID - */ - public int getAD_Org_ID() { - - return po.getAD_Org_ID(); // getAD_Org_ID - } - - /** - * Set Active - * @param active active - */ - public void setIsActive(boolean active) { - - po.setIsActive(active); // setActive - } - - /** - * Is Active - * @return is active - */ - public boolean isActive() { - - return po.isActive(); // isActive - } - - /** - * Get Created - * @return created - */ - public Timestamp getCreated() { - - return po.getCreated(); // getCreated - } - - /** - * Get Updated - * @return updated - */ - public Timestamp getUpdated() { - - return po.getUpdated(); // getUpdated - } - - /** - * Get CreatedBy - * @return AD_User_ID - */ - public int getCreatedBy() { - - return po.getCreatedBy(); // getCreateddBy - } - - /** - * Get UpdatedBy - * @return AD_User_ID - */ - public int getUpdatedBy() { - - return po.getUpdatedBy(); // getUpdatedBy - } - - /************************************************************************** - * Update Value or create new record. - * To reload call load() - not updated - * @return true if saved - */ - public boolean save() { - - return po.save(); // save - } - - /** - * Update Value or create new record. - * To reload call load() - not updated - * @param trxName transaction - * @return true if saved - */ - public boolean save(String trxName) { - - return po.save(trxName); // save - } - - /** - * Is there a Change to be saved? - * @return true if record changed - */ - public boolean is_Changed() { - - return po.is_Changed(); // is_Change - } - - /** - * Create Single/Multi Key Where Clause - * @param withValues if true uses actual values otherwise ? - * @return where clause - */ - public String get_WhereClause(boolean withValues) { - - return po.get_WhereClause(withValues); // getWhereClause - } - - /************************************************************************** - * Delete Current Record - * @param force delete also processed records - * @return true if deleted - */ - public boolean delete(boolean force) { - - return po.delete(force); // delete - } - - /** - * Delete Current Record - * @param force delete also processed records - * @param trxName transaction - */ - public boolean delete(boolean force, String trxName) { - - return po.delete(force, trxName); // delete - } - - /************************************************************************** - * Lock it. - * @return true if locked - */ - public boolean lock() { - - return po.lock(); // lock - } - - /** - * UnLock it - * @return true if unlocked (false only if unlock fails) - */ - public boolean unlock(String trxName) { - - return po.unlock(trxName); // unlock - } - - /** - * Set Trx - * @param trxName transaction - */ - public void set_TrxName(String trxName) { - - po.set_TrxName(trxName); // setTrx - } - - /** - * Get Trx - * @return transaction - */ - public String get_TrxName() { - - return po.get_TrxName(); // getTrx - } - - /************************************************************************** - * Get Attachments. - * An attachment may have multiple entries - * @return Attachment or null - */ - public MAttachment getAttachment() { - - return po.getAttachment(); // getAttachment - } - - /** - * Get Attachments - * @param requery requery - * @return Attachment or null - */ - public MAttachment getAttachment(boolean requery) { - - return po.getAttachment(requery); // getAttachment - } - - /** - * Create/return Attachment for PO. - * If not exist, create new - * @return attachment - */ - public MAttachment createAttachment() { - - return po.createAttachment(); // createAttachment - } - - /** - * Do we have a Attachment of type - * @param extension extension e.g. .pdf - * @return true if there is a attachment of type - */ - public boolean isAttachment(String extension) { - - return po.isAttachment(extension); // isAttachment - } - - /** - * Get Attachment Data of type - * @param extension extension e.g. .pdf - * @return data or null - */ - public byte[] getAttachmentData(String extension) { - - return po.getAttachmentData(extension); // getAttachmentData - } - - /** - * Do we have a PDF Attachment - * @return true if there is a PDF attachment - */ - public boolean isPdfAttachment() { - - return po.isPdfAttachment(); // isPdfAttachment - } - - /** - * Get PDF Attachment Data - * @return data or null - */ - public byte[] getPdfAttachment() { - - return po.getPdfAttachment(); // getPDFAttachment - } - - /************************************************************************** - * Dump Record - */ - public void dump() { - - po.dump(); // dump - } - - /** - * Dump column - * @param index index - */ - public void dump(int index) { - - po.dump(index); // dump - } - -} \ No newline at end of file diff --git a/base/src/org/eevolution/model/wrapper/BOMLineWrapper.java b/base/src/org/eevolution/model/wrapper/BOMLineWrapper.java deleted file mode 100644 index c1deb41333..0000000000 --- a/base/src/org/eevolution/model/wrapper/BOMLineWrapper.java +++ /dev/null @@ -1,424 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.model.wrapper; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Properties; - -import org.compiere.model.PO; -import org.eevolution.model.MPPOrderBOMLine; -import org.eevolution.model.MPPProductBOMLine; - -/** - * @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany - * @version 1.0, October 14th 2005 - */ -public class BOMLineWrapper extends AbstractPOWrapper { - - public static String tableName(String type) { - - if(BOMWrapper.BOM_TYPE_PRODUCT.equals(type)) { - - return MPPProductBOMLine.Table_Name; - } - else if(BOMWrapper.BOM_TYPE_ORDER.equals(type)) { - - return MPPOrderBOMLine.Table_Name; - } - - return ""; - } - - public static String idColumn(String type) { - - return tableName(type)+"_ID"; - } - - public BOMLineWrapper(Properties ctx, int id, String trxName, String type) { - - super(ctx, id, trxName, type); - } - - protected PO receivePO(Properties ctx, int id, String trxName, String type) { - - PO po = null; - if(BOMWrapper.BOM_TYPE_PRODUCT.equals(type)) { - - po = new MPPProductBOMLine(ctx, id, trxName); - } - else if(BOMWrapper.BOM_TYPE_ORDER.equals(type)) { - - po = new MPPOrderBOMLine(ctx, id, trxName); - } - - return po; - } - - public String getComponentType() { - - String type = null; - if(get() instanceof MPPProductBOMLine) { - - type = ((MPPProductBOMLine)get()).getComponentType(); - } - else if(get() instanceof MPPOrderBOMLine) { - - type = ((MPPOrderBOMLine)get()).getComponentType(); - } - - return type; - } - - public BigDecimal getAssay() { - - BigDecimal assay = null; - if(get() instanceof MPPProductBOMLine) { - - assay = ((MPPProductBOMLine)get()).getAssay(); - } - else if(get() instanceof MPPOrderBOMLine) { - - assay = ((MPPOrderBOMLine)get()).getAssay(); - } - - return assay; - } - - public int getM_ChangeNotice_ID() { - - int M_ChangeNotice_ID = 0; - if(get() instanceof MPPProductBOMLine) { - - M_ChangeNotice_ID = ((MPPProductBOMLine)get()).getM_ChangeNotice_ID(); - } - else if(get() instanceof MPPOrderBOMLine) { - - M_ChangeNotice_ID = ((MPPOrderBOMLine)get()).getM_ChangeNotice_ID(); - } - - return M_ChangeNotice_ID; - } - - public String getHelp() { - - String Help = null; - if(get() instanceof MPPProductBOMLine) { - - Help = ((MPPProductBOMLine)get()).getHelp(); - } - else if(get() instanceof MPPOrderBOMLine) { - - Help = ((MPPOrderBOMLine)get()).getHelp(); - } - - return Help; - } - - - public BigDecimal getQtyBatch() { - - BigDecimal qty = null; - if(get() instanceof MPPProductBOMLine) { - - qty = ((MPPProductBOMLine)get()).getQtyBatch(); - } - else if(get() instanceof MPPOrderBOMLine) { - - qty = ((MPPOrderBOMLine)get()).getQtyBatch(); - } - - return qty; - } - - public BigDecimal getForecast() { - - BigDecimal fc = null; - if(get() instanceof MPPProductBOMLine) { - - fc = ((MPPProductBOMLine)get()).getForecast(); - } - else if(get() instanceof MPPOrderBOMLine) { - - fc = ((MPPOrderBOMLine)get()).getForecast(); - } - - return fc; - } - - public Integer getLeadTimeOffset() { - - Integer offset = null; - if(get() instanceof MPPProductBOMLine) { - - offset = ((MPPProductBOMLine)get()).getLeadTimeOffset(); - } - else if(get() instanceof MPPOrderBOMLine) { - - offset = ((MPPOrderBOMLine)get()).getLeadTimeOffset(); - } - - return offset; - } - - public boolean isQtyPercentage() { - - boolean percentage = false; - if(get() instanceof MPPProductBOMLine) { - - percentage = ((MPPProductBOMLine)get()).isQtyPercentage(); - } - else if(get() instanceof MPPOrderBOMLine) { - - percentage = ((MPPOrderBOMLine)get()).isQtyPercentage(); - } - - return percentage; - } - - public boolean isCritical() { - - boolean critical = false; - if(get() instanceof MPPProductBOMLine) { - - critical = ((MPPProductBOMLine)get()).isCritical(); - } - else if(get() instanceof MPPOrderBOMLine) { - - critical = ((MPPOrderBOMLine)get()).isCritical(); - } - - return critical; - } - - public String getIssueMethod() { - - String issue = null; - if(get() instanceof MPPProductBOMLine) { - - issue = ((MPPProductBOMLine)get()).getIssueMethod(); - } - else if(get() instanceof MPPOrderBOMLine) { - - issue = ((MPPOrderBOMLine)get()).getIssueMethod(); - } - - return issue; - } - - public int getLine() { - - int line = 0; - if(get() instanceof MPPProductBOMLine) { - - line = ((MPPProductBOMLine)get()).getLine(); - } - else if(get() instanceof MPPOrderBOMLine) { - - line = ((MPPOrderBOMLine)get()).getLine(); - } - - return line; - } - - public String getDescription() { - - String type = null; - if(get() instanceof MPPProductBOMLine) { - - type = ((MPPProductBOMLine)get()).getDescription(); - } - else if(get() instanceof MPPOrderBOMLine) { - - type = ((MPPOrderBOMLine)get()).getDescription(); - } - - return type; - } - - public int getM_Product_ID() { - - int id = 0; - if(get() instanceof MPPProductBOMLine) { - - id = ((MPPProductBOMLine)get()).getM_Product_ID(); - } - else if(get() instanceof MPPOrderBOMLine) { - - id = ((MPPOrderBOMLine)get()).getM_Product_ID(); - } - - return id; - } - - public int getPP_Order_ID() { - - int id = 0; - - if(get() instanceof MPPOrderBOMLine) { - - MPPOrderBOMLine line = (MPPOrderBOMLine)get(); - id = line.getPP_Order_ID(); - } - - return id; - } - - public int getPP_BOM_ID() { - - int id = 0; - if(get() instanceof MPPProductBOMLine) { - - id = ((MPPProductBOMLine)get()).getPP_Product_BOM_ID(); - } - else if(get() instanceof MPPOrderBOMLine) { - - id = ((MPPOrderBOMLine)get()).getPP_Order_BOM_ID(); - } - - return id; - } - - public int getM_AttributeSetInstance_ID() { - - int id = 0; - if(get() instanceof MPPProductBOMLine) { - - id = ((MPPProductBOMLine)get()).getM_AttributeSetInstance_ID(); - } - else if(get() instanceof MPPOrderBOMLine) { - - id = ((MPPOrderBOMLine)get()).getM_AttributeSetInstance_ID(); - } - - return id; - } - - public void setM_AttributeSetInstance_ID(int id) { - - if(get() instanceof MPPProductBOMLine) { - - ((MPPProductBOMLine)get()).setM_AttributeSetInstance_ID(id); - } - else if(get() instanceof MPPOrderBOMLine) { - - ((MPPOrderBOMLine)get()).setM_AttributeSetInstance_ID(id); - } - } - - public void setQtyBOM(BigDecimal qty) { - - if(get() instanceof MPPProductBOMLine) { - - ((MPPProductBOMLine)get()).setQtyBOM(qty); - } - else if(get() instanceof MPPOrderBOMLine) { - - ((MPPOrderBOMLine)get()).setQtyBOM(qty); - } - } - - public BigDecimal getQtyBOM() { - - BigDecimal value = null; - if(get() instanceof MPPProductBOMLine) { - - value = ((MPPProductBOMLine)get()).getQtyBOM(); - } - else if(get() instanceof MPPOrderBOMLine) { - - value = ((MPPOrderBOMLine)get()).getQtyBOM(); - } - - return value; - } - - public int getC_UOM_ID() { - - int value = 0; - if(get() instanceof MPPProductBOMLine) { - - value = ((MPPProductBOMLine)get()).getC_UOM_ID(); - } - else if(get() instanceof MPPOrderBOMLine) { - - value = ((MPPOrderBOMLine)get()).getC_UOM_ID(); - } - - return value; - } - - public int getPo() { - - int value = 0; - if(get() instanceof MPPProductBOMLine) { - - value = ((MPPProductBOMLine)get()).getLine(); - } - else if(get() instanceof MPPOrderBOMLine) { - - value = ((MPPOrderBOMLine)get()).getLine(); - } - - return value; - } - - public BigDecimal getScrap() { - - BigDecimal value = new BigDecimal(0); - if(get() instanceof MPPProductBOMLine) { - - value = ((MPPProductBOMLine)get()).getScrap(); - } - else if(get() instanceof MPPOrderBOMLine) { - - value = ((MPPOrderBOMLine)get()).getScrap(); - } - - return value; - } - - public Timestamp getValidFrom() { - - Timestamp value = null; - if(get() instanceof MPPProductBOMLine) { - - value = ((MPPProductBOMLine)get()).getValidFrom(); - } - else if(get() instanceof MPPOrderBOMLine) { - - value = ((MPPOrderBOMLine)get()).getValidFrom(); - } - - return value; - } - - public Timestamp getValidTo() { - - Timestamp value = null; - if(get() instanceof MPPProductBOMLine) { - - value = ((MPPProductBOMLine)get()).getValidTo(); - } - else if(get() instanceof MPPOrderBOMLine) { - - value = ((MPPOrderBOMLine)get()).getValidTo(); - } - - return value; - } -} diff --git a/base/src/org/eevolution/model/wrapper/BOMWrapper.java b/base/src/org/eevolution/model/wrapper/BOMWrapper.java deleted file mode 100644 index 1f7f928aad..0000000000 --- a/base/src/org/eevolution/model/wrapper/BOMWrapper.java +++ /dev/null @@ -1,287 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.model.wrapper; - -import java.sql.Timestamp; -import java.util.Properties; - -import org.compiere.model.PO; -import org.eevolution.model.I_PP_Order_BOM; -import org.eevolution.model.I_PP_Product_BOM; -import org.eevolution.model.MPPOrderBOM; -import org.eevolution.model.MPPProductBOM; -import org.eevolution.model.reasoner.StorageReasoner; - -/** - * @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany - * @version 1.0, October 14th 2005 - */ -public class BOMWrapper extends AbstractPOWrapper { - - final public static String BOM_TYPE_PRODUCT = "productBOM"; - final public static String BOM_TYPE_ORDER = "orderBOM"; - - public static String tableName(String type) { - - if (BOM_TYPE_PRODUCT.equals(type)) { - return I_PP_Product_BOM.Table_Name; - } - else if(BOM_TYPE_ORDER.equals(type)) { - return I_PP_Order_BOM.Table_Name; - } - - return ""; - } - - public static String idColumn(String type) { - - String value = null; - if (BOM_TYPE_PRODUCT.equals(type)) { - return I_PP_Product_BOM.Table_Name; - } - else if(BOM_TYPE_ORDER.equals(type)) { - return I_PP_Order_BOM.Table_Name; - } - - return value+"_ID"; - } - - public BOMWrapper(Properties ctx, int id, String trxName, String type) { - - super(ctx, id, trxName, type); - } - - protected PO receivePO(Properties ctx, int id, String trxName, String type) { - - PO po = null; - if(BOM_TYPE_PRODUCT.equals(type)) { - - po = new MPPProductBOM(ctx, id, trxName); - } - else if(BOM_TYPE_ORDER.equals(type)) { - - po = new MPPOrderBOM(ctx, id, trxName); - } - - return po; - } - - public String getName() { - - String name = null; - if(get() instanceof MPPProductBOM) { - - name = ((MPPProductBOM)get()).getName(); - } - else if(get() instanceof MPPOrderBOM) { - - name = ((MPPOrderBOM)get()).getName(); - } - - return name; - } - - public String getDescription() { - - String name = null; - if(get() instanceof MPPProductBOM) { - - name = ((MPPProductBOM)get()).getDescription(); - } - else if(get() instanceof MPPOrderBOM) { - - name = ((MPPOrderBOM)get()).getDescription(); - } - - return name; - } - - public String getRevision() { - - String name = null; - if(get() instanceof MPPProductBOM) { - - name = ((MPPProductBOM)get()).getRevision(); - } - else if(get() instanceof MPPOrderBOM) { - - name = ((MPPOrderBOM)get()).getRevision(); - } - - return name; - } - - public String getDocumentNo() { - - String value = null; - if(get() instanceof MPPProductBOM) { - - value = ((MPPProductBOM)get()).getDocumentNo(); - } - else if(get() instanceof MPPOrderBOM) { - - value = ((MPPOrderBOM)get()).getDocumentNo(); - } - - return value; - } - - public int getM_Product_ID() { - - int id = 0; - if(get() instanceof MPPProductBOM) { - - id = ((MPPProductBOM)get()).getM_Product_ID(); - } - else if(get() instanceof MPPOrderBOM) { - - id = ((MPPOrderBOM)get()).getM_Product_ID(); - } - - return id; - } - - public int getM_AttributeSetInstance_ID() { - - int id = 0; - if(get() instanceof MPPProductBOM) { - - id = ((MPPProductBOM)get()).getM_AttributeSetInstance_ID(); - } - else if(get() instanceof MPPOrderBOM) { - - id = ((MPPOrderBOM)get()).getM_AttributeSetInstance_ID(); - } - - return id; - } - - public int getC_UOM_ID() { - - int id = 0; - if(get() instanceof MPPProductBOM) { - - id = ((MPPProductBOM)get()).getC_UOM_ID(); - } - else if(get() instanceof MPPOrderBOM) { - - id = ((MPPOrderBOM)get()).getC_UOM_ID(); - } - - return id; - } - - public Timestamp getValidFrom() { - - Timestamp value = null; - if(get() instanceof MPPProductBOM) { - - value = ((MPPProductBOM)get()).getValidFrom(); - } - else if(get() instanceof MPPOrderBOM) { - - value = ((MPPOrderBOM)get()).getValidFrom(); - } - - return value; - } - - public Timestamp getValidTo() { - - Timestamp value = null; - if(get() instanceof MPPProductBOM) { - - value = ((MPPProductBOM)get()).getValidTo(); - } - else if(get() instanceof MPPOrderBOM) { - - value = ((MPPOrderBOM)get()).getValidTo(); - } - - return value; - } - - public String getValue() { - - String value = null; - if(get() instanceof MPPProductBOM) { - - value = ((MPPProductBOM)get()).getValue(); - } - else if(get() instanceof MPPOrderBOM) { - - value = ((MPPOrderBOM)get()).getValue(); - } - - return value; - } - - public String getBOMType() { - - String value = null; - if(get() instanceof MPPProductBOM) { - - value = ((MPPProductBOM)get()).getBOMType(); - } - else if(get() instanceof MPPOrderBOM) { - - value = ((MPPOrderBOM)get()).getBOMType(); - } - - return value; - } - - public int getPP_Order_ID() { - - int id = 0; - - if(get() instanceof MPPOrderBOM) { - - MPPOrderBOM bom = (MPPOrderBOM)get(); - id = bom.getPP_Order_ID(); - } - - return id; - } - - public BOMLineWrapper[] getLines() { - - int[] ids = null; - - String type = null; - if(get() instanceof MPPProductBOM) { - - type = BOM_TYPE_PRODUCT; - } - else if(get() instanceof MPPOrderBOM) { - - type = BOM_TYPE_ORDER; - } - - StorageReasoner mr = new StorageReasoner(); - ids = mr.getPOIDs(BOMLineWrapper.tableName(type), idColumn(type)+" = "+getID(), null); - - BOMLineWrapper[] lines = new BOMLineWrapper[ids.length]; - - - for(int i = 0; i < ids.length; i++) { - - lines[i] = new BOMLineWrapper(getCtx(), ids[i], null, type); - } - return lines; - } -} diff --git a/base/src/org/eevolution/msg/HTMLMessenger.java b/base/src/org/eevolution/msg/HTMLMessenger.java deleted file mode 100644 index 14153b89ee..0000000000 --- a/base/src/org/eevolution/msg/HTMLMessenger.java +++ /dev/null @@ -1,416 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.msg; - -import java.math.BigDecimal; -import java.text.MessageFormat; -import java.text.SimpleDateFormat; - -import org.compiere.model.MAttribute; -import org.compiere.model.MAttributeInstance; -import org.compiere.model.MAttributeSet; -import org.compiere.model.MAttributeSetInstance; -import org.compiere.model.MAttributeValue; -import org.compiere.model.MLocator; -import org.compiere.model.MProduct; -import org.compiere.model.MProject; -import org.compiere.model.MStorage; -import org.compiere.model.MWarehouse; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.eevolution.model.MPPOrder; -import org.eevolution.model.reasoner.StorageReasoner; -import org.eevolution.model.wrapper.BOMLineWrapper; -import org.eevolution.model.wrapper.BOMWrapper; - -/** - * @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany - * @version 1.0, October 14th 2005 - */ -public class HTMLMessenger { - - final protected String PRODUCT_TOOLTIP = - "

    "+Msg.translate(Env.getCtx(), "M_Product_ID")+"

    "+ - ""+ - ""+ - "
    "+Msg.translate(Env.getCtx(), "Description")+":{0}
    "; - - final protected String LENGTHTRANSFORM_INFO_PATTERN = - "" + - ""+ - ""+ - ""+ - ""+ - "
    {0}
    {1}
    {2}
    "; - - final protected String PP_ORDER_INFO_PATTERN = - "

    "+Msg.translate(Env.getCtx(), "PP_Order_ID")+"

    "+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - "
    "+Msg.translate(Env.getCtx(), "DocumentNo")+":{0}
    "+Msg.translate(Env.getCtx(), "DateStartSchedule")+":{1}
    "+Msg.translate(Env.getCtx(), "DateFinishSchedule")+":{2}
    "+Msg.translate(Env.getCtx(), "C_Project_ID")+":{3}
    "+Msg.translate(Env.getCtx(), "M_Product_ID")+":{4}
    "+Msg.translate(Env.getCtx(), "QtyOrdered")+":{5}
    "+Msg.translate(Env.getCtx(), "QtyDelivered")+":{6}
    "; - - final protected String PP_ORDER_HEADER_INFO_PATTERN = - "

    {0}

    "+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - "
    "+Msg.translate(Env.getCtx(), "DocumentNo")+""+Msg.translate(Env.getCtx(), "DateStartSchedule")+""+Msg.translate(Env.getCtx(), "DateFinishSchedule")+""+Msg.translate(Env.getCtx(), "C_Project_ID")+""+Msg.translate(Env.getCtx(), "M_Product_ID")+""+Msg.translate(Env.getCtx(), "QtyOrdered")+""+Msg.translate(Env.getCtx(), "QtyDelivered")+"
    "; - - final protected String PP_ORDER_LINE_INFO_PATTERN = - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - "
    {0}{1}{2}{3}{4}{5}{6}
    "; - - final protected String BOM_INFO_PATTERN = - "

    "+Msg.translate(Env.getCtx(), "PP_Product_BOM_ID")+"

    "+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - "
    "+Msg.translate(Env.getCtx(), "DocumentNo")+":{0}
    "+Msg.translate(Env.getCtx(), "PP_Product_BOM_ID")+":{1}
    "+Msg.translate(Env.getCtx(), "ValidFrom")+":{2} - {3}
    "+Msg.translate(Env.getCtx(), "Value")+":{4}
    "+Msg.translate(Env.getCtx(), "M_Product_ID")+":{5}
    {6}
    "+ - "

    {7}

    "+ - ""; - - final protected String BOM_HEADER_INFO_PATTERN = - "" - +"" - +"" - +"" - +"" - +""; - - final protected String BOM_LINE_INFO_PATTERN = - "" - +"" - +"" - +"" - +"" - +""; - - final protected String BOMLINE_INFO_PATTERN = - "

    "+Msg.translate(Env.getCtx(), "Line")+": {0}

    "+ - "
    "+Msg.translate(Env.getCtx(), "Line")+""+Msg.translate(Env.getCtx(), "Qty")+""+Msg.translate(Env.getCtx(), "M_Product_ID")+""+Msg.translate(Env.getCtx(), "M_AttributeSetInstance_ID")+"
    {0}{1}{2}{3}
    "+ - ""+ - ""+ - ""+ - ""+ - "" + - "
    "+Msg.translate(Env.getCtx(), "ComponentType")+":{1}
    "+Msg.translate(Env.getCtx(), "ValidFrom")+":{2} - {3}
    "+Msg.translate(Env.getCtx(), "Qty")+":{4}
    "+Msg.translate(Env.getCtx(), "M_Product_ID")+":{5}
    {6}
    "+ - "

    {7}

    "+ - ""; - - final protected String STORAGE_HEADER_INFO_PATTERN = - "" - +"" - +"" - +"" - +"" - +"" - +"" - +""; - - final protected String STORAGE_LINE_INFO_PATTERN = - "" - +"" - +"" - +"" - +"" - +"" - +"" - +""; - - final protected String STORAGE_SUM_LINE_INFO_PATTERN = - "" - +"" - +"" - +"" - +"" - +"" - +"" - +""; - - final protected String STORAGE_NOINVENTORY_INFO_PATTERN = - "" - +"" - +""; - - final protected String STORAGE_FOOTER_INFO_PATTERN = "
    "+Msg.translate(Env.getCtx(), "M_Locator_ID")+""+Msg.translate(Env.getCtx(), "M_Warehouse_ID")+""+Msg.translate(Env.getCtx(), "QtyOnHand")+""+Msg.translate(Env.getCtx(), "QtyReserved")+""+Msg.translate(Env.getCtx(), "QtyOrdered")+""+Msg.translate(Env.getCtx(), "QtyAvailable")+"
    {0}{1}{2}{3}{4}{5}

    {0}

    {1}

    {2}

    {3}
    "+Msg.translate(Env.getCtx(), Msg.getMsg(Env.getCtx(), "NoQtyAvailable"))+"
    "; - - final protected String ATTRIBUTE_INFO_PATTERN = "{0} = {1}"; - - public String getProductInfo(MProduct p) { - - - Object[] obj = new Object[] { - p.getDescription() == null ? "" : p.getDescription() - }; - - return MessageFormat.format(PRODUCT_TOOLTIP, obj); - } - - public String getLengthTransformInfo(MProduct p, BigDecimal srcLength, BigDecimal tgtLength, BigDecimal pieces) { - - BigDecimal scrapLength = srcLength.subtract(tgtLength.multiply(pieces)); - - Object[] obj = new Object[] { - p.getName()+" ("+p.getValue()+")", - "1 x "+srcLength.setScale(2, BigDecimal.ROUND_HALF_DOWN)+" → "+pieces+" x "+tgtLength.setScale(2, BigDecimal.ROUND_HALF_DOWN), - Msg.translate(Env.getCtx(), "Scrap")+": 1 x "+scrapLength.setScale(2, BigDecimal.ROUND_HALF_DOWN), - }; - - return MessageFormat.format(LENGTHTRANSFORM_INFO_PATTERN, obj); - } - - public String getMfcOrderInfo(MPPOrder o) { - - MProject pj = new MProject(Env.getCtx(), o.getC_Project_ID(), null); - MProduct pd = new MProduct(Env.getCtx(), o.getM_Product_ID(), null); - - Object[] obj = new Object[] { - o.getDocumentNo(), - o.getDateStartSchedule(), - o.getDateFinishSchedule(), - (pj.getName() == null ? "-" : pj.getName())+(pj.getValue() == null ? "" : " ("+pj.getValue()+")"), - pd.getName()+" ("+pd.getValue()+")", - o.getQtyOrdered(), - o.getQtyDelivered() - }; - return MessageFormat.format(PP_ORDER_INFO_PATTERN, obj); - } - - public String getBOMLinesInfo(BOMLineWrapper[] lines) { - - MProduct p = null; - MAttributeSetInstance asi = null; - - StringBuffer sb = new StringBuffer(BOM_HEADER_INFO_PATTERN); - for(int i = 0; i < lines.length; i++) { - - p = new MProduct(Env.getCtx(), lines[i].getM_Product_ID(), MProduct.Table_Name); - asi = new MAttributeSetInstance(Env.getCtx(), lines[i].getM_AttributeSetInstance_ID(), MAttributeSetInstance.Table_Name); - - Object[] obj = new Object[] { - new Integer(lines[i].getPo()), - lines[i].getQtyBOM(), - p.getName(), - getAttributeSetInstanceInfo(asi, true) - }; - - sb.append(MessageFormat.format(BOM_LINE_INFO_PATTERN, obj)); - } - - return sb.toString(); - } - - public String getBOMLineInfo(BOMLineWrapper mpbl) { - - SimpleDateFormat df = Env.getLanguage(Env.getCtx()).getDateFormat(); - - MProduct p = new MProduct(Env.getCtx(), mpbl.getM_Product_ID(), MProduct.Table_Name); - MAttributeSetInstance asi = new MAttributeSetInstance(Env.getCtx(), mpbl.getM_AttributeSetInstance_ID(), MAttributeSetInstance.Table_Name); - - Object[] obj = new Object[] { - new Integer(mpbl.getPo()), - mpbl.getComponentType(), - mpbl.getValidFrom() == null ? "" : df.format(mpbl.getValidFrom()), - mpbl.getValidTo() == null ? "" : df.format(mpbl.getValidTo()), - mpbl.getQtyBOM(), - p.getName(), - getAttributeSetInstanceInfo(asi, false), - getStorageInfo(p, asi) - }; - - return MessageFormat.format(BOMLINE_INFO_PATTERN, obj); - } - - public String getBOMInfo(BOMWrapper pb) { - - SimpleDateFormat df = Env.getLanguage(Env.getCtx()).getDateFormat(); - - MProduct p = new MProduct(Env.getCtx(), pb.getM_Product_ID(), MProduct.Table_Name); - MAttributeSetInstance asi = new MAttributeSetInstance(Env.getCtx(), pb.getM_AttributeSetInstance_ID(), "M_AttributeSetInstance"); - - Object[] obj = new Object[] { - pb.getDocumentNo(), - pb.getName(), - pb.getValidFrom() == null ? "" : df.format(pb.getValidFrom()), - pb.getValidTo() == null ? "" : df.format(pb.getValidTo()), - pb.getValue(), - p.getName(), - getAttributeSetInstanceInfo(asi, false), - getBOMLinesInfo(pb.getLines()) - }; - - return MessageFormat.format(BOM_INFO_PATTERN, obj); - } - - public String getAttributeSetInstanceInfo(MAttributeSetInstance asi, boolean singleRow) { - - MAttributeSet as = new MAttributeSet(Env.getCtx(), asi.getM_AttributeSet_ID(), null); - - StorageReasoner mr = new StorageReasoner(); - int[] ids = mr.getAttributeIDs(asi); - - MAttributeInstance ai = null; - MAttribute a = null; - MAttributeValue av = null; - - StringBuffer sb = new StringBuffer(); - String value = null; - Object[] obj = null; - for(int i = 0; i < ids.length; i++) { - - ai = new MAttributeInstance(Env.getCtx(), ids[i], asi.get_ID(), (String)null, null); - ai.load(null); - a = new MAttribute(Env.getCtx(), ai.getM_Attribute_ID(), null); - av = new MAttributeValue(Env.getCtx(), ai.getM_AttributeValue_ID(), null); - - // Switchs value to referenced value of M_AttributeValue, if no value is directly available, - // e.g. the list validation type 'L' - if(ai.getValue() == null) { - - value = av.getValue(); - } - // Takes the value of the M_AttributeInstance itself - else { - - // Round number values to a scale of 2, if type is 'N' - if(MAttribute.ATTRIBUTEVALUETYPE_Number.equals(a.getAttributeValueType())) { - - BigDecimal number = ai.getValueNumber(); - value = number.setScale(2, BigDecimal.ROUND_HALF_UP).toString(); - } - else { - - value = ai.getValue(); - } - } - - obj = new Object[] { - a.getName(), - value - }; - - sb.append(MessageFormat.format(ATTRIBUTE_INFO_PATTERN, obj)); - - if(singleRow) { - - sb.append(" "); - } - else { - - sb.append("
    "); - } - } - - return sb.toString(); - } - - public String getStorageInfo(MProduct p, MAttributeSetInstance asi) { - - StorageReasoner mr = new StorageReasoner(); - int[] ids = mr.getPOIDs(MLocator.Table_Name, null, null); - - MWarehouse warehouse = null; - MStorage storage = null; - MLocator locator = null; - StringBuffer sb = new StringBuffer(STORAGE_HEADER_INFO_PATTERN); - Object[] obj = null; - - BigDecimal sumQtyOnHand = BigDecimal.ZERO; - BigDecimal sumQtyReserved = BigDecimal.ZERO; - BigDecimal sumQtyOrdered = BigDecimal.ZERO; - - int count = 0; - for(int i = 0; i < ids.length; i++) { - - storage = MStorage.get(Env.getCtx(), ids[i], p.get_ID(), asi.get_ID(), null); - if(storage == null) { - - continue; - } - count++; - - warehouse = new MWarehouse(Env.getCtx(), storage.getM_Warehouse_ID(), null); - locator = new MLocator(Env.getCtx(), storage.getM_Locator_ID(), null); - - sumQtyOnHand = sumQtyOnHand.add(storage.getQtyOnHand()); - sumQtyReserved = sumQtyReserved.add(storage.getQtyReserved()); - sumQtyOrdered = sumQtyOrdered.add(storage.getQtyOrdered()); - - // the quantities of specific locator - obj = new Object[] { - locator.getX()+" - "+locator.getY()+" - "+locator.getZ(), - warehouse.getName(), - storage.getQtyOnHand(), - storage.getQtyReserved(), - storage.getQtyOrdered(), - storage.getQtyOnHand().subtract(storage.getQtyReserved()) - }; - - sb.append(MessageFormat.format(STORAGE_LINE_INFO_PATTERN, obj)); - } - - // the sum of the single quantities, if there is more than one line - if(count > 1) { - - obj = new Object[] { - sumQtyOnHand, - sumQtyReserved, - sumQtyOrdered, - sumQtyOnHand.subtract(sumQtyReserved) - }; - - sb.append(MessageFormat.format(STORAGE_SUM_LINE_INFO_PATTERN, obj)); - } - - double available = sumQtyOnHand.subtract(sumQtyReserved).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - if(count == 0 || (available <= 0.00d)) { - - sb.append(MessageFormat.format(STORAGE_NOINVENTORY_INFO_PATTERN, obj)); - } - - sb.append(STORAGE_FOOTER_INFO_PATTERN); - - return sb.toString(); - } -} diff --git a/base/src/org/eevolution/process/BankTransfer.java b/base/src/org/eevolution/process/BankTransfer.java deleted file mode 100644 index 4b8105ddd8..0000000000 --- a/base/src/org/eevolution/process/BankTransfer.java +++ /dev/null @@ -1,189 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2008 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.process; - - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.logging.Level; - -import org.compiere.model.MBankAccount; -import org.compiere.model.MPayment; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.AdempiereUserError; -import org.compiere.util.Env; - -/** - * Bank Transfer. Generate two Payments entry - * - * For Bank Transfer From Bank Account "A" - * - * @author victor.perez@e-evoltuion.com - * - **/ -public class BankTransfer extends SvrProcess -{ - private String p_DocumentNo= ""; // Document No - private String p_Description= ""; // Description - private int p_C_BPartner_ID = 0; // Business Partner to be used as bridge - private int p_C_Currency_ID = 0; // Payment Currency - private int p_C_ConversionType_ID = 0; // Payment Conversion Type - private int p_C_Charge_ID = 0; // Charge to be used as bridge - - private BigDecimal p_Amount = new BigDecimal(0); // Amount to be transfered between the accounts - private int p_From_C_BankAccount_ID = 0; // Bank Account From - private int p_To_C_BankAccount_ID= 0; // Bank Account To - private Timestamp p_StatementDate = null; // Date Statement - private Timestamp p_DateAcct = null; // Date Account - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - if (name.equals("From_C_BankAccount_ID")) - p_From_C_BankAccount_ID = para[i].getParameterAsInt(); - else if (name.equals("To_C_BankAccount_ID")) - p_To_C_BankAccount_ID = para[i].getParameterAsInt(); - else if (name.equals("C_BPartner_ID")) - p_C_BPartner_ID = para[i].getParameterAsInt(); - else if (name.equals("C_Currency_ID")) - p_C_Currency_ID = para[i].getParameterAsInt(); - else if (name.equals("C_ConversionType_ID")) - p_C_ConversionType_ID = para[i].getParameterAsInt(); - else if (name.equals("C_Charge_ID")) - p_C_Charge_ID = para[i].getParameterAsInt(); - else if (name.equals("DocumentNo")) - p_DocumentNo = (String)para[i].getParameter(); - else if (name.equals("Amount")) - p_Amount = ((BigDecimal)para[i].getParameter()); - else if (name.equals("Description")) - p_Description = (String)para[i].getParameter(); - else if (name.equals("StatementDate")) - p_StatementDate = (Timestamp)para[i].getParameter(); - else if (name.equals("DateAcct")) - p_DateAcct = (Timestamp)para[i].getParameter(); - else - log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name); - } - } // prepare - - /** - * Perform process. - * @return Message (translated text) - * @throws Exception if not successful - */ - protected String doIt() throws Exception - { - log.info("From Bank="+p_From_C_BankAccount_ID+" - To Bank="+p_To_C_BankAccount_ID - + " - C_BPartner_ID="+p_C_BPartner_ID+"- C_Charge_ID= "+p_C_Charge_ID+" - Amount="+p_Amount+" - DocumentNo="+p_DocumentNo - + " - Description="+p_Description+ " - Statement Date="+p_StatementDate+ - " - Date Account="+p_DateAcct); - - if (p_To_C_BankAccount_ID == 0 || p_From_C_BankAccount_ID == 0) - throw new IllegalArgumentException("Banks required"); - - if (p_DocumentNo == null || p_DocumentNo.length() == 0) - throw new IllegalArgumentException("Document No required"); - - if (p_To_C_BankAccount_ID == p_From_C_BankAccount_ID) - throw new AdempiereUserError ("Banks From and To must be different"); - - if (p_C_BPartner_ID == 0) - throw new AdempiereUserError ("Business Partner required"); - - if (p_C_Currency_ID == 0) - throw new AdempiereUserError ("Currency required"); - - if (p_C_Charge_ID == 0) - throw new AdempiereUserError ("Business Partner required"); - - if (p_Amount.compareTo(new BigDecimal(0)) == 0) - throw new AdempiereUserError ("Amount required"); - - // Login Date - if (p_StatementDate == null) - p_StatementDate = Env.getContextAsDate(getCtx(), "#Date"); - if (p_StatementDate == null) - p_StatementDate = new Timestamp(System.currentTimeMillis()); - - if (p_DateAcct == null) - p_DateAcct = p_StatementDate; - - generateBankTransfer(); - - return "@OK@ "; - } // doIt - - - /** - * Generate BankTransfer() - * - */ - private void generateBankTransfer() - { - - MBankAccount mBankFrom = new MBankAccount(getCtx(),p_From_C_BankAccount_ID, get_TrxName()); - MBankAccount mBankTo = new MBankAccount(getCtx(),p_To_C_BankAccount_ID, get_TrxName()); - - MPayment paymentBankFrom = new MPayment(getCtx(), 0 , get_TrxName()); - paymentBankFrom.setC_BankAccount_ID(mBankFrom.getC_BankAccount_ID()); - paymentBankFrom.setDocumentNo(p_DocumentNo); - paymentBankFrom.setDateAcct(p_DateAcct); - paymentBankFrom.setDateTrx(p_StatementDate); - paymentBankFrom.setTenderType(MPayment.TENDERTYPE_DirectDeposit); - paymentBankFrom.setDescription(p_Description); - paymentBankFrom.setC_BPartner_ID (p_C_BPartner_ID); - paymentBankFrom.setC_Currency_ID(p_C_Currency_ID); - if (p_C_ConversionType_ID > 0) - paymentBankFrom.setC_ConversionType_ID(p_C_ConversionType_ID); - paymentBankFrom.setPayAmt(p_Amount); - paymentBankFrom.setOverUnderAmt(Env.ZERO); - paymentBankFrom.setC_DocType_ID(false); - paymentBankFrom.setC_Charge_ID(p_C_Charge_ID); - paymentBankFrom.save(); - paymentBankFrom.processIt(MPayment.DOCACTION_Complete); - paymentBankFrom.saveEx(); - - MPayment paymentBankTo = new MPayment(getCtx(), 0 , get_TrxName()); - paymentBankTo.setC_BankAccount_ID(mBankTo.getC_BankAccount_ID()); - paymentBankTo.setDocumentNo(p_DocumentNo); - paymentBankTo.setDateAcct(p_DateAcct); - paymentBankTo.setDateTrx(p_StatementDate); - paymentBankTo.setTenderType(MPayment.TENDERTYPE_DirectDeposit); - paymentBankTo.setDescription(p_Description); - paymentBankTo.setC_BPartner_ID (p_C_BPartner_ID); - paymentBankTo.setC_Currency_ID(p_C_Currency_ID); - if (p_C_ConversionType_ID > 0) - paymentBankFrom.setC_ConversionType_ID(p_C_ConversionType_ID); - paymentBankTo.setPayAmt(p_Amount); - paymentBankTo.setOverUnderAmt(Env.ZERO); - paymentBankTo.setC_DocType_ID(true); - paymentBankTo.setC_Charge_ID(p_C_Charge_ID); - paymentBankTo.save(); - paymentBankTo.processIt(MPayment.DOCACTION_Complete); - paymentBankTo.saveEx(); - - return; - - } // createCashLines - -} // ImmediateBankTransfer diff --git a/base/src/org/eevolution/process/ComponentChange.java b/base/src/org/eevolution/process/ComponentChange.java deleted file mode 100644 index 74465ca4d2..0000000000 --- a/base/src/org/eevolution/process/ComponentChange.java +++ /dev/null @@ -1,185 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.process; - - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import org.adempiere.exceptions.AdempiereException; -import org.adempiere.exceptions.FillMandatoryException; -import org.compiere.model.MRefList; -import org.compiere.model.Query; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.eevolution.model.MPPProductBOMLine; - - -/** - * Component Change into BOM - * - * @author victor.perez@e-evolution.com - * @version $Id: ComponentChange.java - * - * @author Teo Sarca, www.arhipac.ro - */ -public class ComponentChange extends SvrProcess -{ - private static final int ACTION_AD_Reference_ID = 53227; - private static final String ACTION_Add = "A"; - private static final String ACTION_Deactivate = "D"; - private static final String ACTION_Expire = "E"; - private static final String ACTION_Replace = "R"; - private static final String ACTION_ReplaceAndExpire = "RE"; - - private int p_M_Product_ID = 0; - private Timestamp p_ValidTo = null; - private Timestamp p_ValidFrom = null; - private String p_Action; - private int p_New_M_Product_ID =0; - private BigDecimal p_Qty = null; - private int p_M_ChangeNotice_ID=0; - - @Override - protected void prepare() - { - int morepara = 0; - - for (ProcessInfoParameter para : getParameter()) - { - String name = para.getParameterName(); - - if (para.getParameter() == null) - ; - else if (name.equals("M_Product_ID") && morepara == 0) - { - p_M_Product_ID = para.getParameterAsInt(); - morepara = 1; - } - else if (name.equals("ValidTo")) - p_ValidTo = ((Timestamp)para.getParameter()); - else if (name.equals("ValidFrom")) - p_ValidFrom = ((Timestamp)para.getParameter()); - else if (name.equals("Action")) - p_Action = ((String)para.getParameter()); - else if (name.equals("M_Product_ID")) - p_New_M_Product_ID = para.getParameterAsInt(); - else if (name.equals("Qty")) - p_Qty = ((BigDecimal)para.getParameter()); - else if (name.equals("M_ChangeNotice_ID")) - p_M_ChangeNotice_ID = para.getParameterAsInt(); - else - log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); - } - } // prepare - - @Override - protected String doIt() throws Exception - { - if (p_Action == null) - { - throw new FillMandatoryException("Action"); - } - - List params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - - whereClause.append(MPPProductBOMLine.COLUMNNAME_M_Product_ID+"=?"); - params.add(p_M_Product_ID); - - if (p_ValidTo != null) - { - whereClause.append(" AND TRUNC("+MPPProductBOMLine.COLUMNNAME_ValidTo+") <= ?"); - params.add(p_ValidTo); - } - if (p_ValidFrom != null) - { - whereClause.append(" AND TRUNC("+MPPProductBOMLine.COLUMNNAME_ValidFrom+") >= ?"); - params.add(p_ValidFrom); - } - - List components = new Query(getCtx(), MPPProductBOMLine.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(params) - .list(); - for(MPPProductBOMLine bomline : components) - { - if (p_Action.equals(ACTION_Add)) - { - actionAdd(bomline, 0); - } - else if (p_Action.equals(ACTION_Deactivate)) - { - actionDeactivate(bomline); - } - else if (p_Action.equals(ACTION_Expire)) - { - actionExpire(bomline); - } - else if (p_Action.equals(ACTION_Replace)) - { - actionAdd(bomline, bomline.getLine() + 1); - actionDeactivate(bomline); - } - else if (p_Action.equals(ACTION_ReplaceAndExpire)) - { - actionAdd(bomline, bomline.getLine() + 1); - actionExpire(bomline); - } - else - { - throw new AdempiereException("Action not supported - "+p_Action); - } - addLog(MRefList.getListName(getCtx(), ACTION_AD_Reference_ID, p_Action)); - } - return "@OK@"; - } // doIt - - protected void actionAdd(MPPProductBOMLine bomline, int line) - { - MPPProductBOMLine newbomline = new MPPProductBOMLine(getCtx(), 0, get_TrxName()); - MPPProductBOMLine.copyValues(bomline, newbomline); - newbomline.setIsActive(true); - newbomline.setLine(line); - newbomline.setM_ChangeNotice_ID(p_M_ChangeNotice_ID); - // - newbomline.setM_Product_ID(p_New_M_Product_ID); - if (p_Qty.signum() != 0) - { - newbomline.setQtyBOM(p_Qty); - } - newbomline.setValidFrom(newbomline.getUpdated()); - newbomline.saveEx(); - } - - protected void actionDeactivate(MPPProductBOMLine bomline) - { - bomline.setIsActive(false); - bomline.setM_ChangeNotice_ID(p_M_ChangeNotice_ID); - bomline.saveEx(); - } - - protected void actionExpire(MPPProductBOMLine bomline) - { - bomline.setIsActive(true); - bomline.setValidTo(bomline.getUpdated()); - bomline.setM_ChangeNotice_ID(p_M_ChangeNotice_ID); - bomline.saveEx(); - } -} // Component Change diff --git a/base/src/org/eevolution/process/CopyFromBOM.java b/base/src/org/eevolution/process/CopyFromBOM.java deleted file mode 100644 index 8c33cec0d1..0000000000 --- a/base/src/org/eevolution/process/CopyFromBOM.java +++ /dev/null @@ -1,98 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.process; - -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.AdempiereSystemError; -import org.compiere.util.Env; -import org.eevolution.model.MPPProductBOM; -import org.eevolution.model.MPPProductBOMLine; - -/** - * CopyFromBOM Process - * Copies BOM Lines from Selected BOM to the Current BOM - * The BOM being copied to must have no pre-existing BOM Lines - * - * @author Tony Snook - * @version $Id: CopyFromBOM.java,v 1.0 2008/07/04 05:24:03 tspc Exp $ - */ -public class CopyFromBOM extends SvrProcess { - /** */ - private int p_Record_ID = 0; - private int p_PP_Product_BOM_ID = 0; - private int no = 0; - private Properties ctx = Env.getCtx(); - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() { - ProcessInfoParameter[] para = getParameter(); - - for (int i = 0; i < para.length; i++) { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) - ; - else if (name.equals("PP_Product_BOM_ID")) - p_PP_Product_BOM_ID = para[i].getParameterAsInt(); - else - log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name); - } - p_Record_ID = getRecord_ID(); - - } // prepare - - protected String doIt() throws Exception { - - log.info("From PP_Product_BOM_ID=" + p_PP_Product_BOM_ID + " to " + p_Record_ID); - if (p_Record_ID == 0) - throw new IllegalArgumentException("Target PP_Product_BOM_ID == 0"); - if (p_PP_Product_BOM_ID == 0) - throw new IllegalArgumentException("Source PP_Product_BOM_ID == 0"); - - MPPProductBOM fromBom = new MPPProductBOM(ctx, p_PP_Product_BOM_ID, get_TrxName()); - MPPProductBOM toBOM = new MPPProductBOM(ctx, p_Record_ID, get_TrxName()); - if (toBOM.getLines().length > 0) - throw new AdempiereSystemError("@Error@ Existing BOM Line(s)"); - - MPPProductBOMLine[] frombomlines = fromBom.getLines(); - for (MPPProductBOMLine frombomline : frombomlines) { - MPPProductBOMLine tobomline = new MPPProductBOMLine(ctx, 0, get_TrxName()); - MPPProductBOMLine.copyValues(frombomline, tobomline); - tobomline.setPP_Product_BOM_ID(toBOM.getPP_Product_BOM_ID()); - tobomline.save(); - ++no; - } - return "OK"; - } - - /** - * Post process actions (outside trx). - * - * @param success true if the process was success - * @since 3.1.4 - */ - protected void postProcess(boolean success) { - - this.addLog("@Copied@=" + no); - - } -} diff --git a/base/src/org/eevolution/process/DistributionRunOrders.java b/base/src/org/eevolution/process/DistributionRunOrders.java deleted file mode 100644 index 6201a5676d..0000000000 --- a/base/src/org/eevolution/process/DistributionRunOrders.java +++ /dev/null @@ -1,375 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.process; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.logging.Level; - -import org.compiere.model.MDistributionRun; -import org.compiere.model.MDistributionRunLine; -import org.compiere.model.MDocType; -import org.compiere.model.MPInstance; -import org.compiere.model.MPInstancePara; -import org.compiere.model.MProcess; -import org.compiere.model.MStorage; -import org.compiere.process.ProcessInfo; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.compiere.util.Trx; - -/** - * DistributionRun Orders - * @author victor.perez@e-evolution.com - *
  • FR Let use the Distribution List and Distribution Run for DO - * @see http://sourceforge.net/tracker/index.php?func=detail&aid=2030865&group_id=176962&atid=879335 - */ -public class DistributionRunOrders extends SvrProcess -{ - /** The Run to execute */ - - private int p_M_DistributionList_ID = 0; - - - /** Date Promised */ - private Timestamp p_DatePromised = null; - /** Date Promised */ - //private Timestamp p_DatePromised_To = null; - /** Organization */ - private int p_AD_Org_ID = 0; - /** Is Only Test */ - private String p_IsTest = "N"; - /** Warehouse */ - private int p_M_Warehouse_ID = 0; - /** Create Distribution Order Consolidate */ - private String p_ConsolidateDocument = "N"; - /** Create Distribution Based in the DRP Demand */ - private String p_BasedInDamnd = "N"; - - private MDistributionRun m_run = null; - - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - - if (para[i].getParameter() == null) - ; - else if (name.equals("AD_Org_ID")) - p_AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue(); - else if (name.equals("M_Warehouse_ID")) - p_M_Warehouse_ID = ((BigDecimal)para[i].getParameter()).intValue(); - else if (name.equals("M_DistributionList_ID")) - p_M_DistributionList_ID = ((BigDecimal)para[i].getParameter()).intValue(); - else if (name.equals("DatePromised")) - { - p_DatePromised = (Timestamp)para[i].getParameter(); - //p_DatePromised_To = (Timestamp)para[i].getParameter_To(); - } - else if(name.equals("ConsolidateDocument")) - p_ConsolidateDocument = (String)para[i].getParameter(); - else if (name.equals("IsRequiredDRP")) - p_BasedInDamnd = (String)para[i].getParameter(); - else if (name.equals("IsTest")) - p_IsTest = (String)para[i].getParameter(); - else - log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); - } - - } // prepare - - - /** - * doIT - run process - */ - protected String doIt() throws Exception - { - if(p_BasedInDamnd.equals("Y")) - { - if(!generateDistributionDemand()) - throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); - } - else - { - if(!generateDistribution()) - throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); - } - - if(!executeDistribution()) - throw new Exception(Msg.getMsg(getCtx(), "ProcessFailed"),CLogger.retrieveException()); - - return Msg.getMsg(getCtx(), "ProcessOK"); - } - - //Create Distribution Run Line - public boolean generateDistribution() - { - m_run = new MDistributionRun(this.getCtx(), 0 , this.get_TrxName()); - m_run.setName("Generate from DRP " + p_DatePromised); - //m_run.setDescription("Generate from DRP"); - m_run.save(); - - StringBuffer sql = new StringBuffer("SELECT M_Product_ID , SUM (QtyOrdered-QtyDelivered) AS TotalQty, l.M_Warehouse_ID FROM DD_OrderLine ol INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_Locator_ID) INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) "); - sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised <= ? AND l.M_Warehouse_ID=? GROUP BY M_Product_ID"); - - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql.toString(),get_TrxName()); - pstmt.setTimestamp(1, p_DatePromised); - //pstmt.setTimestamp(2, p_DatePromised_To); - pstmt.setInt(2, p_M_Warehouse_ID); - - rs = pstmt.executeQuery(); - int line = 10; - while (rs.next()) - { - int M_Product_ID = rs.getInt("M_Product_ID"); - BigDecimal QtyAvailable = MStorage.getQtyAvailable(p_M_Warehouse_ID,0 , M_Product_ID , 0, get_TrxName()); - BigDecimal QtyOrdered = rs.getBigDecimal("TotalQty"); - - MDistributionRunLine m_runLine = new MDistributionRunLine(getCtx(),0 ,get_TrxName()); - m_runLine.setM_DistributionRun_ID(m_run.getM_DistributionRun_ID()); - m_runLine.setAD_Org_ID(p_AD_Org_ID); - m_runLine.setM_DistributionList_ID(p_M_DistributionList_ID); - m_runLine.setLine(line); - m_runLine.setM_Product_ID(M_Product_ID); - m_runLine.setDescription(Msg.getMsg(getCtx(), "QtyAvailable") +" : " + QtyAvailable + " " +Msg.getMsg(getCtx(), "QtyOrdered") + " : " + QtyOrdered); - if(QtyOrdered.compareTo(QtyAvailable) > 0) - { - QtyOrdered = QtyAvailable; - } - m_runLine.setTotalQty(QtyOrdered); - m_runLine.save(); - line += 10; - } - } - catch (Exception e) - { - log.log(Level.SEVERE,"doIt - " + sql, e); - return false; - } - finally - { - DB.close(rs, pstmt); - rs = null; - pstmt = null; - } - - return true; - } - - //Create Distribution Run Line - public boolean generateDistributionDemand() - { - m_run = new MDistributionRun(this.getCtx(), 0 , null); - m_run.setName("Generate from DRP " + p_DatePromised); - m_run.save(); - - StringBuffer sql = new StringBuffer("SELECT M_Product_ID , SUM (TargetQty) AS MinQty, SUM (QtyOrdered-QtyDelivered) AS TotalQty FROM DD_OrderLine ol INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_Locator_ID) INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) "); - sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised <= ? AND l.M_Warehouse_ID=? GROUP BY M_Product_ID"); - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql.toString(),get_TrxName()); - pstmt.setTimestamp(1, p_DatePromised); - //pstmt.setTimestamp(2, p_DatePromised_To); - pstmt.setInt(2, p_M_Warehouse_ID); - - rs = pstmt.executeQuery(); - int line = 10; - while (rs.next()) - { - int M_Product_ID = rs.getInt("M_Product_ID"); - BigDecimal QtyAvailable = MStorage.getQtyAvailable(p_M_Warehouse_ID,0 , M_Product_ID , 0, get_TrxName()); - if(QtyAvailable.signum()<= 0) - continue; - BigDecimal QtyToDistribute = rs.getBigDecimal("TotalQty"); - if(QtyAvailable.compareTo(QtyToDistribute) >= 0) - QtyAvailable = QtyToDistribute; - else - { - BigDecimal QtyReserved = getTargetQty(M_Product_ID); - QtyToDistribute = QtyAvailable.subtract(QtyReserved); - } - - //if(QtyToDistribute.equals(Env.ZERO)) - // continue; - - MDistributionRunLine m_runLine = new MDistributionRunLine(getCtx(),0 ,get_TrxName()); - m_runLine.setM_DistributionRun_ID(m_run.getM_DistributionRun_ID()); - m_runLine.setAD_Org_ID(p_AD_Org_ID); - m_runLine.setM_DistributionList_ID(p_M_DistributionList_ID); - m_runLine.setLine(line); - m_runLine.setM_Product_ID(M_Product_ID); - m_runLine.setDescription(Msg.translate(getCtx(), "QtyAvailable") +" : " + QtyAvailable + " " +Msg.translate(getCtx(), "QtyOrdered") + " : " + QtyToDistribute); - //m_runLine.setMinQty(rs.getBigDecimal("MinQty")); - - - m_runLine.setTotalQty(QtyToDistribute); - m_runLine.saveEx(); - line += 10; - } - } - catch (Exception e) - { - log.log(Level.SEVERE,"doIt - " + sql, e); - return false; - } - finally - { - DB.close(rs, pstmt); - rs = null; - pstmt = null; - } - - return true; - } - /** - * Get Qty TargetQty for a Warehouse - * @param M_Product_ID - * @return - */ - private BigDecimal getTargetQty(int M_Product_ID) - { - StringBuffer sql = new StringBuffer("SELECT SUM (TargetQty) FROM DD_OrderLine ol INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_Locator_ID) INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) "); - sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised <= ? AND l.M_Warehouse_ID=? AND ol.M_Product_ID=? GROUP BY M_Product_ID"); - BigDecimal qty = DB.getSQLValueBD(get_TrxName(), sql.toString(), new Object[]{p_DatePromised, p_M_Warehouse_ID, M_Product_ID}); - // SQL may return no rows or null - if (qty == null) - return Env.ZERO; - - return qty; - } - - /** - * Execute Distribution Run - * @return - * @throws Exception - */ - public boolean executeDistribution() throws Exception - { - - int M_DocType_ID = 0; - MDocType[] doc = MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_DistributionOrder); - - if (doc==null || doc.length == 0) - { - log.severe ("Not found default document type for docbasetype " + MDocType.DOCBASETYPE_DistributionOrder); - throw new Exception(Msg.getMsg(getCtx(), "SequenceDocNotFound"),CLogger.retrieveException()); - } - else - M_DocType_ID = doc[0].getC_DocType_ID(); - - String trxName = Trx.createTrxName("Run Distribution to DRP"); - Trx trx = Trx.get(trxName, true); //trx needs to be committed too - - //Prepare Process - int AD_Process_ID = 271; - AD_Process_ID = MProcess.getProcess_ID("M_DistributionRun Create",get_TrxName()); - - MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0); - if (!instance.save()) - { - throw new Exception(Msg.getMsg(getCtx(), "ProcessNoInstance"),CLogger.retrieveException()); - } - - //call process - ProcessInfo pi = new ProcessInfo ("M_DistributionRun Orders", AD_Process_ID); - pi.setAD_PInstance_ID (instance.getAD_PInstance_ID()); - pi.setRecord_ID(m_run.getM_DistributionRun_ID()); - // Add Parameter - Selection=Y - MPInstancePara ip = new MPInstancePara(instance, 10); - ip.setParameter("C_DocType_ID", M_DocType_ID ); - if (!ip.save()) - { - String msg = "No Parameter added"; // not translated - throw new Exception(msg,CLogger.retrieveException()); - } - // Add Parameter - DatePromised - ip = new MPInstancePara(instance, 20); - ip.setParameter("DatePromised", ""); - ip.setP_Date(p_DatePromised); - //ip.setP_Date_To(p_DatePromised_To); - if (!ip.save()) - { - String msg = "No Parameter added"; // not translated - throw new Exception(msg,CLogger.retrieveException()); - } - // Add Parameter - M_Warehouse_ID - ip = new MPInstancePara(instance, 30); - ip.setParameter("M_Warehouse_ID",p_M_Warehouse_ID); - if (!ip.save()) - { - String msg = "No Parameter added"; // not translated - throw new Exception(msg,CLogger.retrieveException()); - } - // Add Parameter - CreateDO - ip = new MPInstancePara(instance, 40); - ip.setParameter("ConsolidateDocument",p_ConsolidateDocument); - if (!ip.save()) - { - String msg = "No Parameter added"; // not translated - throw new Exception(msg,CLogger.retrieveException()); - } - // Add Parameter - IsTest=Y - ip = new MPInstancePara(instance, 50); - ip.setParameter("IsTest",p_IsTest); - if (!ip.save()) - { - String msg = "No Parameter added"; // not translated - throw new Exception(msg,CLogger.retrieveException()); - } - //Distribution List - ip = new MPInstancePara(instance, 60); - ip.setParameter("M_DistributionList_ID",p_M_DistributionList_ID); - if (!ip.save()) - { - String msg = "No Parameter added"; // not translated - throw new Exception(msg,CLogger.retrieveException()); - } - //Based in DRP Demand - ip = new MPInstancePara(instance, 70); - ip.setParameter("IsRequiredDRP",p_BasedInDamnd); - if (!ip.save()) - { - String msg = "No Parameter added"; // not translated - throw new Exception(msg,CLogger.retrieveException()); - } - - // Execute Process - MProcess worker = new MProcess(getCtx(),AD_Process_ID,get_TrxName()); - worker.processIt(pi, Trx.get(get_TrxName(), true)); - m_run.delete(true); - return true; - } -} diff --git a/base/src/org/eevolution/process/EnableNativeSequence.java b/base/src/org/eevolution/process/EnableNativeSequence.java deleted file mode 100644 index 5b1b7e23d4..0000000000 --- a/base/src/org/eevolution/process/EnableNativeSequence.java +++ /dev/null @@ -1,103 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.process; - - - -import java.util.List; -import java.util.logging.Level; - -import org.adempiere.exceptions.AdempiereException; -import org.compiere.Adempiere; -import org.compiere.model.MSequence; -import org.compiere.model.MSysConfig; -import org.compiere.model.MTable; -import org.compiere.model.Query; -import org.compiere.model.X_AD_Table; -import org.compiere.process.SvrProcess; -import org.compiere.util.CLogMgt; -import org.compiere.util.DB; - -/** - * Enable Native Sequence - * - * @author Victor Perez, e-Evolution, S.C. - */ -public class EnableNativeSequence extends SvrProcess -{ - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - } // prepare - - protected String doIt() - { - boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue("SYSTEM_NATIVE_SEQUENCE",false); - - if(SYSTEM_NATIVE_SEQUENCE) - throw new AdempiereException("Native Sequence is Actived"); - else - { - DB.executeUpdateEx("UPDATE AD_SysConfig SET Value='Y' WHERE Name='SYSTEM_NATIVE_SEQUENCE'",null); - MSysConfig.resetCache(); - } - - List tables = new Query(getCtx(),X_AD_Table.Table_Name,"", get_TrxName()).list(); - for(MTable table : tables) - { - if(!table.isView()) - { - if(!MSequence.createTableSequence(getCtx(), table.getTableName(), get_TrxName())) - { - DB.executeUpdateEx("UPDATE AD_SysConfig SET Value='N' WHERE Name='SYSTEM_NATIVE_SEQUENCE'",null); - MSysConfig.resetCache(); - new AdempiereException("Can not create Native Sequence"); - } - else - { - this.addLog("Create Native Sequence for : "+table.getTableName()); - } - } - } - - - return "@OK@"; - } - - /** - * Main test - * @param args - * @throws Exception - */ - public static void main(String[] args) - { - - try { - Adempiere.startupEnvironment(true); - CLogMgt.setLevel(Level.ALL); - EnableNativeSequence seqs = new EnableNativeSequence(); - seqs.doIt(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } -} - diff --git a/base/src/org/eevolution/process/Export.java b/base/src/org/eevolution/process/Export.java deleted file mode 100644 index 1ce937fe54..0000000000 --- a/base/src/org/eevolution/process/Export.java +++ /dev/null @@ -1,408 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - e-Evolution (http://www.e-evolution.com/) * - **********************************************************************/ - -package org.eevolution.process; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.logging.Level; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.compiere.model.MClient; -import org.compiere.model.MColumn; -import org.compiere.model.MTable; -import org.compiere.model.PO; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.eevolution.model.MEXPFormat; -import org.eevolution.model.MEXPFormatLine; -import org.eevolution.model.X_EXP_FormatLine; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Text; - -/** - * - * @author Trifon Trifonov - * @version $Id: $ - */ -public class Export extends SvrProcess -{ - private static final String TOTAL_SEGMENTS = "${totalSegments}"; - - /** Client Parameter */ - protected int p_AD_Client_ID = 0; - - /** Table Parameter */ - protected int p_AD_Table_ID = 0; - - /** Record ID */ - protected int p_Record_ID = 0; - - /** XML Document */ - private Document outDocument = null; - - /** Date Time Format */ -// private SimpleDateFormat m_dateTimeFormat = null; - - /** Date Format */ -// private SimpleDateFormat m_dateFormat = null; - - /** Custom Date Format */ -// private SimpleDateFormat m_customDateFormat = null; - - /** Table ID */ - int AD_Table_ID = 0; - - /** - * Get Parameters - */ - protected void prepare () - { - - p_Record_ID = getRecord_ID(); - if (p_AD_Client_ID == 0) - p_AD_Client_ID = Env.getAD_Client_ID(getCtx()); - AD_Table_ID = getTable_ID(); - - // C_Invoice; AD_Table_ID = 318 - StringBuffer sb = new StringBuffer ("AD_Table_ID=").append(AD_Table_ID); - sb.append("; Record_ID=").append(getRecord_ID()); - // Parameter - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) - ; - else if (name.equals("AD_Table_ID")) - p_AD_Table_ID = para[i].getParameterAsInt(); - else - log.log(Level.SEVERE, "Unknown Parameter: " + name); - } - - // TODO - we can get Language from Business Partner -// m_dateTimeFormat = DisplayType.getDateFormat(DisplayType.DateTime, Env.getLanguage(getCtx())); -// m_dateFormat = DisplayType.getDateFormat(DisplayType.Date, Env.getLanguage(getCtx())); - // - log.info(sb.toString()); - } - - // create new Document - Document createNewDocument() throws ParserConfigurationException { - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - return documentBuilder.newDocument(); - - } - - /** - * Process - Generate Export Format - * @return info - */ - @SuppressWarnings("unchecked") - protected String doIt () throws Exception - { - outDocument = createNewDocument(); - - MClient client = MClient.get (getCtx(), p_AD_Client_ID); - log.info(client.toString()); - // TODO - get proper Export Format! - int EXP_Format_ID = 1000000; - - MTable table = MTable.get(getCtx(), AD_Table_ID); - log.info("Table = " + table); - PO po = table.getPO (p_Record_ID, get_TrxName()); - - if (po.get_KeyColumns().length > 1 || po.get_KeyColumns().length < 1) { - throw new Exception(Msg.getMsg (getCtx(), "ExportMultiColumnNotSupported")); - } - MEXPFormat exportFormat = new MEXPFormat(getCtx(), EXP_Format_ID, get_TrxName()); - - StringBuffer sql = new StringBuffer("SELECT * ") - .append("FROM ").append(table.getTableName()).append(" ") - .append("WHERE ").append(po.get_KeyColumns()[0]).append("=?") - ; - - if (exportFormat.getWhereClause() != null & !"".equals(exportFormat.getWhereClause())) { - sql.append(" AND ").append(exportFormat.getWhereClause()); - } - - ResultSet rs = null; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - pstmt.setInt(1, p_Record_ID); - rs = pstmt.executeQuery(); - if (rs.next()) - { - HashMap variableMap = new HashMap(); - variableMap.put(TOTAL_SEGMENTS, new Integer(1)); - - Element rootElement = outDocument.createElement(exportFormat.getValue()); - rootElement.appendChild(outDocument.createComment(exportFormat.getDescription())); - outDocument.appendChild(rootElement); - generateExportFormat(rootElement, exportFormat, rs, po, p_Record_ID, variableMap); - } - - } finally { - try { - if (rs != null) rs.close(); - if (pstmt != null) pstmt.close(); - } catch (SQLException ex) {/*ignored*/} - rs = null; - pstmt = null; - } - -/* int C_EDIProcessorType_ID = ediProcessor.getC_EDIProcessorType_ID(); - X_C_EDIProcessorType ediProcessType = new X_C_EDIProcessorType(getCtx(), C_EDIProcessorType_ID, get_TrxName() ); - - String javaClass = ediProcessType.getJavaClass(); - try { - Class clazz = Class.forName(javaClass); - IOutbandEdiProcessor outbandProcessor = (IOutbandEdiProcessor)clazz.newInstance(); - - outbandProcessor.process(getCtx(), ediProcessor, result.toString(), "C_Invoice-"+p_Record_ID+".txt", Trx.get( get_TrxName(), false )); - } catch (Exception e) { - result = new StringBuffer( e.toString() ); - } -*/ - addLog(0, null, null, Msg.getMsg (getCtx(), "ExportProcessResult") + "\n" + outDocument.toString()); - return outDocument.toString(); - } - - - /* - * Trifon Generate Export Format process; RESULT = - * - * 101 - * - */ - private void generateExportFormat(Element rootElement, MEXPFormat exportFormat, ResultSet rs, PO masterPO, int masterID, HashMap variableMap) throws SQLException, Exception - { - MEXPFormatLine[] formatLines = (MEXPFormatLine[]) exportFormat.getFormatLines(); - @SuppressWarnings("unused") - boolean elementHasValue = false; - - for (int i = 0; i < formatLines.length; i++) { - if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_XMLElement) ) { - // process single XML Attribute - // Create new element - Element newElement = outDocument.createElement(formatLines[i].getValue()); - - if (formatLines[i].getAD_Column_ID() == 0) { - throw new Exception(Msg.getMsg (getCtx(), "EXPColumnMandatory")); - } - MColumn column = MColumn.get(getCtx(), formatLines[i].getAD_Column_ID()); - if (column == null) { - throw new Exception(Msg.getMsg (getCtx(), "EXPColumnMandatory")); - } - if ( column.isVirtualColumn() ) { - log.info("This is Virtual Column!"); - } else { } - //log.info("["+column.getColumnName()+"]"); - - Object value = rs.getObject(column.getColumnName()); - String valueString = null; - if (value != null) { - valueString = value.toString(); - } else { - if (formatLines[i].isMandatory()) { - throw new Exception(Msg.getMsg (getCtx(), "EXPFieldMandatory")); - } - } -/* if (column.getAD_Reference_ID() == DisplayType.Date) { - if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" - //Date date = m_customDateFormat.parse ( valueString ); - valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); - } else { - valueString = m_dateFormat.format (Timestamp.valueOf (valueString)); - } - - } - } else if (column.getAD_Reference_ID() == DisplayType.DateTime) { - if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" - //Date date = m_customDateFormat.parse ( valueString ); - valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); - } else { - valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString)); - } - } - }*/ - log.info("EXP Field - column=["+column.getColumnName()+"]; value=" + value); - if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) { - Text newText = outDocument.createTextNode(valueString); - newElement.appendChild(newText); - rootElement.appendChild(newElement); - elementHasValue = true; - //increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable - //increaseVariable(variableMap, TOTAL_SEGMENTS); - } else { - // Empty field. - } - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_XMLAttribute) ) { - // process single XML Attribute -/* // Create new element - Element newElement = outDocument.createElement(formatLines[i].getValue()); - if (hasContent) { - rootElement.appendChild(newElement); - }*/ - if (formatLines[i].getAD_Column_ID() == 0) { - throw new Exception(Msg.getMsg (getCtx(), "EXPColumnMandatory")); - } - MColumn column = MColumn.get(getCtx(), formatLines[i].getAD_Column_ID()); - if (column == null) { - throw new Exception(Msg.getMsg (getCtx(), "EXPColumnMandatory")); - } - if ( column.isVirtualColumn() ) { - log.info("This is Virtual Column!"); - } else { } - //log.info("["+column.getColumnName()+"]"); - - Object value = rs.getObject(column.getColumnName()); - String valueString = null; - if (value != null) { - valueString = value.toString(); - } else { - if (formatLines[i].isMandatory()) { - throw new Exception(Msg.getMsg (getCtx(), "EXPFieldMandatory")); - } - } -/* if (column.getAD_Reference_ID() == DisplayType.Date) { - if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" - //Date date = m_customDateFormat.parse ( valueString ); - valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); - } else { - valueString = m_dateFormat.format (Timestamp.valueOf (valueString)); - } - - } - } else if (column.getAD_Reference_ID() == DisplayType.DateTime) { - if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" - //Date date = m_customDateFormat.parse ( valueString ); - valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); - } else { - valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString)); - } - } - }*/ - log.info("EXP Field - column=["+column.getColumnName()+"]; value=" + value); - if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) { - rootElement.setAttribute(formatLines[i].getValue(), valueString); - elementHasValue = true; - //increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable - //increaseVariable(variableMap, TOTAL_SEGMENTS); - } else { - // Empty field. - } - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_EmbeddedEXPFormat) ) { - // process Embedded Export Format - - int embeddedFormat_ID = formatLines[i].getEXP_EmbeddedFormat_ID(); - MEXPFormat embeddedFormat = new MEXPFormat(getCtx(), embeddedFormat_ID, get_TrxName()); - - MTable tableEmbedded = MTable.get(getCtx(), embeddedFormat.getAD_Table_ID()); - log.info("Table Embedded = " + tableEmbedded); - StringBuffer sql = new StringBuffer("SELECT * ") - .append("FROM ").append(tableEmbedded.getTableName()).append(" ") - .append("WHERE ").append(masterPO.get_KeyColumns()[0]).append("=?") - //+ "WHERE " + po.get_WhereClause(false) - ; - if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) { - sql.append(" AND ").append(embeddedFormat.getWhereClause()); - } - ResultSet rsEmbedded = null; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - pstmt.setInt(1, masterID); - rsEmbedded = pstmt.executeQuery(); - while (rsEmbedded.next()) - { - //System.out.println("Trifon - tableEmbedded.getTableName()_ID = "+ tableEmbedded.getTableName() + "_ID"); - int embeddedID = rsEmbedded.getInt(tableEmbedded.getTableName() + "_ID"); - PO poEmbedded = tableEmbedded.getPO (embeddedID, get_TrxName()); - - Element embeddedElement = outDocument.createElement(formatLines[i].getValue()); - embeddedElement.appendChild(outDocument.createComment(formatLines[i].getDescription())); - generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap); - rootElement.appendChild(embeddedElement); - } - - } finally { - try { - if (rsEmbedded != null) rsEmbedded.close(); - if (pstmt != null) pstmt.close(); - } catch (SQLException ex) { } - rsEmbedded = null; - pstmt = null; - } - - } else { - throw new Exception(Msg.getMsg (getCtx(), "EXPUnknownLineType")); - } - } - } - - /** - * @param variableMap - * @param variableName - */ - @SuppressWarnings("unused") - private void increaseVariable(HashMap variableMap, String variableName) { - if (variableName != null && !"".equals(variableName) ) { - Integer var = variableMap.get(variableName); - if (var == null) { - var = new Integer(0); - } - int intValue = var.intValue(); - intValue++; - variableMap.put(variableName, new Integer(intValue)); - } - } - -} diff --git a/base/src/org/eevolution/process/ExportFormatGenerator.java b/base/src/org/eevolution/process/ExportFormatGenerator.java deleted file mode 100644 index d5097cdc65..0000000000 --- a/base/src/org/eevolution/process/ExportFormatGenerator.java +++ /dev/null @@ -1,324 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.process; - -import java.util.Hashtable; -import java.util.logging.Level; - -import org.compiere.model.MColumn; -import org.compiere.model.MTab; -import org.compiere.model.MTable; -import org.compiere.model.MWindow; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.eevolution.model.MEXPFormat; -import org.eevolution.model.MEXPFormatLine; - - - -/** - * Create a Export Format from a Window - * - * @author Victor Perez www.e-evolution.com - * @version $Id: ExportFormatGenerator.java,v 1.0 - */ -public class ExportFormatGenerator extends SvrProcess -{ - - private int p_AD_Window_ID = 0; - private boolean p_IsMandatory = false; - private boolean p_IsInsertRecord= false; - private Hashtable m_formats = new Hashtable(); - private String m_parent_table = null; - private String m_format_value = null; - private int m_level = -1; - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) - ; - else if (name.equals("AD_Window_ID")) - p_AD_Window_ID = para[i].getParameterAsInt(); - else if (name.equals("IsMandatory")) - { - p_IsMandatory = "Y".equals(para[i].getParameter()); - } - else if (name.equals("IsInsertRecord")) - { - p_IsInsertRecord = "Y".equals(para[i].getParameter()); - } - else - log.log(Level.SEVERE, "Unknown Parameter: " + name); - } - } // prepare - - /** - * Generate Export Format - * @return info - * @throws Exception - */ - protected String doIt () throws Exception - { - MWindow window = new MWindow(getCtx(),p_AD_Window_ID, get_TrxName()); - MTab[] tabs = window.getTabs(true, get_TrxName()); - - - for(MTab tab:tabs) - { - MTable table = null; - String format = null; - if(tab.isActive()) - { - if(p_IsInsertRecord&tab.isInsertRecord()) - { - table = new MTable(getCtx(), tab.getAD_Table_ID(), get_TrxName()); - format = createFormat(table); - } - else if(!p_IsInsertRecord) - { - table = new MTable(getCtx(), tab.getAD_Table_ID(), get_TrxName()); - format = createFormat(table); - }else - continue; - - if (tab.getTabLevel() > m_level) - { - m_parent_table = table.getTableName(); - m_format_value = format; - } - } - } - return "ok"; - } // doIt - - private String createFormat(MTable table) throws Exception - { - log.info("Table Name:"+table.getTableName()); - MColumn[] cols = table.getColumns(true); - String unique = null; - boolean fieldname = false; - for(MColumn col : cols) - { - if(col.isIdentifier() && col.getSeqNo() == 1) - { - unique = col.getColumnName(); - if(unique.equals("Name")) - fieldname = true; - log.info("Unique Key"+unique); - break; - } - } - - if (unique==null) - unique="Name"; - - MEXPFormat format = null; - //String formatValue = table.getTableName()+"_"+unique; - String formatValue = table.getTableName(); - log.info("Export Format Value:"+formatValue); - format = (MEXPFormat) m_formats.get(formatValue); - if (format != null) - return format.getValue(); - - format = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(getCtx(), formatValue, getAD_Client_ID(), "1", get_TrxName()); - if(format == null) - format = new MEXPFormat(getCtx(), 0 , get_TrxName()); - - format.setValue(formatValue); - format.setName(table.getName()); - format.setAD_Table_ID(table.getAD_Table_ID()); - format.setDescription(table.getDescription()); - format.setHelp(table.getHelp()); - format.setVersion("1"); - format.save(); - if (format != null) - m_formats.put(format.getValue(), format); - - int position = 10; - for(MColumn col : cols) - { - if(p_IsMandatory) - { - if(col.isMandatory()) - createFormatLine(format, table, col, position,false); - } - else - createFormatLine(format, table, col, position,false); - - position++; - } - return format.getValue(); - } - - private int createFormatLine(MEXPFormat format, MTable table, MColumn col, int position,boolean force) throws Exception - { - - MEXPFormatLine format_line =null; - String formatlinevalue= col.getColumnName(); - format_line = MEXPFormatLine.getFormatLineByValue(getCtx(),formatlinevalue ,format.getEXP_Format_ID(),get_TrxName()); - if(format_line==null) - format_line = new MEXPFormatLine(getCtx(),0,get_TrxName()); - - format_line.setEXP_Format_ID(format.getEXP_Format_ID()); - format_line.setValue(formatlinevalue); - format_line.setName(col.getName()); - format_line.setDescription(col.getDescription()); - format_line.setHelp(col.getHelp()); - format_line.setPosition(position); - format_line.setIsMandatory(col.isMandatory()); - if(force||col.isIdentifier()) - { - format_line.setIsPartUniqueIndex(true); - format_line.setIsActive(true); - } - else - format_line.setIsActive(false); - MTable tabledir = null; - - if(col.getColumnName().equals(m_parent_table+"_ID")&(col.getAD_Reference_ID()==DisplayType.Search|col.getAD_Reference_ID()==DisplayType.TableDir)) - { - MEXPFormat referenceFormat = null; - referenceFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(getCtx(), m_parent_table+"_Key", getAD_Client_ID(), "1", get_TrxName()); - if(referenceFormat == null) - referenceFormat = new MEXPFormat(getCtx(), 0 , get_TrxName()); - referenceFormat.setValue(m_parent_table+"_Key"); - referenceFormat.setName(m_parent_table+"_Key"); - referenceFormat.setAD_Table_ID(table.getAD_Table_ID()); - referenceFormat.setDescription(table.getDescription()); - referenceFormat.setHelp(table.getHelp()); - referenceFormat.setVersion("1"); - referenceFormat.save(); - - int AD_Column_ID=DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='DocumentNo'",m_parent_table); - if(AD_Column_ID>0) - { - //used if the export format is a document like invoice, etc. - createFormatLine(referenceFormat, table, new MColumn(getCtx(),AD_Column_ID,get_TrxName()), 10,true); - AD_Column_ID=0; - AD_Column_ID=DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='C_DocType_ID'",m_parent_table); - if(AD_Column_ID>0) - createFormatLine(referenceFormat, table, new MColumn(getCtx(),AD_Column_ID,get_TrxName()), 20,true); - - format_line.setValue(m_parent_table+"_DocumentNo_C_DocType_Key"); - format_line.setName("Key DocumentNo_C_DocType"); - format_line.setAD_Column_ID(col.getAD_Column_ID()); - format_line.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); - format_line.setEXP_EmbeddedFormat_ID(referenceFormat.getEXP_Format_ID()); - format_line.save(); - return format_line.getEXP_FormatLine_ID(); - }else - { - AD_Column_ID=DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='NAME'",m_parent_table); - if(AD_Column_ID>0) - createFormatLine(referenceFormat, table, new MColumn(getCtx(),AD_Column_ID,get_TrxName()), 10,true); - else - { - AD_Column_ID=DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='VALUE'",m_parent_table); - if(AD_Column_ID>0) - createFormatLine(referenceFormat, table, new MColumn(getCtx(),AD_Column_ID,get_TrxName()), 10,true); - else - throw new Exception("Table without name or value column"); - } - format_line.setValue(m_parent_table+"_Key"); - format_line.setName("Key "+ col.getColumnName()); - format_line.setAD_Column_ID(col.getAD_Column_ID()); - format_line.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); - format_line.setEXP_EmbeddedFormat_ID(referenceFormat.getEXP_Format_ID()); - format_line.save(); - return format_line.getEXP_FormatLine_ID(); - } - } - - if((col.getAD_Reference_ID()==DisplayType.Table||col.getAD_Reference_ID()==DisplayType.Search)&col.getAD_Reference_Value_ID()>0) - { - int AD_Table_ID = DB.getSQLValue(get_TrxName(), "SELECT rt.AD_Table_ID FROM AD_Reference r INNER JOIN AD_Ref_Table rt ON (r.AD_Reference_ID=rt.AD_Reference_ID) WHERE r.AD_Reference_ID=?", col.getAD_Reference_Value_ID()); - if (AD_Table_ID > 0) - { - tabledir = MTable.get(getCtx(), AD_Table_ID); - format_line.setValue(col.getColumnName()+"_Reference"); - format_line.setName("Referenced "+ tabledir.getTableName()); - format_line.setAD_Column_ID(col.getAD_Column_ID()); - String format_value = createFormat(tabledir); - int embedded = ((MEXPFormat)m_formats.get(format_value)).getEXP_Format_ID(); - format_line.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); - format_line.setEXP_EmbeddedFormat_ID(embedded); - format_line.save(); - return format_line.getEXP_FormatLine_ID(); - } - - } - - if((col.getAD_Reference_ID()==DisplayType.TableDir & col.isKey()== false) || (col.getAD_Reference_ID()==DisplayType.TableDir & col.isParent() == true)) - { - - String tableName = col.getColumnName().substring(0, col.getColumnName().lastIndexOf("_ID")); - log.info("Table Name:"+tableName); - - if(tableName==null) - log.info("Table Name: null"); - - tabledir = MTable.get(getCtx(), tableName); - if(tabledir==null) - throw new Exception ("Ilegal Table Name"); - - format_line.setValue(tabledir.getTableName()+"_Reference"); - format_line.setName("Referenced "+ tabledir.getTableName()); - - if (tabledir!=null) - { - if(m_parent_table != null) - { - if (col.isParent() && col.getColumnName().contains(m_parent_table)) - { - - int embedded = ((MEXPFormat)m_formats.get(m_format_value)).getEXP_Format_ID(); - format_line.setValue(format.getValue()+"_Embedded"); - format_line.setName("Embedded "+ format.getName()); - format_line.setEXP_EmbeddedFormat_ID(format_line.getEXP_Format_ID()); - format_line.setEXP_Format_ID(embedded); - format_line.setType(MEXPFormatLine.TYPE_EmbeddedEXPFormat); - format_line.setAD_Column_ID(col.getAD_Column_ID()); - format_line.save(); - log.info("Export Format Line:"+format_line.getName()); - return format_line.getEXP_FormatLine_ID(); - - } - } - String format_value = createFormat(tabledir); - int embedded = ((MEXPFormat)m_formats.get(format_value)).getEXP_Format_ID(); - format_line.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); - format_line.setEXP_EmbeddedFormat_ID(embedded); - } - else - format_line.setType(MEXPFormatLine.TYPE_XMLElement); - } - - format_line.setAD_Column_ID(col.getAD_Column_ID()); - format_line.save(); - log.info("Export Format Line:"+format_line.getName()); - return format_line.getEXP_FormatLine_ID(); - - } -} // Generate Export Format diff --git a/base/src/org/eevolution/process/FixPaymentCashLine.java b/base/src/org/eevolution/process/FixPaymentCashLine.java deleted file mode 100644 index 7665aba0dc..0000000000 --- a/base/src/org/eevolution/process/FixPaymentCashLine.java +++ /dev/null @@ -1,190 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - * created by Victor Perez are Copyright (C) e-Evolution,SC. All Rights Reserved. - * Contributor(s): Victor Perez - *****************************************************************************/ -package org.eevolution.process; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.model.MCashLine; -import org.compiere.model.MPayment; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Trx; - - - -/** - * Fix Payment Cash Line - * [ 1866214 ] Adempiere need can void a Cash Journal - * https://sourceforge.net/tracker/?func=detail&atid=879335&aid=1866214&group_id=176962 - * - * @author Sergio Ramazzina,Victor Perez - * @version $Id: FixPaymentCashLine.java,v 1.2 2005/04/19 12:54:30 srama Exp $ - */ -public class FixPaymentCashLine extends SvrProcess { - - - private static final Properties ctx = Env.getCtx(); - private static CLogger s_log = CLogger.getCLogger (FixPaymentCashLine.class); - //private static final String AD_Client_ID = ctx.getProperty("#AD_Client_ID"); - //private static final String AD_Org_ID = ctx.getProperty("#AD_Org_ID"); - - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - - } // prepare - - /** - * Perform process. - * @return Message (clear text) - * @throws Exception if not successful - */ - protected String doIt() throws Exception { - - String sql = "SELECT cl.C_CashLine_ID, c.Name FROM C_CashLine cl INNER JOIN C_Cash c ON (c.C_Cash_ID=cl.C_Cash_ID) WHERE cl.CashType='T'"; - - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, get_TrxName()); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - Trx trx = Trx.get(Trx.createTrxName(), true); - MCashLine cashline = new MCashLine(Env.getCtx(),rs.getInt(1),trx.getTrxName()); - Integer c_cashline_id = cashline.getC_CashLine_ID(); - MPayment[] payments = getOfCash(Env.getCtx(), rs.getString(2), - cashline.getAmount(), cashline.getC_BankAccount_ID(), cashline.getAD_Client_ID(), - trx.getTrxName()); - for(MPayment payment : payments) - { - - cashline.setC_Payment_ID(payment.getC_Payment_ID()); - - if(!cashline.save()) - throw new IllegalStateException("Cannot assign payment to Cash Line"); - - break; // only the first - } - trx.commit(); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - s_log.log(Level.SEVERE, sql, e); - } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } - - return "@ProcessOK@"; - } // doIt - - /** - * Get Payment of Cash - * @param ctx context - * @param cashName Cash Name - * @return payments of cash - * @param trxName transaction - */ - public static MPayment[] getOfCash (Properties ctx, String cashName, BigDecimal amt, int C_BankAccount_ID, int AD_Client_ID, - String trxName) - { - String sql = "SELECT * FROM C_Payment p WHERE p.DocumentNo=? AND R_PnRef=? AND PayAmt=? AND C_BankAccount_ID=? AND AD_Client_ID=? " + - " AND TrxType='X' AND TenderType='X'"; - - ArrayList list = new ArrayList(); - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, trxName); - pstmt.setString(1, cashName); - pstmt.setString(2, cashName); - pstmt.setBigDecimal(3, amt.negate()); - pstmt.setInt(4, C_BankAccount_ID); - pstmt.setInt(5, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - list.add (new MPayment(ctx, rs, trxName)); - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - s_log.log(Level.SEVERE, sql, e); - } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } - MPayment[] retValue = new MPayment[list.size()]; - list.toArray(retValue); - return retValue; - } // getOfPayment - - /************************************************************************** - * Test - * @param args ignored - */ - public static void main(String[] args) - { - org.compiere.Adempiere.startup(true); - Env.setContext(Env.getCtx(), "#AD_Client_ID", 11); - FixPaymentCashLine pcf = new FixPaymentCashLine(); - try - { - pcf.doIt(); - } - catch (Exception e) - { - System.out.println("Error" + e.getMessage()); - } - - } // main - -} diff --git a/base/src/org/eevolution/process/InvoiceCalculateTax.java b/base/src/org/eevolution/process/InvoiceCalculateTax.java deleted file mode 100644 index e73b627597..0000000000 --- a/base/src/org/eevolution/process/InvoiceCalculateTax.java +++ /dev/null @@ -1,91 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.process; - - - -import org.adempiere.exceptions.FillMandatoryException; -import org.compiere.model.MBPartner; -import org.compiere.model.MFactAcct; -import org.compiere.model.MInvoice; -import org.compiere.model.MPeriod; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; - - -/** - * Re-calculate Invoice Tax (and unpost the document) - * @author victor.perez@e-evolution.com, e-Evolution http://www.e-evolution.com - *
  • FR [ 2520591 ] Support multiples calendar for Org - * @see http://sourceforge.net/tracker2/?func=detail&atid=879335&aid=2520591&group_id=176962 - * @author Teo Sarca, www.arhipac.ro - */ -public class InvoiceCalculateTax extends SvrProcess -{ - public static final String PARAM_C_Invoice_ID = "C_Invoice_ID"; - - private int p_C_Invoice_ID = 0; - - @Override - protected void prepare() - { - for (ProcessInfoParameter para : getParameter()) - { - String name = para.getParameterName(); - if (para.getParameter() == null) - { - ; - } - else if (name.equals(PARAM_C_Invoice_ID)) - { - p_C_Invoice_ID = para.getParameterAsInt(); - } - } - - if (p_C_Invoice_ID <= 0) - { - throw new FillMandatoryException(PARAM_C_Invoice_ID); - } - } - - @Override - protected String doIt() throws Exception - { - MInvoice invoice = new MInvoice(getCtx(), p_C_Invoice_ID, get_TrxName()); - recalculateTax(invoice); - // - return "@ProcessOK@"; - } - - public static void recalculateTax(MInvoice invoice) - { - // - // Delete accounting /UnPost - MPeriod.testPeriodOpen(invoice.getCtx(), invoice.getDateAcct(), invoice.getC_DocType_ID(), invoice.getAD_Org_ID()); - MFactAcct.deleteEx(MInvoice.Table_ID, invoice.get_ID(), invoice.get_TrxName()); - // - // Update Invoice - invoice.calculateTaxTotal(); - invoice.setPosted(false); - invoice.saveEx(); - // - // Update balance - MBPartner bp = new MBPartner (invoice.getCtx(), invoice.getC_BPartner_ID(), invoice.get_TrxName()); - bp.setTotalOpenBalance(); - bp.setSOCreditStatus(); - bp.saveEx(); - } -} diff --git a/base/src/org/eevolution/process/MovementGenerate.java b/base/src/org/eevolution/process/MovementGenerate.java deleted file mode 100644 index efe90e7d7f..0000000000 --- a/base/src/org/eevolution/process/MovementGenerate.java +++ /dev/null @@ -1,714 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.process; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.logging.Level; - -import org.compiere.model.MAttributeSet; -import org.compiere.model.MClient; -import org.compiere.model.MLocator; -import org.compiere.model.MMovement; -import org.compiere.model.MMovementLine; -import org.compiere.model.MProduct; -import org.compiere.model.MProductCategory; -import org.compiere.model.MStorage; -import org.compiere.process.DocAction; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.AdempiereUserError; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.eevolution.model.MDDOrder; -import org.eevolution.model.MDDOrderLine; - - - -/** - * Generate Movement - * Manual or Automatic - * - * @author Victor Perez www.e-evolution.com - * @version $Id: MovementGenerate.java,v 1.0 - */ -public class MovementGenerate extends SvrProcess -{ - /** Manual Selection */ - private boolean p_Selection = false; - /** Warehouse */ - private int p_M_Warehouse_ID = 0; - /** BPartner */ - private int p_C_BPartner_ID = 0; - /** Promise Date */ - private Timestamp p_DatePromised = null; - /** Include Orders w. unconfirmed Shipments */ - private boolean p_IsUnconfirmedInOut = false; - /** DocAction */ - private String p_docAction = DocAction.ACTION_Complete; - /** Consolidate */ - private boolean p_ConsolidateDocument = true; - /** Shipment Date */ - private Timestamp p_DateShipped = null; - - /** The current Shipment */ - private MMovement m_movement = null; - /** Numner of Shipments */ - private int m_created = 0; - /** Line Number */ - private int m_line = 0; - /** Movement Date */ - private Timestamp m_movementDate = null; - /** Last BP Location */ - private int m_lastC_BPartner_Location_ID = -1; - - /** The Query sql */ - private String m_sql = null; - - - /** Storages temp space */ - private HashMap m_map = new HashMap(); - /** Last Parameter */ - private SParameter m_lastPP = null; - /** Last Storage */ - private MStorage[] m_lastStorages = null; - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) - ; - else if (name.equals("M_Warehouse_ID")) - p_M_Warehouse_ID = para[i].getParameterAsInt(); - else if (name.equals("C_BPartner_ID")) - p_C_BPartner_ID = para[i].getParameterAsInt(); - else if (name.equals("DatePromised")) - p_DatePromised = (Timestamp)para[i].getParameter(); - else if (name.equals("Selection")) - p_Selection = "Y".equals(para[i].getParameter()); - else if (name.equals("IsUnconfirmedInOut")) - p_IsUnconfirmedInOut = "Y".equals(para[i].getParameter()); - else if (name.equals("ConsolidateDocument")) - p_ConsolidateDocument = "Y".equals(para[i].getParameter()); - else if (name.equals("DocAction")) - p_docAction = (String)para[i].getParameter(); - else if (name.equals("MovementDate")) - p_DateShipped = (Timestamp)para[i].getParameter(); - else - log.log(Level.SEVERE, "Unknown Parameter: " + name); - - // juddm - added ability to specify a shipment date from Generate Shipments - if (p_DateShipped == null) { - m_movementDate = Env.getContextAsDate(getCtx(), "#Date"); - if (m_movementDate == null) - m_movementDate = new Timestamp(System.currentTimeMillis()); - } else - m_movementDate = p_DateShipped; - // DocAction check - if (!DocAction.ACTION_Complete.equals(p_docAction)) - p_docAction = DocAction.ACTION_Prepare; - } - } // prepare - - /** - * Generate Movemements - * @return info - * @throws Exception - */ - protected String doIt () throws Exception - { - log.info("Selection=" + p_Selection - + ", M_Warehouse_ID=" + p_M_Warehouse_ID - + ", C_BPartner_ID=" + p_C_BPartner_ID - + ", Consolidate=" + p_ConsolidateDocument - + ", IsUnconfirmed=" + p_IsUnconfirmedInOut - + ", Movement=" + m_movementDate); - - if (p_M_Warehouse_ID == 0) - throw new AdempiereUserError("@NotFound@ @M_Warehouse_ID@"); - - if (p_Selection) // VInOutGen - { - m_sql = "SELECT DD_Order.* FROM DD_Order, T_Selection " - + "WHERE DD_Order.DocStatus='CO' AND DD_Order.IsSOTrx='Y' AND DD_Order.AD_Client_ID=? " - + "AND DD_Order.DD_Order_ID = T_Selection.T_Selection_ID " - + "AND T_Selection.AD_PInstance_ID=? "; - } - else - { - m_sql = "SELECT * FROM DD_Order o " - + "WHERE DocStatus='CO' AND IsSOTrx='Y'" - // No Offer,POS - + " AND o.C_DocType_ID IN (SELECT C_DocType_ID FROM C_DocType " - + "WHERE DocBaseType='DOO')" - + " AND o.IsDropShip='N'" - // No Manual - + " AND o.DeliveryRule<>'M'" - // Open Order Lines with Warehouse - + " AND EXISTS (SELECT * FROM DD_OrderLine ol " - + "WHERE ol.M_Warehouse_ID=?"; // #1 - if (p_DatePromised != null) - m_sql += " AND TRUNC(ol.DatePromised)<=?"; // #2 - m_sql += " AND o.DD_Order_ID=ol.DD_Order_ID AND ol.QtyOrdered<>ol.QtyIntransit)"; - // - if (p_C_BPartner_ID != 0) - m_sql += " AND o.C_BPartner_ID=?"; // #3 - } - m_sql += " ORDER BY M_Warehouse_ID, PriorityRule, M_Shipper_ID, C_BPartner_ID, C_BPartner_Location_ID, DD_Order_ID"; - // m_sql += " FOR UPDATE"; - - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (m_sql, get_TrxName()); - int index = 1; - if (p_Selection) - { - pstmt.setInt(index++, Env.getAD_Client_ID(getCtx())); - pstmt.setInt(index++, getAD_PInstance_ID()); - } - else - { - pstmt.setInt(index++, p_M_Warehouse_ID); - if (p_DatePromised != null) - pstmt.setTimestamp(index++, p_DatePromised); - if (p_C_BPartner_ID != 0) - pstmt.setInt(index++, p_C_BPartner_ID); - } - } - catch (Exception e) - { - log.log(Level.SEVERE, m_sql, e); - } - return generate(pstmt); - } // doIt - - /** - * Generate Shipments - * @param pstmt Order Query - * @return info - */ - private String generate (PreparedStatement pstmt) - { - MClient client = MClient.get(getCtx()); - try - { - ResultSet rs = pstmt.executeQuery (); - while (rs.next ()) // Order - { - MDDOrder order = new MDDOrder (getCtx(), rs, get_TrxName()); - // New Header different Shipper, Shipment Location - if (!p_ConsolidateDocument - || (m_movement != null - && (m_movement.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID() - || m_movement.getM_Shipper_ID() != order.getM_Shipper_ID() ))) - completeMovement(); - log.fine("check: " + order + " - DeliveryRule=" + order.getDeliveryRule()); - // - Timestamp minGuaranteeDate = m_movementDate; - boolean completeOrder = MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule()); - // OrderLine WHERE - String where = " AND " + p_M_Warehouse_ID + " IN (SELECT l.M_Warehouse_ID FROM M_Locator l WHERE l.M_Locator_ID=M_Locator_ID) "; - if (p_DatePromised != null) - where += " AND (TRUNC(DatePromised)<=" + DB.TO_DATE(p_DatePromised, true) - + " OR DatePromised IS NULL)"; - // Exclude Auto Delivery if not Force - if (!MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) - where += " AND (DD_OrderLine.M_Product_ID IS NULL" - + " OR EXISTS (SELECT * FROM M_Product p " - + "WHERE DD_OrderLine.M_Product_ID=p.M_Product_ID" - + " AND IsExcludeAutoDelivery='N'))"; - // Exclude Unconfirmed - if (!p_IsUnconfirmedInOut) - where += " AND NOT EXISTS (SELECT * FROM M_MovementLine iol" - + " INNER JOIN M_Movement io ON (iol.M_Movement_ID=io.M_Movement_ID) " - + "WHERE iol.DD_OrderLine_ID=DD_OrderLine.DD_OrderLine_ID AND io.DocStatus IN ('IP','WC'))"; - // Deadlock Prevention - Order by M_Product_ID - MDDOrderLine[] lines = order.getLines (where, "M_Product_ID"); - for (int i = 0; i < lines.length; i++) - { - MDDOrderLine line = lines[i]; - MLocator l = new MLocator(getCtx(),line.getM_Locator_ID(), get_TrxName()); - if (l.getM_Warehouse_ID() != p_M_Warehouse_ID) - continue; - log.fine("check: " + line); - BigDecimal onHand = Env.ZERO; - //BigDecimal toDeliver = line.getQtyOrdered() - BigDecimal toDeliver = line.getConfirmedQty() - .subtract(line.getQtyDelivered()); - MProduct product = line.getProduct(); - // Nothing to Deliver - if (product != null && toDeliver.signum() == 0) - continue; - - // or it's a charge - Bug#: 1603966 - if (line.getC_Charge_ID()!=0 && toDeliver.signum() == 0) - continue; - - // Check / adjust for confirmations - BigDecimal unconfirmedShippedQty = Env.ZERO; - if (p_IsUnconfirmedInOut && product != null && toDeliver.signum() != 0) - { - String where2 = "EXISTS (SELECT * FROM M_Movement io WHERE io.M_Movement_ID=M_MovementLine.M_Movement_ID AND io.DocStatus IN ('IP','WC'))"; - MMovementLine[] iols = MMovementLine.getOfOrderLine(getCtx(), - line.getDD_OrderLine_ID(), where2, null); - for (int j = 0; j < iols.length; j++) - unconfirmedShippedQty = unconfirmedShippedQty.add(iols[j].getMovementQty()); - String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty - + " - ToDeliver=" + toDeliver + "->"; - toDeliver = toDeliver.subtract(unconfirmedShippedQty); - logInfo += toDeliver; - if (toDeliver.signum() < 0) - { - toDeliver = Env.ZERO; - logInfo += " (set to 0)"; - } - // Adjust On Hand - onHand = onHand.subtract(unconfirmedShippedQty); - log.fine(logInfo); - } - - // Comments & lines w/o product & services - if ((product == null || !product.isStocked()) - && (line.getQtyOrdered().signum() == 0 // comments - || toDeliver.signum() != 0)) // lines w/o product - { - if (!MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule())) // printed later - createLine (order, line, toDeliver, null, false); - continue; - } - - // Stored Product - MProductCategory pc = MProductCategory.get(order.getCtx(), product.getM_Product_Category_ID()); - String MMPolicy = pc.getMMPolicy(); - if (MMPolicy == null || MMPolicy.length() == 0) - MMPolicy = client.getMMPolicy(); - // - MStorage[] storages = getStorages(l.getM_Warehouse_ID(), - line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), - product.getM_AttributeSet_ID(), - line.getM_AttributeSetInstance_ID()==0, minGuaranteeDate, - MClient.MMPOLICY_FiFo.equals(MMPolicy)); - - for (int j = 0; j < storages.length; j++) - { - MStorage storage = storages[j]; - onHand = onHand.add(storage.getQtyOnHand()); - } - boolean fullLine = onHand.compareTo(toDeliver) >= 0 - || toDeliver.signum() < 0; - - // Complete Order - if (completeOrder && !fullLine) - { - log.fine("Failed CompleteOrder - OnHand=" + onHand - + " (Unconfirmed=" + unconfirmedShippedQty - + "), ToDeliver=" + toDeliver + " - " + line); - completeOrder = false; - break; - } - // Complete Line - else if (fullLine && MDDOrder.DELIVERYRULE_CompleteLine.equals(order.getDeliveryRule())) - { - log.fine("CompleteLine - OnHand=" + onHand - + " (Unconfirmed=" + unconfirmedShippedQty - + ", ToDeliver=" + toDeliver + " - " + line); - // - createLine (order, line, toDeliver, storages, false); - } - // Availability - else if (MDDOrder.DELIVERYRULE_Availability.equals(order.getDeliveryRule()) - && (onHand.signum() > 0 - || toDeliver.signum() < 0)) - { - BigDecimal deliver = toDeliver; - if (deliver.compareTo(onHand) > 0) - deliver = onHand; - log.fine("Available - OnHand=" + onHand - + " (Unconfirmed=" + unconfirmedShippedQty - + "), ToDeliver=" + toDeliver - + ", Delivering=" + deliver + " - " + line); - // - createLine (order, line, deliver, storages, false); - } - // Force - else if (MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) - { - BigDecimal deliver = toDeliver; - log.fine("Force - OnHand=" + onHand - + " (Unconfirmed=" + unconfirmedShippedQty - + "), ToDeliver=" + toDeliver - + ", Delivering=" + deliver + " - " + line); - // - createLine (order, line, deliver, storages, true); - } - // Manual - else if (MDDOrder.DELIVERYRULE_Manual.equals(order.getDeliveryRule())) - log.fine("Manual - OnHand=" + onHand - + " (Unconfirmed=" + unconfirmedShippedQty - + ") - " + line); - else - log.fine("Failed: " + order.getDeliveryRule() + " - OnHand=" + onHand - + " (Unconfirmed=" + unconfirmedShippedQty - + "), ToDeliver=" + toDeliver + " - " + line); - } // for all order lines - - // Complete Order successful - if (completeOrder && MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule())) - { - for (int i = 0; i < lines.length; i++) - { - MDDOrderLine line = lines[i]; - MLocator l = new MLocator(getCtx(),line.getM_Locator_ID(), get_TrxName()); - if (l.getM_Warehouse_ID() != p_M_Warehouse_ID) - continue; - MProduct product = line.getProduct(); - BigDecimal toDeliver = line.getQtyOrdered().subtract(line.getQtyDelivered()); - // - MStorage[] storages = null; - if (product != null && product.isStocked()) - { - MProductCategory pc = MProductCategory.get(order.getCtx(), product.getM_Product_Category_ID()); - String MMPolicy = pc.getMMPolicy(); - if (MMPolicy == null || MMPolicy.length() == 0) - MMPolicy = client.getMMPolicy(); - // - storages = getStorages(l.getM_Warehouse_ID(), - line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), - product.getM_AttributeSet_ID(), - line.getM_AttributeSetInstance_ID()==0, minGuaranteeDate, - MClient.MMPOLICY_FiFo.equals(MMPolicy)); - } - // - createLine (order, line, toDeliver, storages, false); - } - } - m_line += 1000; - } // while order - rs.close (); - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE, m_sql, e); - } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } - completeMovement(); - return "@Created@ = " + m_created; - } // generate - - - - /************************************************************************** - * Create Line - * @param Distribution order order - * @param orderLine line - * @param qty qty - * @param storages storage info - * @param force force delivery - */ - private void createLine (MDDOrder order, MDDOrderLine orderLine, BigDecimal qty, - MStorage[] storages, boolean force) - { - // Complete last Shipment - can have multiple shipments - if (m_lastC_BPartner_Location_ID != order.getC_BPartner_Location_ID() ) - completeMovement(); - m_lastC_BPartner_Location_ID = order.getC_BPartner_Location_ID(); - // Create New Shipment - if (m_movement == null) - { - m_movement = new MMovement (order, 0, m_movementDate); - //m_movement.setM_Warehouse_ID(orderLine.getM_Warehouse_ID()); // sets Org too - m_movement.setIsInTransit(true); - m_movement.setDD_Order_ID(order.getDD_Order_ID()); - if (order.getC_BPartner_ID() != order.getC_BPartner_ID()) - m_movement.setC_BPartner_ID(order.getC_BPartner_ID()); - if (order.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID()) - m_movement.setC_BPartner_Location_ID(order.getC_BPartner_Location_ID()); - if (!m_movement.save()) - throw new IllegalStateException("Could not create Movement"); - } - // Non Inventory Lines - if (storages == null) - { - MMovementLine line = new MMovementLine (m_movement); - line.setOrderLine(orderLine, Env.ZERO, false); - line.setMovementQty(qty); // Correct UOM - if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) - line.setMovementQty(qty - .multiply(orderLine.getQtyEntered()) - .divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP)); - line.setLine(m_line + orderLine.getLine()); - if (!line.save()) - throw new IllegalStateException("Could not create Shipment Line"); - log.fine(line.toString()); - return; - } - - // Product - MProduct product = orderLine.getProduct(); - boolean linePerASI = false; - if (product.getM_AttributeSet_ID() != 0) - { - MAttributeSet mas = MAttributeSet.get(getCtx(), product.getM_AttributeSet_ID()); - linePerASI = mas.isInstanceAttribute(); - } - - // Inventory Lines - ArrayList list = new ArrayList(); - BigDecimal toDeliver = qty; - for (int i = 0; i < storages.length; i++) - { - MStorage storage = storages[i]; - BigDecimal deliver = toDeliver; - // Not enough On Hand - if (deliver.compareTo(storage.getQtyOnHand()) > 0 - && storage.getQtyOnHand().signum() >= 0) // positive storage - { - if (!force // Adjust to OnHand Qty - || (force && i+1 != storages.length)) // if force not on last location - deliver = storage.getQtyOnHand(); - } - if (deliver.signum() == 0) // zero deliver - continue; - int M_Locator_ID = storage.getM_Locator_ID(); - // - MMovementLine line = null; - if (!linePerASI) // find line with Locator - { - for (int ll = 0; ll < list.size(); ll++) - { - MMovementLine test = (MMovementLine)list.get(ll); - if (test.getM_Locator_ID() == M_Locator_ID) - { - line = test; - break; - } - } - } - if (line == null) // new line - { - line = new MMovementLine (m_movement); - line.setOrderLine(orderLine, deliver , false); - line.setMovementQty(deliver); - list.add(line); - } - else // existing line - line.setMovementQty(line.getMovementQty().add(deliver)); - if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) - line.setMovementQty(line.getMovementQty().multiply(orderLine.getQtyEntered()) - .divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP)); - line.setLine(m_line + orderLine.getLine()); - if (linePerASI) - line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID()); - if (!line.save()) - throw new IllegalStateException("Could not create Shipment Line"); - log.fine("ToDeliver=" + qty + "/" + deliver + " - " + line); - toDeliver = toDeliver.subtract(deliver); - // Temp adjustment - storage.setQtyOnHand(storage.getQtyOnHand().subtract(deliver)); - // - if (toDeliver.signum() == 0) - break; - } - if (toDeliver.signum() != 0) - throw new IllegalStateException("Not All Delivered - Remainder=" + toDeliver); - } // createLine - - - /** - * Get Storages - * @param M_Warehouse_ID - * @param M_Product_ID - * @param M_AttributeSetInstance_ID - * @param M_AttributeSet_ID - * @param allAttributeInstances - * @param minGuaranteeDate - * @param FiFo - * @return storages - */ - private MStorage[] getStorages(int M_Warehouse_ID, - int M_Product_ID, int M_AttributeSetInstance_ID, int M_AttributeSet_ID, - boolean allAttributeInstances, Timestamp minGuaranteeDate, - boolean FiFo) - { - m_lastPP = new SParameter(M_Warehouse_ID, - M_Product_ID, M_AttributeSetInstance_ID, M_AttributeSet_ID, - allAttributeInstances, minGuaranteeDate, FiFo); - // - m_lastStorages = m_map.get(m_lastPP); - - if (m_lastStorages == null) - { - m_lastStorages = MStorage.getWarehouse(getCtx(), - M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID, - M_AttributeSet_ID, allAttributeInstances, minGuaranteeDate, - FiFo, get_TrxName()); - m_map.put(m_lastPP, m_lastStorages); - } - return m_lastStorages; - } // getStorages - - - /** - * Complete Shipment - */ - private void completeMovement() - { - if (m_movement != null) - { - // Fails if there is a confirmation - if (!m_movement.processIt(p_docAction)) - log.warning("Failed: " + m_movement); - m_movement.save(); - // - addLog(m_movement.getM_Movement_ID(), m_movement.getMovementDate(), null, m_movement.getDocumentNo()); - m_created++; - m_map = new HashMap(); - if (m_lastPP != null && m_lastStorages != null) - m_map.put(m_lastPP, m_lastStorages); - } - m_movement = null; - m_line = 0; - } // completeOrder - - /** - * MovementGenerate Parameter - */ - class SParameter - { - /** - * Parameter - * @param p_Warehouse_ID warehouse - * @param p_Product_ID - * @param p_AttributeSetInstance_ID - * @param p_AttributeSet_ID - * @param p_allAttributeInstances - * @param p_minGuaranteeDate - * @param p_FiFo - */ - protected SParameter (int p_Warehouse_ID, - int p_Product_ID, int p_AttributeSetInstance_ID, int p_AttributeSet_ID, - boolean p_allAttributeInstances, Timestamp p_minGuaranteeDate, - boolean p_FiFo) - { - this.M_Warehouse_ID = p_Warehouse_ID; - this.M_Product_ID = p_Product_ID; - this.M_AttributeSetInstance_ID = p_AttributeSetInstance_ID; - this.M_AttributeSet_ID = p_AttributeSet_ID; - this.allAttributeInstances = p_allAttributeInstances; - this.minGuaranteeDate = p_minGuaranteeDate; - this.FiFo = p_FiFo; - } - /** Warehouse */ - public int M_Warehouse_ID; - /** Product */ - public int M_Product_ID; - /** ASI */ - public int M_AttributeSetInstance_ID; - /** AS */ - public int M_AttributeSet_ID; - /** All instances */ - public boolean allAttributeInstances; - /** Mon Guarantee Date */ - public Timestamp minGuaranteeDate; - /** FiFo */ - public boolean FiFo; - - /** - * Equals - * @param obj - * @return true if equal - */ - public boolean equals (Object obj) - { - if (obj != null && obj instanceof SParameter) - { - SParameter cmp = (SParameter)obj; - boolean eq = cmp.M_Warehouse_ID == M_Warehouse_ID - && cmp.M_Product_ID == M_Product_ID - && cmp.M_AttributeSetInstance_ID == M_AttributeSetInstance_ID - && cmp.M_AttributeSet_ID == M_AttributeSet_ID - && cmp.allAttributeInstances == allAttributeInstances - && cmp.FiFo == FiFo; - if (eq) - { - if (cmp.minGuaranteeDate == null && minGuaranteeDate == null) - ; - else if (cmp.minGuaranteeDate != null && minGuaranteeDate != null - && cmp.minGuaranteeDate.equals(minGuaranteeDate)) - ; - else - eq = false; - } - return eq; - } - return false; - } // equals - - /** - * hashCode - * @return hash code - */ - public int hashCode () - { - long hash = M_Warehouse_ID - + (M_Product_ID * 2) - + (M_AttributeSetInstance_ID * 3) - + (M_AttributeSet_ID * 4); - - if (allAttributeInstances) - hash *= -1; - if (FiFo); - hash *= -2; - if (hash < 0) - hash = -hash + 7; - while (hash > Integer.MAX_VALUE) - hash -= Integer.MAX_VALUE; - // - if (minGuaranteeDate != null) - { - hash += minGuaranteeDate.hashCode(); - while (hash > Integer.MAX_VALUE) - hash -= Integer.MAX_VALUE; - } - - return (int)hash; - } // hashCode - - } // Parameter - -} // MovementGenerate diff --git a/base/src/org/eevolution/process/PP_Product_BOM_Check.java b/base/src/org/eevolution/process/PP_Product_BOM_Check.java deleted file mode 100755 index 71b6013521..0000000000 --- a/base/src/org/eevolution/process/PP_Product_BOM_Check.java +++ /dev/null @@ -1,126 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - * Portions created by Carlos Ruiz are Copyright (C) 2005 QSS Ltda. - * Contributor(s): Carlos Ruiz (globalqss) - *****************************************************************************/ -package org.eevolution.process; - -import java.util.logging.Level; - -import org.compiere.model.MProduct; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.AdempiereUserError; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.ValueNamePair; -import org.eevolution.model.MPPProductBOM; -import org.eevolution.model.MPPProductBOMLine; - -/** - * Title: Check BOM Structure (free of cycles) Description: Tree cannot contain - * BOMs which are already referenced - * - * @author Tony Snook (tspc) - * @author Teo Sarca, SC ARHIPAC SERVICE SRL - */ -public class PP_Product_BOM_Check extends SvrProcess -{ - - /** The Record */ - private int p_Record_ID = 0; - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) - ; - else - log.log(Level.SEVERE, "Unknown Parameter: " + name); - } - p_Record_ID = getRecord_ID(); - } // prepare - - /** - * Process - * - * @return message - * @throws Exception - */ - protected String doIt() throws Exception - { - log.info("Check BOM Structure"); - - // Record ID is M_Product_ID of product to be tested - MProduct xp = new MProduct(Env.getCtx(), p_Record_ID, get_TrxName()); - - if (!xp.isBOM()) - { - log.info("Product is not a BOM"); - // No BOM - should not happen, but no problem - return "OK"; - } - - // Check Parent Level - int lowlevel = MPPProductBOMLine.getLowLevel(getCtx(), p_Record_ID, get_TrxName()); - xp.setLowLevel(lowlevel); - xp.setIsVerified(true); - xp.saveEx(); - - // Get Default BOM from this product - MPPProductBOM tbom = MPPProductBOM.getDefault(xp, get_TrxName()); - if (tbom == null) { - raiseError("No Default BOM found: ", "Check BOM Parent search key"); - } - - // Check All BOM Lines - if (tbom.getM_Product_ID() != 0) - { - MPPProductBOMLine[] tbomlines = tbom.getLines(); - for (MPPProductBOMLine tbomline : tbomlines) - { - lowlevel = tbomline.getLowLevel(); - MProduct p = new MProduct(getCtx(), tbomline.getM_Product_ID(), get_TrxName()); - p.setLowLevel(lowlevel); - p.setIsVerified(true); - p.saveEx(); - } - } - return "OK"; - } // doIt - - private void raiseError(String string, String hint) throws Exception - { - DB.rollback(false, get_TrxName()); - MProduct xp = new MProduct(getCtx(), p_Record_ID, null); // parent - xp.setIsVerified(false); // set BOM not verified - xp.saveEx(); - String msg = string; - ValueNamePair pp = CLogger.retrieveError(); - if (pp != null) - msg = pp.getName() + " - "; - msg += hint; - throw new AdempiereUserError(msg); - } - -} // M_Product_BOM_Check diff --git a/base/src/org/eevolution/process/ProcessInfoHandler.java b/base/src/org/eevolution/process/ProcessInfoHandler.java deleted file mode 100644 index 24fdda8a8d..0000000000 --- a/base/src/org/eevolution/process/ProcessInfoHandler.java +++ /dev/null @@ -1,152 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.process; - -import java.util.Enumeration; -import java.util.Hashtable; - -import org.compiere.model.MPInstance; -import org.compiere.model.MPInstancePara; -import org.compiere.model.MProcess; -import org.compiere.process.ProcessInfo; -import org.compiere.util.Env; -import org.compiere.util.Msg; - -/** - * @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany - * @version 1.0, October 14th 2005 - */ -public class ProcessInfoHandler { - - protected ProcessInfo pi; - protected MPInstance pinstance; - protected Hashtable param; - protected MProcess process; - - public ProcessInfoHandler(int processID) { - - init(processID); - } - - private void init(int processID) { - - process = new MProcess(Env.getCtx(), processID, null); - - if(process != null) { - - pi = getProcessInfo(Msg.translate(Env.getCtx(), process.getName()), process.get_ID()); - pinstance = getProcessInstance(pi); - pi.setAD_PInstance_ID (pinstance.getAD_PInstance_ID()); - } - } - - protected ProcessInfo getProcessInfo(String name, int id) { - - ProcessInfo info = new ProcessInfo(name, id); - info.setAD_User_ID (Env.getAD_User_ID(Env.getCtx())); - info.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx())); - - return info; - } - - protected MPInstance getProcessInstance(ProcessInfo info) { - - MPInstance instance = new MPInstance(Env.getCtx(), info.getAD_Process_ID(), info.getRecord_ID()); - if (!instance.save()) { - - info.setSummary (Msg.getMsg(Env.getCtx(), "ProcessNoInstance")); - info.setError (true); - return null; - } - - return instance; - } - - protected int countParams() { - - return (process != null) ? process.getParameters().length : 0; - } - - protected Hashtable extractParameters() { - - Hashtable param = new Hashtable(); - - MPInstancePara p = null; - int i = 0; - int b = countParams(); - while(i < b) { - - p = new MPInstancePara(getProcessInstance(), i); - p.load(null); - - param.put(p.getParameterName(), getValueFrom(p)); - i++; - } - - return param; - } - - protected Object getValueFrom(MPInstancePara p) { - - Object o = null; - - o = (o == null) ? p.getP_Date() : o; - o = (o == null) ? p.getP_Date_To() : o; - o = (o == null) ? p.getP_Number() : o; - o = (o == null) ? p.getP_Number_To() : o; - o = (o == null) ? p.getP_String() : o; - o = (o == null) ? p.getP_String_To() : o; - - return o; - } - - public void setProcessError() { - - pi.setSummary(Msg.getMsg(Env.getCtx(), "ProcessCancelled")); - pi.setError(true); - } - - public MPInstance getProcessInstance() { - - return pinstance; - } - - public ProcessInfo getProcessInfo() { - - return pi; - } - - public Object getParameterValue(String param) { - - if(this.param == null) { - - this.param = extractParameters(); - } - - return this.param.get(param); - } - - public Enumeration getParameters() { - - if(this.param == null) { - - this.param = extractParameters(); - } - - return param.keys(); - } -} diff --git a/base/src/org/eevolution/tools/GenerateModel.java b/base/src/org/eevolution/tools/GenerateModel.java deleted file mode 100644 index d8118e030d..0000000000 --- a/base/src/org/eevolution/tools/GenerateModel.java +++ /dev/null @@ -1,879 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - * Contributor(s): Carlos Ruiz - globalqss * - * Teo Sarca - *****************************************************************************/ -package org.eevolution.tools; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.logging.Level; - -import org.compiere.Adempiere; -import org.compiere.util.CLogMgt; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -/** - * Generate Model Classes extending PO. - * Base class for CMP interface - will be extended to create byte code directly - * - * @author Jorg Janke - * @version $Id: GenerateModel.java,v 1.5 2006/07/30 00:54:36 jjanke Exp $ - * - * globalqss - Grant independence to GenerateModel from AD_Table_ID - * globalqss - Filter by table (LIKE) - * - * globalqss - integrate Teo Sarca hint [ 1617928 ] Ineficient use of Boolean ctor for gen. model - * teo_sarca - bug fix [ 1651801 ] GenerateModel: duplicate "getKeyNamePair" methods - * teo_sarca - feature request [ 1662447 ] Add column names in model classes - */ -public class GenerateModel -{ - /** - * Generate PO Class - * @param AD_Table_ID table id - * @param directory directory with \ or / at the end. - * @param packageName package name - */ - public GenerateModel (int AD_Table_ID, String directory, String packageName) - { - // create column access methods - StringBuffer mandatory = new StringBuffer(); - StringBuffer sb = createColumns(AD_Table_ID, mandatory); - // add header stuff - String tableName = createHeader(AD_Table_ID, sb, mandatory, packageName); - // Save it - writeToFile (sb, directory + tableName + ".java"); - } // GenerateModel - - /** File Header */ - public static final String COPY = - "/******************************************************************************\n" - +" * Product: Adempiere ERP & CRM Smart Business Solution *\n" - +" * Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. *\n" - +" * This program is free software; you can redistribute it and/or modify it *\n" - +" * under the terms version 2 of the GNU General Public License as published *\n" - +" * by the Free Software Foundation. This program is distributed in the hope *\n" - +" * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *\n" - +" * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *\n" - +" * See the GNU General Public License for more details. *\n" - +" * You should have received a copy of the GNU General Public License along *\n" - +" * with this program; if not, write to the Free Software Foundation, Inc., *\n" - +" * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *\n" - +" * For the text or an alternative of this public license, you may reach us *\n" - +" * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *\n" - +" * or via info@compiere.org or http://www.compiere.org/license.html *\n" - +" *****************************************************************************/\n"; - - /** Logger */ - private static CLogger log = CLogger.getCLogger (GenerateModel.class); - - /** - * Add Header info to buffer - * @param AD_Table_ID table - * @param sb buffer - * @param mandatory init call for mandatory columns - * @param packageName package name - * @return class name - */ - private String createHeader (int AD_Table_ID, StringBuffer sb, StringBuffer mandatory, String packageName) - { - String tableName = ""; - int accessLevel = 0; - String sql = "SELECT TableName, AccessLevel FROM AD_Table WHERE AD_Table_ID=?"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, AD_Table_ID); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) - { - tableName = rs.getString(1); - accessLevel = rs.getInt(2); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE, sql, e); - } - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } - if (tableName == null) - throw new RuntimeException ("TableName not found for ID=" + AD_Table_ID); - // - String accessLevelInfo = accessLevel + " "; - if (accessLevel >= 4 ) - accessLevelInfo += "- System "; - if (accessLevel == 2 || accessLevel == 3 || accessLevel == 6 || accessLevel == 7) - accessLevelInfo += "- Client "; - if (accessLevel == 1 || accessLevel == 3 || accessLevel == 5 || accessLevel == 7) - accessLevelInfo += "- Org "; - - String keyColumn = tableName + "_ID"; - String className = "X_" + tableName; - // - StringBuffer start = new StringBuffer () - .append (COPY) - .append ("package " + packageName + ";\n" - + "/** Generated Model - DO NOT CHANGE */\n"); - if (!packageName.equals("org.compiere.model")) - start.append("import org.compiere.model.*;"); - start.append("import java.util.*;" - + "import java.sql.*;" - + "import java.math.*;" - + "import org.compiere.util.*;" - // Class - + "/** Generated Model for ").append(tableName).append("\n" - + " * @author Adempiere (generated) \n" - + " * @version ").append(Adempiere.MAIN_VERSION).append(" - $Id$") - // .append(s_run) // Timestamp - .append(" */\n" - + "public class ").append(className).append(" extends PO" - + "{" - // Standard Constructor - + "/** Standard Constructor\n@param ctx context\n@param " - + keyColumn + " id\n@param trxName transaction\n*/\n" - + "public ").append(className).append(" (Properties ctx, int ").append(keyColumn) - .append(", String trxName)" - + "{" - + "super (ctx, ").append(keyColumn).append(", trxName);" - + "/** if (").append(keyColumn).append(" == 0)" - + "{").append(mandatory).append("} */\n" - + "}" // Constructor End - // Short Constructor - // + "/** Short Constructor */\n" - // + "public ").append(className).append(" (Properties ctx, int ").append(keyColumn).append(")" - // + "{" - // + "this (ctx, ").append(keyColumn).append(", null);" - // + "}" // Constructor End - - // Load Constructor - + "/** Load Constructor \n@param ctx context\n@param rs result set \n@param trxName transaction\n*/\n" - + "public ").append(className).append(" (Properties ctx, ResultSet rs, String trxName)" - + "{" - + "super (ctx, rs, trxName);" - + "}" // Load Constructor End - // - // globalqss - Grant independence to GenerateModel from AD_Table_ID - + "/** TableName=").append(tableName).append(" */\n" - + "public static final String Table_Name=\"").append(tableName).append("\";\n" - // + "public static final int Table_ID=").append(AD_Table_ID).append(";\n" - + "/** AD_Table_ID=").append(AD_Table_ID).append(" */\n" - + "public static final int Table_ID=MTable.getTable_ID(Table_Name);\n" - // - // globalqss - // + "protected static KeyNamePair Model = new KeyNamePair(").append(AD_Table_ID).append(",\"").append(tableName).append("\");\n" - + "protected static KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name);\n" - // - + "protected BigDecimal accessLevel = BigDecimal.valueOf(").append(accessLevel).append(");" - + "/** AccessLevel\n@return ").append(accessLevelInfo).append("\n*/\n" - + "protected int get_AccessLevel()" - + "{" - + "return accessLevel.intValue();" - + "}" - // - + "/** Load Meta Data\n@param ctx context\n@return PO Info\n*/\n" - + "protected POInfo initPO (Properties ctx)" - + "{" - + "POInfo poi = POInfo.getPOInfo (ctx, Table_ID);" - + "return poi;" - + "}" // initPO - // - + "/** Info\n@return info\n*/\n" - + "public String toString()" - + "{" - + "StringBuffer sb = new StringBuffer (\"").append(className).append("[\")" - + ".append(get_ID()).append(\"]\");" - + "return sb.toString();" - + "}"); - - StringBuffer end = new StringBuffer ("}"); - // - sb.insert(0, start); - sb.append(end); - - return className; - } // createHeader - - - /** - * Create Column access methods - * @param AD_Table_ID table - * @param mandatory init call for mandatory columns - * @return set/get method - */ - private StringBuffer createColumns (int AD_Table_ID, StringBuffer mandatory) - { - StringBuffer sb = new StringBuffer(); - String sql = "SELECT c.ColumnName, c.IsUpdateable, c.IsMandatory," // 1..3 - + " c.AD_Reference_ID, c.AD_Reference_Value_ID, DefaultValue, SeqNo, " // 4..7 - + " c.FieldLength, c.ValueMin, c.ValueMax, c.VFormat, c.Callout, " // 8..12 - + " c.Name, c.Description, c.ColumnSQL, c.IsEncrypted, " // 13..16 - + " c.IsIdentifier " // 17 - + "FROM AD_Column c " - + "WHERE c.AD_Table_ID=?" - + " AND c.IsActive='Y'" - + " AND c.ColumnName <> 'AD_Client_ID'" - + " AND c.ColumnName <> 'AD_Org_ID'" - + " AND c.ColumnName <> 'IsActive'" - + " AND c.ColumnName NOT LIKE 'Created%'" - + " AND c.ColumnName NOT LIKE 'Updated%' " - + "ORDER BY c.ColumnName"; - boolean isKeyNamePairCreated = false; // true if the method "getKeyNamePair" is already generated - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, AD_Table_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - String columnName = rs.getString(1); - boolean isUpdateable = "Y".equals(rs.getString(2)); - boolean isMandatory = "Y".equals(rs.getString(3)); - int displayType = rs.getInt(4); - int AD_Reference_Value_ID = rs.getInt(5); - String defaultValue = rs.getString(6); - int seqNo = rs.getInt(7); - int fieldLength = rs.getInt(8); - String ValueMin = rs.getString(9); - String ValueMax = rs.getString(10); - String VFormat = rs.getString(11); - String Callout = rs.getString(12); - String Name = rs.getString(13); - String Description = rs.getString(14); - String ColumnSQL = rs.getString(15); - boolean virtualColumn = ColumnSQL != null && ColumnSQL.length() > 0; - boolean IsEncrypted = "Y".equals(rs.getString(16)); - // - sb.append(createColumnMethods (mandatory, - columnName, isUpdateable, isMandatory, - displayType, AD_Reference_Value_ID, fieldLength, - defaultValue, ValueMin, ValueMax, VFormat, - Callout, Name, Description, virtualColumn, IsEncrypted)); - // - if (seqNo == 1 && "Y".equals(rs.getString("IsIdentifier"))) { - if (!isKeyNamePairCreated) { - sb.append(createKeyNamePair(columnName, displayType)); - isKeyNamePairCreated = true; - } - else { - throw new RuntimeException("More than one primary identifier found " - + " (AD_Table_ID=" + AD_Table_ID + ", ColumnName=" + columnName + ")"); - } - } - // Create COLUMNNAME_ property (teo_sarca, [ 1662447 ]) - sb.append("/** Column name ").append(columnName).append(" */\n") - .append("public static final String COLUMNNAME_").append(columnName) - .append(" = \"").append(columnName).append("\";"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE, sql, e); - } - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } - return sb; - } // createColumns - - /** - * Create set/get methods for column - * @param mandatory init call for mandatory columns - * @param columnName column name - * @param isUpdateable updateable - * @param isMandatory mandatory - * @param displayType display type - * @param AD_Reference_ID validation reference - * @param fieldLength int - * @param defaultValue default value - * @param ValueMin String - * @param ValueMax String - * @param VFormat String - * @param Callout String - * @param Name String - * @param Description String - * @param virtualColumn virtual column - * @param IsEncrypted stored encrypted - @return set/get method - */ - private String createColumnMethods (StringBuffer mandatory, - String columnName, boolean isUpdateable, boolean isMandatory, - int displayType, int AD_Reference_ID, int fieldLength, - String defaultValue, String ValueMin, String ValueMax, String VFormat, - String Callout, String Name, String Description, - boolean virtualColumn, boolean IsEncrypted) - { - // Clazz - Class clazz = DisplayType.getClass(displayType, true); - if (defaultValue == null) - defaultValue = ""; - if (DisplayType.isLOB(displayType)) // No length check for LOBs - fieldLength = 0; - - // Handle Posted - if (columnName.equalsIgnoreCase("Posted") - || columnName.equalsIgnoreCase("Processed") - || columnName.equalsIgnoreCase("Processing")) - { - clazz = Boolean.class; - AD_Reference_ID = 0; - } - // Record_ID - else if (columnName.equalsIgnoreCase("Record_ID")) - { - clazz = Integer.class; - AD_Reference_ID = 0; - } - // String Key - else if (columnName.equalsIgnoreCase("AD_Language") - || columnName.equalsIgnoreCase("EntityType")) - { - clazz = String.class; - } - // Data Type - String dataType = clazz.getName(); - dataType = dataType.substring(dataType.lastIndexOf('.')+1); - if (dataType.equals("Boolean")) - dataType = "boolean"; - else if (dataType.equals("Integer")) - dataType = "int"; - else if (displayType == DisplayType.Binary) - dataType = "byte[]"; - - - StringBuffer sb = new StringBuffer(); - // ****** Set Comment ****** - sb.append("/** Set ").append(Name); - sb.append(".\n@param ").append(columnName).append(" "); - if (Description != null && Description.length() > 0) - sb.append(Description); - else - sb.append(Name); - sb.append(" */\n"); - - // Set ******** - String setValue = "set_Value"; - if (IsEncrypted) - setValue = "set_ValueE"; - // public void setColumn (xxx variable) - sb.append("public "); - if (!isUpdateable) - { - setValue = "set_ValueNoCheck"; - if (IsEncrypted) - setValue = "set_ValueNoCheckE"; - } - sb.append("void set").append(columnName).append(" (").append(dataType).append(" ").append(columnName).append(")" - + "{"); - // List Validation - if (AD_Reference_ID != 0) - { - String staticVar = addListValidation (sb, AD_Reference_ID, columnName, !isMandatory); - sb.insert(0, staticVar); // first check - } - // setValue ("ColumnName", xx); - if (virtualColumn) - { - sb.append ("throw new IllegalArgumentException (\"").append(columnName).append(" is virtual column\");"); - } - // Integer - else if (clazz.equals(Integer.class)) - { - if (columnName.endsWith("_ID")) - { - if (isMandatory) // check mandatory ID - { - int firstOK = 1; // Valid ID 0 - if (columnName.equals("AD_Client_ID") || columnName.equals("AD_Org_ID") - || columnName.equals("Record_ID") || columnName.equals("C_DocType_ID") - || columnName.equals("Node_ID") || columnName.equals("AD_Role_ID") - || columnName.equals("M_AttributeSet_ID") || columnName.equals("M_AttributeSetInstance_ID")) - firstOK = 0; - sb.append("if (").append (columnName) - .append (" < ").append(firstOK).append(") throw new IllegalArgumentException (\"") - .append(columnName).append(" is mandatory.\");"); - } - else // set optional _ID to null if 0 - sb.append("if (").append (columnName).append (" <= 0) ") - .append(setValue).append(" (\"").append(columnName).append("\", null); else \n"); - } - sb.append(setValue).append(" (\"").append(columnName).append("\", Integer.valueOf(").append(columnName).append("));"); - } - // Boolean - else if (clazz.equals(Boolean.class)) - sb.append(setValue).append(" (\"").append(columnName).append("\", Boolean.valueOf(").append(columnName).append("));"); - else - { - if (isMandatory && AD_Reference_ID == 0) // does not apply to int/boolean - { - sb.append("if (") - .append (columnName).append (" == null)" - + " throw new IllegalArgumentException (\"") - .append(columnName).append(" is mandatory.\");"); - } - // String length check - if (clazz.equals(String.class) && fieldLength > 0) - { - sb.append ("if ("); - if (!isMandatory) - sb.append(columnName).append(" != null && "); - sb.append(columnName).append(".length() > ").append(fieldLength) - .append("){log.warning(\"Length > ") - .append(fieldLength).append(" - truncated\");") - .append(columnName).append(" = ") - .append(columnName).append(".substring(0,").append(fieldLength-1).append(");}"); - } - - // - sb.append (setValue).append(" (\"").append (columnName).append ("\", ") - .append (columnName).append (");"); - } - sb.append("}"); - - // Mandatory call in constructor - if (isMandatory) - { - mandatory.append("set").append(columnName).append(" ("); - if (clazz.equals(Integer.class)) - mandatory.append("0"); - else if (clazz.equals(Boolean.class)) - { - if (defaultValue.indexOf('Y') != -1) - mandatory.append(true); - else - mandatory.append("false"); - } - else if (clazz.equals(BigDecimal.class)) - mandatory.append("Env.ZERO"); - else if (clazz.equals(Timestamp.class)) - mandatory.append("new Timestamp(System.currentTimeMillis())"); - else - mandatory.append("null"); - mandatory.append(");"); - if (defaultValue.length() > 0) - mandatory.append("// ").append(defaultValue).append(Env.NL); - } - - - // ****** Get Comment ****** - sb.append("/** Get ").append(Name); - if (Description != null && Description.length() > 0) - sb.append(".\n@return ").append(Description); - else - sb.append(".\n@return ").append(Name); - sb.append(" */\n"); - - // Get ******** - String getValue = "get_Value"; - if (IsEncrypted) - getValue = "get_ValueE"; - sb.append("public ").append(dataType); - if (clazz.equals(Boolean.class)) - { - sb.append(" is"); - if (columnName.toLowerCase().startsWith("is")) - sb.append(columnName.substring(2)); - else - sb.append(columnName); - } - else - sb.append(" get").append(columnName); - sb.append("() {"); - if (clazz.equals(Integer.class)) - sb.append("Integer ii = (Integer)") - .append(getValue).append("(\"").append(columnName).append("\");" - + "if (ii == null)" - + " return 0;" - + "return ii.intValue();"); - else if (clazz.equals(BigDecimal.class)) - sb.append("BigDecimal bd = (BigDecimal)").append(getValue) - .append("(\"").append(columnName).append("\");" - + "if (bd == null)" - + " return Env.ZERO;" - + "return bd;"); - else if (clazz.equals(Boolean.class)) - sb.append("Object oo = ").append(getValue) - .append("(\"").append(columnName).append("\");" - + "if (oo != null) { if (oo instanceof Boolean) return ((Boolean)oo).booleanValue(); return \"Y\".equals(oo);}" - + "return false;"); - else if (dataType.equals("Object")) - sb.append("return ").append(getValue) - .append("(\"").append(columnName).append("\");"); - else - sb.append("return (").append(dataType).append(")").append(getValue) - .append("(\"").append(columnName).append("\");"); - sb.append("}"); - // - return sb.toString(); - } // createColumnMethods - - - /** - * Add List Validation - * @param sb buffer - example: - if (NextAction.equals("N") || NextAction.equals("F")); - else throw new IllegalArgumentException ("NextAction Invalid value - Reference_ID=219 - N - F"); - * @param AD_Reference_ID reference - * @param columnName column - * @param nullable the validation must allow null values - * @return static parameter - Example: - public static final int NEXTACTION_AD_Reference_ID=219; - public static final String NEXTACTION_None = "N"; - public static final String NEXTACTION_FollowUp = "F"; - */ - private String addListValidation (StringBuffer sb, int AD_Reference_ID, - String columnName, boolean nullable) - { - StringBuffer retValue = new StringBuffer(); - retValue.append("\n/** ").append(columnName).append(" AD_Reference_ID=").append(AD_Reference_ID) .append(" */\n") - .append("public static final int ").append(columnName.toUpperCase()) - .append("_AD_Reference_ID=").append(AD_Reference_ID).append(";"); - // - boolean found = false; - StringBuffer values = new StringBuffer("Reference_ID=") - .append(AD_Reference_ID); - StringBuffer statement = new StringBuffer(); - if (nullable) - statement.append("if (").append(columnName).append(" == null"); - // - String sql = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=?"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, AD_Reference_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - String value = rs.getString(1); - values.append(" - ").append(value); - if (statement.length() == 0) - statement.append("if (").append(columnName) - .append(".equals(\"").append(value).append("\")"); - else - statement.append(" || ").append(columnName) - .append(".equals(\"").append(value).append("\")"); - // - if (!found) - { - found = true; - if (!nullable) - sb.append("if (") - .append (columnName).append (" == null)" - + " throw new IllegalArgumentException (\"") - .append(columnName).append(" is mandatory\");"); - } - - - // Name (SmallTalkNotation) - String name = rs.getString(2); - char[] nameArray = name.toCharArray(); - StringBuffer nameClean = new StringBuffer(); - boolean initCap = true; - for (int i = 0; i < nameArray.length; i++) - { - char c = nameArray[i]; - if (Character.isJavaIdentifierPart(c)) - { - if (initCap) - nameClean.append(Character.toUpperCase(c)); - else - nameClean.append(c); - initCap = false; - } - else - { - if (c == '+') - nameClean.append("Plus"); - else if (c == '-') - nameClean.append("_"); - else if (c == '>') - { - if (name.indexOf('<') == -1) // ignore - nameClean.append("Gt"); - } - else if (c == '<') - { - if (name.indexOf('>') == -1) // ignore - nameClean.append("Le"); - } - else if (c == '!') - nameClean.append("Not"); - else if (c == '=') - nameClean.append("Eq"); - else if (c == '~') - nameClean.append("Like"); - initCap = true; - } - } - retValue.append("/** ").append(name).append(" = ").append(value).append(" */\n"); - retValue.append("public static final String ").append(columnName.toUpperCase()) - .append("_").append(nameClean) - .append(" = \"").append(value).append("\";"); - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE, sql, e); - found = false; - } - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } - statement.append(")" - + "; " - + "else " - + "throw new IllegalArgumentException (\"").append(columnName) - .append(" Invalid value - \" + ").append(columnName) - .append(" + \" - ").append(values).append("\");"); - // - if (found && !columnName.equals("EntityType")) - sb.append (statement); - return retValue.toString(); - } // addListValidation - - /** - * Create getKeyNamePair() method with first identifier - * @param columnName name - * * @param displayType int - @return method code - */ - private StringBuffer createKeyNamePair (String columnName, int displayType) - { - String method = "get" + columnName + "()"; - if (displayType != DisplayType.String) - method = "String.valueOf(" + method + ")"; - StringBuffer sb = new StringBuffer("/** Get Record ID/ColumnName\n@return ID/ColumnName pair\n*/" - + "public KeyNamePair getKeyNamePair() " - + "{return new KeyNamePair(get_ID(), ").append(method).append(");}"); - return sb; - } // createKeyNamePair - - - /************************************************************************** - * Write to file - * @param sb string buffer - * @param fileName file name - */ - private void writeToFile (StringBuffer sb, String fileName) - { - try - { - File out = new File (fileName); - // FileWriter fw = new FileWriter (out); - // http://sourceforge.net/tracker/index.php?func=detail&aid=1629947&group_id=176962&atid=879332 - Writer fw = new OutputStreamWriter(new FileOutputStream(out, false), "UTF-8"); - for (int i = 0; i < sb.length(); i++) - { - char c = sb.charAt(i); - // after - if (c == ';' || c == '}') - { - fw.write (c); - if (sb.substring(i+1).startsWith("//")) - fw.write('\t'); - else - fw.write(Env.NL); - } - // before & after - else if (c == '{') - { - fw.write(Env.NL); - fw.write (c); - fw.write(Env.NL); - } - else - fw.write (c); - } - fw.flush (); - fw.close (); - float size = out.length(); - size /= 1024; - log.info(out.getAbsolutePath() + " - " + size + " kB"); - } - catch (Exception ex) - { - log.log(Level.SEVERE, fileName, ex); - } - } // writeToFile - - /** - * String representation - * @return string representation - */ - public String toString() - { - StringBuffer sb = new StringBuffer ("GenerateModel[") - .append("]"); - return sb.toString(); - } // toString - - - - /************************************************************************** - * Generate PO Model Class. - *
    -	 * 	Example: java GenerateModel.class mydirectory myPackage 'U','A'
    -	 * 	would generate entity type User and Application classes into mydirectory.
    -	 * 	Without parameters, the default is used:
    -	 * 	C:\Adempiere\adempiere-all\extend\src\adempiere\model\ adempiere.model 'U','A'
    -	 * 	
    - * @param args directory package entityType - * - directory where to save the generated file - * - package of the classes to be generated - * - entityType to be generated - */ - public static void main (String[] args) - { - org.compiere.Adempiere.startupEnvironment(true); - CLogMgt.setLevel(Level.FINE); - // CLogMgt.setLevel(Level.ALL); - log.info("Generate Model $Revision: 1.5 $"); - log.info("----------------------------------"); - // first parameter - String directory = "/Users/Horus/Documents/adempiere/clientes/libero/src/org/eevolution/model/"; - if (args.length > 0) - directory = args[0]; - if (directory == null || directory.length() == 0) - { - System.err.println("No Directory"); - System.exit(1); - } - log.info("Directory: " + directory); - - // second parameter - String packageName = "org.eevolution.model"; - if (args.length > 1) - packageName = args[1]; - if (packageName == null || packageName.length() == 0) - { - System.err.println("No package"); - System.exit(1); - } - log.info("Package: " + packageName); - - // third parameter - String entityType = "'U','A','D','EE01'"; // User, Application - if (args.length > 2) - entityType = args[2]; - if (entityType == null || entityType.length() == 0) - { - System.err.println("No EntityType"); - System.exit(1); - } - StringBuffer sql = new StringBuffer("EntityType IN (") - .append(entityType).append(")"); - log.info(sql.toString()); - log.info("----------------------------------"); - - // globalqss - add filter LIKE table - String tableLike = "'%PP_%'"; // All tables - if (args.length > 3) - tableLike = args[3]; - log.info("Table Like: " + tableLike); - - // complete sql - sql.insert(0, "SELECT AD_Table_ID " - + "FROM AD_Table " - + "WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')" // special views - + " OR IsView='N')" - + " AND TableName NOT LIKE '%_Trl' AND "); - // globalqss - sql.append(" AND TableName LIKE ").append(tableLike); - // - sql.append(" ORDER BY TableName"); - - // - int count = 0; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), null); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - new GenerateModel(rs.getInt(1), directory, packageName); - count++; - } - rs.close(); - pstmt.close(); - pstmt = null; - } - catch (Exception e) - { - log.severe("main - " + e); - } - finally - { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; - } - log.info("Generated = " + count); - - } // main - -} // GenerateModel diff --git a/base/src/org/eevolution/tools/PLoader.java b/base/src/org/eevolution/tools/PLoader.java deleted file mode 100644 index 700ae3b424..0000000000 --- a/base/src/org/eevolution/tools/PLoader.java +++ /dev/null @@ -1,74 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -package org.eevolution.tools; - -import java.io.InputStream; -import java.util.Properties; - -/** -* @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany -* @version 1.0, October 14th 2005 -*/ -public class PLoader { - - protected Properties properties; - - public PLoader(String properties) { - - init(getClass(), properties); - } - - public PLoader(Class clazz, String properties) { - - init(clazz, properties); - } - - protected void init(Class clazz, String name) { - - properties = new Properties(); - InputStream is = clazz.getResourceAsStream(name); - try { - - if(is != null) { - - properties.load(is); - } - } - catch(Exception e) { - - e.printStackTrace(); - } - finally { - - try { - - if(is != null) { - - is.close(); - } - } - catch(Exception ee) { - - ee.printStackTrace(); - } - } - } - - public Properties getProperties() { - - return properties; - } -} diff --git a/base/src/org/eevolution/tools/swing/AbstractLimiterPlainDocument.java b/base/src/org/eevolution/tools/swing/AbstractLimiterPlainDocument.java deleted file mode 100644 index 35cbf9fce1..0000000000 --- a/base/src/org/eevolution/tools/swing/AbstractLimiterPlainDocument.java +++ /dev/null @@ -1,130 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.tools.swing; - -import java.math.BigDecimal; - -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.PlainDocument; - -/** -* @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany -* @version 1.0, October 14th 2005 -*/ -public abstract class AbstractLimiterPlainDocument extends PlainDocument { - - protected int charCount; - protected BigDecimal maxNumber; - protected BigDecimal minNumber; - - protected CharDefinition charDefinition; - - public abstract void action(String value); - - public AbstractLimiterPlainDocument(CharDefinition def){ - - super(); - - charDefinition = def; - - charCount = -1; - } - - public int getCharCount() { - - return charCount; - } - - public void setCharCount(int charCount) { - - this.charCount = charCount; - } - - public BigDecimal getMaxNumber() { - - return maxNumber; - } - - public BigDecimal getMinNumber() { - - return minNumber; - } - - public void setMaxNumber(BigDecimal number) { - - this.maxNumber = number; - } - - public void setMinNumber(BigDecimal number) { - - this.minNumber = number; - } - - public CharDefinition getCharDefinition() { - - return charDefinition; - } - - public void insertString (int offset, String str, AttributeSet attr) throws BadLocationException { - - if ((str == null) || !charDefinition.contains(str.charAt(0)) ) { - - return; - } - - if(getCharCount() > 0) { - - if ((getLength() + str.length()) > charCount){ - - return; - } - } - String value = getText(0, offset)+str; - if(!isValidNumber(value)) { - - return; - } - - action(value); - super.insertString(offset, str, attr); - } - - protected boolean isValidNumber(String str) { - - if(str == null || str.length() == 0) { - - return true; - } - - boolean valid = true; - - if(maxNumber != null) { - - BigDecimal actual = new BigDecimal(str); - - valid = maxNumber.compareTo(actual) >= 0; - if(valid && minNumber != null) { - - valid = minNumber.compareTo(actual) < 0; - } - } - - return valid; - } -} - diff --git a/base/src/org/eevolution/tools/swing/CharDefinition.java b/base/src/org/eevolution/tools/swing/CharDefinition.java deleted file mode 100644 index d469fd6aab..0000000000 --- a/base/src/org/eevolution/tools/swing/CharDefinition.java +++ /dev/null @@ -1,76 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.tools.swing; - - -/** -* @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany -* @version 1.0, October 14th 2005 -*/ -public class CharDefinition { - - public CharDefinition() { - } - - - public static CharDefinition getDefaultDef() { - - CharDefinition def = new CharDefinition(); - def.setAllowed("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 .,&-/+*$%"); - - return def; - } - public static CharDefinition getNumberDef() { - - CharDefinition def = new CharDefinition(); - def.setAllowed("1234567890"); - - return def; - } - public static CharDefinition getLetterDef() { - - CharDefinition def = new CharDefinition(); - def.setAllowed("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); - - return def; - } - public static CharDefinition getCurrencyDef() { - - CharDefinition def = new CharDefinition(); - def.setAllowed("1234567890,"); - - return def; - } - - public boolean contains(char c) { - - for(int i = 0; i < g_definition.length; i++) { - - if(c == g_definition[i]) return true; - } - - return false; - } - - public void setAllowed(String str) { - - g_definition = str.toCharArray(); - } - - - private char[] g_definition; -} \ No newline at end of file diff --git a/base/src/org/eevolution/tools/swing/SwingTool.java b/base/src/org/eevolution/tools/swing/SwingTool.java deleted file mode 100644 index 86e6697180..0000000000 --- a/base/src/org/eevolution/tools/swing/SwingTool.java +++ /dev/null @@ -1,267 +0,0 @@ -package org.eevolution.tools.swing; - -import java.awt.Adjustable; -import java.awt.Component; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.Event; -import java.awt.ItemSelectable; -import java.awt.event.ContainerAdapter; -import java.awt.event.ContainerEvent; -import java.util.Iterator; -import java.util.List; - -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.KeyStroke; -import javax.swing.text.JTextComponent; - -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -/** -* @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany -* @version 1.0, October 14th 2005 -*/ -public class SwingTool { - - public static synchronized void setCursorsFromChild(Component child, boolean waiting) { - - Component com = child; - - while(com.getParent() != null) { - - com = (Component)(com.getParent()); - } - - setCursorsFromParent((Container)com, waiting); - } - - protected static boolean isIgnoredComponent(Component c) { - - boolean retVal = true; - - if(c instanceof ItemSelectable && c.isEnabled()) { - - retVal = false; - } - else if(c instanceof JTextComponent && c.isEnabled()) { - - retVal = false; - } - else if(c instanceof JFrame && c.isEnabled()) { - - retVal = false; - } - else if(c instanceof JPanel && c.isEnabled()) { - - retVal = false; - } - else if(c instanceof JLabel && c.isEnabled()) { - - retVal = false; - } - else if(c instanceof Adjustable && c.isEnabled()) { - - retVal = false; - } - - return retVal; - } - - public static void setCursor(Component c, boolean waiting) { - - if(isIgnoredComponent(c)) { - - return; - } - - Cursor cursor_wait = new Cursor(Cursor.WAIT_CURSOR); - Cursor cursor_def = getPredefinedCursor(c); - - Component com = c; - - if(waiting) { - - com.setCursor(cursor_wait); - } - else { - - com.setCursor(cursor_def); - } - } - - public static Cursor getPredefinedCursor(Component c) { - - Cursor cursor = Cursor.getDefaultCursor(); - - if(c instanceof JTextComponent) { - - cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR); - } - else if(c instanceof ItemSelectable || c instanceof Adjustable) { - - cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); - } - - return cursor; - } - - public static void setCursors(Component[] components, boolean waiting) { - - for( int i = 0; i < components.length; i++) { - - setCursor(components[i], waiting); - } - } - - public synchronized static void setCursorsFromParent(Container parent, boolean waiting) { - - Container con = parent; - - for(int i = 0; i < con.getComponentCount(); i++) { - - setCursor(con.getComponent(i), waiting); - - if(con.getComponent(i) instanceof Container) { - - setCursorsFromParent((Container)con.getComponent(i), waiting); - } - } - } - - public static Component searchComponent(Container parent, Class clazz, boolean remove) { - - Container con = parent; - Component retVal = null; - Component c = null; - - for(int i = 0; i < con.getComponentCount(); i++) { - - c = con.getComponent(i); - - //Found the given class and breaks the loop - if(clazz.isInstance(c)) { - - if(remove) { - - con.remove(c); - } - - return c; - } - - //Recursively calling this method to search in deep - if(c instanceof Container) { - - c = searchComponent((Container)c , clazz, remove); - - if(clazz.isInstance(c)) { - - if(remove) { - - con.remove(retVal); - } - - return c; - } - } - } - - return null; - } - - public static void addOpaque(JComponent c, final boolean opaque) { - - ContainerAdapter ca = new ContainerAdapter() { - - public void componentAdded(ContainerEvent e) { - - setOpaque(e.getChild()); - } - - private void setOpaque(Component c) { - - //ignores all selectable items, like buttons - if(c instanceof ItemSelectable) { - - return; - } - // sets transparent - else if(c instanceof JComponent) { - - ((JComponent)c).setOpaque(opaque); - } - // recursively calls this method for all container components - else if(c instanceof Container) { - - for(int i = 0; i > ((Container)c).getComponentCount(); i++) { - - setOpaque(((Container)c).getComponent(i)); - } - } - } - }; - c.addContainerListener(ca); - } - - - - public static KeyStroke getKeyStrokeFor(String name, List usedStrokes) { - - return (name == null) ? null : getKeyStrokeFor(name.charAt(0), usedStrokes); - } - - public static KeyStroke getKeyStrokeFor(char c, List usedStrokes) { - - int m = Event.CTRL_MASK; - - KeyStroke o = null; - for(Iterator i = usedStrokes.iterator(); i.hasNext();) { - - o = (KeyStroke)i.next(); - if(c == o.getKeyChar()) { - - if(c == o.getKeyChar()) { - - if(o.getModifiers() != Event.SHIFT_MASK+Event.CTRL_MASK) { - - m = Event.SHIFT_MASK+Event.CTRL_MASK; - } - else if(o.getModifiers() != Event.SHIFT_MASK+Event.ALT_MASK) { - - m = Event.SHIFT_MASK+Event.ALT_MASK; - } - else { - - m = -1; - } - } - } - } - - KeyStroke s = null; - if(m != -1) { - - s = KeyStroke.getKeyStroke(c, m); - usedStrokes.add(s); - } - - return s; - } -} diff --git a/base/src/org/eevolution/tools/worker/MultiWorker.java b/base/src/org/eevolution/tools/worker/MultiWorker.java deleted file mode 100644 index cb8009d65e..0000000000 --- a/base/src/org/eevolution/tools/worker/MultiWorker.java +++ /dev/null @@ -1,105 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.tools.worker; - -/** -* @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany -* @version 1.0, October 14th 2005 -*/ -public abstract class MultiWorker { - - protected abstract class WorkerThread extends Thread { - - abstract public Object doWork(); - - public void run() { - - isWorking = true; - value = doWork(); - isWorking = false; - } - - public void interrupt() { - - super.interrupt(); - isWorking = false; - } - } - - protected boolean isWorking; - protected WorkerThread workerThread; - protected int timeout; - protected Object value; - - public MultiWorker() { - - setTimeout(-1); - } - - public abstract void start(); - - - public int getTimeout() { - - return timeout; - } - - public void setTimeout(int timeout) { - - this.timeout = timeout; - } - - public boolean isWorking() { - - return isWorking; - } - - public void waitForComplete(int timeout) { - - setTimeout(timeout); - waitForComplete(); - } - - public void stop() { - - workerThread.interrupt(); - } - - public void waitForComplete() { - - boolean to = getTimeout() > -1; - - int c = 0; - int i = 1000; - while(isWorking()) { - - try { - - Thread.sleep(i); - c+= to ? c+=i : -1; - } - catch(Exception e) {} - - if(to && c >= getTimeout()) { - - workerThread.interrupt(); - workerThread = null; - break; - } - } - } -} diff --git a/base/src/org/eevolution/tools/worker/SingleWorker.java b/base/src/org/eevolution/tools/worker/SingleWorker.java deleted file mode 100644 index 47119cdab6..0000000000 --- a/base/src/org/eevolution/tools/worker/SingleWorker.java +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.tools.worker; - -/** -* @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany -* @version 1.0, October 14th 2005 -*/ -public abstract class SingleWorker extends MultiWorker { - - public SingleWorker() { - - super(); - } - - public void start() { - - workerThread = new WorkerThread() { - - public Object doWork() { - - return doIt(); - }; - }; - workerThread.start(); - } - - protected abstract Object doIt(); -} diff --git a/client/src/org/compiere/grid/ed/VLookup.java b/client/src/org/compiere/grid/ed/VLookup.java index 6414f850b3..9b52d7824a 100644 --- a/client/src/org/compiere/grid/ed/VLookup.java +++ b/client/src/org/compiere/grid/ed/VLookup.java @@ -75,7 +75,7 @@ import org.compiere.util.Ini; import org.compiere.util.Msg; import org.compiere.util.NamePair; import org.compiere.util.ValueNamePair; -import org.eevolution.model.MPPProductBOMLine; +import org.eevolution.model.X_PP_Product_BOMLine; /** * Lookup Visual Field. @@ -822,7 +822,7 @@ public class VLookup extends JComponent { int AD_Table_ID = MColumn.getTable_ID(Env.getCtx(), m_mField.getAD_Column_ID(), null); - multipleSelection = (MOrderLine.Table_ID == AD_Table_ID) || (MInvoiceLine.Table_ID == AD_Table_ID) || (MPPProductBOMLine.Table_ID == AD_Table_ID) || (MProductPrice.Table_ID == AD_Table_ID); + multipleSelection = (MOrderLine.Table_ID == AD_Table_ID) || (MInvoiceLine.Table_ID == AD_Table_ID) || (X_PP_Product_BOMLine.Table_ID == AD_Table_ID) || (MProductPrice.Table_ID == AD_Table_ID); } // Show Info InfoProduct ip = new InfoProduct (frame, true, m_lookup.getWindowNo(), diff --git a/extend/src/org/adempiere/model/ExportModelValidator.java b/extend/src/org/adempiere/model/ExportModelValidator.java deleted file mode 100644 index dd043f0b1e..0000000000 --- a/extend/src/org/adempiere/model/ExportModelValidator.java +++ /dev/null @@ -1,238 +0,0 @@ -/********************************************************************** -* This file is part of Adempiere ERP Bazaar * -* http://www.adempiere.org * -* * -* Copyright (C) Trifon Trifonov. * -* Copyright (C) Contributors * -* * -* This program is free software; you can redistribute it and/or * -* modify it under the terms of the GNU General Public License * -* as published by the Free Software Foundation; either version 2 * -* of the License, or (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the Free Software * -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * -* MA 02110-1301, USA. * -* * -* Contributors: * -* - Trifon Trifonov (trifonnt@users.sourceforge.net) * -* * -* Sponsors: * -* - E-evolution (http://www.e-evolution.com) * -***********************************************************************/ - -package org.adempiere.model; - -import org.adempiere.process.rpl.exp.ExportHelper; -import org.compiere.model.MClient; -import org.compiere.model.MReplicationStrategy; -import org.compiere.model.MTable; -import org.compiere.model.ModelValidationEngine; -import org.compiere.model.ModelValidator; -import org.compiere.model.PO; -import org.compiere.model.X_AD_ReplicationDocument; -import org.compiere.model.X_AD_ReplicationTable; -import org.compiere.util.CLogger; - - -/** - * Export Validator which is responsible to create XML document. - * - * @author Trifon Trifonov - * @version $Id$ - */ -public class ExportModelValidator implements ModelValidator -{ - - /** Logger */ - private static CLogger log = CLogger.getCLogger(ExportModelValidator.class); - - /** Client */ - private int m_AD_Client_ID = -1; - - /** Organization */ - private int m_AD_Org_ID = -1; - - /** Role */ - private int m_AD_Role_ID = -1; - - /** User */ - private int m_AD_User_ID = -1; - - /** Replication Strategy **/ - private int m_AD_ReplicationStrategy_ID = -1; - - /** Export Helper */ - ExportHelper expHelper = null; - - /** - * Constructor. - * The class is instantiated when logging in and client is selected/known - */ - public ExportModelValidator () - { - super (); - } - - /** - * Initialize Validation - * @param engine validation engine - * @param client client - */ - public void initialize (ModelValidationEngine engine, MClient client) - { - m_AD_Client_ID = client.getAD_Client_ID(); - log.info(client.toString()); - - MReplicationStrategy rplStrategy = null; - - m_AD_ReplicationStrategy_ID = client.getAD_ReplicationStrategy_ID(); - log.info("client.getAD_ReplicationStrategy_ID() = " + m_AD_ReplicationStrategy_ID); - - if (m_AD_ReplicationStrategy_ID > 0) { - rplStrategy = new MReplicationStrategy(client.getCtx(), m_AD_ReplicationStrategy_ID, null); - expHelper = new ExportHelper(client, rplStrategy); - } - // Add Tables - // We want to be informed when records in Replication tables are created/updated/deleted! - //engine.addModelChange(MBPartner.Table_Name, this); - //engine.addModelChange(MOrder.Table_Name, this); - //engine.addModelChange(MOrderLine.Table_Name, this); - if (rplStrategy != null) { - - for (X_AD_ReplicationTable rplTable : rplStrategy.getReplicationTables()) { - if (X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(rplTable.getReplicationType()) - || X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(rplTable.getReplicationType())) - { - MTable table = MTable.get (client.getCtx(), rplTable.getAD_Table_ID()); - engine.addModelChange(table.getTableName(), this); - } - } - } - // Add Documents - // We want to be informed when Replication documents are created/updated/deleted! - if (rplStrategy != null) { - for (X_AD_ReplicationDocument rplDocument : rplStrategy.getReplicationDocuments()) { - if (X_AD_ReplicationDocument.REPLICATIONTYPE_Merge.equals(rplDocument.getReplicationType()) - || X_AD_ReplicationDocument.REPLICATIONTYPE_Reference.equals(rplDocument.getReplicationType())) - { - //MDocType docType = MDocType.get(client.getCtx(), rplDocuments[i].getC_DocType_ID()); - MTable table = MTable.get (client.getCtx(), rplDocument.getAD_Table_ID()); - engine.addDocValidate(table.getTableName(), this); - } - } - } - - } - - /** - * Model Change of a monitored Table. - * Called after PO.beforeSave/PO.beforeDelete - * @param po persistent object - * @param type TYPE_ - * @return error message or null - * @exception Exception if the recipient wishes the change to be not accept. - */ - public String modelChange (PO po, int type) throws Exception - { - String Mode = "Table"; - log.info("po.get_TableName() = " + po.get_TableName()); - if (expHelper != null) { - if ( type == TYPE_AFTER_CHANGE - || type == TYPE_AFTER_NEW - || type == TYPE_BEFORE_DELETE) // After Change or After New - { - expHelper.exportRecord( po, - MReplicationStrategy.REPLICATION_TABLE, - MReplicationStrategy.getReplicationDocument(po.getCtx(), m_AD_ReplicationStrategy_ID, po.get_Table_ID()).getReplicationType(), - type); - } - } - - return null; - } - - /** - * Validate Document. - * Called as first step of DocAction.prepareIt - * when you called addDocValidate for the table. - * @param po persistent object - * @param type see TIMING_ constants - * @return error message or null - * @throws Exception - */ - public String docValidate (PO po, int type) - { - log.info("po.get_TableName() = " + po.get_TableName()); - String result = null; - if (expHelper != null) { - try { - if ( type == TIMING_AFTER_COMPLETE - || type == TIMING_AFTER_CLOSE - || type == TIMING_AFTER_REVERSECORRECT - || type == TIMING_AFTER_VOID - || type == TIMING_AFTER_VOID - || type == TIMING_AFTER_PREPARE - ) - { - expHelper.exportRecord( po, - MReplicationStrategy.REPLICATION_DOCUMENT , - MReplicationStrategy.getReplicationDocument(po.getCtx(), m_AD_ReplicationStrategy_ID, po.get_Table_ID()).getReplicationType(), - type); - - } - } catch (Exception e) { - e.printStackTrace(); - result = e.toString(); - } - } - return result; - } - - /** - * User Login. - * Called when preferences are set - * @param AD_Org_ID org - * @param AD_Role_ID role - * @param AD_User_ID user - * @return error message or null - */ - public String login (int AD_Org_ID, int AD_Role_ID, int AD_User_ID) - { - m_AD_Org_ID = AD_Org_ID; - m_AD_Role_ID = AD_Role_ID; - m_AD_User_ID = AD_User_ID; - - log.info("AD_Org_ID =" + m_AD_Org_ID); - log.info("AD_Role_ID =" + m_AD_Role_ID); - log.info("AD_User_ID =" + m_AD_User_ID); - return null; - } - - - /** - * Get Client to be monitored - * @return AD_Client_ID client - */ - public int getAD_Client_ID() - { - return m_AD_Client_ID; - } - - /** - * String Representation - * @return info - */ - public String toString () - { - StringBuffer sb = new StringBuffer (ExportModelValidator.class.getName()); - return sb.toString(); - } - -} diff --git a/extend/src/org/adempiere/process/rpl/IExportProcessor.java b/extend/src/org/adempiere/process/rpl/IExportProcessor.java deleted file mode 100644 index 579dafacfb..0000000000 --- a/extend/src/org/adempiere/process/rpl/IExportProcessor.java +++ /dev/null @@ -1,46 +0,0 @@ -/********************************************************************** -* This file is part of Adempiere ERP Bazaar * -* http://www.adempiere.org * -* * -* Copyright (C) Trifon Trifonov. * -* Copyright (C) Contributors * -* * -* This program is free software; you can redistribute it and/or * -* modify it under the terms of the GNU General Public License * -* as published by the Free Software Foundation; either version 2 * -* of the License, or (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the Free Software * -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * -* MA 02110-1301, USA. * -* * -* Contributors: * -* - Trifon Trifonov (trifonnt@users.sourceforge.net) * -* * -* Sponsors: * -* - E-evolution (http://www.e-evolution.com) * -***********************************************************************/ - -package org.adempiere.process.rpl; - -import java.util.Properties; - -import org.compiere.util.Trx; -import org.eevolution.model.MEXPProcessor; -import org.w3c.dom.Document; - -/** - * @author Trifon N. Trifonov - */ -public interface IExportProcessor { - - public void process(Properties ctx, MEXPProcessor expProcessor, Document document, Trx trx) - throws Exception; - -} diff --git a/extend/src/org/adempiere/process/rpl/exp/ExportHelper.java b/extend/src/org/adempiere/process/rpl/exp/ExportHelper.java deleted file mode 100644 index fd93a66673..0000000000 --- a/extend/src/org/adempiere/process/rpl/exp/ExportHelper.java +++ /dev/null @@ -1,599 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * - Antonio Cañaveral, e-Evolution * - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ -package org.adempiere.process.rpl.exp; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.text.SimpleDateFormat; -import java.util.HashMap; -import java.util.Properties; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.adempiere.process.rpl.IExportProcessor; -import org.compiere.model.MClient; -import org.compiere.model.MColumn; -import org.compiere.model.MReplicationStrategy; -import org.compiere.model.MTable; -import org.compiere.model.PO; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.Language; -import org.compiere.util.Msg; -import org.compiere.util.Trx; -import org.eevolution.model.MEXPFormat; -import org.eevolution.model.MEXPFormatLine; -import org.eevolution.model.MEXPProcessor; -import org.eevolution.model.MEXPProcessorType; -import org.eevolution.model.X_EXP_FormatLine; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Text; - -/** - * @author Trifon N. Trifonov - * @author Antonio Cañaveral, e-Evolution - *
  • [ 2195016 ] Implementation delete records messages - *
  • http://sourceforge.net/tracker/index.php?func=detail&aid=2195016&group_id=176962&atid=879332 - */ -public class ExportHelper { - - /** Logger */ - private static CLogger log = CLogger.getCLogger(ExportHelper.class); - - /** XML Document */ - private Document outDocument = null; - - /** Date Time Format */ - private SimpleDateFormat m_dateTimeFormat = null; - - /** Date Format */ - private SimpleDateFormat m_dateFormat = null; - - /** Custom Date Format */ - private SimpleDateFormat m_customDateFormat = null; - - /** Client */ - private int m_AD_Client_ID = -1; - - /** Replication Strategy */ - MReplicationStrategy m_rplStrategy = null; - - - public ExportHelper(MClient client, MReplicationStrategy rplStrategy) { - m_AD_Client_ID = client.getAD_Client_ID(); - m_rplStrategy = rplStrategy; - - m_dateTimeFormat = DisplayType.getDateFormat(DisplayType.DateTime, Language.getLanguage(Env.getAD_Language(client.getCtx()))); - m_dateFormat = DisplayType.getDateFormat(DisplayType.Date, Language.getLanguage(Env.getAD_Language(client.getCtx()))); - } - - public ExportHelper(Properties ctx , int AD_Client_ID) { - m_AD_Client_ID = AD_Client_ID; - m_dateTimeFormat = DisplayType.getDateFormat(DisplayType.DateTime, Language.getLanguage(Env.getAD_Language(ctx))); - m_dateFormat = DisplayType.getDateFormat(DisplayType.Date, Language.getLanguage(Env.getAD_Language(ctx))); - } - - /** - * Process - Generate Export Format - * @return info - */ - @SuppressWarnings("unchecked") - public String exportRecord (PO po, Integer ReplicationMode , String ReplicationType, Integer ReplicationEvent) throws Exception - { - MClient client = MClient.get (po.getCtx(), m_AD_Client_ID); - log.info("Client = " + client.toString()); - - log.info("TRIFON - po.getAD_Org_ID() = " + po.getAD_Org_ID()); - - log.info("TRIFON - po.get_TrxName() = " + po.get_TrxName()); - if (po.get_TrxName() == null || po.get_TrxName().equals("")) { - po.set_TrxName("exportRecord"); - } - - - log.info("Table = " + po.get_TableName()); - //PO po = table.getPO (po.get_ID(), po.get_TrxName()); - - if (po.get_KeyColumns().length > 1 || po.get_KeyColumns().length < 1) { - throw new Exception(Msg.getMsg (po.getCtx(), "ExportMultiColumnNotSupported")); - } - // TODO - get proper Export Format! - String version = "3.2.0"; - //int EXP_Format_ID = 1000006; - MEXPFormat exportFormat = null; - //exportFormat = new MFormat(po.getCtx(), EXP_Format_ID, po.get_TrxName()); - exportFormat = MEXPFormat.getFormatByAD_Client_IDAD_Table_IDAndVersion(po.getCtx(), m_AD_Client_ID, po.get_Table_ID(), version, po.get_TrxName()); - log.fine("exportFormat = " + exportFormat); - if (exportFormat == null || exportFormat.getEXP_Format_ID() == 0) { - // Fall back to System Client - MClient systemClient = MClient.get (po.getCtx(), 0); - log.info(systemClient.toString()); - exportFormat = MEXPFormat.getFormatByAD_Client_IDAD_Table_IDAndVersion(po.getCtx(), 0, po.get_Table_ID(), version, po.get_TrxName()); - - if (exportFormat == null || exportFormat.getEXP_Format_ID() == 0) { - throw new Exception(Msg.getMsg(po.getCtx(), "EXPFormatNotFound")); - } - } - - outDocument = createNewDocument(); - - StringBuffer sql = new StringBuffer("SELECT * ") - .append("FROM ").append(po.get_TableName()).append(" ") - .append("WHERE ").append(po.get_KeyColumns()[0]).append("=?") - ; - - if (exportFormat.getWhereClause() != null & !"".equals(exportFormat.getWhereClause())) { - sql.append(" AND ").append(exportFormat.getWhereClause()); - } - - ResultSet rs = null; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), po.get_TrxName()); - pstmt.setInt(1, po.get_ID()); - rs = pstmt.executeQuery(); - if (rs.next()) - { - HashMap variableMap = new HashMap(); - //variableMap.put(TOTAL_SEGMENTS, new Integer(1)); - - Element rootElement = outDocument.createElement(exportFormat.getValue()); - if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) { - rootElement.appendChild(outDocument.createComment(exportFormat.getDescription())); - } - rootElement.setAttribute("AD_Client_Value", client.getValue()); - rootElement.setAttribute("Version", exportFormat.getVersion()); - rootElement.setAttribute("ReplicationMode", ReplicationMode.toString()); - rootElement.setAttribute("ReplicationType", ReplicationType); - rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString()); - outDocument.appendChild(rootElement); - generateExportFormat(rootElement, exportFormat, rs, po, po.get_ID(), variableMap); - } - - } finally { - try { - if (rs != null) rs.close(); - if (pstmt != null) pstmt.close(); - } catch (SQLException ex) {/*ignored*/} - rs = null; - pstmt = null; - } - - MEXPProcessor mExportProcessor = null; - mExportProcessor = new MEXPProcessor (po.getCtx(), m_rplStrategy.getEXP_Processor_ID(), po.get_TrxName() ); - log.fine("ExportProcessor = " + mExportProcessor); - int EXP_ProcessorType_ID = 0; - EXP_ProcessorType_ID = mExportProcessor.getEXP_Processor_Type_ID(); - MEXPProcessorType expProcessor_Type = new MEXPProcessorType(po.getCtx(), EXP_ProcessorType_ID, po.get_TrxName() ); - - - String javaClass = expProcessor_Type.getJavaClass(); - try { - Class clazz = Class.forName(javaClass); - IExportProcessor exportProcessor = (IExportProcessor)clazz.newInstance(); - - exportProcessor.process(po.getCtx(), mExportProcessor, outDocument, Trx.get( po.get_TrxName(), false )); - - } catch (Exception e) { - log.severe(e.toString()); - throw e; - } - - return outDocument.toString(); - } - - - /** - * Process - Generate Export Format - * @param - * - * @return Document - */ - @SuppressWarnings("unchecked") - public Document exportRecord (MEXPFormat exportFormat, String where , Integer ReplicationMode , String ReplicationType, Integer ReplicationEvent) throws Exception - { - MClient client = MClient.get (exportFormat.getCtx(), m_AD_Client_ID); - MTable table = MTable.get(exportFormat.getCtx(), exportFormat.getAD_Table_ID()); - log.info("Table = " + table); - int[] ids = MTable.getAllIDs(table.getTableName(), where, null); - - for (int id : ids) - { - PO po = table.getPO(id, null); - log.info("Client = " + client.toString()); - - log.info("TRIFON - po.getAD_Org_ID() = " + po.getAD_Org_ID()); - - log.info("TRIFON - po.get_TrxName() = " + po.get_TrxName()); - if (po.get_TrxName() == null || po.get_TrxName().equals("")) { - po.set_TrxName("exportRecord"); - } - - if (po.get_KeyColumns().length > 1 || po.get_KeyColumns().length < 1) { - throw new Exception(Msg.getMsg (po.getCtx(), "ExportMultiColumnNotSupported")); - } - // TODO - get proper Export Format! - String version = "3.2.0"; - outDocument = createNewDocument(); - - StringBuffer sql = new StringBuffer("SELECT * ") - .append("FROM ").append(table.getTableName()).append(" ") - .append("WHERE ").append(po.get_KeyColumns()[0]).append("=?") - ; - - if (exportFormat.getWhereClause() != null & !"".equals(exportFormat.getWhereClause())) { - sql.append(" AND ").append(exportFormat.getWhereClause()); - } - - ResultSet rs = null; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), po.get_TrxName()); - pstmt.setInt(1, po.get_ID()); - rs = pstmt.executeQuery(); - if (rs.next()) - { - HashMap variableMap = new HashMap(); - //variableMap.put(TOTAL_SEGMENTS, new Integer(1)); - - Element rootElement = outDocument.createElement(exportFormat.getValue()); - if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) { - rootElement.appendChild(outDocument.createComment(exportFormat.getDescription())); - } - rootElement.setAttribute("AD_Client_Value", client.getValue()); - rootElement.setAttribute("Version", exportFormat.getVersion()); - rootElement.setAttribute("ReplicationMode", ReplicationMode.toString()); - rootElement.setAttribute("ReplicationType", ReplicationType); - rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString()); - outDocument.appendChild(rootElement); - generateExportFormat(rootElement, exportFormat, rs, po, po.get_ID(), variableMap); - } - - } finally { - try { - if (rs != null) rs.close(); - if (pstmt != null) pstmt.close(); - } catch (SQLException ex) {/*ignored*/} - rs = null; - pstmt = null; - } - }// finish record read - return outDocument; - } - - - /* - * Trifon Generate Export Format process; RESULT = - * - * 101 - * - */ - private void generateExportFormat(Element rootElement, MEXPFormat exportFormat, ResultSet rs, PO masterPO, int masterID, HashMap variableMap) throws SQLException, Exception - { - MEXPFormatLine[] formatLines = (MEXPFormatLine[]) exportFormat.getFormatLines(); - @SuppressWarnings("unused") - boolean elementHasValue = false; - - for (int i = 0; i < formatLines.length; i++) { - if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_XMLElement) ) { - // process single XML Attribute - // Create new element - Element newElement = outDocument.createElement(formatLines[i].getValue()); - - if (formatLines[i].getAD_Column_ID() == 0) { - throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); - } - MColumn column = MColumn.get(masterPO.getCtx(), formatLines[i].getAD_Column_ID()); - if (column == null) { - throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); - } - if ( column.isVirtualColumn() ) { - log.info("This is Virtual Column!"); - } else { } - //log.info("["+column.getColumnName()+"]"); - - Object value = rs.getObject(column.getColumnName()); - String valueString = null; - if (value != null) { - valueString = value.toString(); - } else { - // Could remove this exception and create empty XML Element when column do not have value. - if (formatLines[i].isMandatory()) { - //throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPFieldMandatory")); - } - } - if (column.getAD_Reference_ID() == DisplayType.Date) { - if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" - //Date date = m_customDateFormat.parse ( valueString ); - valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); - newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute" - } else { - //valueString = m_dateFormat.format (Timestamp.valueOf (valueString)); - //newElement.setAttribute("DateFormat", m_dateTimeFormat.toPattern()); // Add "DateForamt attribute - //Standard Japanese Format (default) works better (yyyy-mm-dd) - newElement.setAttribute("DateFormat", valueString); - } - - } - } else if (column.getAD_Reference_ID() == DisplayType.DateTime) { - if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" - //Date date = m_customDateFormat.parse ( valueString ); - valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); - newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute" - } else { - //valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString)); - //newElement.setAttribute("DateFormat", m_dateTimeFormat.toPattern()); // Add "DateForamt attribute - //Standard Japanese Format (default) works better (yyyy-mm-dd hh:mm:ss m.mm) - newElement.setAttribute("DateFormat", valueString); - } - } - } - log.info("EXP Field - column=["+column.getColumnName()+"]; value=" + value); - if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) { - Text newText = outDocument.createTextNode(valueString); - newElement.appendChild(newText); - rootElement.appendChild(newElement); - elementHasValue = true; - //increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable - //increaseVariable(variableMap, TOTAL_SEGMENTS); - } else { - // Empty field. - if (formatLines[i].isMandatory()) { - Text newText = outDocument.createTextNode(""); - newElement.appendChild(newText); - rootElement.appendChild(newElement); - elementHasValue = true; - } - } - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_XMLAttribute) ) { - // process single XML Attribute - if (formatLines[i].getAD_Column_ID() == 0) { - throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); - } - MColumn column = MColumn.get(masterPO.getCtx(), formatLines[i].getAD_Column_ID()); - if (column == null) { - throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); - } - if ( column.isVirtualColumn() ) { - log.info("This is Virtual Column!"); - } else { } - //log.info("["+column.getColumnName()+"]"); - - Object value = rs.getObject(column.getColumnName()); - String valueString = null; - if (value != null) { - valueString = value.toString(); - } else { - if (formatLines[i].isMandatory()) { - throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPFieldMandatory")); - } - } -/* if (column.getAD_Reference_ID() == DisplayType.Date) { - if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" - //Date date = m_customDateFormat.parse ( valueString ); - valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); - } else { - valueString = m_dateFormat.format (Timestamp.valueOf (valueString)); - } - - } - } else if (column.getAD_Reference_ID() == DisplayType.DateTime) { - if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" - //Date date = m_customDateFormat.parse ( valueString ); - valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); - } else { - valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString)); - } - } - }*/ - log.info("EXP Field - column=["+column.getColumnName()+"]; value=" + value); - if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) { - rootElement.setAttribute(formatLines[i].getValue(), valueString); - elementHasValue = true; - //increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable - //increaseVariable(variableMap, TOTAL_SEGMENTS); - } else { - // Empty field. - } - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_EmbeddedEXPFormat) ) { - // process Embedded Export Format - - int embeddedFormat_ID = formatLines[i].getEXP_EmbeddedFormat_ID(); - MEXPFormat embeddedFormat = new MEXPFormat(masterPO.getCtx(), embeddedFormat_ID, masterPO.get_TrxName()); - - MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID()); - log.info("Table Embedded = " + tableEmbedded); - StringBuffer sql = new StringBuffer("SELECT * ") - .append("FROM ").append(tableEmbedded.getTableName()).append(" ") - .append("WHERE ").append(masterPO.get_KeyColumns()[0]).append("=?") - //+ "WHERE " + po.get_WhereClause(false) - ; - if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) { - sql.append(" AND ").append(embeddedFormat.getWhereClause()); - } - log.info(sql.toString()); - ResultSet rsEmbedded = null; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), masterPO.get_TrxName()); - pstmt.setInt(1, masterID); - rsEmbedded = pstmt.executeQuery(); - while (rsEmbedded.next()) - { - //System.out.println("Trifon - tableEmbedded.getTableName()_ID = "+ tableEmbedded.getTableName() + "_ID"); - int embeddedID = rsEmbedded.getInt(tableEmbedded.getTableName() + "_ID"); - PO poEmbedded = tableEmbedded.getPO (embeddedID, masterPO.get_TrxName()); - - Element embeddedElement = outDocument.createElement(formatLines[i].getValue()); - if (formatLines[i].getDescription() != null && !"".equals(formatLines[i].getDescription())) { - embeddedElement.appendChild(outDocument.createComment(formatLines[i].getDescription())); - } - generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap); - rootElement.appendChild(embeddedElement); - } - - } finally { - try { - if (rsEmbedded != null) rsEmbedded.close(); - if (pstmt != null) pstmt.close(); - } catch (SQLException ex) { } - rsEmbedded = null; - pstmt = null; - } - - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_ReferencedEXPFormat) ) { - // process Referenced Export Format - - int embeddedFormat_ID = formatLines[i].getEXP_EmbeddedFormat_ID(); - MEXPFormat embeddedFormat = new MEXPFormat(masterPO.getCtx(), embeddedFormat_ID, masterPO.get_TrxName()); - - MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID()); - log.info("Table Embedded = " + tableEmbedded); - StringBuffer sql = new StringBuffer("SELECT * ") - .append("FROM ").append(tableEmbedded.getTableName()).append(" ") - .append("WHERE ").append(tableEmbedded.getTableName() + "_ID").append("=?") - //+ "WHERE " + po.get_WhereClause(false) - ; - if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) { - sql.append(" AND ").append(embeddedFormat.getWhereClause()); - } - log.info(sql.toString()); - if (formatLines[i].getAD_Column_ID() == 0) { - throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); - } - MColumn column = MColumn.get(masterPO.getCtx(), formatLines[i].getAD_Column_ID()); - if (column == null) { - throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); - } - if ( column.isVirtualColumn() ) { - log.info("This is Virtual Column!"); - } else { } - //log.info("["+column.getColumnName()+"]"); - Object value = rs.getObject(column.getColumnName()); -/* String valueString = null; - if (value != null) { - valueString = value.toString(); - } else { - throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPFieldMandatory")); - } -*/ - log.info(sql.toString()); - ResultSet rsEmbedded = null; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), masterPO.get_TrxName()); - pstmt.setObject(1, value); - rsEmbedded = pstmt.executeQuery(); - while (rsEmbedded.next()) - { - //System.out.println("Trifon - tableEmbedded.getTableName()_ID = "+ tableEmbedded.getTableName() + "_ID"); - int embeddedID = rsEmbedded.getInt(tableEmbedded.getTableName() + "_ID"); - PO poEmbedded = tableEmbedded.getPO (embeddedID, masterPO.get_TrxName()); - - Element embeddedElement = outDocument.createElement(formatLines[i].getValue()); - if (formatLines[i].getDescription() != null && !"".equals(formatLines[i].getDescription())) { - embeddedElement.appendChild(outDocument.createComment(formatLines[i].getDescription())); - } - generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap); - rootElement.appendChild(embeddedElement); - } - - } finally { - try { - if (rsEmbedded != null) rsEmbedded.close(); - if (pstmt != null) pstmt.close(); - } catch (SQLException ex) { } - rsEmbedded = null; - pstmt = null; - } - - } - - else { - throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPUnknownLineType")); - } - } - } - - /** - * @param variableMap - * @param variableName - */ - @SuppressWarnings("unused") - private void increaseVariable(HashMap variableMap, String variableName) { - if (variableName != null && !"".equals(variableName) ) { - Integer var = variableMap.get(variableName); - if (var == null) { - var = new Integer(0); - } - int intValue = var.intValue(); - intValue++; - variableMap.put(variableName, new Integer(intValue)); - } - } - - /** - * Utility method which is responsible to create new XML Document - * - * @return Document - * @throws ParserConfigurationException - */ - // create new Document - Document createNewDocument() throws ParserConfigurationException - { - Document result = null; - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - - result = documentBuilder.newDocument(); - return result; - } - - -} diff --git a/extend/src/org/adempiere/process/rpl/exp/HDDExportProcessor.java b/extend/src/org/adempiere/process/rpl/exp/HDDExportProcessor.java deleted file mode 100644 index 3ca534974f..0000000000 --- a/extend/src/org/adempiere/process/rpl/exp/HDDExportProcessor.java +++ /dev/null @@ -1,118 +0,0 @@ -/********************************************************************** -* This file is part of Adempiere ERP Bazaar * -* http://www.adempiere.org * -* * -* Copyright (C) Trifon Trifonov. * -* Copyright (C) Contributors * -* * -* This program is free software; you can redistribute it and/or * -* modify it under the terms of the GNU General Public License * -* as published by the Free Software Foundation; either version 2 * -* of the License, or (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the Free Software * -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * -* MA 02110-1301, USA. * -* * -* Contributors: * -* - Trifon Trifonov (trifonnt@users.sourceforge.net) * -* * -* Sponsors: * -* - E-evolution (http://www.e-evolution.com) * -***********************************************************************/ -package org.adempiere.process.rpl.exp; - -import java.io.File; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Properties; - -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.adempiere.process.rpl.IExportProcessor; -import org.compiere.util.CLogger; -import org.compiere.util.Trx; -import org.eevolution.model.MEXPProcessor; -import org.eevolution.model.X_EXP_ProcessorParameter; -import org.w3c.dom.Document; - -/** - * @author Trifon N. Trifonov - */ -public class HDDExportProcessor implements IExportProcessor { - - /** Logger */ - protected CLogger log = CLogger.getCLogger (getClass()); - - public void process(Properties ctx, MEXPProcessor expProcessor, Document document, Trx trx) - throws Exception - { - //String host = expProcessor.getHost(); - //int port = expProcessor.getPort(); - //String account = expProcessor.getAccount(); - //String password = expProcessor.getPasswordInfo(); - String fileName = ""; - - // Read all processor parameters and set them! - X_EXP_ProcessorParameter[] processorParameters = expProcessor.getEXP_ProcessorParameters(trx.getTrxName()); - if (processorParameters != null && processorParameters.length > 0) { - for (int i = 0; i < processorParameters.length; i++) { - - // One special parameter which will be used for remote folder name. - // Or could add flag to ProcessorParameters table which will distinguish between - // connection parameters and FTP Upload parameters. - log.info("ProcesParameter Value = " + processorParameters[i].getValue()); - log.info("ProcesParameter ParameterValue = " + processorParameters[i].getParameterValue()); - if (! processorParameters[i].getValue().equals("fileName")) { - //pt.setProperty(processorParameters[i].getValue(), processorParameters[i].getParameterValue()); - } else { - fileName = processorParameters[i].getParameterValue(); - } - } - } - - if (fileName == null || fileName.length() == 0) { - throw new Exception("Missing EXP_ProcessorParameter with key 'fileName'!"); - } - // Save the document to the disk file - TransformerFactory tranFactory = TransformerFactory.newInstance(); - tranFactory.setAttribute("indent-number", Integer.valueOf(1)); - - Transformer aTransformer = tranFactory.newTransformer(); - aTransformer.setOutputProperty(OutputKeys.INDENT, "yes"); - Source src = new DOMSource(document); - - // =================================== Write to String - Writer writer = new StringWriter(); - Result dest2 = new StreamResult(writer); - aTransformer.transform(src, dest2); - System.err.println(writer.toString()); - - //writer = new OutputStreamWriter(new FileOutputStream(out), "utf-8"); - // =================================== Write to Disk - try { - Result dest = new StreamResult(new File("XmlExport-test-" + fileName + ".xml")); - aTransformer.transform(src, dest); - - writer.close(); - } catch (TransformerException ex) { - ex.printStackTrace(); - throw ex; - } - - } - -} diff --git a/extend/src/org/adempiere/process/rpl/exp/ModelExporter.java b/extend/src/org/adempiere/process/rpl/exp/ModelExporter.java deleted file mode 100644 index d2e2c68426..0000000000 --- a/extend/src/org/adempiere/process/rpl/exp/ModelExporter.java +++ /dev/null @@ -1,168 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Contributor(s): Victor Perez www.e-evolution.com * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - *****************************************************************************/ -package org.adempiere.process.rpl.exp; - -import java.io.File; -import java.io.StringWriter; -import java.io.Writer; -import java.util.logging.Level; - -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.compiere.Adempiere; -import org.compiere.model.MReplicationStrategy; -import org.compiere.model.ModelValidator; -import org.compiere.model.X_AD_ReplicationTable; -import org.compiere.process.ProcessInfo; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.CLogMgt; -import org.compiere.util.Env; -import org.eevolution.model.MEXPFormat; -import org.w3c.dom.Document; - -/** - * - * @author victor.perez@e-evolution.com - * FB [1963487 ] Is necessary new process to export and import with an Export - * @see http://sourceforge.net/tracker/?func=detail&atid=879335&aid=1963487&group_id=176962 - * @version $Id:$ - */ -public class ModelExporter extends SvrProcess { - - /** Client Parameter */ - protected int p_AD_Client_ID = 0; - - /** Document Type Parameter */ - protected int p_C_DocType_ID = 0; - - /** Record ID */ - protected int p_Record_ID = 0; - /** EXP_Format_ID */ - protected int p_EXP_Format_ID = 0; - /** File Name **/ - protected String p_FileName = ""; - - /** Table ID */ - int AD_Table_ID = 0; - - - /** - * Get Parameters - */ - protected void prepare() { - - p_Record_ID = getRecord_ID(); - if (p_AD_Client_ID == 0) - p_AD_Client_ID = Env.getAD_Client_ID(getCtx()); - AD_Table_ID = getTable_ID(); - - StringBuffer sb = new StringBuffer("AD_Table_ID=").append(AD_Table_ID); - sb.append("; Record_ID=").append(getRecord_ID()); - // Parameter - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) - ; - else if (name.equals("EXP_Format_ID")) - p_EXP_Format_ID = para[i].getParameterAsInt(); - else if (name.equals("FileName")) - p_FileName = (String)para[i].getParameter(); - else - log.log(Level.SEVERE, "Unknown Parameter: " + name); - } - - if(p_EXP_Format_ID == 0) - p_EXP_Format_ID = p_Record_ID; - if(p_FileName == null) - { - // Load XML file and parse it - String fileNameOr = org.compiere.util.Ini.findAdempiereHome() - + System.getProperty("file.separator") - + "data" - + System.getProperty("file.separator") - + "ExportFile.xml"; - p_FileName = fileNameOr; - } - log.info(sb.toString()); - } - - /** - * Process - * - * @return info - */ - protected String doIt() throws Exception - { - ExportHelper expHelper = new ExportHelper(getCtx(),p_AD_Client_ID); - MEXPFormat exportFormat = new MEXPFormat (getCtx(), p_EXP_Format_ID, get_TrxName() ); - File file = new File(p_FileName); - Document doc = expHelper.exportRecord(exportFormat,"", MReplicationStrategy.REPLICATION_TABLE, X_AD_ReplicationTable.REPLICATIONTYPE_Merge,ModelValidator.TYPE_AFTER_CHANGE); - // Save the document to the disk file - TransformerFactory tranFactory = TransformerFactory.newInstance(); - - tranFactory.setAttribute("indent-number", 4); - - Transformer aTransformer = tranFactory.newTransformer(); - //aTransformer.setOutputProperty(OutputKeys.INDENT, "yes"); - //aTransformer.setOutputProperty("omit-xml-declaration","yes"); - aTransformer.setOutputProperty(OutputKeys.METHOD, "xml"); - aTransformer.setOutputProperty(OutputKeys.INDENT, "yes"); - Source src = new DOMSource(doc); - - // =================================== Write to String - Writer writer = new StringWriter(); - Result dest2 = new StreamResult(writer); - aTransformer.transform(src, dest2); - // =================================== Write to Disk - try { - Result dest = new StreamResult(file); - aTransformer.transform(src, dest); - writer.flush(); - writer.close(); - - } catch (TransformerException ex) { - ex.printStackTrace(); - throw ex; - } - return "Exported"; - } - - public static void main(String[] args) - { - CLogMgt.setLoggerLevel(Level.INFO, null); - CLogMgt.setLevel(Level.INFO); - - Adempiere.startupEnvironment(true); - ProcessInfo pi = new ProcessInfo("Test Import Model", 1000000); - pi.setAD_Client_ID(11); - pi.setAD_User_ID(100); - - ModelExporter modelExporter = new ModelExporter(); - modelExporter.startProcess(Env.getCtx(), pi, null); - - System.out.println("Process=" + pi.getTitle() + " Error="+pi.isError() + " Summary=" + pi.getSummary()); - } - -} \ No newline at end of file diff --git a/extend/src/org/adempiere/process/rpl/exp/MultiplePublisher.java b/extend/src/org/adempiere/process/rpl/exp/MultiplePublisher.java deleted file mode 100644 index cef12d4164..0000000000 --- a/extend/src/org/adempiere/process/rpl/exp/MultiplePublisher.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.adempiere.process.rpl.exp; - -//MultiplePublisher.java - -import javax.jms.JMSException; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.jms.Topic; -import javax.jms.TopicConnection; -import javax.jms.TopicConnectionFactory; -import javax.jms.TopicPublisher; -import javax.jms.TopicSession; -import javax.naming.InitialContext; - -public class MultiplePublisher { - TopicConnection topicConnection = null; - TopicSession topicSession = null; - Topic topic = null; - TopicPublisher topicPublisher = null; - public final String topicName = "asunto"; - static int startindex = 0; - - public MultiplePublisher() { - TopicConnectionFactory topicConnectionFactory = null; - - try { - InitialContext contexto = new InitialContext(); - topicConnectionFactory = (TopicConnectionFactory) contexto.lookup("TopicDurable"); - topicConnection = topicConnectionFactory.createTopicConnection(); - topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - topic = (Topic) contexto.lookup("asunto"); - topicPublisher = topicSession.createPublisher(topic); - } catch (Exception e) { - System.out.println("Error en constructor de MultiplePublisher"); - } - } - - public void publishMessages() { - TextMessage message = null; - int i; - final int NUMMSGS = 3; - final String MSG_TEXT = new String("Message"); - - try { - message = topicSession.createTextMessage(); - for (i = startindex; i < startindex + NUMMSGS; i++) { - message.setText(MSG_TEXT + " " + (i + 1)); - System.out.println("Publicado mensaje: " + message.getText()); - topicPublisher.publish( message ); - } - - topicPublisher.publish( topicSession.createMessage() ); - startindex = i; - } catch (Exception e) { - System.out.println("Error en metodo publishMessages() de MultiplePublisher"); - e.printStackTrace(); - } - } - - public void finish() { - if (topicConnection != null) { - try { - topicConnection.close(); - } catch (JMSException e) { - } - } - } -} diff --git a/extend/src/org/adempiere/process/rpl/exp/TopicExportProcessor.java b/extend/src/org/adempiere/process/rpl/exp/TopicExportProcessor.java deleted file mode 100644 index 87d2b7a5c3..0000000000 --- a/extend/src/org/adempiere/process/rpl/exp/TopicExportProcessor.java +++ /dev/null @@ -1,210 +0,0 @@ -/********************************************************************** -* This file is part of Adempiere ERP Bazaar * -* http://www.adempiere.org * -* * -* Copyright (C) Trifon Trifonov. * -* Copyright (C) Contributors * -* * -* This program is free software; you can redistribute it and/or * -* modify it under the terms of the GNU General Public License * -* as published by the Free Software Foundation; either version 2 * -* of the License, or (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the Free Software * -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * -* MA 02110-1301, USA. * -* * -* Contributors: * -* - Trifon Trifonov (trifonnt@users.sourceforge.net) -* - Antonio Cañaveral, e-Evolution -* * -* Sponsors: * -* - E-evolution (http://www.e-evolution.com) * -***********************************************************************/ -package org.adempiere.process.rpl.exp; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.Properties; - -import javax.jms.Connection; -import javax.jms.DeliveryMode; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.adempiere.process.rpl.IExportProcessor; -import org.apache.activemq.ActiveMQConnectionFactory; -import org.compiere.util.CLogger; -import org.compiere.util.Trx; -import org.eevolution.model.MEXPProcessor; -import org.eevolution.model.X_EXP_ProcessorParameter; -import org.w3c.dom.Document; - -/** - * @author Trifon N. Trifonov - * @author Antonio Cañaveral, e-Evolution - *
  • [ 2195051 ] Implementing Message Transaction - *
  • http://sourceforge.net/tracker/index.php?func=detail&aid=2195051&group_id=176962&atid=879335 - - */ -public class TopicExportProcessor implements IExportProcessor { - - /** Logger */ - protected CLogger log = CLogger.getCLogger (getClass()); - - /** - * - */ - public void process(Properties ctx, MEXPProcessor expProcessor, Document document, Trx trx) - throws Exception - { - String host = expProcessor.getHost(); - int port = expProcessor.getPort(); - String account = expProcessor.getAccount(); - String password = expProcessor.getPasswordInfo(); - String protocol = null; - String topicName = ""; - String clientID = null; - String timeToLiveStr = null; - int timeToLive = 10000; - boolean isDeliveryModePersistent = true; - - // Read all processor parameters and set them! - X_EXP_ProcessorParameter[] processorParameters = expProcessor.getEXP_ProcessorParameters(trx.getTrxName()); - if (processorParameters != null && processorParameters.length > 0) { - for (int i = 0; i < processorParameters.length; i++) { - log.info("ProcesParameter Value = " + processorParameters[i].getValue()); - log.info("ProcesParameter ParameterValue = " + processorParameters[i].getParameterValue()); - if (processorParameters[i].getValue().equals("topicName")) { - topicName = processorParameters[i].getParameterValue(); - } else if (processorParameters[i].getValue().equals("protocol")) { - protocol = processorParameters[i].getParameterValue(); - } else if (processorParameters[i].getValue().equals("clientID")) { - clientID = processorParameters[i].getParameterValue(); - } else if (processorParameters[i].getValue().equals("timeToLive")) { - timeToLiveStr = processorParameters[i].getParameterValue(); - timeToLive = Integer.parseInt( timeToLiveStr ); - } else if (processorParameters[i].getValue().equals("isDeliveryModePersistent")) { - isDeliveryModePersistent = Boolean.parseBoolean( processorParameters[i].getParameterValue() ); - } else { - // Some other mandatory parameter here - } - } - } - - if (topicName == null || topicName.length() == 0) { - throw new Exception("Missing "+X_EXP_ProcessorParameter.Table_Name+" with key 'topicName'!"); - } - if (protocol == null || protocol.length() == 0) { - throw new Exception("Missing "+X_EXP_ProcessorParameter.Table_Name+" with key 'protocol'!"); - } - if (clientID == null || clientID.length() == 0) { - throw new Exception("Missing "+X_EXP_ProcessorParameter.Table_Name+" with key 'clientID'!"); - } - if (timeToLiveStr == null || timeToLiveStr.length() == 0) { - throw new Exception("Missing "+X_EXP_ProcessorParameter.Table_Name+" with key 'timeToLive'!"); - } - - // Construct Transformer Factory and Transformer - TransformerFactory tranFactory = TransformerFactory.newInstance(); - tranFactory.setAttribute("indent-number", Integer.valueOf(1)); - - Transformer aTransformer = tranFactory.newTransformer(); - aTransformer.setOutputProperty(OutputKeys.INDENT, "yes"); - Source src = new DOMSource( document ); - - // =================================== Write to String - Writer writer = new StringWriter(); - Result dest2 = new StreamResult(writer); - aTransformer.transform(src, dest2); - - sendJMSMessage(host, port, writer.toString(), protocol, topicName, clientID, account, password, timeToLive, isDeliveryModePersistent); - - } - - private void sendJMSMessage(String host, int port, String msg, String protocol, String topicName - , String clientID, String userName, String password, int timeToLive - , boolean isDeliveryModePersistent) throws JMSException - { - // Create a ConnectionFactory - // network protocol (tcp, ...) set as EXP_ProcessorParameter - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(protocol + "://" + host + ":" + port); - - Connection connection = null; - Session session = null; - try { - // Create a Connection - if (userName != null && password != null) { - connection = connectionFactory.createConnection(userName, password); - } else { - connection = connectionFactory.createConnection(); - } - - connection.setClientID( clientID );// Commented by Victor as he had issue! - connection.start(); - - // Create a Session - session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); //TODO - Trifon could be EXP_ProcessorParameter - - // Create the destination (Topic or Queue) - Destination destination = session.createTopic(topicName); - - // Create a MessageProducer from the Session to the Topic or Queue - MessageProducer producer = session.createProducer( destination ); - producer.setTimeToLive( timeToLive ); // EXP_ProcessorParameter - if ( isDeliveryModePersistent ) { - producer.setDeliveryMode( DeliveryMode.PERSISTENT ); // EXP_ProcessorParameter - } else { - producer.setDeliveryMode( DeliveryMode.NON_PERSISTENT ); // EXP_ProcessorParameter - } - - // How to send to multiple destinations. - //MessageProducer producer = session.createProducer(null); - //producer.send(someDestination, message); - //producer.send(anotherDestination, message); - - // Create a message - TextMessage message = session.createTextMessage( msg ); - - // Tell the producer to send the message - try - { - producer.send(destination, message); - session.commit(); - log.info("JMS Message sent!"); - }catch(JMSException ex) - { - session.rollback(); - log.info("JMS Can't send the message!"); - throw ex; - } - - } finally { - // Clean up - if (session != null) { - try { session.close(); } catch (JMSException ex) {} - } - if (connection != null) { - try { connection.close(); } catch (JMSException ex) {} - } - } - } - - -} diff --git a/serverRoot/src/main/server/org/adempiere/server/JAXPParserMaker.java b/serverRoot/src/main/server/org/adempiere/server/JAXPParserMaker.java deleted file mode 100644 index ed2c9e8f96..0000000000 --- a/serverRoot/src/main/server/org/adempiere/server/JAXPParserMaker.java +++ /dev/null @@ -1,112 +0,0 @@ -/********************************************************************** -* This file is part of Adempiere ERP Bazaar * -* http://www.adempiere.org * -* * -* Copyright (C) Trifon Trifonov. * -* Copyright (C) Contributors * -* * -* This program is free software; you can redistribute it and/or * -* modify it under the terms of the GNU General Public License * -* as published by the Free Software Foundation; either version 2 * -* of the License, or (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the Free Software * -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * -* MA 02110-1301, USA. * -* * -* Contributors: * -* - Trifon Trifonov (trifonnt@users.sourceforge.net) * -* * -* Sponsors: * -* - E-evolution (http://www.e-evolution.com) * -***********************************************************************/ -package org.adempiere.server; - -import java.io.IOException; -import java.io.StringReader; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * - * @author Trifon N. Trifonov - * - */ -public class JAXPParserMaker { - - public static StringBuffer text = new StringBuffer("") - .append("") - .append(" ") - .append(" GardenWorld") - .append(" ") - .append(" ") - .append(" 0") - .append(" ") - .append(" SYSTEM") - .append(" ") - .append(" ") - .append(" C&W-test05") - .append(" C&W Construction-05") - .append(" ") - .append(" Standard") - .append(" ") - .append(" GardenWorld") - .append(" ") - .append(" ") - .append(" 04/11/2001 09:11:36") - .append(" ") - .append(" SuperUser") - .append(" ") - .append(" SYSTEM") - .append(" ") - .append(" ") - .append(" 11/17/2007 01:49:50") - .append(" ") - .append(" System") - .append(" ") - .append(" SYSTEM") - .append(" ") - .append(" ") - .append("") - ; - - public static void main(String[] args) { - - try { - DocumentBuilderFactory builderFactory = DocumentBuilderFactory - .newInstance(); - DocumentBuilder parser = builderFactory.newDocumentBuilder(); - - try { - // Read the entire document into memory - Document document = parser.parse( new InputSource(new StringReader( text.toString() ) ) ); - - System.out.println( "Document = " + document); - // work with the document... - } catch (SAXException e) { - System.err.println(e); - } catch (IOException e) { - System.err.println(e); - } - - - } catch (ParserConfigurationException e) { - System.err.println("You need to install a JAXP aware parser."); - } - - } - -} - diff --git a/serverRoot/src/main/server/org/adempiere/server/SimpleMessageToTopic.java b/serverRoot/src/main/server/org/adempiere/server/SimpleMessageToTopic.java deleted file mode 100644 index b34e2dd119..0000000000 --- a/serverRoot/src/main/server/org/adempiere/server/SimpleMessageToTopic.java +++ /dev/null @@ -1,124 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ -package org.adempiere.server; - -import javax.jms.Connection; -import javax.jms.DeliveryMode; -import javax.jms.Destination; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.activemq.ActiveMQConnectionFactory; - -public class SimpleMessageToTopic { - - private static final String TOPIC_NAME = "ExampleTopic"; - - private static StringBuffer text = new StringBuffer("") - .append("") - .append(" ") - .append(" GardenWorld") - .append(" ") - .append(" ") - .append(" 0") - .append(" ") - .append(" SYSTEM") - .append(" ") - .append(" ") - .append(" C&W-test06") - .append(" C&W Construction-06") - .append(" ") - .append(" Standard") - .append(" ") - .append(" GardenWorld") - .append(" ") - .append(" ") - .append(" 04/11/2001 09:11:36") - .append(" ") - .append(" SuperUser") - .append(" ") - .append(" SYSTEM") - .append(" ") - .append(" ") - .append(" 11/17/2007 01:49:50") - .append(" ") - .append(" System") - .append(" ") - .append(" SYSTEM") - .append(" ") - .append(" ") - .append("") - ; - - - - public static void main(String[] args) { - runTool("localhost", 61616); - } - - public static void runTool(String host, int port) { - try { - // Create a ConnectionFactory - ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory( - "tcp://"+host+":"+port); - - // Create a Connection - Connection connection = connectionFactory.createConnection(); - connection.setClientID("GardenWorld"); - connection.start(); - - // Create a Session - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Create the destination (Topic or Queue) - Destination destination = session.createTopic(TOPIC_NAME); - - // Create a MessageProducer from the Session to the Topic or Queue - MessageProducer producer = session.createProducer(destination); - producer.setTimeToLive(10000); - producer.setDeliveryMode(DeliveryMode.PERSISTENT); - - // Create a message - - TextMessage message = session.createTextMessage(text.toString()); - - // Tell the producer to send the message - System.out.println("Sent message"); - producer.send(message); - - // Clean up - session.close(); - connection.close(); - } catch (Exception e) { - System.out.println("Caught: " + e); - e.printStackTrace(); - } - } -} diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/IImportProcessor.java b/serverRoot/src/main/server/org/adempiere/server/rpl/IImportProcessor.java deleted file mode 100644 index 7afc009a6f..0000000000 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/IImportProcessor.java +++ /dev/null @@ -1,57 +0,0 @@ -/********************************************************************** -* This file is part of Adempiere ERP Bazaar * -* http://www.adempiere.org * -* * -* Copyright (C) Trifon Trifonov. * -* Copyright (C) Contributors * -* * -* This program is free software; you can redistribute it and/or * -* modify it under the terms of the GNU General Public License * -* as published by the Free Software Foundation; either version 2 * -* of the License, or (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the Free Software * -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * -* MA 02110-1301, USA. * -* * -* Contributors: * -* - Trifon Trifonov (trifonnt@users.sourceforge.net) * -* * -* Sponsors: * -* - E-evolution (http://www.e-evolution.com) * -***********************************************************************/ -package org.adempiere.server.rpl; - -import java.util.Properties; - -import org.compiere.server.ReplicationProcessor; - -/** - * Interface for Import processor - * @author Trifon Trifonov - * - */ -public interface IImportProcessor { - - /** - * @param ctx - * @param expProcessor - * @param trxName - * @return void - * @throws Exception - */ - public void process(Properties ctx, ReplicationProcessor replicationProcessor, String trxName) throws Exception; - - /** - * - * @throws Exception - */ - public void stop() throws Exception; - -} diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/XMLHelper.java b/serverRoot/src/main/server/org/adempiere/server/rpl/XMLHelper.java deleted file mode 100644 index fc894d6dd0..0000000000 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/XMLHelper.java +++ /dev/null @@ -1,140 +0,0 @@ -/********************************************************************** -* This file is part of Adempiere ERP Bazaar * -* http://www.adempiere.org * -* * -* Copyright (C) Trifon Trifonov. * -* Copyright (C) Contributors * -* * -* This program is free software; you can redistribute it and/or * -* modify it under the terms of the GNU General Public License * -* as published by the Free Software Foundation; either version 2 * -* of the License, or (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program; if not, write to the Free Software * -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * -* MA 02110-1301, USA. * -* * -* Contributors: * -* - Trifon Trifonov (trifonnt@users.sourceforge.net) * -* * -* Sponsors: * -* - E-evolution (http://www.e-evolution.com) * -***********************************************************************/ -package org.adempiere.server.rpl; - -import java.io.File; -import java.io.IOException; -import java.io.StringReader; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * Utility class which helps with XML processing. - * - * @author Trifon Trifonov - * @version $Id$ - */ -public class XMLHelper { - - private static XPath xPath = XPathFactory.newInstance().newXPath(); - - public static Element getElement(String xPathExpression, Node node) - throws XPathExpressionException { - return (Element) xPath.evaluate(xPathExpression, node, - XPathConstants.NODE); - } - - public static Node getNode(String xPathExpression, Node node) - throws XPathExpressionException { - return (Node) xPath - .evaluate(xPathExpression, node, XPathConstants.NODE); - } - - public static NodeList getNodeList(String xPathExpression, Node node) - throws XPathExpressionException { - return (NodeList) xPath.evaluate(xPathExpression, node, - XPathConstants.NODESET); - } - - public static Double getNumber(String xPathExpression, Node node) - throws XPathExpressionException { - return (Double) xPath.evaluate(xPathExpression, node, - XPathConstants.NUMBER); - } - - public static String getString(String xPathExpression, Node node) - throws XPathExpressionException { - return (String) xPath.evaluate(xPathExpression, node, - XPathConstants.STRING); - } - - public static Boolean getBoolean(String xPathExpression, Node node) - throws XPathExpressionException { - return (Boolean) xPath.evaluate(xPathExpression, node, - XPathConstants.BOOLEAN); - } - - - - public static Document createDocumentFromFile(String pathToXmlFile) - throws ParserConfigurationException, SAXException, IOException { - // path to file is global - String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; - String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; - // String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; - - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - // validate against XML Schema in dbsql2xml.xsd - // documentBuilderFactory.setNamespaceAware(true); - - //INFO change validation to true. Someday when xsd file is complete... - documentBuilderFactory.setValidating(false); - documentBuilderFactory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); - // documentBuilderFactory.setAttribute(JAXP_SCHEMA_SOURCE, new File(pathToXsdFile)); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - Document document = documentBuilder.parse(new File(pathToXmlFile)); - - return document; - } - - public static Document createDocumentFromString(String str) - throws ParserConfigurationException, SAXException, IOException { - // path to file is global -// String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; -// String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; - // String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; - - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - // validate against XML Schema in dbsql2xml.xsd - // documentBuilderFactory.setNamespaceAware(true); - - //INFO change validation to true. Someday when xsd file is complete... - documentBuilderFactory.setValidating(false); -// documentBuilderFactory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); - // documentBuilderFactory.setAttribute(JAXP_SCHEMA_SOURCE, new File(pathToXsdFile)); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - Document document = documentBuilder.parse( new InputSource(new StringReader( str ) ) ); - - return document; - } - -} diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/FileImportProcessor.java b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/FileImportProcessor.java deleted file mode 100644 index 557bf3464b..0000000000 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/FileImportProcessor.java +++ /dev/null @@ -1,89 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ -package org.adempiere.server.rpl.imp; - -import java.util.Properties; - -import org.adempiere.server.rpl.IImportProcessor; -import org.adempiere.server.rpl.XMLHelper; -import org.compiere.server.ReplicationProcessor; -import org.compiere.util.CLogger; -import org.eevolution.model.MIMPProcessor; -import org.eevolution.model.X_IMP_ProcessorParameter; -import org.w3c.dom.Document; - -/** - * - * @author Trifon N. Trifonov - * @version $Id:$ - */ -public class FileImportProcessor implements IImportProcessor { - - /** Logger */ - protected CLogger log = CLogger.getCLogger (FileImportProcessor.class); - - public void process(Properties ctx, ReplicationProcessor replicationProcessor, String trxName) - throws Exception { - - MIMPProcessor impProcessor = replicationProcessor.getMImportProcessor(); - - X_IMP_ProcessorParameter[] processorParameters = impProcessor.getIMP_ProcessorParameters(trxName); - - String fileName = null; - if (processorParameters != null && processorParameters.length > 0) { - for (int i = 0; i < processorParameters.length; i++) { - log.info("ProcesParameter Value = " + processorParameters[i].getValue()); - log.info("ProcesParameter ParameterValue = " + processorParameters[i].getParameterValue()); - if (processorParameters[i].getValue().equals("fileName")) { - fileName = processorParameters[i].getParameterValue(); - } else { - // Some other mandatory parameter here - } - } - } - - if (fileName == null || fileName.length() == 0) { - throw new Exception("Missing IMP_ProcessorParameter with key 'fileName'!"); - } - - Document documentToBeImported = XMLHelper.createDocumentFromFile(fileName); - StringBuffer result = new StringBuffer(); - - ImportHelper impHelper = new ImportHelper( ctx ); - impHelper.importXMLDocument(result, documentToBeImported, trxName ); - -// addLog(0, null, null, Msg.getMsg(ctx, "ImportModelProcessResult") + "\n" + result.toString()); - } - - public void stop() throws Exception { - // do nothing! - - } - -} diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java deleted file mode 100644 index 7b6434272b..0000000000 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java +++ /dev/null @@ -1,671 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ -package org.adempiere.server.rpl.imp; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Properties; -import java.util.logging.Level; - -import javax.xml.xpath.XPathExpressionException; - -import org.adempiere.server.rpl.XMLHelper; -import org.compiere.model.MClient; -import org.compiere.model.MColumn; -import org.compiere.model.MTable; -import org.compiere.model.ModelValidator; -import org.compiere.model.PO; -import org.compiere.model.X_AD_Client; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.compiere.util.Util; -import org.eevolution.model.MEXPFormat; -import org.eevolution.model.MEXPFormatLine; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -/** - * @author Trifon N. Trifonov -* @author Antonio Cañaveral, e-Evolution - *
  • [ 2195016 ] Implementation delete records messages - *
  • http://sourceforge.net/tracker/index.php?func=detail&aid=2195016&group_id=176962&atid=879332 - */ -public class ImportHelper { - - /** Instance Logger */ - private CLogger log = CLogger.getCLogger(ImportHelper.class); - - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger(ImportHelper.class); - - /** Date Time Format */ - private SimpleDateFormat m_dateTimeFormat = null; - - /** Date Format */ - private SimpleDateFormat m_dateFormat = null; - - /** Custom Date Format */ - private SimpleDateFormat m_customDateFormat = null; - - /** Context */ - private Properties ctx = null; - - public ImportHelper(Properties ctx) { - this.ctx = ctx; - // Construct DateFromat and DateTimeFormat - m_dateTimeFormat = DisplayType.getDateFormat(DisplayType.DateTime, Env.getLanguage(ctx)); - m_dateFormat = DisplayType.getDateFormat(DisplayType.Date, Env.getLanguage(ctx)); - } - - /** - * @param ctx - * @param result - * @param documentToBeImported - * @param trxName - * @throws Exception - * @throws SQLException - * @throws XPathExpressionException - */ - public void importXMLDocument(StringBuffer result, Document documentToBeImported, String trxName) - throws Exception, SQLException, XPathExpressionException - { - //Element rootNode = importedDocument.getFirstChild(); - Element rootElement = documentToBeImported.getDocumentElement(); - //NodeList nl = rootElement.getChildNodes(); - // iterate over all address nodes and find the one that has the correct addressee - //for (int i = 0; i < nl.getLength(); i++) { /* */ } - - // Find which Export format to Load... - String AD_Client_Value = null; - //AD_Client_Value = XMLHelper.getString("@AD_Client_Value", rootNode); - AD_Client_Value = rootElement.getAttribute("AD_Client_Value"); - log.info("AD_Client_Value = " + AD_Client_Value); - if (AD_Client_Value == null || "".equals(AD_Client_Value)) { - throw new Exception(Msg.getMsg(ctx, "XMLClientValueMandatory")); - } - String version = null; - version = rootElement.getAttribute("Version"); - log.info("Version = " + version); - if (version == null || "".equals(version)) { - throw new Exception(Msg.getMsg(ctx, "XMLVersionAttributeMandatory")); - } - ///Getting Attributes. - - ; - - int ReplicationMode = new Integer(rootElement.getAttribute("ReplicationMode")); - String ReplicationType = rootElement.getAttribute("ReplicationType"); - int ReplicationEvent = new Integer(rootElement.getAttribute("ReplicationEvent")); - - MClient client = null; - client = getAD_ClientByValue(ctx, AD_Client_Value, trxName); - if (client == null) { - throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound")); - } - log.info(client.toString()); - - String EXP_Format_Value = null; - EXP_Format_Value = rootElement.getNodeName(); - log.info("EXP_Format_Value = " + EXP_Format_Value); - - MEXPFormat expFormat = null; - expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, client.getAD_Client_ID(), version, trxName); - if (expFormat == null || expFormat.getEXP_Format_ID() == 0) { - // Fall back to SYSTEM Client. - // Try to search Export format defined for SYSTEM Client!!! - MClient systemClient = null; - systemClient = MClient.get(ctx, 0); - if (systemClient == null) { - throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound")); - } - log.info(systemClient.toString()); - expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, systemClient.getAD_Client_ID(), version, trxName); - } - if (expFormat == null || expFormat.getEXP_Format_ID() == 0) { - throw new Exception(Msg.getMsg(ctx, "EXPFormatNotFound")); - } - log.info("expFormat = " + expFormat.toString()); - - PO po = importElement(ctx, result, rootElement, expFormat, trxName); - // Here must invoke other method else we get cycle... - boolean resultSave=false; - if(ReplicationEvent == ModelValidator.TYPE_BEFORE_DELETE || - ReplicationEvent == ModelValidator.TYPE_BEFORE_DELETE_REPLICATION || - ReplicationEvent == ModelValidator.TYPE_DELETE) - resultSave=po.delete(true); - else - resultSave = po.saveReplica(true); - - result.append("ResultSave=").append(resultSave).append("; "); - /*if (resultSave) - { - if(ReplicationMode == MReplicationStrategy.REPLICATION_DOCUMENT && - ReplicationType == X_AD_ReplicationDocument.REPLICATIONTYPE_Merge) - { - String status = po.get_ValueAsString("DocStatus"); - String action = po.get_ValueAsString("DocAction"); - DocAction m_document; - m_document=(DocAction) po; - DocumentEngine engine = new DocumentEngine (m_document, status); - engine.processIt (action); - } - // Success in save - } else { - // Failed in save - throw new Exception(Msg.getMsg(ctx, "EXPFormatFailedSave")); - }*/ - } - - /** - * @param result - * @param rootElement - * @param expFormat - * @throws Exception - * @throws XPathExpressionException - */ - @SuppressWarnings("unchecked") - private PO importElement(Properties ctx, StringBuffer result, Element rootElement, - MEXPFormat expFormat, String trxName) throws Exception, XPathExpressionException - { - // get AD_Table ID from export Format. - int AD_Table_ID = expFormat.getAD_Table_ID(); - - // Load appropriate Model class... - MTable table = MTable.get(ctx, AD_Table_ID); - log.info("Table = " + table); - - int record_ID = 0; - // Find Record_ID by ???Value??? In fact by Columns set as Part Of Unique Index in Export Format! - record_ID = getID(ctx, expFormat, rootElement, rootElement.getNodeName(), trxName); - log.info("record_ID = " + record_ID); - - PO po = table.getPO(record_ID, trxName); - log.info("PO.toString() = " + po.toString()); - - if (po.get_KeyColumns().length > 1 || po.get_KeyColumns().length < 1) { - throw new Exception(Msg.getMsg(ctx, "EDIMultiColumnNotSupported")); - } - - StringBuffer orderBy = new StringBuffer(MEXPFormatLine.COLUMNNAME_IsMandatory).append(" DESC ") - .append(", ").append(MEXPFormatLine.COLUMNNAME_Position) - ; - MEXPFormatLine[] formatLines = expFormat.getFormatLinesOrderedBy(orderBy.toString()); - if (formatLines == null || formatLines.length < 1) { - throw new Exception(Msg.getMsg(ctx, "EXPFormatNoLines")); - } - Object value = null; - // Iterate all Export Format Lines (even this marked as part of unique index) - // and set value of column! - for (int i = 0; i < formatLines.length; i++) { - log.info("=================== Beginnig of Format Line ==============================="); - log.info("formatLines["+i+"]=[" + formatLines[i].toString() + "]"); - - if (MEXPFormatLine.TYPE_XMLElement.equals(formatLines[i].getType())) { - // XML Element - value = XMLHelper.getString(formatLines[i].getValue(), rootElement); - log.info("value=[" + value + "]"); - - } else if (MEXPFormatLine.TYPE_ReferencedEXPFormat.equals(formatLines[i].getType())) { - // Referenced Export Format -/* - - 0 - - SYSTEM - - - ... - */ - - MEXPFormat referencedExpFormat = new MEXPFormat(ctx, formatLines[i].getEXP_EmbeddedFormat_ID(), trxName); - log.info("referencedExpFormat = " + referencedExpFormat); - - int refRecord_ID = 0; - // Find Record_ID by ???Value??? In fact by Columns set as Part Of Unique Index in Export Format! - String xPath = null; - //xPath = ""+rootElement.getNodeName() + "/" + formatLines[i].getValue() + ""; // Do not work - xPath = "" + formatLines[i].getValue() + ""; // - - log.info("SEARCH FOR XML Element = " + xPath); - Element referencedNode = XMLHelper.getElement(xPath, rootElement); - - //NodeList nodeList = XMLHelper.getNodeList(xPath, rootElement); - //referencedNode = (Element)nodeList.item(0); - - log.info("referencedNode = " + referencedNode); - if(referencedNode!=null) - { - refRecord_ID = getID(ctx, referencedExpFormat, referencedNode, formatLines[i].getValue(), trxName); - log.info("refRecord_ID = " + refRecord_ID); - value = new Integer(refRecord_ID); - } - else - { - log.info("NULL VALUE FOR " + xPath.toString()); - value=null; - } - log.info("value=[" + value + "]"); - } else if (MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(formatLines[i].getType())) { - boolean resSave = false; - if (po.get_ID() == 0) { - resSave = po.saveReplica(true); - result.append("ResultSave-MasterPO=").append(resSave).append("; "); - log.info("ResultSave-MasterPO = " + resSave); - } else { - resSave = true; - } - if (resSave) { - // Success in save - } else { - throw new Exception("Failed to save Master PO"); - } - // Embedded Export Format -/* - GardenWorls - ... - ... <-- MUST save Master Record here! Else we can't set orderLine.setC_Order_ID(..) - ... - ... - */ - MEXPFormat referencedExpFormat = new MEXPFormat(ctx, formatLines[i].getEXP_EmbeddedFormat_ID(), trxName); - log.info("embeddedExpFormat = " + referencedExpFormat); - - NodeList nodeList = XMLHelper.getNodeList("/"+rootElement.getNodeName() + "/" + formatLines[i].getValue(), rootElement); - for (int j = 0; j < nodeList.getLength(); j++) { - Element referencedElement = (Element)nodeList.item(j); - log.info("EmbeddedEXPFormat - referencedElement.getNodeName = " + referencedElement.getNodeName()); - - PO embeddedPo = null; - // Import embedded PO - log.info("=== BEGIN RECURSION CALL ==="); - embeddedPo = importElement(ctx, result, referencedElement, referencedExpFormat, trxName); - log.info("embeddedPo = " + embeddedPo); - - //embeddedPo.set_CustomColumn(po.get_KeyColumns()[0], po.get_ID()); - //log.info("embeddedPo.set"+po.get_KeyColumns()[0]+" = [" + po.get_ID()+"]"); - - boolean rSave = embeddedPo.saveReplica(true); - result.append("ResultSave-EmbeddedPO=").append(rSave).append("; "); - } - - } else if (MEXPFormatLine.TYPE_XMLAttribute.equals(formatLines[i].getType())) { - // XML Attribute - value = XMLHelper.getString("@" + formatLines[i].getValue(), rootElement); - log.info("value=[" + value + "]"); - } else { - // Export Format Line is not one of two possible values...ERROR - throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNonValidType")); - } - if (value == null) { - - } else { -/* if (column.getColumnName().equals("AD_Client_ID")) { - //Env.setContext(Env.getCtx(), "#AD_Client_ID", value.toString()); - } - if (column.getColumnName().equals("AD_Org_ID")) { - //Env.setContext(Env.getCtx(), "#AD_Org_ID", value.toString()); - } */ - if ( MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(formatLines[i].getType()) ) { - // do nothing - } else { - MColumn column = MColumn.get(ctx, formatLines[i].getAD_Column_ID()); - log.info("column=[" + column + "]"); - - // Clazz - Class clazz = DisplayType.getClass(column.getAD_Reference_ID(), true); - // Handle Posted - if (column.getColumnName().equalsIgnoreCase("Posted") - || column.getColumnName().equalsIgnoreCase("Processed") - || column.getColumnName().equalsIgnoreCase("Processing")) - { - clazz = Boolean.class; - } else if (column.getColumnName().equalsIgnoreCase("Record_ID")) - { - clazz = Integer.class; - } else if (column.getColumnName().equalsIgnoreCase("AD_Language") - || column.getColumnName().equalsIgnoreCase("EntityType")) - { - clazz = String.class; - } - log.info("clazz = " + clazz.getName()); - // Handle Date and Time - value = handleDateTime(value, column, formatLines[i]); - - log.info("formatLinesType = " + formatLines[i].getType()); - if (MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals( formatLines[i].getType() ) ) { - // DO NOTHING - throw new Exception("We can't be here!!!"); - } else { - if (column.getAD_Reference_ID() == DisplayType.DateTime - || column.getAD_Reference_ID() == DisplayType.Date - ) - { - // - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - log.info("Set value of column ["+column.getColumnName()+"]=["+value+"]"); - } else if (column.getAD_Reference_ID() == DisplayType.ID - || column.getAD_Reference_ID() == DisplayType.Integer - || column.getAD_Reference_ID() == DisplayType.Search - || column.getAD_Reference_ID() == DisplayType.TableDir - || column.getAD_Reference_ID() == DisplayType.Table - ) - { - // - if (! Util.isEmpty(value.toString())) - { - int intValue = Integer.parseInt(value.toString()); - value = new Integer( intValue ); - }else - value=null; - log.info("Abut to set int value of column ["+column.getColumnName()+"]=["+value+"]"); - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - log.info("Set int value of column ["+column.getColumnName()+"]=["+value+"]"); - } else if (column.getAD_Reference_ID() == DisplayType.Amount - || column.getAD_Reference_ID() == DisplayType.Number - || column.getAD_Reference_ID() == DisplayType.CostPrice - || column.getAD_Reference_ID() == DisplayType.Quantity - ) - { - // - if (! Util.isEmpty(value.toString())) - { - double doubleValue = Double.parseDouble(value.toString()); - value = new BigDecimal(doubleValue); - }else - value=null; - //value = new Double( doubleValue ); - log.info("About to set BigDecimal value of column ["+column.getColumnName()+"]=["+value+"]"); - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - log.info("Set BigDecimal value of column ["+column.getColumnName()+"]=["+value+"]"); - } - else if(column.getAD_Reference_ID() == DisplayType.YesNo) - { - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - } - else { - // - try { - log.info("About to set value of column ["+column.getColumnName()+"]=["+value+"]"); - if(clazz == Boolean.class) - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - else - po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), clazz.cast(value)); - log.info("Set value of column ["+column.getColumnName()+"]=["+value+"]"); - } catch (ClassCastException ex) { - ex.printStackTrace(); - throw new Exception(ex); - } - - //po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value); - } - result.append(column.getColumnName()).append("=").append(value).append("; "); - } - } - } - - } - - return po; - } - - public static MClient getAD_ClientByValue(Properties ctx, String value, String trxName) - throws SQLException - { - MClient result = null; - - StringBuffer sql = new StringBuffer("SELECT AD_Client_ID ") - .append(" FROM ").append(X_AD_Client.Table_Name) - .append(" WHERE ").append(X_AD_Client.COLUMNNAME_Value).append(" = ?") - // .append(" AND IsActive = ?") - ; - //s_log.info(sql.toString()); - s_log.info("Client_Value =[" + value + "]"); - - PreparedStatement pstmt = null; - try { - pstmt = DB.prepareStatement(sql.toString(), trxName); - pstmt.setString(1, value); - ResultSet rs = pstmt.executeQuery(); - if (rs.next()) { - int AD_Client_ID = rs.getInt(1); - s_log.info("AD_Client_ID = " + AD_Client_ID); - result = new MClient(ctx, AD_Client_ID, trxName); - } - rs.close(); - pstmt.close(); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - throw e; - } finally { - try { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } catch (Exception e) { - pstmt = null; - } - } - - return result; - } - - public int getID(Properties ctx, MEXPFormat expFormat, Element rootElement, String rootNodeName, String trxName) throws Exception { - int result = 0; - - if (expFormat == null || rootElement == null || rootNodeName == null) { - throw new IllegalArgumentException("expFormat, rootNode and RootnodeName can't be null!"); - } - log.info("expFormat = " + expFormat); - log.info("rootNode.getNodeName() = " + rootElement.getNodeName()); - log.info("rootNodeName = " + rootNodeName); - if (rootElement.getParentNode() != null) { - log.info("rootNode.ParentName = " + rootElement.getParentNode().getNodeName()); - } - - // get AD_Table ID from export Format. - int AD_Table_ID = expFormat.getAD_Table_ID(); - - // Load appropriate Model class... - MTable table = MTable.get(ctx, AD_Table_ID); - log.info("Table = " + table); - - //Select * FROM table.getTableName() WHERE Value or ANY IDENTIFIER column - StringBuffer sql = new StringBuffer("SELECT * ") - .append(" FROM ").append(table.getTableName()) - .append(" WHERE ") - ; - // Get list with all Unique columns! - MEXPFormatLine[] uniqueFormatLines = expFormat.getUniqueColumns(); - if (uniqueFormatLines == null || uniqueFormatLines.length < 1) { - throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns")); - } - Object[] values = new Object[uniqueFormatLines.length]; - for (int i = 0; i < uniqueFormatLines.length; i++) { - log.info("--- iterate unique column with index = ["+i+"]"); - MColumn column = MColumn.get(ctx, uniqueFormatLines[i].getAD_Column_ID()); - log.info("column = ["+column+"]"); - String valuecol=column.getColumnName(); - if(column.getAD_Reference_ID() == DisplayType.Amount - || column.getAD_Reference_ID() == DisplayType.Number - || column.getAD_Reference_ID() == DisplayType.CostPrice - || column.getAD_Reference_ID() == DisplayType.Quantity) - { - valuecol="Round("+valuecol+",2)"; - } - - if (MEXPFormatLine.TYPE_XMLElement.equals(uniqueFormatLines[i].getType())) { - // XML Element - //values[i] = XMLHelper.getString("/"+rootElement.getNodeName() + "/" + uniqueFormatLines[i].getValue(), rootElement); - String xPath = null; - //xPath = "/"+rootNodeName + "/" + uniqueFormatLines[i].getValue(); -- works - //xPath = "/"+ uniqueFormatLines[i].getValue(); // do not work - xPath = ""+ uniqueFormatLines[i].getValue(); - - values[i] = XMLHelper.getString(xPath, rootElement); - //log.info("xml PATH =" + rootElement.getNodeName() + "." + xPath ); - log.info("values[" + i + "]=" + values[i]); - - } else if (MEXPFormatLine.TYPE_ReferencedEXPFormat.equals(uniqueFormatLines[i].getType())) { - // Referenced Export Format - log.info("referencedExpFormat.EXP_EmbeddedFormat_ID = " + uniqueFormatLines[i].getEXP_EmbeddedFormat_ID()); - MEXPFormat referencedExpFormat = new MEXPFormat(ctx, uniqueFormatLines[i].getEXP_EmbeddedFormat_ID(), trxName); - log.info("referencedExpFormat = " + referencedExpFormat); - /* - - - 0 - - SYSTEM - - - ... - - */ - int record_ID = 0; - // Find Record_ID by ???Value??? In fact by Columns set as Part Of Unique Index in Export Format! - Element referencedNode = ((Element) rootElement.getElementsByTagName(uniqueFormatLines[i].getValue()).item(0)); - log.info("referencedNode = " + referencedNode); - - record_ID = getID(ctx, referencedExpFormat, referencedNode, uniqueFormatLines[i].getValue(), trxName); - log.info("record_ID = " + record_ID); - - values[i] = new Integer(record_ID); - } else { - // Export Format Line is not one of two possible values...ERROR - throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNonValidType")); - } - if (i == 0) { - sql.append(" ").append(valuecol).append(" = ? "); - } else { - sql.append(" AND ").append(valuecol).append(" = ? "); - } - - } - log.info("sql = " + sql.toString()); - - PreparedStatement pstmt = null; - try { - pstmt = DB.prepareStatement (sql.toString(), trxName); - for (int i = 0; i < uniqueFormatLines.length; i++) { - MColumn col = MColumn.get(ctx, uniqueFormatLines[i].getAD_Column_ID()); - - if (col.getAD_Reference_ID() == DisplayType.DateTime - || col.getAD_Reference_ID() == DisplayType.Date) - { - - Timestamp value = (Timestamp)handleDateTime(values[i], col , uniqueFormatLines[i]); - pstmt.setTimestamp(i+1, value); - } - else if(col.getAD_Reference_ID() == DisplayType.String) - { - String value = (String)values[i]; - pstmt.setString(i+1, value); - } - else if(col.getAD_Reference_ID() == DisplayType.Amount - || col.getAD_Reference_ID() == DisplayType.Number - || col.getAD_Reference_ID() == DisplayType.CostPrice - || col.getAD_Reference_ID() == DisplayType.Quantity) - { - BigDecimal value = new BigDecimal((String)values[i]); - pstmt.setBigDecimal(i+1, value.setScale(2, BigDecimal.ROUND_HALF_UP)); - } - else - { - pstmt.setObject(i+1, values[i]); - log.info("pstmt.setObject["+(i+1)+"] = [" + values[i]+"]"); - } - - } - ResultSet rs = pstmt.executeQuery(); - if ( rs.next() ) { - result = rs.getInt(1); - } - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - throw e; - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } - } - log.info("result = " + result); - return result; - } - - private Object handleDateTime(Object value, MColumn column, MEXPFormatLine formatLine) throws ParseException { - String valueString = null; - valueString = value.toString(); // We are sure that value is not null - Object result = value; - - if (column.getAD_Reference_ID() == DisplayType.Date) { - if (valueString != null) { - if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy"; MM/dd/yyyy hh:mm:ss - result = new Timestamp(m_customDateFormat.parse(valueString).getTime()); - log.info("Custom Date Format; Parsed value = " + result.toString()); - } else { - //result = new Timestamp(m_dateFormat.parse(valueString).getTime()); - //log.info("Custom Date Format; Parsed value = " + result.toString()); - //NOW Using Standard Japanese Format yyyy-mm-dd hh:mi:ss.mil so don't care about formats.... - result = Timestamp.valueOf(valueString); - } - } - } else if (column.getAD_Reference_ID() == DisplayType.DateTime) { - if (valueString != null) { - if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy" - result = new Timestamp(m_customDateFormat.parse(valueString).getTime()); - log.info("Custom Date Format; Parsed value = " + result.toString()); - } else { - //result = new Timestamp(m_dateTimeFormat.parse(valueString).getTime()); - //log.info("Custom Date Format; Parsed value = " + result.toString()); - //NOW Using Standard Japanese Format yyyy-mm-dd hh:mi:ss.mil so don't care about formats.... - result = Timestamp.valueOf(valueString); - } - - } - - } - return result; - } - -} diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ModelImporter.java b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ModelImporter.java deleted file mode 100644 index aba442b57d..0000000000 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ModelImporter.java +++ /dev/null @@ -1,154 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ -package org.adempiere.server.rpl.imp; - -import java.util.logging.Level; - -import org.adempiere.server.rpl.XMLHelper; -import org.compiere.Adempiere; -import org.compiere.process.ProcessInfo; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.CLogMgt; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.w3c.dom.Document; - -/** - * - * @author Trifon N. Trifonov - * @author victor.perez@e-evolution.com - * FB [1963487 ] Is necessary new process to export and import with an Export - * @see http://sourceforge.net/tracker/?func=detail&atid=879335&aid=1963487&group_id=176962 - * @version $Id:$ - */ -public class ModelImporter extends SvrProcess { - - /** Client Parameter */ - protected int p_AD_Client_ID = 0; - - /** Document Type Parameter */ - protected int p_C_DocType_ID = 0; - - /** Record ID */ - protected int p_Record_ID = 0; - /** EXP_Format_ID */ - protected int p_EXP_Format_ID = 0; - /** File Name **/ - protected String p_FileName = ""; - - /** Table ID */ - int AD_Table_ID = 0; - - - /** - * Get Parameters - */ - protected void prepare() { - - p_Record_ID = getRecord_ID(); - if (p_AD_Client_ID == 0) - p_AD_Client_ID = Env.getAD_Client_ID(getCtx()); - AD_Table_ID = getTable_ID(); - - StringBuffer sb = new StringBuffer("AD_Table_ID=").append(AD_Table_ID); - sb.append("; Record_ID=").append(getRecord_ID()); - // Parameter - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) - ; - else if (name.equals("EXP_Format_ID")) - p_EXP_Format_ID = para[i].getParameterAsInt(); - else if (name.equals("FileName")) - p_FileName = (String)para[i].getParameter(); - else - log.log(Level.SEVERE, "Unknown Parameter: " + name); - } - - if(p_EXP_Format_ID == 0) - p_EXP_Format_ID = p_Record_ID; - if(p_FileName == null) - { - // Load XML file and parse it - String fileNameOr = org.compiere.util.Ini.findAdempiereHome() - + System.getProperty("file.separator") - + "data" - + System.getProperty("file.separator") - + "ExportFile.xml"; - p_FileName = fileNameOr; - } - - log.info(sb.toString()); - } - - /** - * Process - * - * @return info - */ - protected String doIt() throws Exception - { - StringBuffer result = new StringBuffer(""); - - // Load XML file and parse it - /*String fileNameOr = org.compiere.util.Ini.findAdempiereHome() - + System.getProperty("file.separator") - + "data" - + System.getProperty("file.separator"); - - String pathToXmlFile = fileNameOr+"XmlExport-test.xml"; - Document documentToBeImported = XMLHelper.createDocumentFromFile(pathToXmlFile);*/ - Document documentToBeImported = XMLHelper.createDocumentFromFile(p_FileName); - - ImportHelper impHelper = new ImportHelper(getCtx()); - impHelper.importXMLDocument(result, documentToBeImported, get_TrxName()); - - addLog(0, null, null, Msg.getMsg(getCtx(), "ImportModelProcessResult") + "\n" + result.toString()); - return result.toString(); - } - - public static void main(String[] args) - { - CLogMgt.setLoggerLevel(Level.INFO, null); - CLogMgt.setLevel(Level.INFO); - - Adempiere.startupEnvironment(false); - ProcessInfo pi = new ProcessInfo("Test Import Model", 1000000); - pi.setAD_Client_ID(11); - pi.setAD_User_ID(100); - - ModelImporter modelImporter = new ModelImporter(); - modelImporter.startProcess(Env.getCtx(), pi, null); - - System.out.println("Process=" + pi.getTitle() + " Error="+pi.isError() + " Summary=" + pi.getSummary()); - } - -} \ No newline at end of file diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicImportProcessor.java b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicImportProcessor.java deleted file mode 100644 index 39718ded48..0000000000 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicImportProcessor.java +++ /dev/null @@ -1,130 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ -package org.adempiere.server.rpl.imp; - -import java.util.Properties; - -import org.adempiere.server.rpl.IImportProcessor; -import org.compiere.server.ReplicationProcessor; -import org.compiere.util.CLogger; -import org.eevolution.model.MIMPProcessor; -import org.eevolution.model.X_IMP_ProcessorParameter; - -/** - * Aim of this class is to import records from JMS Server. - * - * @author Trifon N. Trifonov - * @version $Id:$ - */ -public class TopicImportProcessor implements IImportProcessor { - - /** Logger */ - protected CLogger log = CLogger.getCLogger (TopicImportProcessor.class); - - /** - * Topic Listener - */ - private TopicListener topicListener = null; - - - public void process(Properties ctx, ReplicationProcessor replicationProcessor, String trxName) - throws Exception { - - log.info("replicationProcessor = " + replicationProcessor); - log.info("replicationProcessor.getMImportProcessor() = " + replicationProcessor.getMImportProcessor()); - - MIMPProcessor impProcessor = replicationProcessor.getMImportProcessor(); - - X_IMP_ProcessorParameter[] processorParameters = impProcessor.getIMP_ProcessorParameters(trxName); - - String host = impProcessor.getHost(); - int port = impProcessor.getPort(); - String account = impProcessor.getAccount(); - String password = impProcessor.getPasswordInfo(); - - // mandatory parameters! - String topicName = null; - String protocol = null; - boolean isDurableSubscription = true; - String subscriptionName = null; - String options = null; - String clientID = null; - - if (processorParameters != null && processorParameters.length > 0) { - for (int i = 0; i < processorParameters.length; i++) { - log.info("ProcesParameter Value = " + processorParameters[i].getValue()); - log.info("ProcesParameter ParameterValue = " + processorParameters[i].getParameterValue()); - if (processorParameters[i].getValue().equals("topicName")) { - topicName = processorParameters[i].getParameterValue(); - } else if (processorParameters[i].getValue().equals("protocol")) { - protocol = processorParameters[i].getParameterValue(); - } else if (processorParameters[i].getValue().equals("isDurableSubscription")) { - isDurableSubscription = Boolean.parseBoolean( processorParameters[i].getParameterValue() ); - } else if (processorParameters[i].getValue().equals("subscriptionName")) { - subscriptionName = processorParameters[i].getParameterValue(); - } else if (processorParameters[i].getValue().equals("clientID")) { - clientID = processorParameters[i].getParameterValue(); - } else { - // Some other mandatory parameter here - } - } - } - - if (topicName == null || topicName.length() == 0) { - throw new Exception("Missing "+X_IMP_ProcessorParameter.Table_Name+" with key 'topicName'!"); - } - if (protocol == null || protocol.length() == 0) { - throw new Exception("Missing "+X_IMP_ProcessorParameter.Table_Name+" with key 'protocol'!"); - } - if (isDurableSubscription && subscriptionName == null || subscriptionName.length() == 0) { - throw new Exception("Missing "+X_IMP_ProcessorParameter.Table_Name+" with key 'subscriptionName'!"); - } - if (clientID == null || clientID.length() == 0) { - throw new Exception("Missing "+X_IMP_ProcessorParameter.Table_Name+" with key 'clientID'!"); - } - - topicListener = new TopicListener(ctx, replicationProcessor, protocol, host, port - , isDurableSubscription, subscriptionName, topicName, clientID - , account, password, options, trxName); - - topicListener.run(); - log.info("Started topicListener = " + topicListener); - } - - public void stop() throws Exception { - - if ( topicListener != null ) { - topicListener.stop(); - log.info("Stoped topicListener." ); - } - - } - - -} diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicListener.java b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicListener.java deleted file mode 100644 index 79e35f822b..0000000000 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicListener.java +++ /dev/null @@ -1,309 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * - Antonio Cañaveral (antonio.canaveral@e-evolution.com) - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ - -package org.adempiere.server.rpl.imp; - -import java.util.Properties; - -import javax.jms.Connection; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.jms.Topic; - -import org.adempiere.server.rpl.XMLHelper; -import org.apache.activemq.ActiveMQConnectionFactory; -import org.compiere.server.ReplicationProcessor; -import org.compiere.util.CLogger; -import org.eevolution.model.MIMPProcessorLog; -import org.w3c.dom.Document; - -/** - * Listen for JMS Messages - * @author Trifon N. Trifonov - * @author Antonio Cañaveral, e-Evolution - *
  • [ 2194986 ] Already connected ClientID issue. - *
  • http://sourceforge.net/tracker/index.php?func=detail&aid=2194986&group_id=176962&atid=879332 - */ -public class TopicListener implements MessageListener { - - /** - * Connection to JMS Server - */ - private Connection conn; - - /** - * JMS Session - */ - private Session session; - - /** - * JMS Topic - */ - private Topic topic; - -// private String url="tcp://localhost:61616?jms.dispatchAsync=true&jms.useAsyncSend=true&jms.optimizeAcknowledge=true&jms.disableTimeStampsByDefault=true&jms.optimizedMessageDispatch=true&wireFormat.cacheEnabled=false&wireFormat.tightEncodingEnabled=false"; - private String url="tcp://localhost:61616"; - - /** - * host where JMS server is running - */ - private String host = "localhost"; - - /** - * port of JMS Server - */ - private int port = 61616; - - /** - * Network protocol - */ - private String protocol = "tcp"; - - /** - * Context - */ - private Properties ctx = null; - - /** - * Transaction name - */ - private String trxName = null; - - /** - * Topic Name - */ - private String topicName = null; - - /** - * Replication processor - */ - private ReplicationProcessor replicationProcessor = null; - - /** Logger */ - protected CLogger log = CLogger.getCLogger (TopicListener.class); - - /** - * Is Durable Subscription - */ - private boolean isDurableSubscription = false; - - /** - * Subscription Name - */ - private String subscriptionName = null; - - /** - * JMS Connection ClientID - */ - private String clientID = null; - - /** - * String User Name - */ - private String userName = null; - - /** - * Password - */ - private String password = null; - - - /** - * - */ - public TopicListener(Properties ctx, ReplicationProcessor replicationProcessor, String protocol, String host, int port - , boolean isDurableSubscription, String subscriptionName, String topicName - , String clientID, String userName, String password - , String options, String trxName) { - if ( host != null && !host.equals("") ) { - this.host = host; - } - - if ( port > 0 ) { - this.port = port; - } - - if ( protocol != null && !protocol.equals("") ) { - this.protocol = protocol; - } - - this.topicName = topicName; - - String uri=this.protocol + "://" + this.host + ":" + this.port; - - if(options!=null && options.length()>0) - { - if(!options.contains("?")) - uri+="?"+options; - } - this.setUrl(uri); - - this.ctx = ctx; - - this.trxName = trxName; - - this.replicationProcessor = replicationProcessor; - - this.isDurableSubscription = isDurableSubscription; - - this.subscriptionName = subscriptionName; - - this.clientID = clientID; - - this.userName = userName; - - this.password = password; - - } - - public void run() throws JMSException { - ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory( url ); - log.finest("ActiveMQConnectionFactory = " + factory); - - if (userName !=null && password != null) { - conn = factory.createConnection(userName, password); - } else { - conn = factory.createConnection(); - } - - log.finest("conn = " + conn ); - - if(conn.getClientID()==null) - { - conn.setClientID( clientID ); - }else - { - if(conn.getClientID().equals(clientID)) - { - log.warning("Connection with clientID '" + clientID - + "' already exists"); - return; - }else - conn.setClientID( clientID ); - } - - - session = conn.createSession(true, Session.AUTO_ACKNOWLEDGE); // TODO - could be parameter - log.finest("session = " + session ); - - log.finest("topicName = " + topicName ); - log.finest("subscriptionName = " + subscriptionName); - - topic = session.createTopic( topicName ); - log.finest("topic = " + topic ); - - MessageConsumer consumer = null; - if (isDurableSubscription) { - // http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.pmc.express.doc/tasks/tjn0012_.html - // The subscriptionName assigned to a durable subscription must be unique within a given client ID. - consumer = session.createDurableSubscriber( topic, subscriptionName ); - } else { - consumer = session.createConsumer( topic ); - } - - log.finest("consumer = " + consumer ); - - consumer.setMessageListener( this ); - - conn.start(); - log.finest("Waiting for JMS messages..."); - // - MIMPProcessorLog pLog = new MIMPProcessorLog(replicationProcessor.getMImportProcessor(), "Connected to JMS Server. Waiting for messages!"); - StringBuffer logReference = new StringBuffer("topicName = ").append(topicName) - .append(", subscriptionName = ").append( subscriptionName ) - ; - pLog.setReference( logReference.toString() ); - boolean resultSave = pLog.save(); - log.finest("Result Save = " + resultSave); - } - - /** - * - */ - public void onMessage(Message message) { - if ( message instanceof TextMessage ) { - - try { - TextMessage txtMessage = (TextMessage) message; - - String text = txtMessage.getText(); - //log.finest("Received message: \n" + text ); - - Document documentToBeImported = XMLHelper.createDocumentFromString( text ); - StringBuffer result = new StringBuffer(); - - ImportHelper impHelper = new ImportHelper( ctx ); - - impHelper.importXMLDocument(result, documentToBeImported, trxName ); - - // - MIMPProcessorLog pLog = new MIMPProcessorLog(replicationProcessor.getMImportProcessor(), "Imported Document!"); - //pLog.setReference("topicName = " + topicName ); - if (text.length() > 2000 ) { - pLog.setTextMsg( text.substring(0, 1999) ); - } else { - pLog.setTextMsg( text); - } - - boolean resultSave = pLog.save(); - log.finest("Result Save = " + resultSave); - - session.commit(); - - } catch (Exception e) { - replicationProcessor.setProcessRunning(false); - try { - session.rollback(); - } catch (JMSException e1) { - e1.printStackTrace(); - } - e.printStackTrace(); - } - - } else { - log.finest("Received NO TEXT Message: " ); - // Received non text message!!! - } - } - - public void setUrl(String url) { - this.url = url; - } - - public void stop() throws JMSException { - // Close JMS Connection - log.finest("Closing JMS Connection!"); - conn.close(); - } -} diff --git a/serverRoot/src/main/server/org/compiere/server/AdempiereServer.java b/serverRoot/src/main/server/org/compiere/server/AdempiereServer.java index 34462dc705..2a92ba63c4 100644 --- a/serverRoot/src/main/server/org/compiere/server/AdempiereServer.java +++ b/serverRoot/src/main/server/org/compiere/server/AdempiereServer.java @@ -35,7 +35,6 @@ import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.util.TimeUtil; import org.compiere.wf.MWorkflowProcessor; -import org.eevolution.model.MIMPProcessor; /** * Adempiere Server Base @@ -64,8 +63,6 @@ public abstract class AdempiereServer extends Thread return new Scheduler ((MScheduler)model); if (model instanceof MLdapProcessor) return new LdapProcessor((MLdapProcessor)model); - if (model instanceof MIMPProcessor) // @Trifon - return new ReplicationProcessor((MIMPProcessor)model); // throw new IllegalArgumentException("Unknown Processor"); } // create diff --git a/serverRoot/src/main/server/org/compiere/server/AdempiereServerMgr.java b/serverRoot/src/main/server/org/compiere/server/AdempiereServerMgr.java index d9a7fd9702..d9a7145022 100644 --- a/serverRoot/src/main/server/org/compiere/server/AdempiereServerMgr.java +++ b/serverRoot/src/main/server/org/compiere/server/AdempiereServerMgr.java @@ -31,7 +31,6 @@ import org.compiere.model.MSession; import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.wf.MWorkflowProcessor; -import org.eevolution.model.MIMPProcessor; /** * Adempiere Server Manager @@ -164,18 +163,7 @@ public class AdempiereServerMgr server.start(); server.setPriority(Thread.NORM_PRIORITY-1); m_servers.add(server); - } - // ImportProcessor - @Trifon - MIMPProcessor[] importModels = MIMPProcessor.getActive(m_ctx); - for (int i = 0; i < importModels.length; i++) - { - MIMPProcessor lp = importModels[i]; - AdempiereServer server = AdempiereServer.create(lp); - server.start(); - server.setPriority(Thread.NORM_PRIORITY-1); - m_servers.add(server); - } - + } log.fine("#" + noServers); return startAll(); } // startEnvironment diff --git a/serverRoot/src/main/server/org/compiere/server/ReplicationProcessor.java b/serverRoot/src/main/server/org/compiere/server/ReplicationProcessor.java deleted file mode 100644 index b4309d9d94..0000000000 --- a/serverRoot/src/main/server/org/compiere/server/ReplicationProcessor.java +++ /dev/null @@ -1,168 +0,0 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) Trifon Trifonov. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Trifon Trifonov (trifonnt@users.sourceforge.net) * - * * - * Sponsors: * - * - E-evolution (http://www.e-evolution.com/) * - **********************************************************************/ -package org.compiere.server; - -import java.sql.Timestamp; - -import org.adempiere.server.rpl.IImportProcessor; -import org.compiere.model.MClient; -import org.compiere.util.TimeUtil; -import org.eevolution.model.MIMPProcessor; -import org.eevolution.model.MIMPProcessorLog; -import org.eevolution.model.X_IMP_Processor_Type; - -/** - * - * @author Trifon N. Trifonov - * - */ -public class ReplicationProcessor extends AdempiereServer { - - /** Last Summary */ - private StringBuffer m_summary = new StringBuffer(); - - /** Client info */ - private MClient m_client = null; - - private MIMPProcessor mImportProcessor = null; - - /** - * flag showing if process is working! - */ - private boolean isProcessRunning = false; - - - protected ReplicationProcessor(MIMPProcessor model, int initialNap) { - super (model, initialNap); - mImportProcessor = model; - m_client = MClient.get(mImportProcessor.getCtx(), mImportProcessor.getAD_Client_ID()); - } - - protected ReplicationProcessor(MIMPProcessor model) { - super (model, 30); - mImportProcessor = model; - m_client = MClient.get(mImportProcessor.getCtx(), mImportProcessor.getAD_Client_ID()); - } - - @SuppressWarnings("unchecked") - @Override - protected void doWork() { - if (isProcessRunning) { - // process is already started successfully! - - } else { - // process is not started! - - m_summary = new StringBuffer(); - String trxName = mImportProcessor.get_TrxName(); - if ( trxName == null || "".equals(trxName) ) { -// trxName = "ImportProcessor-" + System.currentTimeMillis(); - } - log.fine("trxName = " + trxName); - log.fine("ImportProcessor = " + mImportProcessor); - - int IMP_ProcessorType_ID = 0; - IMP_ProcessorType_ID = mImportProcessor.getIMP_Processor_Type_ID(); - X_IMP_Processor_Type impProcessor_Type = new X_IMP_Processor_Type(mImportProcessor.getCtx(), IMP_ProcessorType_ID, trxName ); - log.fine("impProcessor_Type = " + impProcessor_Type); // TODO --- REMOVE - - String javaClass = impProcessor_Type.getJavaClass(); - IImportProcessor importProcessor = null; - try { - Class clazz = Class.forName(javaClass); - importProcessor = (IImportProcessor)clazz.newInstance(); - - importProcessor.process(mImportProcessor.getCtx(), this, trxName ); - - } catch (Exception e) { - isProcessRunning = false; - log.fine("ReplicationProcessor caught an exception !!!" ); - e.printStackTrace(); - - log.severe( e.getMessage() ); - - MIMPProcessorLog pLog = new MIMPProcessorLog(mImportProcessor, e.getMessage() ); - pLog.setReference("#" + String.valueOf(p_runCount) + " - " + TimeUtil.formatElapsed(new Timestamp(p_startWork))); - boolean resultSave = pLog.save(); - - try { - importProcessor.stop(); - } catch (Exception e1) { - e1.printStackTrace(); - MIMPProcessorLog pLog2 = new MIMPProcessorLog(mImportProcessor, e1.getMessage() ); - - boolean resultSave2 = pLog2.save(); - } - } - - // - int no = mImportProcessor.deleteLog(); - m_summary.append("Logs Records deleted=").append(no).append("; "); - // - MIMPProcessorLog pLog = new MIMPProcessorLog(mImportProcessor, m_summary.toString()); - pLog.setReference("#" + String.valueOf(p_runCount) + " - " + TimeUtil.formatElapsed(new Timestamp(p_startWork))); - boolean resultSave = pLog.save(); - } - } - - @Override - public String getServerInfo() - { - return "#" + p_runCount + " - Last=" + m_summary.toString(); - } - - /** - * @return the isProcessRunning - */ - public boolean isProcessRunning() { - return isProcessRunning; - } - - /** - * @param isProcessRunning the isProcessRunning to set - */ - public void setProcessRunning(boolean isProcessRunning) { - this.isProcessRunning = isProcessRunning; - } - - /** - * @return the mImportProcessor - */ - public MIMPProcessor getMImportProcessor() { - return mImportProcessor; - } - - /** - * @param importProcessor the mImportProcessor to set - */ - public void setMImportProcessor(MIMPProcessor importProcessor) { - mImportProcessor = importProcessor; - } - -}