/* * [PrepMinnesota.java] * * Summary: One shot program to process tax data for Minnesota. 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 2010-12-17 initial version */ package com.mindprod.americantax; import com.mindprod.common18.ST; import com.mindprod.csv.CSVReader; import java.io.IOException; import java.util.HashMap; import static java.lang.System.*; /** * One shot program to process tax data for Minnesota. Generates code for AmericanTax.java table. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2010-12-17 initial version - produce CSV file without state tax included. * @since 2010-12-17 */ public final class PrepMinnesota extends PrepStateBase { private final HashMap lookupCountyByCity = new HashMap<>( 1000 ); /** * Constructor */ private PrepMinnesota() { super( "MN", "minnesota", 6.875, true /* counties */, true /* cities */, false /* files include state rate */, false /* convert to book case */, 50 ); } /** * Default method to read and prepare one county record. * You must read, and add SalesTaxItem to salesTaxItems, and skipToNewLine * * @param c open CSV reader. * * @throws IOException if cannot read file */ void prepareCity( final CSVReader c ) throws IOException { final String item = ST.toBookTitleCase( c.get() ); final double percent = c.getDouble(); c.skipToNextLine(); String county; final String city; if ( item.endsWith( "County" ) ) { county = ST.chopTrailingString( item, "County" ); city = ""; salesTaxItems.add( new SalesTaxItem( county, "", percent ) ); } else { city = item; county = lookupCountyByCity.get( city ); if ( county == null ) { err.println( "city with unknown county: " + city ); county = ""; } } salesTaxItems.add( new SalesTaxItem( county, city, percent ) ); } /* * Generates code for AmericanTax.java table. * http://www.lmic.state.mn.us/datanetweb/php/citycountylist.php has list of cities/counties. * home: http://taxes.state.mn.us/sales/pages/local_tax_information_sales_local_taxes.aspx * download http://taxes.state.mn.us/use/Documents/publications_fact_sheets_content_BAT_1100111.pdf iowa.pdf * contains short list of counties and cities intermixed. * Extract with copy/paste. *

* Will look like this: *

* Albert Lea, 0.50 * Austin, 0.50 * Baxter, 0.50 * Bemidji, 0.50 *

* and save as E:\com\mindprod\americantax\iowacities.csv * Use HTMLValidator to strip tags from city/county list and massage till it looks like this: * #city, county * Ada ,Norman * Adams ,Mower * Adrian ,Nobles * Afton ,Washington * has no tax info, just lookup. */ /** * Default method to read and prepare one county record. * You must read, and add SalesTaxItem to salesTaxItems, and skipToNewLine * * @param c open CSV reader. * * @throws IOException if cannot read file */ void prepareCounty( final CSVReader c ) throws IOException { final String cityName = c.get(); final String countyName = c.get(); c.skipToNextLine(); lookupCountyByCity.put( cityName, countyName ); // if dups use last one. } public static void main( String[] args ) throws IOException { new PrepMinnesota().prepare(); } }