KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > order > thirdparty > taxware > TaxwareServices


1 /*
2  * $Id: TaxwareServices.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.order.thirdparty.taxware;
25
26
27 import java.util.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.ofbiz.entity.GenericValue;
32 import org.ofbiz.service.DispatchContext;
33 import org.ofbiz.service.ModelService;
34
35 /**
36  * TaxwareServices
37  *
38  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
39  * @version $Rev: 5462 $
40  * @since 2.0
41  */

42 public class TaxwareServices {
43
44     public static Map JavaDoc calcTax(DispatchContext dctx, Map JavaDoc context) {
45         Map JavaDoc result = new HashMap JavaDoc();
46         List JavaDoc items = (List JavaDoc) context.get("itemProductList");
47         List JavaDoc amnts = (List JavaDoc) context.get("itemAmountList");
48         List JavaDoc ishpn = (List JavaDoc) context.get("itemShippingList");
49         Double JavaDoc shipping = (Double JavaDoc) context.get("orderShippingAmount");
50         GenericValue address = (GenericValue) context.get("shippingAddress");
51
52         if (items.size() != amnts.size()) {
53             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
54             result.put(ModelService.ERROR_MESSAGE, "ERROR: Items, Amount, or ItemShipping lists are not valid size.");
55             return result;
56         }
57
58         try {
59             TaxwareUTL utl = new TaxwareUTL();
60
61             utl.setShipping(shipping != null ? shipping.doubleValue() : 0.0);
62             utl.setShipAddress(address);
63             for (int i = 0; i < items.size(); i++) {
64                 GenericValue p = (GenericValue) items.get(i);
65                 Double JavaDoc amount = (Double JavaDoc) amnts.get(i);
66                 Double JavaDoc ishp = ishpn != null ? (Double JavaDoc) ishpn.get(i) : new Double JavaDoc(0.0);
67
68                 utl.addItem(p, amount.doubleValue(), ishp.doubleValue());
69             }
70
71             int resp = utl.process();
72
73             if (resp == 0) {
74                 result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
75                 result.put(ModelService.ERROR_MESSAGE, "ERROR: No records processed.");
76                 return result;
77             }
78
79             result.put("orderAdjustments", utl.getOrderAdjustments());
80             result.put("itemAdjustments", utl.getItemAdjustments());
81
82         } catch (TaxwareException e) {
83             e.printStackTrace();
84             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
85             result.put(ModelService.ERROR_MESSAGE, "ERROR: Taxware problem (" + e.getMessage() + ").");
86         }
87
88         return result;
89     }
90
91     public static Map JavaDoc verifyZip(DispatchContext dctx, Map JavaDoc context) {
92
93         return new HashMap JavaDoc();
94     }
95 }
96
Popular Tags