From: ivan Date: Thu, 1 Apr 2004 00:44:33 +0000 (+0000) Subject: get sub-countries from Locale::SubCountry now X-Git-Tag: NET_WHOIS_RAW_0_31~18 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=db1025e6dcb7b5d68c08a455db0b0326bf8ecc62 get sub-countries from Locale::SubCountry now --- diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm index 76c982ae8..ef2793ad1 100644 --- a/FS/FS/cust_main_county.pm +++ b/FS/FS/cust_main_county.pm @@ -110,7 +110,7 @@ sub check { $self->exempt_amount(0) unless $self->exempt_amount; $self->ut_numbern('taxnum') - || $self->ut_textn('state') + || $self->ut_anything('state') || $self->ut_textn('county') || $self->ut_text('country') || $self->ut_float('tax') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 7512cc18c..522c0a1a2 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -6,6 +6,8 @@ BEGIN { $FS::Record::setup_hack = 1; } use strict; use vars qw($opt_s); use Getopt::Std; +use Locale::Country; +use Locale::SubCountry; use DBI; use DBIx::DBSchema 0.21; use DBIx::DBSchema::Table; @@ -230,60 +232,40 @@ foreach my $statement ( $dbdef->sql($dbh) ) { or die "CREATE error: ". $dbh->errstr. "\ndoing statement: $statement"; } -#not really sample data (and shouldn't default to US) - #cust_main_county +foreach my $country ( sort map uc($_), all_country_codes ) { -#USPS state codes -foreach ( qw( -AL AK AS AZ AR CA CO CT DC DE FM FL GA GU HI ID IL IN IA KS KY LA -ME MH MD MA MI MN MS MO MT NC ND NE NH NJ NM NV NY MP OH OK OR PA PW PR RI -SC SD TN TX UT VT VI VA WA WV WI WY AE AA AP -) ) { - my($cust_main_county)=new FS::cust_main_county({ - 'state' => $_, - 'tax' => 0, - 'country' => 'US', - }); - my($error); - $error=$cust_main_county->insert; - die $error if $error; -} + my $subcountry = eval { new Locale::SubCountry($country) }; + my @states = $subcountry ? $subcountry->all_codes : undef; -#AU "offical" state codes ala mark.williamson@ebbs.com.au (Mark Williamson) -foreach ( qw( -VIC NSW NT QLD TAS ACT WA SA -) ) { - my($cust_main_county)=new FS::cust_main_county({ - 'state' => $_, - 'tax' => 0, - 'country' => 'AU', - }); - my($error); - $error=$cust_main_county->insert; - die $error if $error; -} + if ( !scalar(@states) || ( scalar(@states) == 1 && !defined($states[0]) ) ) { -#ISO 2-letter country codes (same as country TLDs) except US and AU -foreach ( qw( -AF AL DZ AS AD AO AI AQ AG AR AM AW AT AZ BS BH BD BB BY BE BZ BJ BM BT BO -BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CK CR CI -HR CU CY CZ DK DJ DM DO TP EC EG SV GQ ER EE ET FK FO FJ FI FR FX GF PF TF GA -GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT HM HN HK HU IS IN ID IR IQ IE IL -IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV -ML MT MH MQ MR MU YT MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG -NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO RU RW KN LC VC WS SM -ST SA SN SC SL SG SK SI SB SO ZA GS ES LK SH PM SD SR SJ SZ SE CH SY TW TJ TZ -TH TG TK TO TT TN TR TM TC TV UG UA AE GB UM UY UZ VU VA VE VN VG VI WF EH -YE YU ZR ZM ZW -) ) { - my($cust_main_county)=new FS::cust_main_county({ - 'tax' => 0, - 'country' => $_, - }); - my($error); - $error=$cust_main_county->insert; - die $error if $error; + my $cust_main_county = new FS::cust_main_county({ + 'tax' => 0, + 'country' => $country, + }); + my $error = $cust_main_county->insert; + die $error if $error; + + } else { + + if ( $states[0] =~ /^(\d+|\w)$/ ) { + @states = map $subcountry->full_name($_), @states + } + + foreach my $state ( @states ) { + + my $cust_main_county = new FS::cust_main_county({ + 'state' => $state, + 'tax' => 0, + 'country' => $country, + }); + my $error = $cust_main_county->insert; + die $error if $error; + + } + + } } #billing events