You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ha...@apache.org on 2009/11/06 10:19:03 UTC

svn commit: r833326 - /ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java

Author: hansbak
Date: Fri Nov  6 09:19:02 2009
New Revision: 833326

URL: http://svn.apache.org/viewvc?rev=833326&view=rev
Log:
as result of investigation of previous commit made the selection of tax and non-tax records consistent, better formatting and replaced get( with getString( on genericValues. No functional changes

Modified:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java

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?rev=833326&r1=833325&r2=833326&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceWorker.java Fri Nov  6 09:19:02 2009
@@ -39,10 +39,8 @@
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.condition.EntityConditionList;
-import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.util.EntityUtil;
-import org.ofbiz.service.LocalDispatcher;
 
 /**
  * InvoiceWorker - Worker methods of invoices
@@ -57,14 +55,24 @@
     private static int taxRounding = UtilNumber.getBigDecimalRoundingMode("salestax.rounding");
 
     /**
-     * Method to return the total amount of an invoice
-     * @param invoice GenericValue object of the Invoice
-     * @return the invoice total as BigDecimal
+     * Return the total amount of the invoice (including tax) using the the invoiceId as input.
+     * @param delegator
+     * @param invoiceId
+     * @return
      */
     public static BigDecimal getInvoiceTotal(Delegator delegator, String invoiceId) {
         return getInvoiceTotal(delegator, invoiceId, Boolean.TRUE);
     }
 
+    /**
+     * Return the total amount of the invoice (including tax) using the the invoiceId as input.
+     * with the ability to specify if the actual currency is required.
+     * @param delegator
+     * @param invoiceId
+     * @param actualCurrency true: provide the actual currency of the invoice (could be different from the system currency)
+     *                       false: if required convert the actual currency into the system currency.
+     * @return
+     */
     public static BigDecimal getInvoiceTotal(Delegator delegator, String invoiceId, Boolean actualCurrency) {
         if (delegator == null) {
             throw new IllegalArgumentException("Null delegator is not allowed in this method");
@@ -103,7 +111,7 @@
         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"));
+            typeIds.add(invoiceItemTaxType.getString("enumId"));
         }
         return typeIds;
     }
@@ -118,7 +126,7 @@
         try {
             Delegator delegator = invoice.getDelegator();
             EntityConditionList condition = EntityCondition.makeCondition(UtilMisc.toList(
-                    EntityCondition.makeCondition("invoiceId", invoice.get("invoiceId")),
+                    EntityCondition.makeCondition("invoiceId", invoice.getString("invoiceId")),
                     EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.IN, getTaxableInvoiceItemTypeIds(delegator))),
                     EntityOperator.AND);
             invoiceTaxItems = delegator.findList("InvoiceItem", condition, null, null, null, false);
@@ -155,7 +163,16 @@
         return getInvoiceTotal(invoice, Boolean.TRUE);
     }
 
-    public static BigDecimal getInvoiceTotal(GenericValue invoice, Boolean actualCurrency) {
+     /**
+      * 
+      * Return the total amount of the invoice (including tax) using the the invoice GenericValue as input.
+      * with the ability to specify if the actual currency is required.
+      * @param invoice
+      * @param actualCurrency true: provide the actual currency of the invoice (could be different from the system currency)
+      *                       false: if required convert the actual currency into the system currency.
+      * @return
+      */
+     public static BigDecimal getInvoiceTotal(GenericValue invoice, Boolean actualCurrency) {
         BigDecimal invoiceTotal = ZERO;
         BigDecimal invoiceTaxTotal = ZERO;
         Map invoiceTaxByTaxAuthGeoAndPartyResult = getInvoiceTaxByTaxAuthGeoAndParty(invoice);
@@ -165,8 +182,19 @@
         List invoiceItems = null;
         try {
             invoiceItems = invoice.getRelated("InvoiceItem");
-            invoiceItems = EntityUtil.filterByAnd(invoiceItems, UtilMisc.toList(EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.NOT_EQUAL, "PINV_SALES_TAX"), EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.NOT_EQUAL, "PITM_SALES_TAX"),
-                    EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.NOT_EQUAL, "ITM_SALES_TAX"), EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.NOT_EQUAL, "INV_SALES_TAX")));
+            if ("SALES_INVOICE".equals(invoice.getString("invoiceTypeId"))) {
+                invoiceItems = EntityUtil.filterByAnd(
+                        invoiceItems, UtilMisc.toList(
+                                EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.NOT_EQUAL, "INV_SALES_TAX"), 
+                                EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.NOT_EQUAL, "ITM_SALES_TAX")));
+            } else if (("PURCHASE_INVOICE".equals(invoice.getString("invoiceTypeId")))) {
+                invoiceItems = EntityUtil.filterByAnd(
+                        invoiceItems, UtilMisc.toList(
+                                EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.NOT_EQUAL, "PINV_SALES_TAX"), 
+                                EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.NOT_EQUAL, "PITM_SALES_TAX")));
+            } else {
+                invoiceItems = null;
+            }
         } catch (GenericEntityException e) {
             Debug.logError(e, "Trouble getting InvoiceItem list", module);
         }
@@ -610,7 +638,11 @@
         return getInvoiceCurrencyConversionRate(invoice);
     }
 
-
+    /**
+     * Return a list of taxes separated by Geo and party and return the tax grandtotal
+     * @param invoice Generic Value
+     * @return  Map: taxByTaxAuthGeoAndPartyList(List) and taxGrandTotal(BigDecimal)
+     */
     public static Map<String, Object> getInvoiceTaxByTaxAuthGeoAndParty(GenericValue invoice) {
         BigDecimal taxGrandTotal = ZERO;
         List<Map<String, Object>> taxByTaxAuthGeoAndPartyList = FastList.newInstance();
@@ -621,10 +653,16 @@
             } catch (GenericEntityException e) {
                 Debug.logError(e, "Trouble getting InvoiceItem list", module);
             }
-            if ("SALES_INVOICE".equals(invoice.get("invoiceTypeId"))) {
-                invoiceItems = EntityUtil.filterByOr(invoiceItems, UtilMisc.toList(EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.EQUALS, "INV_SALES_TAX"), EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.EQUALS, "ITM_SALES_TAX")));
-            } else if (("PURCHASE_INVOICE".equals(invoice.get("invoiceTypeId")))) {
-                invoiceItems = EntityUtil.filterByOr(invoiceItems, UtilMisc.toList(EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.EQUALS, "PINV_SALES_TAX"), EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.EQUALS, "PITM_SALES_TAX")));
+            if ("SALES_INVOICE".equals(invoice.getString("invoiceTypeId"))) {
+                invoiceItems = EntityUtil.filterByOr(
+                        invoiceItems, UtilMisc.toList(
+                                EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.EQUALS, "INV_SALES_TAX"), 
+                                EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.EQUALS, "ITM_SALES_TAX")));
+            } else if (("PURCHASE_INVOICE".equals(invoice.getString("invoiceTypeId")))) {
+                invoiceItems = EntityUtil.filterByOr(
+                        invoiceItems, UtilMisc.toList(
+                                EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.EQUALS, "PINV_SALES_TAX"), 
+                                EntityCondition.makeCondition("invoiceItemTypeId", EntityOperator.EQUALS, "PITM_SALES_TAX")));
             } else {
                 invoiceItems = null;
             }