Skip to content

Commit

Permalink
Add Changes on Withholding Declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosaparadam committed Sep 27, 2019
1 parent 010555b commit 88122ee
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions base/org/spin/process/WithholdingDeclaration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,7 +45,7 @@ protected void prepare() {

@Override
protected String doIt() throws Exception {

String result;
if (isSelection()) {
getSelectionValues()
.entrySet()
Expand All @@ -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<Object> params = new ArrayList<Object>();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -121,10 +122,14 @@ private void addWHDoc(MInvoice invoiceWH) {
/**
* Process Document
*/
private void processWHDoc() {
private String processWHDoc() {
AtomicReference<String> result = new AtomicReference<String>();
result.set("");
m_Declarations.forEach(declaration -> {
declaration.process();
result.set(result.get() + "\n" + "@DocumentNo@ : "+ declaration.getDocumentNo());
});
return result.get();
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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) + "@");
Expand Down Expand Up @@ -230,5 +235,12 @@ public String toString() {
+ "\n Invoice = " + m_InvoicesWH.toString();
}

public String getDocumentNo() {
if (m_Declaration!=null)
return m_Declaration.getDocumentNo();

return "";
}

}

0 comments on commit 88122ee

Please sign in to comment.