Source Code Cross Referenced for TaxwareUTL.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » order » thirdparty » taxware » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » SourceTap CRM » org.ofbiz.order.thirdparty.taxware 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: TaxwareUTL.java,v 1.3 2003/08/22 18:21:08 ajzeneski Exp $
003:         *
004:         * Copyright (c) 2002 The Open For Business Project and repective authors.
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:         */
025:
026:        package org.ofbiz.order.thirdparty.taxware;
027:
028:        import java.io.File;
029:        import java.io.FileNotFoundException;
030:        import java.io.FileOutputStream;
031:        import java.io.IOException;
032:        import java.util.ArrayList;
033:        import java.util.Date;
034:        import java.util.Iterator;
035:        import java.util.List;
036:
037:        import org.ofbiz.base.util.Debug;
038:        import org.ofbiz.base.util.UtilMisc;
039:        import org.ofbiz.base.util.UtilProperties;
040:        import org.ofbiz.base.util.UtilURL;
041:        import org.ofbiz.datafile.DataFile;
042:        import org.ofbiz.datafile.DataFileException;
043:        import org.ofbiz.datafile.ModelRecord;
044:        import org.ofbiz.datafile.ModelField;
045:        import org.ofbiz.datafile.Record;
046:        import org.ofbiz.entity.GenericDelegator;
047:        import org.ofbiz.entity.GenericValue;
048:
049:        /**
050:         * TaxwareUTL - Taxware Universal Tax Link
051:         * Requires taxcommon.class found w/ UTL.
052:         *
053:         *@author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
054:         *@created    June 04, 2002
055:         *@version    1.0
056:         */
057:        public class TaxwareUTL {
058:
059:            public static final String module = TaxwareUTL.class.getName();
060:
061:            // default data files
062:            DataFile outHead = null;
063:            DataFile outItem = null;
064:
065:            double shippingAmount = 0.00;
066:            List orderAdjustments = new ArrayList();
067:            List itemAdjustments = new ArrayList();
068:
069:            boolean setShipping = false;
070:            GenericValue shipToAddress = null;
071:
072:            // list of records to process
073:            List records = new ArrayList();
074:            boolean processed = false;
075:
076:            public TaxwareUTL() throws TaxwareException {
077:                init();
078:            }
079:
080:            public int process() throws TaxwareException {
081:                // make sure we have everything before processing
082:                checkFields();
083:
084:                if (processed)
085:                    throw new TaxwareException("Cannot re-process records.");
086:                processed = true;
087:
088:                Iterator i = records.iterator();
089:
090:                while (i.hasNext()) {
091:                    Record rec = (Record) i.next();
092:
093:                    rec = makeItemData(rec);
094:                    outItem.addRecord(rec);
095:                }
096:
097:                // create a shipping item
098:                if (shippingAmount > 0) {
099:                    Record shipping = outItem.makeRecord("outItem");
100:
101:                    shipping = makeItemData(shipping);
102:                    shipping.set("FREIGHT_AMOUNT", new Double(shippingAmount));
103:                    outItem.addRecord(shipping);
104:                }
105:
106:                // make the header file
107:                Record header = outHead.makeRecord("outHead");
108:
109:                header.set("NUMBER_RECORDS", new Long(outItem.getRecords()
110:                        .size()));
111:                header.set("PROCESS_INDICATOR", "1");
112:                outHead.addRecord(header);
113:
114:                int returnCode = -1;
115:
116:                try {
117:                    // add the header
118:                    StringBuffer outBuffer = new StringBuffer();
119:
120:                    outBuffer.append(outHead.writeDataFile());
121:
122:                    // append the items
123:                    outBuffer.append(outItem.writeDataFile());
124:
125:                    // print out the datafile
126:                    if (Debug.verboseOn())
127:                        Debug.logVerbose("::Out String::", module);
128:                    if (Debug.verboseOn())
129:                        Debug.logVerbose("\"" + outBuffer.toString() + "\"",
130:                                module);
131:
132:                    File outFile = new File("TAXWARE-TEST.IN");
133:                    FileOutputStream fos = null;
134:
135:                    try {
136:                        fos = new FileOutputStream(outFile);
137:                    } catch (FileNotFoundException e) {
138:                        e.printStackTrace();
139:                    }
140:                    outHead.writeDataFile(fos);
141:                    outItem.writeDataFile(fos);
142:                    try {
143:                        fos.close();
144:                    } catch (IOException e) {
145:                        e.printStackTrace();
146:                    }
147:
148:                    outItem.writeDataFile("TaxwareTest.in");
149:
150:                    StringBuffer retBuffer = taxCalc(outBuffer);
151:
152:                    // make the return data file
153:                    returnCode = processOutFile(retBuffer);
154:                } catch (DataFileException dfe) {
155:                    throw new TaxwareException("Problems with the data file.",
156:                            dfe);
157:                }
158:
159:                return returnCode;
160:            }
161:
162:            public void setShipping(double shippingAmount) {
163:                this .shippingAmount = shippingAmount;
164:                setShipping = true;
165:            }
166:
167:            public void setShipAddress(GenericValue v) {
168:                this .shipToAddress = v;
169:            }
170:
171:            public void addItem(GenericValue product, double linePrice,
172:                    double itemShipping) {
173:                Record record = outItem.makeRecord("outItem");
174:
175:                if (product.get("taxable") == null
176:                        || product.getString("taxable").equalsIgnoreCase("Y")) {
177:                    if (product.get("taxCategory") != null)
178:                        record.set("COMMODITY_PRODUCT_CODE", product
179:                                .get("taxCategory"));
180:                    else
181:                        record.set("COMMODITY_PRODUCT_CODE", "DEFAULT");
182:                    record.set("PART_NUMBER", product.get("productId"));
183:                    record.set("LINE_ITEM_AMOUNT", new Double(linePrice));
184:                    if (itemShipping > 0)
185:                        record.set("FREIGHT_AMOUNT", new Double(itemShipping));
186:                }
187:                records.add(record);
188:            }
189:
190:            public List getItemAdjustments() {
191:                return itemAdjustments;
192:            }
193:
194:            public List getOrderAdjustments() {
195:                return orderAdjustments;
196:            }
197:
198:            private void init() throws TaxwareException {
199:                TaxwareUTL.loadLib();
200:                outHead = createDataFile("TaxwareOutHead");
201:                outItem = createDataFile("TaxwareOutItem");
202:            }
203:
204:            private Record makeItemData(Record record) {
205:                addStaticData(record);
206:                addAddresses(record);
207:                record.set("TAXSEL_PARM", "3");
208:                record.set("SYSTEM_INDICATOR", "1");
209:                record.set("INVOICE_DATE", new java.sql.Date(new Date()
210:                        .getTime()));
211:                return record;
212:            }
213:
214:            private void addStaticData(Record record) {
215:                // grab a taxware properties file and get static data
216:                record.set("COMPANY_ID", UtilProperties.getPropertyValue(
217:                        "taxware.properties", "COMPANY_ID", " "));
218:                record.set("AUDIT_FILE_INDICATOR", UtilProperties
219:                        .getPropertyValue("taxware.properties",
220:                                "AUDIT_FILE_INDICATOR", "2"));
221:                record.set("SF_COUNTRY_CODE", UtilProperties.getPropertyValue(
222:                        "taxware.properties", "SF_COUNTRY_CODE", ""));
223:                record.set("SF_STATE_PROVINCE", UtilProperties
224:                        .getPropertyValue("taxware.properties",
225:                                "SF_STATE_PROVINCE", " "));
226:                record.set("SF_CITY", UtilProperties.getPropertyValue(
227:                        "taxware.properties", "SF_CITY", " "));
228:                record.set("SF_POSTAL_CODE", UtilProperties.getPropertyValue(
229:                        "taxware.properties", "SF_POSTAL_CODE", " "));
230:                record.set("POO_COUNTRY_CODE", UtilProperties.getPropertyValue(
231:                        "taxware.properties", "POO_COUNTRY_CODE", ""));
232:                record.set("POO_STATE_PROVINCE", UtilProperties
233:                        .getPropertyValue("taxware.properties",
234:                                "POO_STATE_PROVINCE", " "));
235:                record.set("POO_CITY", UtilProperties.getPropertyValue(
236:                        "taxware.properties", "POO_CITY", " "));
237:                record.set("POO_POSTAL_CODE", UtilProperties.getPropertyValue(
238:                        "taxware.properties", "POO_POSTAL_CODE", " "));
239:                record.set("POA_COUNTRY_CODE", UtilProperties.getPropertyValue(
240:                        "taxware.properties", "POA_COUNTRY_CODE", ""));
241:                record.set("POA_STATE_PROVINCE", UtilProperties
242:                        .getPropertyValue("taxware.properties",
243:                                "POA_STATE_PROVINCE", " "));
244:                record.set("POA_CITY", UtilProperties.getPropertyValue(
245:                        "taxware.properties", "POA_CITY", " "));
246:                record.set("POA_POSTAL_CODE", UtilProperties.getPropertyValue(
247:                        "taxware.properties", "POA_POSTAL_CODE", " "));
248:            }
249:
250:            private void addAddresses(Record record) {
251:                // set the address info from the value objects
252:                if (shipToAddress != null) {
253:                    // set the ship to address
254:                    if (shipToAddress.get("countryGeoId") == null) {
255:                        record.set("ST_COUNTRY_CODE", "US");
256:                    } else if (shipToAddress.getString("countryGeoId").equals(
257:                            "USA")) {
258:                        record.set("ST_COUNTRY_CODE", "US");
259:                    } else {
260:                        record.set("ST_COUNTRY_CODE", shipToAddress
261:                                .get("countryGeoId"));
262:                    }
263:                    record.set("ST_COUNTRY_CODE", "US");
264:                    record.set("ST_STATE_PROVINCE", shipToAddress
265:                            .get("stateProvinceGeoId"));
266:                    record.set("ST_CITY", shipToAddress.get("city"));
267:                    record.set("ST_POSTAL_CODE", shipToAddress
268:                            .get("postalCode"));
269:                }
270:            }
271:
272:            private DataFile createDataFile(String dataFile)
273:                    throws TaxwareException {
274:                DataFile df = null;
275:
276:                try {
277:                    df = DataFile
278:                            .makeDataFile(
279:                                    UtilURL
280:                                            .fromResource("org/ofbiz/thirdparty/taxware/TaxwareFiles.xml"),
281:                                    dataFile);
282:                } catch (DataFileException e) {
283:                    Debug.logError(e, module);
284:                    throw new TaxwareException("Cannot load datafile.");
285:                }
286:                return df;
287:            }
288:
289:            public static void loadLib() throws TaxwareException {
290:                try {
291:                    System.loadLibrary("taxcommon");
292:                } catch (UnsatisfiedLinkError e) {
293:                    Debug.logError(e, module);
294:                    throw new TaxwareException(
295:                            "Cannot load libtaxcommon.so/taxcommon.dll.", e);
296:                }
297:            }
298:
299:            private StringBuffer taxCalc(StringBuffer outBuffer)
300:                    throws DataFileException, TaxwareException {
301:                StringBuffer inBuffer = new StringBuffer();
302:                int result = callTaxware(outBuffer.toString(), inBuffer);
303:
304:                if (Debug.verboseOn())
305:                    Debug.logVerbose("Taxware Return: " + result, module);
306:                if (result != 1)
307:                    throw new TaxwareException("Taxware processing failed ("
308:                            + result + ")");
309:
310:                if (Debug.verboseOn())
311:                    Debug.logVerbose("::Return String::", module);
312:                if (Debug.verboseOn())
313:                    Debug.logVerbose("\"" + inBuffer.toString() + "\"", module);
314:                return inBuffer;
315:            }
316:
317:            private int callTaxware(String inString, StringBuffer outBuffer)
318:                    throws TaxwareException {
319:                try {
320:                    return taxcommon.CalculateTax(inString, outBuffer);
321:                } catch (Exception e) {
322:                    throw new TaxwareException("Problems running JNI wrapper.",
323:                            e);
324:                }
325:            }
326:
327:            private void checkFields() throws TaxwareException {
328:                if (!setShipping)
329:                    throw new TaxwareException(
330:                            "Shipping amount has not been set.");
331:                if (shipToAddress == null)
332:                    throw new TaxwareException(
333:                            "Shipping address has not been set.");
334:                if (records.size() == 0)
335:                    throw new TaxwareException("No items have been defined.");
336:            }
337:
338:            private int processOutFile(StringBuffer retBuffer)
339:                    throws DataFileException, TaxwareException {
340:                DataFile retHead = createDataFile("TaxwareInHead");
341:                DataFile retItem = createDataFile("TaxwareInItem");
342:                String headStr = retBuffer.toString().substring(0, 283);
343:                String itemStr = retBuffer.toString().substring(284);
344:
345:                if (Debug.verboseOn())
346:                    Debug.logVerbose("Return Size: " + retBuffer.length(),
347:                            module);
348:                GenericDelegator delegator = shipToAddress.getDelegator();
349:
350:                retHead.readDataFile(headStr);
351:                retItem.readDataFile(itemStr);
352:
353:                List retRecords = retItem.getRecords();
354:                Iterator i = retRecords.iterator();
355:
356:                if (Debug.verboseOn())
357:                    Debug.logVerbose("Returned Records: " + retRecords.size(),
358:                            module);
359:                if (Debug.verboseOn())
360:                    Debug.logVerbose("Sent Items: " + records.size(), module);
361:
362:                while (i.hasNext()) {
363:                    Record rec = (Record) i.next();
364:                    ModelRecord model = rec.getModelRecord();
365:
366:                    // make the adjustment lists
367:                    if (itemAdjustments.size() < records.size()) {
368:                        List currentItem = new ArrayList();
369:
370:                        if (rec.getDouble("TAX_AMT_COUNTRY").doubleValue() > 0) {
371:                            if (Debug.verboseOn())
372:                                Debug.logVerbose("Country Tax Amount: "
373:                                        + rec.getDouble("TAX_AMT_COUNTRY"),
374:                                        module);
375:                            Double rate = new Double(rec.getDouble(
376:                                    "TAX_RATE_COUNTRY").doubleValue() * 100);
377:                            String type = rec.getString("TAX_TYPE_COUNTRY")
378:                                    .equals("S") ? "SALES TAX" : "USE TAX";
379:                            String jur = rec.get("JUR_COUNTRY") != null ? rec
380:                                    .getString("JUR_COUNTRY").trim() : "";
381:                            String comments = jur + "|" + type + "|"
382:                                    + rate.toString();
383:
384:                            currentItem
385:                                    .add(delegator
386:                                            .makeValue(
387:                                                    "OrderAdjustment",
388:                                                    UtilMisc
389:                                                            .toMap(
390:                                                                    "amount",
391:                                                                    rec
392:                                                                            .getDouble("TAX_AMT_COUNTRY"),
393:                                                                    "orderAdjustmentTypeId",
394:                                                                    "SALES_TAX",
395:                                                                    "comments",
396:                                                                    comments)));
397:                        }
398:
399:                        if (rec.getDouble("TAX_AMT_STATE").doubleValue() > 0) {
400:                            Double rate = new Double(rec.getDouble(
401:                                    "TAX_RATE_STATE").doubleValue() * 100);
402:                            String type = rec.getString("TAX_TYPE_STATE")
403:                                    .equals("S") ? "SALES TAX" : "USE TAX";
404:                            String jur = rec.get("JUR_STATE") != null ? rec
405:                                    .getString("JUR_STATE").trim() : "";
406:                            String comments = jur + "|" + type + "|"
407:                                    + rate.toString();
408:
409:                            currentItem
410:                                    .add(delegator
411:                                            .makeValue(
412:                                                    "OrderAdjustment",
413:                                                    UtilMisc
414:                                                            .toMap(
415:                                                                    "amount",
416:                                                                    rec
417:                                                                            .getDouble("TAX_AMT_STATE"),
418:                                                                    "orderAdjustmentTypeId",
419:                                                                    "SALES_TAX",
420:                                                                    "comments",
421:                                                                    comments)));
422:                        }
423:
424:                        if (rec.getDouble("TAX_AMT_COUNTY").doubleValue() > 0) {
425:                            Double rate = new Double(rec.getDouble(
426:                                    "TAX_RATE_COUNTY").doubleValue() * 100);
427:                            String type = rec.getString("TAX_TYPE_COUNTY")
428:                                    .equals("S") ? "SALES TAX" : "USE TAX";
429:                            String jur = rec.get("JUR_COUNTY_CODE") != null ? rec
430:                                    .getString("JUR_COUNTY_CODE").trim()
431:                                    : "";
432:                            String comments = jur + "|" + type + "|"
433:                                    + rate.toString();
434:
435:                            currentItem
436:                                    .add(delegator
437:                                            .makeValue(
438:                                                    "OrderAdjustment",
439:                                                    UtilMisc
440:                                                            .toMap(
441:                                                                    "amount",
442:                                                                    rec
443:                                                                            .getDouble("TAX_AMT_COUNTY"),
444:                                                                    "orderAdjustmentTypeId",
445:                                                                    "SALES_TAX",
446:                                                                    "comments",
447:                                                                    comments)));
448:                        }
449:
450:                        if (rec.getDouble("TAX_AMT_CITY").doubleValue() > 0) {
451:                            Double rate = new Double(rec.getDouble(
452:                                    "TAX_RATE_CITY").doubleValue() * 100);
453:                            String type = rec.getString("TAX_TYPE_CITY")
454:                                    .equals("S") ? "SALES TAX" : "USE TAX";
455:                            String jur = rec.get("JUR_CITY") != null ? rec
456:                                    .getString("JUR_CITY").trim() : "";
457:                            String comments = jur + "|" + type + "|"
458:                                    + rate.toString();
459:
460:                            currentItem
461:                                    .add(delegator.makeValue("OrderAdjustment",
462:                                            UtilMisc.toMap("amount", rec
463:                                                    .getDouble("TAX_AMT_CITY"),
464:                                                    "orderAdjustmentTypeId",
465:                                                    "SALES_TAX", "comments",
466:                                                    comments)));
467:                        }
468:
469:                        if (rec.getDouble("TAX_AMT_SEC_STATE").doubleValue() > 0) {
470:                            Double rate = new Double(rec.getDouble(
471:                                    "TAX_RATE_SEC_STATE").doubleValue() * 100);
472:                            String type = rec.getString("TAX_TYPE_SEC_STATE")
473:                                    .equals("S") ? "SALES TAX" : "USE TAX";
474:                            String jur = rec.get("JUR_SEC_STATE") != null ? rec
475:                                    .getString("JUR_SEC_STATE").trim() : "";
476:                            String comments = jur + "|" + type + "|"
477:                                    + rate.toString();
478:
479:                            currentItem
480:                                    .add(delegator
481:                                            .makeValue(
482:                                                    "OrderAdjustment",
483:                                                    UtilMisc
484:                                                            .toMap(
485:                                                                    "amount",
486:                                                                    rec
487:                                                                            .getDouble("TAX_AMT_SEC_STATE"),
488:                                                                    "orderAdjustmentTypeId",
489:                                                                    "SALES_TAX",
490:                                                                    "comments",
491:                                                                    comments)));
492:                        }
493:
494:                        if (rec.getDouble("TAX_AMT_SEC_COUNTY").doubleValue() > 0) {
495:                            Double rate = new Double(rec.getDouble(
496:                                    "TAX_RATE_SEC_COUNTY").doubleValue() * 100);
497:                            String type = rec.getString("TAX_TYPE_SEC_COUNTY")
498:                                    .equals("S") ? "SALES TAX" : "USE TAX";
499:                            String jur = rec.get("JUR_SEC_COUNTY_CODE") != null ? rec
500:                                    .getString("JUR_SEC_COUNTY_CODE").trim()
501:                                    : "";
502:                            String comments = jur + "|" + type + "|"
503:                                    + rate.toString();
504:
505:                            currentItem
506:                                    .add(delegator
507:                                            .makeValue(
508:                                                    "OrderAdjustment",
509:                                                    UtilMisc
510:                                                            .toMap(
511:                                                                    "amount",
512:                                                                    rec
513:                                                                            .getDouble("TAX_AMT_SEC_COUNTY"),
514:                                                                    "orderAdjustmentTypeId",
515:                                                                    "SALES_TAX",
516:                                                                    "comments",
517:                                                                    comments)));
518:                        }
519:
520:                        if (rec.getDouble("TAX_AMT_SEC_CITY").doubleValue() > 0) {
521:                            Double rate = new Double(rec.getDouble(
522:                                    "TAX_RATE_SEC_CITY").doubleValue() * 100);
523:                            String type = rec.getString("TAX_TYPE_SEC_CITY")
524:                                    .equals("S") ? "SALES TAX" : "USE TAX";
525:                            String jur = rec.get("JUR_SEC_CITY") != null ? rec
526:                                    .getString("JUR_SEC_CITY").trim() : "";
527:                            String comments = jur + "|" + type + "|"
528:                                    + rate.toString();
529:
530:                            currentItem
531:                                    .add(delegator
532:                                            .makeValue(
533:                                                    "OrderAdjustment",
534:                                                    UtilMisc
535:                                                            .toMap(
536:                                                                    "amount",
537:                                                                    rec
538:                                                                            .getDouble("TAX_AMT_SEC_CITY"),
539:                                                                    "orderAdjustmentTypeId",
540:                                                                    "SALES_TAX",
541:                                                                    "comments",
542:                                                                    comments)));
543:                        }
544:
545:                        // add a list of adjustments to the adjustment list
546:                        itemAdjustments.add(currentItem);
547:
548:                    } else if (orderAdjustments.size() == 0) {
549:                        if (rec.getDouble("TAX_AMT_COUNTRY").doubleValue() > 0) {
550:                            Double rate = new Double(rec.getDouble(
551:                                    "TAX_RATE_COUNTRY").doubleValue() * 100);
552:                            String type = rec.getString("TAX_TYPE_COUNTRY")
553:                                    .equals("S") ? "SALES TAX" : "USE TAX";
554:                            String jur = rec.get("JUR_COUNTRY") != null ? rec
555:                                    .getString("JUR_COUNTRY").trim() : "";
556:                            String comments = jur + "|" + type + "|"
557:                                    + rate.toString();
558:
559:                            orderAdjustments
560:                                    .add(delegator
561:                                            .makeValue(
562:                                                    "OrderAdjustment",
563:                                                    UtilMisc
564:                                                            .toMap(
565:                                                                    "amount",
566:                                                                    rec
567:                                                                            .getDouble("TAX_AMT_COUNTRY"),
568:                                                                    "orderAdjustmentTypeId",
569:                                                                    "SALES_TAX",
570:                                                                    "comments",
571:                                                                    comments)));
572:                        }
573:
574:                        if (rec.getDouble("TAX_AMT_STATE").doubleValue() > 0) {
575:                            Double rate = new Double(rec.getDouble(
576:                                    "TAX_RATE_STATE").doubleValue() * 100);
577:                            String type = rec.getString("TAX_TYPE_STATE")
578:                                    .equals("S") ? "SALES TAX" : "USE TAX";
579:                            String jur = rec.get("JUR_STATE") != null ? rec
580:                                    .getString("JUR_STATE").trim() : "";
581:                            String comments = jur + "|" + type + "|"
582:                                    + rate.toString();
583:
584:                            orderAdjustments
585:                                    .add(delegator
586:                                            .makeValue(
587:                                                    "OrderAdjustment",
588:                                                    UtilMisc
589:                                                            .toMap(
590:                                                                    "amount",
591:                                                                    rec
592:                                                                            .getDouble("TAX_AMT_STATE"),
593:                                                                    "orderAdjustmentTypeId",
594:                                                                    "SALES_TAX",
595:                                                                    "comments",
596:                                                                    comments)));
597:                        }
598:
599:                        if (rec.getDouble("TAX_AMT_COUNTY").doubleValue() > 0) {
600:                            Double rate = new Double(rec.getDouble(
601:                                    "TAX_RATE_COUNTY").doubleValue() * 100);
602:                            String type = rec.getString("TAX_TYPE_COUNTY")
603:                                    .equals("S") ? "SALES TAX" : "USE TAX";
604:                            String jur = rec.get("JUR_COUNTY_CODE") != null ? rec
605:                                    .getString("JUR_COUNTY_CODE").trim()
606:                                    : "";
607:                            String comments = jur + "|" + type + "|"
608:                                    + rate.toString();
609:
610:                            orderAdjustments
611:                                    .add(delegator
612:                                            .makeValue(
613:                                                    "OrderAdjustment",
614:                                                    UtilMisc
615:                                                            .toMap(
616:                                                                    "amount",
617:                                                                    rec
618:                                                                            .getDouble("TAX_AMT_COUNTY"),
619:                                                                    "orderAdjustmentTypeId",
620:                                                                    "SALES_TAX",
621:                                                                    "comments",
622:                                                                    comments)));
623:                        }
624:
625:                        if (rec.getDouble("TAX_AMT_CITY").doubleValue() > 0) {
626:                            Double rate = new Double(rec.getDouble(
627:                                    "TAX_RATE_CITY").doubleValue() * 100);
628:                            String type = rec.getString("TAX_TYPE_CITY")
629:                                    .equals("S") ? "SALES TAX" : "USE TAX";
630:                            String jur = rec.get("JUR_CITY") != null ? rec
631:                                    .getString("JUR_CITY").trim() : "";
632:                            String comments = jur + "|" + type + "|"
633:                                    + rate.toString();
634:
635:                            orderAdjustments
636:                                    .add(delegator.makeValue("OrderAdjustment",
637:                                            UtilMisc.toMap("amount", rec
638:                                                    .getDouble("TAX_AMT_CITY"),
639:                                                    "orderAdjustmentTypeId",
640:                                                    "SALES_TAX", "comments",
641:                                                    comments)));
642:                        }
643:
644:                        if (rec.getDouble("TAX_AMT_SEC_STATE").doubleValue() > 0) {
645:                            Double rate = new Double(rec.getDouble(
646:                                    "TAX_RATE_SEC_STATE").doubleValue() * 100);
647:                            String type = rec.getString("TAX_TYPE_SEC_STATE")
648:                                    .equals("S") ? "SALES TAX" : "USE TAX";
649:                            String jur = rec.get("JUR_SEC_STATE") != null ? rec
650:                                    .getString("JUR_SEC_STATE").trim() : "";
651:                            String comments = jur + "|" + type + "|"
652:                                    + rate.toString();
653:
654:                            orderAdjustments
655:                                    .add(delegator
656:                                            .makeValue(
657:                                                    "OrderAdjustment",
658:                                                    UtilMisc
659:                                                            .toMap(
660:                                                                    "amount",
661:                                                                    rec
662:                                                                            .getDouble("TAX_AMT_SEC_STATE"),
663:                                                                    "orderAdjustmentTypeId",
664:                                                                    "SALES_TAX",
665:                                                                    "comments",
666:                                                                    comments)));
667:                        }
668:
669:                        if (rec.getDouble("TAX_AMT_SEC_COUNTY").doubleValue() > 0) {
670:                            Double rate = new Double(rec.getDouble(
671:                                    "TAX_RATE_SEC_COUNTY").doubleValue() * 100);
672:                            String type = rec.getString("TAX_TYPE_SEC_COUNTY")
673:                                    .equals("S") ? "SALES TAX" : "USE TAX";
674:                            String jur = rec.get("JUR_SEC_COUNTY_CODE") != null ? rec
675:                                    .getString("JUR_SEC_COUNTY_CODE").trim()
676:                                    : "";
677:                            String comments = jur + "|" + type + "|"
678:                                    + rate.toString();
679:
680:                            orderAdjustments
681:                                    .add(delegator
682:                                            .makeValue(
683:                                                    "OrderAdjustment",
684:                                                    UtilMisc
685:                                                            .toMap(
686:                                                                    "amount",
687:                                                                    rec
688:                                                                            .getDouble("TAX_AMT_SEC_COUNTY"),
689:                                                                    "orderAdjustmentTypeId",
690:                                                                    "SALES_TAX",
691:                                                                    "comments",
692:                                                                    comments)));
693:                        }
694:
695:                        if (rec.getDouble("TAX_AMT_SEC_CITY").doubleValue() > 0) {
696:                            Double rate = new Double(rec.getDouble(
697:                                    "TAX_RATE_SEC_CITY").doubleValue() * 100);
698:                            String type = rec.getString("TAX_TYPE_SEC_CITY")
699:                                    .equals("S") ? "SALES TAX" : "USE TAX";
700:                            String jur = rec.get("JUR_SEC_CITY") != null ? rec
701:                                    .getString("JUR_SEC_CITY").trim() : "";
702:                            String comments = jur + "|" + type + "|"
703:                                    + rate.toString();
704:
705:                            orderAdjustments
706:                                    .add(delegator
707:                                            .makeValue(
708:                                                    "OrderAdjustment",
709:                                                    UtilMisc
710:                                                            .toMap(
711:                                                                    "amount",
712:                                                                    rec
713:                                                                            .getDouble("TAX_AMT_SEC_CITY"),
714:                                                                    "orderAdjustmentTypeId",
715:                                                                    "SALES_TAX",
716:                                                                    "comments",
717:                                                                    comments)));
718:                        }
719:
720:                    } else {
721:                        throw new TaxwareException(
722:                                "Invalid number of return adjustments.");
723:                    }
724:
725:                    for (int a = 0; a < model.fields.size(); a++) {
726:                        ModelField mf = (ModelField) model.fields.get(a);
727:                        String name = mf.name;
728:                        String value = rec.getString(name);
729:
730:                        if (Debug.verboseOn())
731:                            Debug.logVerbose("Field: " + name + " => " + value,
732:                                    module);
733:                    }
734:                }
735:                return retRecords.size();
736:            }
737:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.