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

📄 taxwareutl.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: TaxwareUTL.java 6081 2005-11-06 04:16:40Z jonesde $ * * Copyright (c) 2002 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.order.thirdparty.taxware;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.ArrayList;import java.util.Date;import java.util.Iterator;import java.util.List;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilURL;import org.ofbiz.datafile.DataFile;import org.ofbiz.datafile.DataFileException;import org.ofbiz.datafile.ModelRecord;import org.ofbiz.datafile.ModelField;import org.ofbiz.datafile.Record;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericValue;/** * TaxwareUTL - Taxware Universal Tax Link * Requires taxcommon.class found w/ UTL. * *@author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> *@created    June 04, 2002 *@version    1.0 */public class TaxwareUTL {    public static final String module = TaxwareUTL.class.getName();    // default data files    DataFile outHead = null;    DataFile outItem = null;    double shippingAmount = 0.00;    List orderAdjustments = new ArrayList();    List itemAdjustments = new ArrayList();    boolean setShipping = false;    GenericValue shipToAddress = null;    // list of records to process    List records = new ArrayList();    boolean processed = false;    public TaxwareUTL() throws TaxwareException {        init();    }    public int process() throws TaxwareException {        // make sure we have everything before processing        checkFields();        if (processed)            throw new TaxwareException("Cannot re-process records.");        processed = true;        Iterator i = records.iterator();        while (i.hasNext()) {            Record rec = (Record) i.next();            rec = makeItemData(rec);            outItem.addRecord(rec);        }        // create a shipping item        if (shippingAmount > 0) {            Record shipping = outItem.makeRecord("outItem");            shipping = makeItemData(shipping);            shipping.set("FREIGHT_AMOUNT", new Double(shippingAmount));            outItem.addRecord(shipping);        }        // make the header file        Record header = outHead.makeRecord("outHead");        header.set("NUMBER_RECORDS", new Long(outItem.getRecords().size()));        header.set("PROCESS_INDICATOR", "1");        outHead.addRecord(header);        int returnCode = -1;        try {            // add the header            StringBuffer outBuffer = new StringBuffer();            outBuffer.append(outHead.writeDataFile());            // append the items            outBuffer.append(outItem.writeDataFile());            // print out the datafile            if (Debug.verboseOn()) Debug.logVerbose("::Out String::", module);            if (Debug.verboseOn()) Debug.logVerbose("\"" + outBuffer.toString() + "\"", module);            File outFile = new File("TAXWARE-TEST.IN");            FileOutputStream fos = null;            try {                fos = new FileOutputStream(outFile);            } catch (FileNotFoundException e) {                e.printStackTrace();            }            outHead.writeDataFile(fos);            outItem.writeDataFile(fos);            try {                fos.close();            } catch (IOException e) {                e.printStackTrace();            }            outItem.writeDataFile("TaxwareTest.in");            StringBuffer retBuffer = taxCalc(outBuffer);            // make the return data file            returnCode = processOutFile(retBuffer);        } catch (DataFileException dfe) {            throw new TaxwareException("Problems with the data file.", dfe);        }        return returnCode;    }    public void setShipping(double shippingAmount) {        this.shippingAmount = shippingAmount;        setShipping = true;    }    public void setShipAddress(GenericValue v) {        this.shipToAddress = v;    }    public void addItem(GenericValue product, double linePrice, double itemShipping) {        Record record = outItem.makeRecord("outItem");        if (product.get("taxable") == null || product.getString("taxable").equalsIgnoreCase("Y")) {            if (product.get("taxCategory") != null)                record.set("COMMODITY_PRODUCT_CODE", product.get("taxCategory"));            else                record.set("COMMODITY_PRODUCT_CODE", "DEFAULT");            record.set("PART_NUMBER", product.get("productId"));            record.set("LINE_ITEM_AMOUNT", new Double(linePrice));            if (itemShipping > 0)                record.set("FREIGHT_AMOUNT", new Double(itemShipping));        }        records.add(record);    }    public List getItemAdjustments() {        return itemAdjustments;    }    public List getOrderAdjustments() {        return orderAdjustments;    }    private void init() throws TaxwareException {        TaxwareUTL.loadLib();        outHead = createDataFile("TaxwareOutHead");        outItem = createDataFile("TaxwareOutItem");    }    private Record makeItemData(Record record) {        addStaticData(record);        addAddresses(record);        record.set("TAXSEL_PARM", "3");        record.set("SYSTEM_INDICATOR", "1");        record.set("INVOICE_DATE", new java.sql.Date(new Date().getTime()));        return record;    }    private void addStaticData(Record record) {        // grab a taxware properties file and get static data        record.set("COMPANY_ID", UtilProperties.getPropertyValue("taxware.properties", "COMPANY_ID", " "));        record.set("AUDIT_FILE_INDICATOR", UtilProperties.getPropertyValue("taxware.properties", "AUDIT_FILE_INDICATOR", "2"));        record.set("SF_COUNTRY_CODE", UtilProperties.getPropertyValue("taxware.properties", "SF_COUNTRY_CODE", ""));        record.set("SF_STATE_PROVINCE", UtilProperties.getPropertyValue("taxware.properties", "SF_STATE_PROVINCE", " "));        record.set("SF_CITY", UtilProperties.getPropertyValue("taxware.properties", "SF_CITY", " "));        record.set("SF_POSTAL_CODE", UtilProperties.getPropertyValue("taxware.properties", "SF_POSTAL_CODE", " "));        record.set("POO_COUNTRY_CODE", UtilProperties.getPropertyValue("taxware.properties", "POO_COUNTRY_CODE", ""));        record.set("POO_STATE_PROVINCE", UtilProperties.getPropertyValue("taxware.properties", "POO_STATE_PROVINCE", " "));        record.set("POO_CITY", UtilProperties.getPropertyValue("taxware.properties", "POO_CITY", " "));        record.set("POO_POSTAL_CODE", UtilProperties.getPropertyValue("taxware.properties", "POO_POSTAL_CODE", " "));        record.set("POA_COUNTRY_CODE", UtilProperties.getPropertyValue("taxware.properties", "POA_COUNTRY_CODE", ""));        record.set("POA_STATE_PROVINCE", UtilProperties.getPropertyValue("taxware.properties", "POA_STATE_PROVINCE", " "));        record.set("POA_CITY", UtilProperties.getPropertyValue("taxware.properties", "POA_CITY", " "));        record.set("POA_POSTAL_CODE", UtilProperties.getPropertyValue("taxware.properties", "POA_POSTAL_CODE", " "));    }    private void addAddresses(Record record) {        // set the address info from the value objects        if (shipToAddress != null) {            // set the ship to address            if (shipToAddress.get("countryGeoId") == null) {                record.set("ST_COUNTRY_CODE", "US");            } else if (shipToAddress.getString("countryGeoId").equals("USA")) {                record.set("ST_COUNTRY_CODE", "US");            } else {                record.set("ST_COUNTRY_CODE", shipToAddress.get("countryGeoId"));            }            record.set("ST_COUNTRY_CODE", "US");            record.set("ST_STATE_PROVINCE", shipToAddress.get("stateProvinceGeoId"));            record.set("ST_CITY", shipToAddress.get("city"));            record.set("ST_POSTAL_CODE", shipToAddress.get("postalCode"));        }    }    private DataFile createDataFile(String dataFile) throws TaxwareException {        DataFile df = null;        try {            df = DataFile.makeDataFile(UtilURL.fromResource("org/ofbiz/thirdparty/taxware/TaxwareFiles.xml"), dataFile);

⌨️ 快捷键说明

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