You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2007/05/05 01:28:33 UTC

svn commit: r535415 - in /ofbiz/trunk/applications: accounting/entitydef/ accounting/src/org/ofbiz/accounting/invoice/ order/src/org/ofbiz/order/order/

Author: lektran
Date: Fri May  4 16:28:32 2007
New Revision: 535415

URL: http://svn.apache.org/viewvc?view=rev&rev=535415
Log:
Further support for calculating tax to 3 decimal places:
- Removed premature rounding from the order and invoices services
- Changed InvoiceItem to use currency-precise instead of currency-amount

Note: the UI is still displaying currency amounts to 2 decimal places so until that is changed an order/invoice total may not match the sum of the various items/adjustments displayed.

Modified:
    ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java

Modified: ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml?view=diff&rev=535415&r1=535414&r2=535415
==============================================================================
--- ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml Fri May  4 16:28:32 2007
@@ -1031,7 +1031,7 @@
       <field name="uomId" type="id"></field>
       <field name="taxableFlag" type="indicator"></field>
       <field name="quantity" type="floating-point"></field>
-      <field name="amount" type="currency-amount"></field>
+      <field name="amount" type="currency-precise"></field>
       <field name="description" type="description"></field>
       <field name="taxAuthPartyId" type="id-ne"/>
       <field name="taxAuthGeoId" type="id-ne"/>

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java?view=diff&rev=535415&r1=535414&r2=535415
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java Fri May  4 16:28:32 2007
@@ -104,7 +104,7 @@
     private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
     private static int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
     private static int taxDecimals = UtilNumber.getBigDecimalScale("salestax.calc.decimals");
-    private static int taxRounding = UtilNumber.getBigDecimalScale("salestax.rounding");
+    private static int taxRounding = UtilNumber.getBigDecimalRoundingMode("salestax.rounding");
     public static final int taxCalcScale = UtilNumber.getBigDecimalScale("salestax.calc.decimals");
     private static final int INVOICE_ITEM_SEQUENCE_ID_DIGITS = 5; // this is the number of digits used for invoiceItemSeqId: 00001, 00002...
 
@@ -510,7 +510,12 @@
                             // set decimals = 100 means we don't round this intermediate value, which is very important
                             amount = adj.getBigDecimal("amount").divide(originalOrderItem.getBigDecimal("quantity"), 100, rounding);
                             amount = amount.multiply(billingQuantity);
-                            amount = amount.setScale(decimals, rounding);
+                            // Tax needs to be rounded differently from other order adjustments
+                            if (adj.getString("orderAdjustmentTypeId").equals("SALES_TAX")) {
+                                amount = amount.setScale(taxDecimals, taxRounding);
+                            } else {
+                                amount = amount.setScale(decimals, rounding);
+                            }
                         }
                         else if (adj.get("sourcePercentage") != null) { 
                             // pro-rate the amount
@@ -566,7 +571,7 @@
                             }
 
                             // this adjustment amount
