You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by si...@apache.org on 2007/03/19 22:07:31 UTC

svn commit: r520102 - in /ofbiz/trunk/applications/accounting: data/AccountingTypeData.xml src/org/ofbiz/accounting/invoice/InvoiceWorker.java webapp/accounting/WEB-INF/actions/invoice/editInvoice.bsh webapp/accounting/invoice/viewInvoice.fo.ftl

Author: sichen
Date: Mon Mar 19 14:07:28 2007
New Revision: 520102

URL: http://svn.apache.org/viewvc?view=rev&rev=520102
Log:
Resolved issue OFBIZ-405:  The ability to get the invoice total with and without tax.  This clears the way for supporting VAT in invoices. Thanks go to Eriks Dobelis for getting things started and numerous other members of the OFBiz community for suggestions.  Don't forget to reload AccountingTypeData.xml.

Modified:
    ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java
    ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/editInvoice.bsh
    ofbiz/trunk/applications/accounting/webapp/accounting/invoice/viewInvoice.fo.ftl

Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?view=diff&rev=520102&r1=520101&r2=520102
==============================================================================
--- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original)
+++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Mon Mar 19 14:07:28 2007
@@ -399,6 +399,14 @@
     <InvoiceItemTypeMap invoiceTypeId="COMMISSION_INVOICE" invoiceItemMapKey="COM_COMM_ADJ" invoiceItemTypeId="COMM_INV_ADJ"/>
     
     <InvoiceItemTypeMap invoiceTypeId="INTEREST_INVOICE" invoiceItemMapKey="INT_INV_CHRG" invoiceItemTypeId="INV_INTRST_CHRG"/>
+
+    <!-- An Enumeration to identify the taxable invoice item types.  For these, the only important fields are enumId and enumTypeId. -->
+    <EnumerationType description="Taxable Invoice Item Types" enumTypeId="TAXABLE_INV_ITM_TY" hasTable="N" parentTypeId=""/>
+    <Enumeration description="Sales Invoice Sales Tax" enumCode="INV_SALES_TAX" enumId="INV_SALES_TAX" sequenceId="01" enumTypeId="TAXABLE_INV_ITM_TY"/>
+    <Enumeration description="Sales Invoice Line Item Sales Tax" enumCode="ITM_SALES_TAX" enumId="ITM_SALES_TAX" sequenceId="02" enumTypeId="TAXABLE_INV_ITM_TY"/>
+    <Enumeration description="Purchase Invoice Sales Tax" enumCode="PINV_SALES_TAX" enumId="PINV_SALES_TAX" sequenceId="03" enumTypeId="TAXABLE_INV_ITM_TY"/>
+    <Enumeration description="Purchase Invoice Line Item Sales Tax" enumCode="PITM_SALES_TAX" enumId="PITM_SALES_TAX" sequenceId="04" enumTypeId="TAXABLE_INV_ITM_TY"/>
+    <Enumeration description="Customer Return Sales Tax Adjustment" enumCode="CRT_SALES_TAX_ADJ" enumId="CRT_SALES_TAX_ADJ" sequenceId="05" enumTypeId="TAXABLE_INV_ITM_TY"/>
     
     <PaymentMethodType description="Credit Card" paymentMethodTypeId="CREDIT_CARD"/>
     <PaymentMethodType description="Gift Card" paymentMethodTypeId="GIFT_CARD"/>

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java?view=diff&rev=520102&r1=520101&r2=520102
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java Mon Mar 19 14:07:28 2007
@@ -22,6 +22,7 @@
 import java.sql.Timestamp;
 import java.util.Iterator;
 import java.util.List;
+import javolution.util.FastList;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
@@ -41,6 +42,7 @@
 public class InvoiceWorker {
     
     public static String module = InvoiceWorker.class.getName();
+    private static BigDecimal ZERO = new BigDecimal("0");
     private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
     private static int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
 
@@ -71,6 +73,55 @@
         
         return getInvoiceTotalBd(invoice);
     }
