From e9ac5e52df04664d69d84ea1b163c54e82b87357 Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Thu, 4 Dec 2008 11:29:52 +0000 Subject: [PATCH] fix InvoiceCalculateTax: * unpost invoice because we need to repost it after changing tax amounts * refactor + able to run process from outside --- .../process/InvoiceCalculateTax.java | 74 ++++++++++++------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/base/src/org/eevolution/process/InvoiceCalculateTax.java b/base/src/org/eevolution/process/InvoiceCalculateTax.java index f941fe8d40..13f54836d1 100644 --- a/base/src/org/eevolution/process/InvoiceCalculateTax.java +++ b/base/src/org/eevolution/process/InvoiceCalculateTax.java @@ -17,53 +17,73 @@ 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; /** - * Invoice Calculate Tax let re calculate Tax Invoice + * Re-calculate Invoice Tax (and unpost the document) * @author Victor Perez * @author Teo Sarca, www.arhipac.ro */ - public class InvoiceCalculateTax extends SvrProcess { - private int p_C_Invoice_ID = 0; + 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("C_Invoice_ID")) - { - p_C_Invoice_ID = para.getParameterAsInt(); - } - } + @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); + } + } - } // prepare - - @Override - protected String doIt() throws Exception - { + @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()); + 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 (getCtx(), invoice.getC_BPartner_ID(), get_TrxName()); + MBPartner bp = new MBPartner (invoice.getCtx(), invoice.getC_BPartner_ID(), invoice.get_TrxName()); bp.setTotalOpenBalance(); bp.setSOCreditStatus(); bp.saveEx(); - // - return "@ProcessOK@"; - } // doIt + } }