details: https://code.openbravo.com/erp/devel/pi/rev/5b7d0ffec363
changeset: 21909:5b7d0ffec363
user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com>
date: Mon Feb 03 12:11:07 2014 +0100
summary: Fixed bug 25638: [cashvat] Withholding and tax exempt (rate=0%)
support
Cash VAT invoices are allowed to include withholding and exempt (rate=0%) tax
rates.
Cash VAT information at Invoice | Tax level only created for Cash VAT tax rates
(neither withholding nor exempt tax rates).
Cash VAT accounting flow (usage of tax transitory accounts) only for Cash VAT
tax rates (neither withholding nor exempt tax rates).
diffstat:
modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml
| 8 +-
src-db/database/model/functions/C_GETTAX.xml
| 14 +-
src-db/database/model/functions/C_INVOICE_POST.xml
| 4 +-
src-db/database/model/functions/C_ORDER_POST1.xml
| 4 +-
src-db/database/model/triggers/C_INVOICELINE_TRG.xml
| 27 +-
src/org/openbravo/erpCommon/ad_forms/DocInvoice.java
| 16 +-
src/org/openbravo/erpCommon/ad_forms/DocInvoice_data.xsql
| 6 +-
src/org/openbravo/erpCommon/ad_forms/DocTax.java
| 8 +
src/org/openbravo/erpCommon/utility/CashVATUtil.java
| 149 +++++----
9 files changed, 131 insertions(+), 105 deletions(-)
diffs (truncated from 508 to 300 lines):
diff -r a917e66ec065 -r 5b7d0ffec363
modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml
---
a/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml
Thu Jan 30 14:51:58 2014 +0530
+++
b/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml
Mon Feb 03 12:11:07 2014 +0100
@@ -16,7 +16,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2010-2013 Openbravo SLU
+* All portions are Copyright (C) 2010-2014 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************/
@@ -492,8 +492,9 @@
v_PercentageCashVAT :=
abs(c_currency_round(v_scheduledetailamount * 100 / v_GrandTotal,
v_Currency_ID, null));
FOR cur_cinvoicetax IN (
SELECT it.C_InvoiceTax_ID, it.taxamt, it.taxbaseamt
- FROM C_InvoiceTax it
+ FROM C_InvoiceTax it INNER JOIN C_Tax t on (it.c_tax_id =
t.c_tax_id)
WHERE it.c_invoice_id = p_record_id
+ AND t.isCashVAT = 'Y'
)
LOOP
INSERT INTO c_invoicetax_cashvat(
@@ -753,8 +754,9 @@
v_PercentageCashVAT :=
abs(c_currency_round(cur_linktopayment_scheddetails.AMOUNT * 100 /
v_GrandTotal, v_Currency_ID, null));
FOR cur_cinvoicetax IN (
SELECT it.C_InvoiceTax_ID, it.taxamt, it.taxbaseamt
- FROM C_InvoiceTax it
+ FROM C_InvoiceTax it INNER JOIN C_Tax t on (it.c_tax_id =
t.c_tax_id)
WHERE it.c_invoice_id = p_record_id
+ AND t.isCashVAT='Y'
)
LOOP
INSERT INTO c_invoicetax_cashvat(
diff -r a917e66ec065 -r 5b7d0ffec363
src-db/database/model/functions/C_GETTAX.xml
--- a/src-db/database/model/functions/C_GETTAX.xml Thu Jan 30 14:51:58
2014 +0530
+++ b/src-db/database/model/functions/C_GETTAX.xml Mon Feb 03 12:11:07
2014 +0100
@@ -200,14 +200,14 @@
FROM (SELECT C_Tax_ID, C_Country_ID, C_Region_ID, To_Country_Id,
To_Region_ID, ValidFrom, C_TaxCategory_ID,
Parent_Tax_ID, C_BP_TaxCategory_ID, SoPoType,
c_Tax.ad_org_id,c_Tax.ad_client_id,IsDefault,
- isCashVAT
+ isCashVAT, isWithholdingTax, rate
FROM c_Tax
WHERE c_Tax.isActive = 'Y'
UNION
SELECT tz.C_Tax_ID, tz.From_Country_ID, tz.From_Region_ID,
tz.To_Country_ID,
tz.To_Region_ID, ValidFrom, C_TaxCategory_ID,
Parent_Tax_Id, C_BP_TaxCategory_ID, ct.SoPoType,
ct.ad_org_id,ct.ad_client_id,ct.IsDefault,
- isCashVAT
+ ct.isCashVAT, ct.isWithholdingTax, ct.rate
FROM c_Tax_Zone tz,
c_Tax ct
WHERE tz.C_Tax_ID = ct.C_Tax_ID
@@ -228,7 +228,7 @@
-- AND ((t.C_BP_TaxCategory_ID = v_BPTaxCategory) OR
(v_BPTaxCategory IS NULL))
AND ((t.C_BP_TaxCategory_ID IS NOT NULL AND t.C_BP_TaxCategory_ID
= v_BPTaxCategory) OR (t.C_BP_TaxCategory_ID IS NULL))
AND (SoPoType = 'B' OR (SoPoType =(case when p_IsSOTrx='Y' then
'S' else 'P' end)))
- AND t.isCashVAT = v_IsCashVAT
+ AND (t.isCashVAT = v_IsCashVAT OR (t.isCashVAT = 'N' and
(t.isWithholdingTax = 'Y' or t.rate=0)))
ORDER BY ad_isorgincluded(p_org_id,
t.ad_org_id,t.ad_client_id),t.C_BP_TaxCategory_ID, t.IsDefault
DESC,t.C_Country_ID, t.To_Country_ID, t.C_Region_ID, t.To_Region_ID,
t.ValidFrom DESC
)
LOOP
@@ -242,14 +242,14 @@
(SELECT C_Tax_ID, C_Country_ID, C_Region_ID, To_Country_Id,
To_Region_ID, ValidFrom, C_TaxCategory_ID,
Parent_Tax_ID, C_BP_TaxCategory_ID, SoPoType,
c_Tax.ad_org_id,c_Tax.ad_client_id,IsDefault,
- isCashVAT
+ isCashVAT, isWithholdingTax, rate
FROM c_Tax
WHERE c_Tax.isActive = 'Y'
UNION
SELECT tz.C_Tax_ID, tz.From_Country_ID, tz.From_Region_ID,
tz.To_Country_ID,
tz.To_Region_ID, ValidFrom, C_TaxCategory_ID,
Parent_Tax_Id, C_BP_TaxCategory_ID, SoPoType, ct.ad_org_id,
ct.ad_client_id,ct.IsDefault,
- isCashVAT
+ ct.isCashVAT, ct.isWithholdingTax, ct.rate
FROM c_Tax_Zone tz,
c_Tax ct
WHERE tz.C_Tax_ID = ct.C_Tax_ID
@@ -271,7 +271,7 @@
--AND ((t.C_BP_TaxCategory_ID = v_BPTaxCategory) OR
(v_BPTaxCategory IS NULL))
AND ((t.C_BP_TaxCategory_ID IS NOT NULL AND
t.C_BP_TaxCategory_ID = v_BPTaxCategory) OR (t.C_BP_TaxCategory_ID IS NULL))
AND (SoPoType = 'B' OR (SoPoType =(case when p_IsSOTrx='Y' then
'S' else 'P' end)))
- AND t.isCashVAT = v_IsCashVAT
+ AND (t.isCashVAT = v_IsCashVAT OR (t.isCashVAT = 'N' and
(t.isWithholdingTax = 'Y' or t.rate=0)))
ORDER BY ad_isorgincluded(p_org_id,
t.ad_org_id,t.ad_client_id),t.C_BP_TaxCategory_ID,t.IsDefault
DESC,t.C_Country_ID, t.C_Region_ID, t.ValidFrom DESC
)
LOOP
@@ -293,7 +293,7 @@
AND (SoPoType = 'B' OR (SoPoType =(case when p_IsSOTrx='Y' then
'S' else 'P' end)))
AND t.isActive = 'Y'
AND ad_isorgincluded(p_org_id, t.ad_org_id,t.ad_client_id) <> -1
- AND t.isCashVAT = v_IsCashVAT
+ AND (t.isCashVAT = v_IsCashVAT OR (t.isCashVAT = 'N' and
(t.isWithholdingTax = 'Y' or t.rate=0)))
ORDER BY ad_isorgincluded(p_org_id,
t.ad_org_id,t.ad_client_id),t.C_BP_TaxCategory_ID, t.ValidFrom DESC
)
LOOP
diff -r a917e66ec065 -r 5b7d0ffec363
src-db/database/model/functions/C_INVOICE_POST.xml
--- a/src-db/database/model/functions/C_INVOICE_POST.xml Thu Jan 30
14:51:58 2014 +0530
+++ b/src-db/database/model/functions/C_INVOICE_POST.xml Mon Feb 03
12:11:07 2014 +0100
@@ -22,7 +22,7 @@
* parts created by ComPiere are Copyright (C) ComPiere, Inc.;
* All Rights Reserved.
* Contributor(s): Openbravo SLU
- * Contributions are Copyright (C) 2001-2013 Openbravo, S.L.U.
+ * Contributions are Copyright (C) 2001-2014 Openbravo, S.L.U.
*
* Specifically, this derivative work is based upon the following Compiere
* file and version.
@@ -317,6 +317,8 @@
into v_count
from c_invoicetax it inner join c_tax t on (it.c_tax_id = t.c_tax_id)
where it.c_invoice_id = v_Record_ID
+ and t.iswithholdingtax = 'N'
+ and t.rate <> 0
and t.IsCashVat <> v_iscashvat;
IF (v_count > 0) THEN
diff -r a917e66ec065 -r 5b7d0ffec363
src-db/database/model/functions/C_ORDER_POST1.xml
--- a/src-db/database/model/functions/C_ORDER_POST1.xml Thu Jan 30 14:51:58
2014 +0530
+++ b/src-db/database/model/functions/C_ORDER_POST1.xml Mon Feb 03 12:11:07
2014 +0100
@@ -19,7 +19,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2001-2013 Openbravo SLU
+* All portions are Copyright (C) 2001-2014 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************/
@@ -310,6 +310,8 @@
into v_Aux
from c_ordertax ot inner join c_tax t on (ot.c_tax_id = t.c_tax_id)
where ot.c_order_id = v_Record_ID
+ and t.iswithholdingtax = 'N'
+ and t.rate <> 0
and t.IsCashVat <> v_iscashvat;
IF (v_Aux > 0) THEN
diff -r a917e66ec065 -r 5b7d0ffec363
src-db/database/model/triggers/C_INVOICELINE_TRG.xml
--- a/src-db/database/model/triggers/C_INVOICELINE_TRG.xml Thu Jan 30
14:51:58 2014 +0530
+++ b/src-db/database/model/triggers/C_INVOICELINE_TRG.xml Mon Feb 03
12:11:07 2014 +0100
@@ -14,7 +14,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2001-2013 Openbravo SLU
+* All portions are Copyright (C) 2001-2014 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************/
@@ -40,7 +40,9 @@
v_AttrSetValueType M_Product.AttrSetValueType%TYPE;
v_count NUMBER;
v_IsCashVAT_Tax C_Tax.IsCashVAT%TYPE;
+ v_IsWithholding_Tax C_Tax.IsWithholdingTax%TYPE;
v_IsCashVAT_Invoice C_Invoice.IsCashVAT%TYPE;
+ v_Rate_Tax C_Tax.Rate%TYPE;
BEGIN
@@ -106,22 +108,25 @@
-- Update C_Invoice.IsCashVAT flag from the line tax rate.
-- We do it this way to force any invoicing process to properly set the
C_Invoice.IsCashVAT
-- If a user manually changes the tax rate when entering a line, the
invoice's header IsCash VAT may change
+ -- This will just work for not withholding tax rates
IF (INSERTING OR UPDATING) THEN
IF (:NEW.C_TAX_ID IS NOT NULL) THEN
- SELECT COALESCE(IsCashVAT, 'N')
- INTO v_IsCashVAT_Tax
+ SELECT COALESCE(iswithholdingtax, 'N'), COALESCE(IsCashVAT, 'N'),
COALESCE(rate, 0)
+ INTO v_IsWithholding_Tax, v_IsCashVAT_Tax, v_Rate_Tax
FROM C_Tax
WHERE C_Tax_ID=:NEW.C_Tax_ID;
- SELECT COALESCE(IsCashVAT, 'N')
- INTO v_IsCashVAT_Invoice
- FROM C_Invoice
- WHERE C_Invoice_ID=:NEW.C_Invoice_ID;
+ IF (v_IsWithholding_Tax='N' AND v_Rate_Tax<>0) THEN
+ SELECT COALESCE(IsCashVAT, 'N')
+ INTO v_IsCashVAT_Invoice
+ FROM C_Invoice
+ WHERE C_Invoice_ID=:NEW.C_Invoice_ID;
- IF (v_IsCashVAT_Tax <> v_IsCashVAT_Invoice) THEN
- UPDATE C_Invoice
- SET IsCashVAT = v_IsCashVAT_Tax
- WHERE C_Invoice_ID=:NEW.C_Invoice_ID;
+ IF (v_IsCashVAT_Tax <> v_IsCashVAT_Invoice) THEN
+ UPDATE C_Invoice
+ SET IsCashVAT = v_IsCashVAT_Tax
+ WHERE C_Invoice_ID=:NEW.C_Invoice_ID;
+ END IF;
END IF;
END IF;
END IF;
diff -r a917e66ec065 -r 5b7d0ffec363
src/org/openbravo/erpCommon/ad_forms/DocInvoice.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocInvoice.java Thu Jan 30
14:51:58 2014 +0530
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInvoice.java Mon Feb 03
12:11:07 2014 +0100
@@ -174,8 +174,10 @@
}
}
+ boolean taxIsCashVAT = StringUtils.equals(data[i].iscashvat, "Y");
+
DocTax taxLine = new DocTax(C_Tax_ID, name, rate, taxBaseAmt, amount,
isTaxUndeductable,
- isTaxDeductable);
+ isTaxDeductable, taxIsCashVAT);
list.add(taxLine);
}
// Return Array
@@ -379,7 +381,7 @@
StringUtils.isBlank(m_taxes[i].m_amount) ? "0" :
m_taxes[i].m_amount);
BigDecimal taxToTransAccount = BigDecimal.ZERO;
if (IsReversal.equals("Y")) {
- if (isCashVAT) {
+ if (isCashVAT && m_taxes[i].m_isCashVAT) {
percentageFinalAccount =
CashVATUtil.calculatePrepaidPercentageForCashVATTax(
m_taxes[i].m_C_Tax_ID, Record_ID);
taxToTransAccount = CashVATUtil.calculatePercentageAmount(
@@ -393,7 +395,7 @@
C_Currency_ID, taxToFinalAccount.toString(), "",
Fact_Acct_Group_ID,
nextSeqNo(SeqNo), DocumentType, conn);
} else {
- if (isCashVAT) {
+ if (isCashVAT && m_taxes[i].m_isCashVAT) {
percentageFinalAccount =
CashVATUtil.calculatePrepaidPercentageForCashVATTax(
m_taxes[i].m_C_Tax_ID, Record_ID);
taxToTransAccount = CashVATUtil.calculatePercentageAmount(
@@ -547,7 +549,7 @@
final BigDecimal taxesAmountTotal = new
BigDecimal(StringUtils.isBlank(m_taxes[i]
.getAmount()) ? "0" : m_taxes[i].getAmount());
BigDecimal taxToTransAccount = BigDecimal.ZERO;
- if (isCashVAT) {
+ if (isCashVAT && m_taxes[i].m_isCashVAT) {
percentageFinalAccount =
CashVATUtil.calculatePrepaidPercentageForCashVATTax(
m_taxes[i].m_C_Tax_ID, Record_ID);
taxToTransAccount = CashVATUtil.calculatePercentageAmount(
@@ -680,7 +682,7 @@
.getAmount()) ? "0" : m_taxes[i].getAmount());
BigDecimal taxToTransAccount = BigDecimal.ZERO;
if (IsReversal.equals("Y")) {
- if (isCashVAT) {
+ if (isCashVAT && m_taxes[i].m_isCashVAT) {
percentageFinalAccount =
CashVATUtil.calculatePrepaidPercentageForCashVATTax(
m_taxes[i].m_C_Tax_ID, Record_ID);
taxToTransAccount = CashVATUtil.calculatePercentageAmount(
@@ -696,7 +698,7 @@
this.C_Currency_ID, "", taxToFinalAccount.toString(),
Fact_Acct_Group_ID,
nextSeqNo(SeqNo), DocumentType, conn);
} else {
- if (isCashVAT) {
+ if (isCashVAT && m_taxes[i].m_isCashVAT) {
percentageFinalAccount =
CashVATUtil.calculatePrepaidPercentageForCashVATTax(
m_taxes[i].m_C_Tax_ID, Record_ID);
taxToTransAccount = CashVATUtil.calculatePercentageAmount(
@@ -926,7 +928,7 @@
final BigDecimal taxesAmountTotal = new
BigDecimal(StringUtils.isBlank(m_taxes[i]
.getAmount()) ? "0" : m_taxes[i].getAmount());
BigDecimal taxToTransAccount = BigDecimal.ZERO;
- if (isCashVAT) {
+ if (isCashVAT && m_taxes[i].m_isCashVAT) {
percentageFinalAccount =
CashVATUtil.calculatePrepaidPercentageForCashVATTax(
m_taxes[i].m_C_Tax_ID, Record_ID);
taxToTransAccount = CashVATUtil.calculatePercentageAmount(
diff -r a917e66ec065 -r 5b7d0ffec363
src/org/openbravo/erpCommon/ad_forms/DocInvoice_data.xsql
--- a/src/org/openbravo/erpCommon/ad_forms/DocInvoice_data.xsql Thu Jan 30
14:51:58 2014 +0530
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInvoice_data.xsql Mon Feb 03
12:11:07 2014 +0100
@@ -12,7 +12,7 @@
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): Openbravo SLU
- * Contributions are Copyright (C) 2001-2013 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2014 Openbravo S.L.U.
******************************************************************************
-->
@@ -36,10 +36,10 @@
'' AS ISPAID, '' AS CREATEFROM, '' AS GENERATETO, '' AS SENDEMAIL, ''
AS AD_USER_ID, '' AS COPYFROM, '' AS ISSELFSERVICE,
'' AS AD_ORGTRX_ID, '' AS USER1_ID, '' AS USER2_ID, '' as AMOUNT, ''
AS STATUS, '' AS ISRECEIPT, '' AS ISMANUAL, '' AS WRITEOFFAMT,
'' AS C_DEBT_PAYMENT_ID, '' AS P_REVENUE_ACCT, '' AS P_EXPENSE_ACCT,
'' as FIN_PAYMENT_SCHEDULE_ID, '' as FIN_PAYMENTMETHOD_ID, '' AS PREPAIDAMT,
- '' AS FININVCOUNT, '' AS FINACCTCOUNT, '' AS FIN_PAYMENT_ID, '' AS
C_COSTCENTER_ID, '' AS ISCASHVAT
+ '' AS FININVCOUNT, '' AS FINACCTCOUNT, '' AS FIN_PAYMENT_ID, '' AS
C_COSTCENTER_ID, t.isCashVAT AS ISCASHVAT
FROM C_Tax t, C_InvoiceTax it
WHERE t.C_Tax_ID=it.C_Tax_ID AND it.C_Invoice_ID=?
- GROUP BY t.IsTaxUndeductable, it.C_Tax_ID, t.Name, t.Rate,
t.IsTaxDeductable, it.ad_org_id
+ GROUP BY t.IsTaxUndeductable, it.C_Tax_ID, t.Name, t.Rate,
t.IsTaxDeductable, it.ad_org_id, t.isCashVAT
]]>
</Sql>
<Parameter name="invoice"/>
diff -r a917e66ec065 -r 5b7d0ffec363
src/org/openbravo/erpCommon/ad_forms/DocTax.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocTax.java Thu Jan 30 14:51:58
2014 +0530
+++ b/src/org/openbravo/erpCommon/ad_forms/DocTax.java Mon Feb 03 12:11:07
2014 +0100
@@ -38,6 +38,12 @@
m_isTaxDeductable = isTaxDeductable;
} // DocTax
+ public DocTax(String C_Tax_ID, String name, String rate, String taxBaseAmt,
String amount,
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits