1 24 package org.ofbiz.order.thirdparty.taxware; 25 26 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import org.ofbiz.entity.GenericValue; 32 import org.ofbiz.service.DispatchContext; 33 import org.ofbiz.service.ModelService; 34 35 42 public class TaxwareServices { 43 44 public static Map calcTax(DispatchContext dctx, Map context) { 45 Map result = new HashMap (); 46 List items = (List ) context.get("itemProductList"); 47 List amnts = (List ) context.get("itemAmountList"); 48 List ishpn = (List ) context.get("itemShippingList"); 49 Double shipping = (Double ) 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 amount = (Double ) amnts.get(i); 66 Double ishp = ishpn != null ? (Double ) ishpn.get(i) : new Double (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 verifyZip(DispatchContext dctx, Map context) { 92 93 return new HashMap (); 94 } 95 } 96 | Popular Tags |