svn commit: r990006 - in /ofbiz/trunk/applications/accounting: servicedef/services_tax.xml src/org/ofbiz/accounting/tax/TaxAuthorityServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r990006 - in /ofbiz/trunk/applications/accounting: servicedef/services_tax.xml src/org/ofbiz/accounting/tax/TaxAuthorityServices.java

jonesde
Author: jonesde
Date: Fri Aug 27 03:13:27 2010
New Revision: 990006

URL: http://svn.apache.org/viewvc?rev=990006&view=rev
Log:
A few changes to make the code more consistent that determines the address to use for tax calc, especially when there is no shipping address, ie when it is a face-to-face sale

Modified:
    ofbiz/trunk/applications/accounting/servicedef/services_tax.xml
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java

Modified: ofbiz/trunk/applications/accounting/servicedef/services_tax.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_tax.xml?rev=990006&r1=990005&r2=990006&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_tax.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_tax.xml Fri Aug 27 03:13:27 2010
@@ -28,6 +28,7 @@ under the License.
     <service name="calcTaxInterface" engine="interface" location="" invoke="">
         <description>Tax Calc Service Interface</description>
         <attribute name="productStoreId" type="String" mode="IN" optional="true"><!-- this will be used to find the payToPartyId, if the payToPartyId parameter is not explicitly passed, and as one of the columns to constrain by on the lookup --></attribute>
+        <attribute name="facilityId" type="String" mode="IN" optional="true"><!-- if no shippingAddress is passed in this will be used to lookup an address for a face-to-face sale --></attribute>
         <attribute name="payToPartyId" type="String" mode="IN" optional="true"/>
         <attribute name="billToPartyId" type="String" mode="IN" optional="true"><!-- would like to have this not-optional, but in some circumstances may need a tax estimate without knowing who the customer is --></attribute>
         <attribute name="itemProductList" type="java.util.List" mode="IN" optional="false"><!-- List of GenericValues --></attribute>

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java?rev=990006&r1=990005&r2=990006&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java Fri Aug 27 03:13:27 2010
@@ -134,6 +134,7 @@ public class TaxAuthorityServices {
     public static Map rateProductTaxCalc(DispatchContext dctx, Map context) {
         Delegator delegator = dctx.getDelegator();
         String productStoreId = (String) context.get("productStoreId");
+        String facilityId = (String) context.get("facilityId");
         String payToPartyId = (String) context.get("payToPartyId");
         String billToPartyId = (String) context.get("billToPartyId");
         List itemProductList = (List) context.get("itemProductList");
@@ -143,42 +144,55 @@ public class TaxAuthorityServices {
         BigDecimal orderShippingAmount = (BigDecimal) context.get("orderShippingAmount");
         BigDecimal orderPromotionsAmount = (BigDecimal) context.get("orderPromotionsAmount");
         GenericValue shippingAddress = (GenericValue) context.get("shippingAddress");
+        
+        Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
 
-        if (shippingAddress == null || (shippingAddress.get("countryGeoId") == null && shippingAddress.get("stateProvinceGeoId") == null && shippingAddress.get("postalCodeGeoId") == null)) {
-            return ServiceUtil.returnError("The address(es) used for tax calculation did not have State/Province or Country or other tax jurisdiction values set, so we cannot determine the taxes to charge.");
-        }
-
-        // without knowing the TaxAuthority parties, just find all TaxAuthories for the set of IDs...
-        Set taxAuthoritySet = FastSet.newInstance();
         GenericValue productStore = null;
-        // Check value productStore *** New
-        if (productStoreId!=null) {
-            try {
-                getTaxAuthorities(delegator, shippingAddress, taxAuthoritySet);
-                if (productStoreId != null) {
-                    productStore = delegator.findByPrimaryKey("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));
-                }
-
-            } catch (GenericEntityException e) {
-                String errMsg = "Data error getting tax settings: " + e.toString();
-                Debug.logError(e, errMsg, module);
-                return ServiceUtil.returnError(errMsg);
+        GenericValue facility = null;
+        try {
+            if (productStoreId != null) {
+                productStore = delegator.findByPrimaryKey("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));
             }
-
-            if (productStore == null && payToPartyId == null) {
-                throw new IllegalArgumentException("Could not find payToPartyId [" + payToPartyId + "] or ProductStore [" + productStoreId + "] for tax calculation");
+            if (facilityId != null) {
+                facility = delegator.findByPrimaryKey("Facility", UtilMisc.toMap("facilityId", facilityId));
             }
+        } catch (GenericEntityException e) {
+            String errMsg = "Data error getting tax settings: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+
+        if (productStore == null && payToPartyId == null) {
+            throw new IllegalArgumentException("Could not find payToPartyId [" + payToPartyId + "] or ProductStore [" + productStoreId + "] for tax calculation");
         }
-        else
-        {
+        
+        if (shippingAddress == null && facility != null) {
+            // if there is no shippingAddress and there is a facility it means it is a face-to-face sale so get facility's address
             try {
-                getTaxAuthorities(delegator, shippingAddress, taxAuthoritySet);
+                GenericValue facilityContactMech = ContactMechWorker.getFacilityContactMechByPurpose(delegator, facilityId, UtilMisc.toList("SHIP_ORIG_LOCATION", "PRIMARY_LOCATION"));
+                if (facilityContactMech != null) {
+                    shippingAddress = delegator.findByPrimaryKey("PostalAddress",
+                            UtilMisc.toMap("contactMechId", facilityContactMech.getString("contactMechId")));
+                }
             } catch (GenericEntityException e) {
                 String errMsg = "Data error getting tax settings: " + e.toString();
                 Debug.logError(e, errMsg, module);
                 return ServiceUtil.returnError(errMsg);
             }
         }
+        if (shippingAddress == null || (shippingAddress.get("countryGeoId") == null && shippingAddress.get("stateProvinceGeoId") == null && shippingAddress.get("postalCodeGeoId") == null)) {
+            return ServiceUtil.returnError("The address(es) used for tax calculation did not have State/Province or Country or other tax jurisdiction values set, so we cannot determine the taxes to charge.");
+        }
+
+        // without knowing the TaxAuthority parties, just find all TaxAuthories for the set of IDs...
+        Set taxAuthoritySet = FastSet.newInstance();
+        try {
+            getTaxAuthorities(delegator, shippingAddress, taxAuthoritySet);
+        } catch (GenericEntityException e) {
+            String errMsg = "Data error getting tax settings: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
 
         // Setup the return lists.
         List orderAdjustments = FastList.newInstance();