001: /*
002: * $Id: TaxwareServices.java,v 1.1 2003/08/18 19:38:58 jonesde Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: */
024: package org.ofbiz.order.thirdparty.taxware;
025:
026: import java.util.HashMap;
027: import java.util.List;
028: import java.util.Map;
029:
030: import org.ofbiz.entity.GenericValue;
031: import org.ofbiz.service.DispatchContext;
032: import org.ofbiz.service.ModelService;
033:
034: /**
035: * TaxwareServices
036: *
037: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
038: * @version $Revision: 1.1 $
039: * @since 2.0
040: */
041: public class TaxwareServices {
042:
043: public static Map calcTax(DispatchContext dctx, Map context) {
044: Map result = new HashMap();
045: List items = (List) context.get("itemProductList");
046: List amnts = (List) context.get("itemAmountList");
047: List ishpn = (List) context.get("itemShippingList");
048: Double shipping = (Double) context.get("orderShippingAmount");
049: GenericValue address = (GenericValue) context
050: .get("shippingAddress");
051:
052: if (items.size() != amnts.size()) {
053: result.put(ModelService.RESPONSE_MESSAGE,
054: ModelService.RESPOND_ERROR);
055: result
056: .put(ModelService.ERROR_MESSAGE,
057: "ERROR: Items, Amount, or ItemShipping lists are not valid size.");
058: return result;
059: }
060:
061: try {
062: TaxwareUTL utl = new TaxwareUTL();
063:
064: utl.setShipping(shipping != null ? shipping.doubleValue()
065: : 0.0);
066: utl.setShipAddress(address);
067: for (int i = 0; i < items.size(); i++) {
068: GenericValue p = (GenericValue) items.get(i);
069: Double amount = (Double) amnts.get(i);
070: Double ishp = ishpn != null ? (Double) ishpn.get(i)
071: : new Double(0.0);
072:
073: utl
074: .addItem(p, amount.doubleValue(), ishp
075: .doubleValue());
076: }
077:
078: int resp = utl.process();
079:
080: if (resp == 0) {
081: result.put(ModelService.RESPONSE_MESSAGE,
082: ModelService.RESPOND_ERROR);
083: result.put(ModelService.ERROR_MESSAGE,
084: "ERROR: No records processed.");
085: return result;
086: }
087:
088: result.put("orderAdjustments", utl.getOrderAdjustments());
089: result.put("itemAdjustments", utl.getItemAdjustments());
090:
091: } catch (TaxwareException e) {
092: e.printStackTrace();
093: result.put(ModelService.RESPONSE_MESSAGE,
094: ModelService.RESPOND_ERROR);
095: result.put(ModelService.ERROR_MESSAGE,
096: "ERROR: Taxware problem (" + e.getMessage() + ").");
097: }
098:
099: return result;
100: }
101:
102: public static Map verifyZip(DispatchContext dctx, Map context) {
103:
104: return new HashMap();
105: }
106: }
|