/* * [PrepIllinois.java] * * Summary: One shot program to process tax data for Illinois. Generates code for AmericanTax.java table. * * Copyright: (c) 1999-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2008-05-19 * 1.1 2013-04-04 update sources of info, new state tax rate. */ package com.mindprod.americantax; import com.mindprod.common18.Build; import com.mindprod.common18.ST; import java.io.BufferedReader; import java.io.EOFException; import java.io.FileReader; import java.io.IOException; import static java.lang.System.*; /* * home: https://www.revenue.state.il.us/app/trii/ * data comes in COBOL format fixed field length file: * download http://tax.illinois.gov/Publications/Sales/SalesTaxRates/ordfile010113.txt * E:/com/mindprod/americantax/illinoiscities.txt * layout is: http://tax.illinois.gov/Publications/Sales/SalesTaxRates/ordfilelayout010106.pdf * * updates have a different format. PHHT! we ignore them. * alt, presumably out of date. also COBOL format * download http://tax.illinois.gov/Publications/Sales/SalesTaxRates/ORDMACHE.TXT * E:/com/mindprod/americantax/illinoistax2.txt * Check results against PDF document. * sales tax rates in this table include state tax. * offset:length * 1. Location ID PIC X(10) Value "xxx-xxxx-x" * 2.* Location name PIC X(25) [10, 35] * 3.* County Name PIC X(25) [35, 60] * 11.*Purchases General Merchandise High-Rate PIC v99999 A 6.25% rate would be .06250 [69, 74] * 12. Purchases Food and Drug High-Rate PIC v99999 A 6.25% rate would be .06250 * 13.*Purchases General Merchandise Low-Rate PIC v99999 A 6.25% rate would be .06250 [79, 84] */ /** * One shot program to process tax data for Illinois. Generates code for AmericanTax.java table. * * @author Roedy Green, Canadian Mind Products * @version 1.1 2013-04-04 update sources of info, new state tax rate. * @since 2008-05-19 */ public final class PrepIllinois extends PrepStateBase { /** * Constructor */ private PrepIllinois() { super( "IL", "illinois", 6.25 /* state tax */, false /* no illinoiscounties.csv */, true /* illinoiscities.csv exists */, true /* files include state rate */, true /* convert to book case */, 2000 /* est number of cities */ ); } /** * prepare cities by reading a COBOL format flat file. */ void prepareCities() { final String cityFilename = Build.MINDPROD_SOURCE + "/americantax/illinoiscities.txt"; try { // not CSV file, COBOL format. final FileReader r = new FileReader( cityFilename ); final BufferedReader br = new BufferedReader( r, 8092 ); String line; try { while ( ( line = br.readLine() ) != null ) { assert line.length() == 211 : "wrong length line"; String city = ST.toBookTitleCase( line.substring( 10, 35 ) ).trim(); if ( city.endsWith( " County" ) ) { city = ""; } final String county = ST.chopTrailingString( ST.toBookTitleCase( line.substring( 35, 60 ) ).trim(), " County" ); // ignore junk on end of table about out of state taxes if ( county.length() == 0 ) { continue; } final String hiPercentStr = line.substring( 69, 74 ); double percent; try { percent = Integer.parseInt( hiPercentStr ) / 1000d - stateTax; // table has state tax included. } catch ( NumberFormatException e ) { err.println( "malformed percent:" + line ); percent = 0; } if ( percent < 0 ) { percent = stateTax; } /* These show tax rate 0. I presume this is an error and treat them as ILLINOIS_STATE_TAX; Coles Mattoon Cook Bellwood Cook Matteson Dupage Bloomingdale Dupage Lombard Dupage Oakbrook Terrace Effingham Effingham Kane East Dundee Kendall Yorkville Lake Long Grove Madison Alton Madison Collinsville Madison East Alton Madison Edwardsville Madison Glen Carbon Madison Granite City Madison Maryville Madison Troy Madison Wood River Mclean Danvers Mclean Stanford Monroe Waterloo Peoria Peoria Perry Pinckneyville Shelby Shelbyville St. Clair Belleville St. Clair Caseyville St. Clair Fairview Heights St. Clair Millstadt St. Clair New Baden St. Clair Shiloh St. Clair Swansea Tazewell Mackinaw Tazewell Morton Winnebago Loves Park */ salesTaxItems.add( new SalesTaxItem( county, city, percent ) ); } } catch ( EOFException e ) { br.close(); } } catch ( IOException e ) { /* done */ err.println( "can't read " + cityFilename ); } } public static void main( String[] args ) throws IOException { new PrepIllinois().prepare(); } }