freeside/FS/bin freeside-setup,1.33,1.34
ivan
ivan at pouncequick.420.am
Wed Mar 31 16:44:37 PST 2004
Update of /home/cvs/cvsroot/freeside/FS/bin
In directory pouncequick:/tmp/cvs-serv10878/FS/bin
Modified Files:
freeside-setup
Log Message:
get sub-countries from Locale::SubCountry now
Index: freeside-setup
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/bin/freeside-setup,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- freeside-setup 13 Feb 2004 10:57:55 -0000 1.33
+++ freeside-setup 1 Apr 2004 00:44:33 -0000 1.34
@@ -6,6 +6,8 @@
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 @@
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 at 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
More information about the freeside-commits
mailing list