⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taxauthorityservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: OrderServices.java 6133 2005-11-17 03:56:16Z jaz $ * *  Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * *  Permission is hereby granted, free of charge, to any person obtaining a *  copy of this software and associated documentation files (the "Software"), *  to deal in the Software without restriction, including without limitation *  the rights to use, copy, modify, merge, publish, distribute, sublicense, *  and/or sell copies of the Software, and to permit persons to whom the *  Software is furnished to do so, subject to the following conditions: * *  The above copyright notice and this permission notice shall be included *  in all copies or substantial portions of the Software. * *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *  THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.accounting.tax;import java.math.BigDecimal;import java.sql.Timestamp;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import javolution.util.FastList;import javolution.util.FastSet;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.common.geo.GeoWorker;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;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.DispatchContext;import org.ofbiz.service.ServiceUtil;/** * Tax Authority tax calculation and other misc services * * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version    $Rev: 7175 $ * @since      2.0 */public class TaxAuthorityServices {    public static final String module = TaxAuthorityServices.class.getName();    public static final BigDecimal ZERO_BASE = new BigDecimal("0.000");     public static final BigDecimal ONE_BASE = new BigDecimal("1.000");     public static final BigDecimal PERCENT_SCALE = new BigDecimal("100.000");     public static Map rateProductTaxCalcForDisplay(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        String productStoreId = (String) context.get("productStoreId");        String billToPartyId = (String) context.get("billToPartyId");        String productId = (String) context.get("productId");        BigDecimal quantity = (BigDecimal) context.get("quantity");        BigDecimal basePrice = (BigDecimal) context.get("basePrice");        BigDecimal shippingPrice = (BigDecimal) context.get("shippingPrice");        if (quantity == null) quantity = ONE_BASE;        BigDecimal amount = basePrice.multiply(quantity);                BigDecimal taxTotal = ZERO_BASE;        BigDecimal taxPercentage = ZERO_BASE;        BigDecimal priceWithTax = basePrice;        if (shippingPrice != null) priceWithTax = priceWithTax.add(shippingPrice);         try {            GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));            GenericValue productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));            if (productStore == null) {                throw new IllegalArgumentException("Could not find ProductStore with ID [" + productStoreId + "] for tax calculation");            }                        if ("Y".equals(productStore.getString("showPricesWithVatTax"))) {                Set taxAuthoritySet = FastSet.newInstance();                if (productStore.get("vatTaxAuthPartyId") == null) {                    List taxAuthorityRawList = delegator.findByConditionCache("TaxAuthority", new EntityExpr("taxAuthGeoId", EntityOperator.EQUALS, productStore.get("vatTaxAuthGeoId")), null, null);                    taxAuthoritySet.addAll(taxAuthorityRawList);                } else {                    GenericValue taxAuthority = delegator.findByPrimaryKeyCache("TaxAuthority", UtilMisc.toMap("taxAuthGeoId", productStore.get("vatTaxAuthGeoId"), "taxAuthPartyId", productStore.get("vatTaxAuthPartyId")));                    taxAuthoritySet.add(taxAuthority);                }                                if (taxAuthoritySet.size() == 0) {                    throw new IllegalArgumentException("Could not find any Tax Authories for store with ID [" + productStoreId + "] for tax calculation; the store settings may need to be corrected.");                }                                List taxAdustmentList = getTaxAdjustments(delegator, product, productStore, billToPartyId, taxAuthoritySet, basePrice, amount, shippingPrice);                if (taxAdustmentList.size() == 0) {                    // this is something that happens every so often for different products and such, so don't blow up on it...                    Debug.logWarning("Could not find any Tax Authories Rate Rules for store with ID [" + productStoreId + "], productId [" + productId + "], basePrice [" + basePrice + "], amount [" + amount + "], for tax calculation; the store settings may need to be corrected.", module);                }                // add up amounts from adjustments (amount OR exemptAmount, sourcePercentage)                Iterator taxAdustmentIter = taxAdustmentList.iterator();                while (taxAdustmentIter.hasNext()) {                    GenericValue taxAdjustment = (GenericValue) taxAdustmentIter.next();                    taxPercentage = taxPercentage.add(taxAdjustment.getBigDecimal("sourcePercentage"));                    BigDecimal adjAmount = taxAdjustment.getBigDecimal("amount");                    taxTotal = taxTotal.add(adjAmount);                    priceWithTax = priceWithTax.add(adjAmount);                    Debug.logInfo("For productId [" + productId + "] added [" + adjAmount + "] of tax to price for geoId [" + taxAdjustment.getString("taxAuthGeoId") + "], new price is [" + priceWithTax + "]", module);                }            }        } catch (GenericEntityException e) {            String errMsg = "Data error getting tax settings: " + e.toString();            Debug.logError(e, errMsg, module);            return ServiceUtil.returnError(errMsg);        }                // round to 2 decimal places for display/etc        taxTotal.setScale(2, BigDecimal.ROUND_CEILING);        priceWithTax.setScale(2, BigDecimal.ROUND_CEILING);                Map result = ServiceUtil.returnSuccess();        result.put("taxTotal", taxTotal);        result.put("taxPercentage", taxPercentage);        result.put("priceWithTax", priceWithTax);        return result;    }        public static Map rateProductTaxCalc(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        String productStoreId = (String) context.get("productStoreId");        String billToPartyId = (String) context.get("billToPartyId");        List itemProductList = (List) context.get("itemProductList");        List itemAmountList = (List) context.get("itemAmountList");        List itemPriceList = (List) context.get("itemPriceList");        List itemShippingList = (List) context.get("itemShippingList");        BigDecimal orderShippingAmount = (BigDecimal) context.get("orderShippingAmount");        GenericValue shippingAddress = (GenericValue) context.get("shippingAddress");        // without knowing the TaxAuthority parties, just find all TaxAuthories for the set of IDs...        Set taxAuthoritySet = FastSet.newInstance();        GenericValue productStore = null;        try {            Set geoIdSet = FastSet.newInstance();            if (shippingAddress != null) {                if (shippingAddress.getString("countryGeoId") != null) {                    geoIdSet.add(shippingAddress.getString("countryGeoId"));                }                if (shippingAddress.getString("stateProvinceGeoId") != null) {                    geoIdSet.add(shippingAddress.getString("stateProvinceGeoId"));                }            }                        if (geoIdSet.size() == 0) {                return ServiceUtil.returnError("The address(es) used for tax calculation did not have State/Province or Country values set, so we cannot determine the taxes to charge.");            }                        // get the most granular, or all available, geoIds and then find parents by GeoAssoc with geoAssocTypeId="REGIONS" and geoIdTo=<granular geoId> and find the GeoAssoc.geoId            geoIdSet = GeoWorker.expandGeoRegionDeep(geoIdSet, delegator);            List taxAuthorityRawList = delegator.findByConditionCache("TaxAuthority", new EntityExpr("taxAuthGeoId", EntityOperator.IN, geoIdSet), null, null);            taxAuthoritySet.addAll(taxAuthorityRawList);            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);        }                if (productStore == null) {            throw new IllegalArgumentException("Could not find ProductStore with ID [" + productStoreId + "] for tax calculation");        }                // Setup the return lists.        List orderAdjustments = FastList.newInstance();        List itemAdjustments = FastList.newInstance();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -