From 88122ee3f7b657791276d4c2302edd5c57e61672 Mon Sep 17 00:00:00 2001 From: Carlos Parada Date: Fri, 27 Sep 2019 17:31:38 -0400 Subject: [PATCH] Add Changes on Withholding Declaration --- .../spin/process/WithholdingDeclaration.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/base/org/spin/process/WithholdingDeclaration.java b/base/org/spin/process/WithholdingDeclaration.java index a8617d1..5d2d283 100644 --- a/base/org/spin/process/WithholdingDeclaration.java +++ b/base/org/spin/process/WithholdingDeclaration.java @@ -19,6 +19,7 @@ import java.math.BigDecimal; import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicReference; import org.adempiere.exceptions.AdempiereException; import org.compiere.model.MInvoice; @@ -44,7 +45,7 @@ protected void prepare() { @Override protected String doIt() throws Exception { - + String result; if (isSelection()) { getSelectionValues() .entrySet() @@ -53,7 +54,7 @@ protected String doIt() throws Exception { MInvoice invoice= new MInvoice(getCtx(), list.getKey(), get_TrxName()); addWHDoc(invoice); }); - processWHDoc(); + result = processWHDoc(); }else { StringBuffer whereClause = new StringBuffer(); ArrayList params = new ArrayList(); @@ -87,10 +88,10 @@ protected String doIt() throws Exception { .forEach( invoice -> { addWHDoc((MInvoice) invoice); }); - processWHDoc(); + result = processWHDoc(); } - return "@OK@"; + return result; } private void addWHDoc(MInvoice invoiceWH) { @@ -121,10 +122,14 @@ private void addWHDoc(MInvoice invoiceWH) { /** * Process Document */ - private void processWHDoc() { + private String processWHDoc() { + AtomicReference result = new AtomicReference(); + result.set(""); m_Declarations.forEach(declaration -> { declaration.process(); + result.set(result.get() + "\n" + "@DocumentNo@ : "+ declaration.getDocumentNo()); }); + return result.get(); } } @@ -173,7 +178,7 @@ public void process() { if (m_Amt!=null && m_InvoicesWH!=null && m_InvoicesWH.size() > 0) { - if (m_Amt.compareTo(Env.ZERO) > 0) + if (m_Amt.compareTo(Env.ZERO) < 0) GenerateDeclaration(false); else GenerateDeclaration(true); @@ -189,7 +194,7 @@ private void GenerateDeclaration(boolean isCredit) { if (isCredit) m_Declaration.setC_DocTypeTarget_ID(m_WHType.getDeclarationCreditDocType_ID()); else - m_Declaration.setC_DocTypeTarget_ID(m_WHType.getDeclarationCreditDocType_ID()); + m_Declaration.setC_DocTypeTarget_ID(m_WHType.getDeclarationDebitDocType_ID()); if (m_Declaration.getC_DocTypeTarget_ID()==0) throw new AdempiereException("@Invalid@ @" + (isCredit ? MWHType.COLUMNNAME_DeclarationCreditDocType_ID : MWHType.COLUMNNAME_DeclarationDebitDocType_ID) + "@"); @@ -230,5 +235,12 @@ public String toString() { + "\n Invoice = " + m_InvoicesWH.toString(); } + public String getDocumentNo() { + if (m_Declaration!=null) + return m_Declaration.getDocumentNo(); + + return ""; + } + }