+
+    /** Method to get the taxable invoice item types as a List of invoiceItemTypeIds.  These are identified in Enumeration with enumTypeId TAXABLE_INV_ITM_TY. */
+    public static List getTaxableInvoiceItemTypeIds(GenericDelegator delegator) throws GenericEntityException {
+        List typeIds = FastList.newInstance();
+        List invoiceItemTaxTypes = delegator.findByAndCache("Enumeration", UtilMisc.toMap("enumTypeId", "TAXABLE_INV_ITM_TY"));
+        for (Iterator iter = invoiceItemTaxTypes.iterator(); iter.hasNext(); ) {
+            GenericValue invoiceItemTaxType = (GenericValue) iter.next();
+            typeIds.add(invoiceItemTaxType.get("enumId"));
+        }
+        return typeIds;
+    }
+
+    public static double getInvoiceTaxTotal(GenericValue invoice) {
+        BigDecimal invoiceTaxTotal = ZERO;
+        BigDecimal ONE = new BigDecimal("1");
+
+        if (invoice == null)
+           throw new IllegalArgumentException("The invoiceId passed does not match an existing invoice"); 
+        List invoiceTaxItems = null;
+        try {
+            GenericDelegator delegator = invoice.getDelegator();
+            EntityConditionList condition = new EntityConditionList( UtilMisc.toList(
+                    new EntityExpr("invoiceId", EntityOperator.EQUALS, invoice.get("invoiceId")),
+                    new EntityExpr("invoiceItemTypeId", EntityOperator.IN, getTaxableInvoiceItemTypeIds(delegator))
+                    ), EntityOperator.AND);
+            invoiceTaxItems = delegator.findByCondition("InvoiceItem", condition, null, null);
+        } catch (GenericEntityException e) {
+            Debug.logError(e, "Trouble getting InvoiceItem list", module);            
+        }
+        if (invoiceTaxItems != null && invoiceTaxItems.size() > 0) {
+            Iterator invoiceItemsIter = invoiceTaxItems.iterator();
+            while (invoiceItemsIter.hasNext()) {
+                GenericValue invoiceItem = (GenericValue) invoiceItemsIter.next();
+                BigDecimal amount = invoiceItem.getBigDecimal("amount");
+                BigDecimal quantity = invoiceItem.getBigDecimal("quantity");
+                if (amount == null)
+                    amount = ZERO;
+                if (quantity == null)
+                    quantity = ONE;
+                invoiceTaxTotal = invoiceTaxTotal.add(amount.multiply(quantity)).setScale(decimals + 1, rounding);
+            }
+        }
+        return invoiceTaxTotal.setScale(decimals, rounding).doubleValue();
+
+    }
+    
+    public static double getInvoiceNoTaxTotal(GenericValue invoice) {
+        return getInvoiceTotalBd(invoice).doubleValue() - getInvoiceTaxTotal(invoice);
+    }
     
     /**
      * Method to return the total amount of an invoice
@@ -82,7 +133,7 @@
         }
         
         public static BigDecimal getInvoiceTotalBd(GenericValue invoice) {
-        BigDecimal invoiceTotal = new BigDecimal("0");
+        BigDecimal invoiceTotal = ZERO;
         List invoiceItems = null;
         try {
             invoiceItems = invoice.getRelated("InvoiceItem");
@@ -96,7 +147,7 @@
                 BigDecimal amount = invoiceItem.getBigDecimal("amount");
                 BigDecimal quantity = invoiceItem.getBigDecimal("quantity");
                 if (amount == null)
-                    amount = new BigDecimal("0");
+                    amount = ZERO;
                 if (quantity == null)
                     quantity = new BigDecimal("1");
                 invoiceTotal = invoiceTotal.add( amount.multiply(quantity)).setScale(decimals,rounding);
@@ -343,7 +394,7 @@
             throw new IllegalArgumentException("Null delegator is not allowed in this method");
         }
         
-        BigDecimal invoiceApplied = new BigDecimal("0");
+        BigDecimal invoiceApplied = ZERO;
         List paymentApplications = null;
         
         // lookup payment applications which took place before the asOfDateTime for this invoice
@@ -437,7 +488,7 @@
         return getInvoiceItemAppliedBd(invoiceItem).doubleValue();
     }
     public static BigDecimal getInvoiceItemAppliedBd(GenericValue invoiceItem) {
-        BigDecimal invoiceItemApplied = new BigDecimal("0");
+        BigDecimal invoiceItemApplied = ZERO;
         List paymentApplications = null;
         try {
             paymentApplications = invoiceItem.getRelated("PaymentApplication");

Modified: ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/editInvoice.bsh
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/editInvoice.bsh?view=diff&rev=520102&r1=520101&r2=520102
==============================================================================
--- ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/editInvoice.bsh (original)
+++ ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/editInvoice.bsh Mon Mar 19 14:07:28 2007
@@ -37,7 +37,9 @@
     context.put("invoiceItems", invoiceItems);
     
     invoiceTotal = InvoiceWorker.getInvoiceTotal(invoice);
+    invoiceNoTaxTotal = InvoiceWorker.getInvoiceNoTaxTotal(invoice);
     context.put("invoiceTotal", new Double(invoiceTotal));    
+    context.put("invoiceNoTaxTotal", new Double(invoiceNoTaxTotal));
     
     // each invoice of course has two billing addresses, but the one that is relevant for purchase invoices is the PAYMENT_LOCATION of the invoice
     // (ie Accounts Payable address for the supplier), while the right one for sales invoices is the BILLING_LOCATION (ie Accounts Receivable or

Modified: ofbiz/trunk/applications/accounting/webapp/accounting/invoice/viewInvoice.fo.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/invoice/viewInvoice.fo.ftl?view=diff&rev=520102&r1=520101&r2=520102
==============================================================================
--- ofbiz/trunk/applications/accounting/webapp/accounting/invoice/viewInvoice.fo.ftl (original)
+++ ofbiz/trunk/applications/accounting/webapp/accounting/invoice/viewInvoice.fo.ftl Mon Mar 19 14:07:28 2007
@@ -253,13 +253,29 @@
 
                 <#-- the grand total -->
                 <fo:table-row>
-                   <fo:table-cell number-columns-spanned="4">
+                   <fo:table-cell number-columns-spanned="3">
                    </fo:table-cell>
                    <fo:table-cell>
                       <fo:block font-weight="bold">${uiLabelMap.AccountingTotalCapital}</fo:block>
                    </fo:table-cell>
-                   <fo:table-cell text-align="right">
+                   <fo:table-cell text-align="right" number-columns-spanned="2">
                       <fo:block font-weight="bold"><@ofbizCurrency amount=invoiceTotal isoCode=invoice.currencyUomId?if_exists/></fo:block>
+                   </fo:table-cell>
+                </fo:table-row>
+                <fo:table-row height="7px">
+                   <fo:table-cell>
+                   </fo:table-cell>
+                </fo:table-row>
+                <fo:table-row height="14px">
+                   <fo:table-cell number-columns-spanned="3">
+                   </fo:table-cell>
+                   <fo:table-cell number-columns-spanned="2">
+                      <fo:block>Total excl. tax</fo:block>
+                   </fo:table-cell>
+                   <fo:table-cell number-columns-spanned="1" text-align="right">
+                      <fo:block>
+                         <@ofbizCurrency amount=invoiceNoTaxTotal isoCode=invoice.currencyUomId?if_exists/>     
+                      </fo:block>
                    </fo:table-cell>
                 </fo:table-row>
             </fo:table-body>