modular price plans!
[freeside.git] / FS / bin / freeside-setup
index b7a414a..bc27c79 100755 (executable)
@@ -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
@@ -516,7 +498,7 @@ sub tables_hash_hack {
       'unique' => [],
       #'index' => [ ['last'], ['company'] ],
       'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ],
-                   [ 'daytime' ], [ 'night' ], [ 'fax' ],
+                   [ 'daytime' ], [ 'night' ], [ 'fax' ], [ 'refnum' ],
                  ],
     },
 
@@ -570,6 +552,26 @@ sub tables_hash_hack {
       'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ] ],
     },
 
+    'cust_pay_void' => {
+      'columns' => [
+        'paynum',    'int',    '',   '',
+        'custnum',   'int',    '',   '',
+        'paid',      @money_type,
+        '_date',     @date_type,
+        'payby',     'char',   '',     4, # CARD/BILL/COMP, should be index into
+                                          # payment type table.
+        'payinfo',   'varchar',   'NULL', $char_d,  #see cust_main above
+        'paybatch',  'varchar',   'NULL', $char_d, #for auditing purposes.
+        'closed',    'char', 'NULL', 1,
+        'void_date', @date_type,
+        'reason',    'varchar',   'NULL', $char_d,
+        'otaker',   'varchar', '', 32,
+      ],
+      'primary_key' => 'paynum',
+      'unique' => [],
+      'index' => [ [ 'custnum' ] ],
+    },
+
     'cust_bill_pay' => {
       'columns' => [
         'billpaynum', 'serial',     '',   '',
@@ -708,6 +710,7 @@ sub tables_hash_hack {
         'pkgpart',    'int',    '',   '',
         'svcpart',    'int',    '',   '',
         'quantity',   'int',    '',   '',
+        'primary_svc','char', 'NULL',  1,
       ],
       'primary_key' => '',
       'unique' => [ ['pkgpart', 'svcpart'] ],
@@ -841,10 +844,11 @@ sub tables_hash_hack {
 
     'svc_forward' => {
       'columns' => [
-        'svcnum',   'int',    '',  '',
-        'srcsvc',   'int',    '',  '',
-        'dstsvc',   'int',    '',  '',
-        'dst',      'varchar',    'NULL',  $char_d,
+        'svcnum',   'int',            '',   '',
+        'srcsvc',   'int',        'NULL',   '',
+        'src',      'varchar',    'NULL',  255,
+        'dstsvc',   'int',        'NULL',   '',
+        'dst',      'varchar',    'NULL',  255,
       ],
       'primary_key' => 'svcnum',
       'unique'      => [],
@@ -1123,7 +1127,7 @@ sub tables_hash_hack {
     'svc_external' => {
       'columns' => [
         'svcnum', 'int', '', '',
-        'id',     'int', '', '',
+        'id',     'int', 'NULL', '',
         'title',  'varchar', 'NULL', $char_d,
       ],
       'primary_key' => 'svcnum',
@@ -1131,6 +1135,31 @@ sub tables_hash_hack {
       'index'       => [],
     },
 
+    'cust_pay_refund' => {
+      'columns' => [
+        'payrefundnum', 'serial', '', '',
+        'paynum',  'int', '', '',
+        'refundnum',  'int', '', '',
+        '_date',    @date_type,
+        'amount',   @money_type,
+      ],
+      'primary_key' => 'payrefundnum',
+      'unique' => [],
+      'index' => [ ['paynum'], ['refundnum'] ],
+    },
+
+    'part_pkg_option' => {
+      'columns' => [
+        'optionnum', 'serial', '', '',
+        'pkgpart', 'int', '', '',
+        'optionname', 'varchar', '', $char_d,
+        'optionvalue', 'text', 'NULL', '',
+      ],
+      'primary_key' => 'optionnum',
+      'unique'      => [],
+      'index'       => [ [ 'pkgpart' ], [ 'optionname' ] ],
+    },
+
   );
 
   %tables;