-                            BigDecimal thisAdjAmount = new BigDecimal(amount.doubleValue()).setScale(decimals, rounding);
+                            BigDecimal thisAdjAmount = new BigDecimal(amount.doubleValue());
     
                             // adjustments only apply to totals when they are not tax or shipping adjustments
                             if (!"SALES_TAX".equals(adj.getString("orderAdjustmentTypeId")) &&

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=535415&r1=535414&r2=535415
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java Fri May  4 16:28:32 2007
@@ -45,6 +45,8 @@
     private static BigDecimal ZERO = new BigDecimal("0");
     private static int decimals = UtilNumber.getBigDecimalScale("invoice.decimals");
     private static int rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");
+    private static int taxDecimals = UtilNumber.getBigDecimalScale("salestax.calc.decimals");
+    private static int taxRounding = UtilNumber.getBigDecimalRoundingMode("salestax.rounding");
 
     /**
      * Method to return the total amount of an invoice
@@ -134,6 +136,7 @@
         
         public static BigDecimal getInvoiceTotalBd(GenericValue invoice) {
         BigDecimal invoiceTotal = ZERO;
+        BigDecimal invoiceTaxTotal = ZERO;
         List invoiceItems = null;
         try {
             invoiceItems = invoice.getRelated("InvoiceItem");
@@ -150,10 +153,14 @@
                     amount = ZERO;
                 if (quantity == null)
                     quantity = new BigDecimal("1");
-                invoiceTotal = invoiceTotal.add( amount.multiply(quantity)).setScale(decimals,rounding);
+                if ("ITM_SALES_TAX".equals(invoiceItem.get("invoiceItemTypeId"))) {
+                    invoiceTaxTotal = invoiceTaxTotal.add( amount.multiply(quantity)).setScale(taxDecimals, taxRounding);
+                } else {
+                    invoiceTotal = invoiceTotal.add( amount.multiply(quantity)).setScale(decimals,rounding);
+                }
             }
         }
-        return invoiceTotal;        
+        return invoiceTotal.add(invoiceTaxTotal).setScale(decimals, rounding);
     }
 
     /**

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?view=diff&rev=535415&r1=535414&r2=535415
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Fri May  4 16:28:32 2007
@@ -2613,7 +2613,7 @@
         Iterator itemIter = UtilMisc.toIterator(orderItems);
 
         while (itemIter != null && itemIter.hasNext()) {
-            result = result.add(getOrderItemTotalBd((GenericValue) itemIter.next(), adjustments)).setScale(scale, rounding);
+            result = result.add(getOrderItemTotalBd((GenericValue) itemIter.next(), adjustments));
         }
         return result.setScale(scale,  rounding);
     }
@@ -2625,7 +2625,7 @@
 
     public static BigDecimal getOrderItemTotalBd(GenericValue orderItem, List adjustments) {
         // add tax and shipping to subtotal
-        return getOrderItemSubTotalBd(orderItem, adjustments).add(getOrderItemAdjustmentsTotalBd(orderItem, adjustments, false, true, true)).setScale(scale, rounding);
+        return getOrderItemSubTotalBd(orderItem, adjustments).add(getOrderItemAdjustmentsTotalBd(orderItem, adjustments, false, true, true));
     }
 
     /** @deprecated */
@@ -2676,7 +2676,7 @@
         Iterator itemIter = UtilMisc.toIterator(orderItems);
 
         while (itemIter != null && itemIter.hasNext()) {
-            result = result.add(getOrderItemAdjustmentsTotalBd((GenericValue) itemIter.next(), adjustments, includeOther, includeTax, includeShipping)).setScale(scale, rounding);
+            result = result.add(getOrderItemAdjustmentsTotalBd((GenericValue) itemIter.next(), adjustments, includeOther, includeTax, includeShipping));
         }
         return result;
     }
@@ -2729,7 +2729,7 @@
             while (adjIt.hasNext()) {
                 GenericValue orderAdjustment = (GenericValue) adjIt.next();
 
-                adjTotal = adjTotal.add(OrderReadHelper.calcItemAdjustmentBd(orderAdjustment, quantity, unitPrice)).setScale(scale, rounding);
+                adjTotal = adjTotal.add(OrderReadHelper.calcItemAdjustmentBd(orderAdjustment, quantity, unitPrice));
             }
         }
         return adjTotal;
@@ -2774,7 +2774,7 @@
             adjustment = adjustment.add(setScaleByType("SALES_TAX".equals(itemAdjustment.get("orderAdjustmentTypeId")), itemAdjustment.getBigDecimal("sourcePercentage").multiply(quantity).multiply(unitPrice).multiply(percentage)));
         }
         if (Debug.verboseOn()) Debug.logVerbose("calcItemAdjustment: " + itemAdjustment + ", quantity=" + quantity + ", unitPrice=" + unitPrice + ", adjustment=" + adjustment, module);
-        return adjustment.setScale(scale, rounding);
+        return adjustment;
     }
 
     public static BigDecimal calcItemAdjustmentRecurringBd(GenericValue itemAdjustment, BigDecimal quantity, BigDecimal unitPrice) {