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 0.25;
use DBIx::DBSchema::Table;
use DBIx::DBSchema::Column;
use DBIx::DBSchema::ColGroup::Unique;
my $cust_main = $dbdef->table('cust_main');
unless ($ship) { #remove ship_ from cust_main
$cust_main->delcolumn($_) foreach ( grep /^ship_/, $cust_main->columns );
-} else { #add indices on ship_last and ship_company
- push @{$cust_main->index->lol_ref}, ( ['ship_last'], ['ship_company'] )
+} else { #add indices
+ push @{$cust_main->index->lol_ref},
+ map { [ "ship_$_" ] } qw( last company daytime night fax );
}
#add radius attributes to svc_acct
}
#create history tables (false laziness w/create-history-tables)
-foreach my $table ( grep { ! /^h_/ } $dbdef->tables ) {
+foreach my $table (
+ grep { ! /^clientapi_session/ }
+ grep { ! /^h_/ }
+ $dbdef->tables
+) {
my $tableobj = $dbdef->table($table)
or die "unknown table $table";
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
foreach my $aref (
- [ 'COMP', 'Comp invoice', '$cust_bill->comp();', 30, 'comp' ],
+ #[ 'COMP', 'Comp invoice', '$cust_bill->comp();', 30, 'comp' ],
[ 'CARD', 'Batch card', '$cust_bill->batch_card();', 40, 'batch-card' ],
[ 'BILL', 'Send invoice', '$cust_bill->send();', 50, 'send' ],
+ [ 'DCRD', 'Send invoice', '$cust_bill->send();', 50, 'send' ],
+ [ 'DCHK', 'Send invoice', '$cust_bill->send();', 50, 'send' ],
) {
my $part_bill_event = new FS::part_bill_event({
'typenum', 'int', '', '',
'freq', 'int', 'NULL', '',
'prog', @perl_type,
+ 'disabled', 'char', 'NULL', 1,
+ 'username', 'varchar', 'NULL', $char_d,
+ '_password','varchar', 'NULL', $char_d,
],
'primary_key' => 'agentnum',
'unique' => [],
- 'index' => [ ['typenum'] ],
+ 'index' => [ ['typenum'], ['disabled'] ],
},
'agent_type' => {
'type_pkgs' => {
'columns' => [
+ 'typepkgnum', 'serial', '', '',
'typenum', 'int', '', '',
'pkgpart', 'int', '', '',
],
- 'primary_key' => '',
+ 'primary_key' => 'typepkgnum',
'unique' => [ ['typenum', 'pkgpart'] ],
'index' => [ ['typenum'] ],
},
],
'primary_key' => 'invnum',
'unique' => [],
- 'index' => [ ['custnum'] ],
+ 'index' => [ ['custnum'], ['_date'] ],
},
'cust_bill_event' => {
],
'primary_key' => 'eventpart',
'unique' => [],
- 'index' => [ ['payby'] ],
+ 'index' => [ ['payby'], ['disabled'], ],
},
'cust_bill_pkg' => {
'columns' => [
+ 'billpkgnum', 'serial', '', '',
'pkgnum', 'int', '', '',
'invnum', 'int', '', '',
'setup', @money_type,
'edate', @date_type,
'itemdesc', 'varchar', 'NULL', $char_d,
],
- 'primary_key' => '',
+ 'primary_key' => 'billpkgnum',
'unique' => [],
'index' => [ ['invnum'] ],
},
+ 'cust_bill_pkg_detail' => {
+ 'columns' => [
+ 'detailnum', 'serial', '', '',
+ 'pkgnum', 'int', '', '',
+ 'invnum', 'int', '', '',
+ 'detail', 'varchar', '', $char_d,
+ ],
+ 'primary_key' => 'detailnum',
+ 'unique' => [],
+ 'index' => [ [ 'pkgnum', 'invnum' ] ],
+ },
+
'cust_credit' => {
'columns' => [
'crednum', 'serial', '', '',
'last', 'varchar', '', $char_d,
# 'middle', 'varchar', 'NULL', $char_d,
'first', 'varchar', '', $char_d,
- 'ss', 'char', 'NULL', 11,
+ 'ss', 'varchar', 'NULL', 11,
'company', 'varchar', 'NULL', $char_d,
'address1', 'varchar', '', $char_d,
'address2', 'varchar', 'NULL', $char_d,
'city', 'varchar', '', $char_d,
'county', 'varchar', 'NULL', $char_d,
'state', 'varchar', 'NULL', $char_d,
- 'zip', 'varchar', '', 10,
+ 'zip', 'varchar', 'NULL', 10,
'country', 'char', '', 2,
'daytime', 'varchar', 'NULL', 20,
'night', 'varchar', 'NULL', 20,
'ship_night', 'varchar', 'NULL', 20,
'ship_fax', 'varchar', 'NULL', 12,
'payby', 'char', '', 4,
- 'payinfo', 'varchar', 'NULL', $char_d,
+ 'payinfo', 'varchar', 'NULL', 512,
+ 'paycvv', 'varchar', 'NULL', 512,
+ 'paymask', 'varchar', 'NULL', $char_d,
#'paydate', @date_type,
'paydate', 'varchar', 'NULL', 10,
'payname', 'varchar', 'NULL', $char_d,
'primary_key' => 'custnum',
'unique' => [],
#'index' => [ ['last'], ['company'] ],
- 'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ] ],
+ 'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ],
+ [ 'daytime' ], [ 'night' ], [ 'fax' ], [ 'refnum' ],
+ ],
},
'cust_main_invoice' => {
'exempt_amount', @money_type,
'tax', 'real', '', '', #tax %
'taxname', 'varchar', 'NULL', $char_d,
+ 'setuptax', 'char', 'NULL', 1, # Y = setup tax exempt
+ 'recurtax', 'char', 'NULL', 1, # Y = recur tax exempt
],
'primary_key' => 'taxnum',
'unique' => [],
'_date', @date_type,
'payby', 'char', '', 4, # CARD/BILL/COMP, should be index into
# payment type table.
- 'payinfo', 'varchar', 'NULL', 16, #see cust_main above
+ 'payinfo', 'varchar', 'NULL', $char_d, #see cust_main above
'paybatch', 'varchar', 'NULL', $char_d, #for auditing purposes.
'closed', 'char', 'NULL', 1,
],
'primary_key' => 'paynum',
'unique' => [],
- 'index' => [ [ 'custnum' ], [ 'paybatch' ] ],
+ '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' => {
'address2', 'varchar', 'NULL', $char_d,
'city', 'varchar', '', $char_d,
'state', 'varchar', 'NULL', $char_d,
- 'zip', 'varchar', '', 10,
+ 'zip', 'varchar', 'NULL', 10,
'country', 'char', '', 2,
# 'trancode', 'int', '', '',
'cardnum', 'varchar', '', 16,
'otaker', 'varchar', '', 32,
'setup', @date_type,
'bill', @date_type,
+ 'last_bill', @date_type,
'susp', @date_type,
'cancel', @date_type,
'expire', @date_type,
'reason', 'varchar', '', $char_d,
'payby', 'char', '', 4, # CARD/BILL/COMP, should be index
# into payment type table.
- 'payinfo', 'varchar', 'NULL', 16, #see cust_main above
+ 'payinfo', 'varchar', 'NULL', $char_d, #see cust_main above
'paybatch', 'varchar', 'NULL', $char_d,
'closed', 'char', 'NULL', 1,
],
'pkgpart', 'serial', '', '',
'pkg', 'varchar', '', $char_d,
'comment', 'varchar', '', $char_d,
+ 'promo_code', 'varchar', 'NULL', $char_d,
'setup', @perl_type,
- 'freq', 'int', '', '', #billing frequency (months)
+ 'freq', 'varchar', '', $char_d, #billing frequency
'recur', @perl_type,
'setuptax', 'char', 'NULL', 1,
'recurtax', 'char', 'NULL', 1,
],
'primary_key' => 'pkgpart',
'unique' => [],
- 'index' => [],
+ 'index' => [ [ 'promo_code' ], [ 'disabled' ] ],
},
# 'part_title' => {
'pkg_svc' => {
'columns' => [
+ 'pkgsvcnum', 'serial', '', '',
'pkgpart', 'int', '', '',
'svcpart', 'int', '', '',
'quantity', 'int', '', '',
+ 'primary_svc','char', 'NULL', 1,
],
- 'primary_key' => '',
+ 'primary_key' => 'pkgsvcnum',
'unique' => [ ['pkgpart', 'svcpart'] ],
'index' => [ ['pkgpart'] ],
},
'columns' => [
'refnum', 'serial', '', '',
'referral', 'varchar', '', $char_d,
+ 'disabled', 'char', 'NULL', 1,
],
'primary_key' => 'refnum',
'unique' => [],
- 'index' => [],
+ 'index' => [ ['disabled'] ],
},
'part_svc' => {
],
'primary_key' => 'svcpart',
'unique' => [],
- 'index' => [],
+ 'index' => [ [ 'disabled' ] ],
},
'part_svc_column' => {
'columns' => [
'svcnum', 'int', '', '',
'username', 'varchar', '', $username_len, #unique (& remove dup code)
- '_password', 'varchar', '', 50, #13 for encryped pw's plus ' *SUSPENDED* (mp5 passwords can be 34)
+ '_password', 'varchar', '', 72, #13 for encryped pw's plus ' *SUSPENDED* (md5 passwords can be 34, blowfish 60)
'sec_phrase', 'varchar', 'NULL', $char_d,
'popnum', 'int', 'NULL', '',
'uid', 'int', 'NULL', '',
'columns' => [
'recnum', 'serial', '', '',
'svcnum', 'int', '', '',
- 'reczone', 'varchar', '', $char_d,
+ #'reczone', 'varchar', '', $char_d,
+ 'reczone', 'varchar', '', 255,
'recaf', 'char', '', 2,
- 'rectype', 'char', '', 5,
- 'recdata', 'varchar', '', $char_d,
+ 'rectype', 'varchar', '', 5,
+ #'recdata', 'varchar', '', $char_d,
+ 'recdata', 'varchar', '', 255,
],
'primary_key' => 'recnum',
'unique' => [],
'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' => [],
'identifier', 'varchar', '', $char_d,
'amount', @money_type,
'seconds', 'int', 'NULL', '',
+ 'agentnum', 'int', 'NULL', '',
],
'primary_key' => 'prepaynum',
'unique' => [ ['identifier'] ],
'index' => [],
},
- 'ac_type' => {
+ 'router' => {
'columns' => [
- 'actypenum', 'serial', '', '',
- 'actypename', 'varchar', '', $char_d,
+ 'routernum', 'serial', '', '',
+ 'routername', 'varchar', '', $char_d,
+ 'svcnum', 'int', 'NULL', '',
],
- 'primary_key' => 'actypenum',
+ 'primary_key' => 'routernum',
'unique' => [],
'index' => [],
},
- 'ac' => {
+ 'part_svc_router' => {
'columns' => [
- 'acnum', 'serial', '', '',
- 'actypenum', 'int', '', '',
- 'acname', 'varchar', '', $char_d,
+ 'svcrouternum', 'serial', '', '',
+ 'svcpart', 'int', '', '',
+ 'routernum', 'int', '', '',
],
- 'primary_key' => 'acnum',
+ 'primary_key' => 'svcrouternum',
'unique' => [],
- 'index' => [ [ 'actypenum' ] ],
+ 'index' => [],
},
- 'part_ac_field' => {
+ 'addr_block' => {
'columns' => [
- 'acfieldpart', 'serial', '', '',
- 'actypenum', 'int', '', '',
- 'name', 'varchar', '', $char_d,
- 'ut_type', 'varchar', '', $char_d,
+ 'blocknum', 'serial', '', '',
+ 'routernum', 'int', '', '',
+ 'ip_gateway', 'varchar', '', 15,
+ 'ip_netmask', 'int', '', '',
],
- 'primary_key' => 'acfieldpart',
+ 'primary_key' => 'blocknum',
+ 'unique' => [ [ 'blocknum', 'routernum' ] ],
+ 'index' => [],
+ },
+
+ 'svc_broadband' => {
+ 'columns' => [
+ 'svcnum', 'int', '', '',
+ 'blocknum', 'int', '', '',
+ 'speed_up', 'int', '', '',
+ 'speed_down', 'int', '', '',
+ 'ip_addr', 'varchar', '', 15,
+ ],
+ 'primary_key' => 'svcnum',
'unique' => [],
- 'index' => [ [ 'actypenum' ] ],
+ 'index' => [],
},
- 'ac_field' => {
+ 'part_virtual_field' => {
'columns' => [
- 'acfieldpart', 'int', '', '',
- 'acnum', 'int', '', '',
- 'value', 'text', '', '',
+ 'vfieldpart', 'int', '', '',
+ 'dbtable', 'varchar', '', 32,
+ 'name', 'varchar', '', 32,
+ 'check_block', 'text', 'NULL', '',
+ 'length', 'int', 'NULL', '',
+ 'list_source', 'text', 'NULL', '',
+ 'label', 'varchar', 'NULL', 80,
],
- 'primary_key' => '',
- 'unique' => [ [ 'acfieldpart', 'acnum' ] ],
- 'index' => [ [ 'acnum' ] ],
+ 'primary_key' => 'vfieldpart',
+ 'unique' => [],
+ 'index' => [],
},
- 'ac_block' => {
+ 'virtual_field' => {
'columns' => [
- 'acnum', 'int', '', '',
- 'ip_gateway', 'varchar', '', 15,
- 'ip_netmask', 'int', '', '',
+ 'vfieldnum', 'serial', '', '',
+ 'recnum', 'int', '', '',
+ 'vfieldpart', 'int', '', '',
+ 'value', 'varchar', '', 128,
],
- 'primary_key' => '',
- 'unique' => [],
- 'index' => [ [ 'acnum' ] ],
+ 'primary_key' => 'vfieldnum',
+ 'unique' => [ [ 'vfieldpart', 'recnum' ] ],
+ 'index' => [],
},
- 'svc_broadband' => {
+ 'acct_snarf' => {
+ 'columns' => [
+ 'snarfnum', 'int', '', '',
+ 'svcnum', 'int', '', '',
+ 'machine', 'varchar', '', 255,
+ 'protocol', 'varchar', '', $char_d,
+ 'username', 'varchar', '', $char_d,
+ '_password', 'varchar', '', $char_d,
+ ],
+ 'primary_key' => 'snarfnum',
+ 'unique' => [],
+ 'index' => [ [ 'svcnum' ] ],
+ },
+
+ 'svc_external' => {
'columns' => [
'svcnum', 'int', '', '',
- 'actypenum', 'int', '', '',
- 'speed_up', 'int', '', '',
- 'speed_down', 'int', '', '',
- 'acnum', 'int', '', '',
- 'ip_addr', 'varchar', '', 15,
- 'ip_netmask', 'int', '', '',
- 'mac_addr', 'char', '', 17,
- 'location', 'varchar', '', $char_d,
+ 'id', 'int', 'NULL', '',
+ 'title', 'varchar', 'NULL', $char_d,
],
'primary_key' => 'svcnum',
'unique' => [],
- 'index' => [ [ 'actypenum' ] ],
+ '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' ] ],
+ },
+
+ 'rate' => {
+ 'columns' => [
+ 'ratenum', 'serial', '', '',
+ 'ratename', 'varchar', '', $char_d,
+ ],
+ 'primary_key' => 'ratenum',
+ 'unique' => [],
+ 'index' => [],
+ },
+
+ 'rate_detail' => {
+ 'columns' => [
+ 'ratedetailnum', 'serial', '', '',
+ 'ratenum', 'int', '', '',
+ 'orig_regionnum', 'int', 'NULL', '',
+ 'dest_regionnum', 'int', '', '',
+ 'min_included', 'int', '', '',
+ 'min_charge', @money_type,
+ 'sec_granularity', 'int', '', '',
+ #time period (link to table of periods)?
+ ],
+ 'primary_key' => 'ratedetailnum',
+ 'unique' => [ [ 'ratenum', 'orig_regionnum', 'dest_regionnum' ] ],
+ 'index' => [],
+ },
+
+ 'rate_region' => {
+ 'columns' => [
+ 'regionnum', 'serial', '', '',
+ 'regionname', 'varchar', '', $char_d,
+ ],
+ 'primary_key' => 'regionnum',
+ 'unique' => [],
+ 'index' => [],
+ },
+
+ 'rate_prefix' => {
+ 'columns' => [
+ 'prefixnum', 'serial', '', '',
+ 'regionnum', 'int', '', '',,
+ 'countrycode', 'varchar', '', 3,
+ 'npa', 'varchar', 'NULL', 6,
+ 'nxx', 'varchar', 'NULL', 3,
+ ],
+ 'primary_key' => 'prefixnum',
+ 'unique' => [],
+ 'index' => [ [ 'countrycode' ], [ 'regionnum' ] ],
+ },
+
+ 'reg_code' => {
+ 'columns' => [
+ 'codenum', 'serial', '', '',
+ 'code', 'varchar', '', $char_d,
+ 'agentnum', 'int', '', '',
+ ],
+ 'primary_key' => 'codenum',
+ 'unique' => [ [ 'agentnum', 'code' ] ],
+ 'index' => [ [ 'agentnum' ] ],
+ },
+
+ 'reg_code_pkg' => {
+ 'columns' => [
+ 'codepkgnum', 'serial', '', '',
+ 'codenum', 'int', '', '',
+ 'pkgpart', 'int', '', '',
+ ],
+ 'primary_key' => 'codepkgnum',
+ 'unique' => [ [ 'codenum', 'pkgpart' ] ],
+ 'index' => [ [ 'codenum' ] ],
+ },
+
+ 'clientapi_session' => {
+ 'columns' => [
+ 'sessionnum', 'serial', '', '',
+ 'sessionid', 'varchar', '', $char_d,
+ 'namespace', 'varchar', '', $char_d,
+ ],
+ 'primary_key' => 'sessionnum',
+ 'unique' => [ [ 'sessionid', 'namespace' ] ],
+ 'index' => [],
+ },
+
+ 'clientapi_session_field' => {
+ 'columns' => [
+ 'fieldnum', 'serial', '', '',
+ 'sessionnum', 'int', '', '',
+ 'fieldname', 'varchar', '', $char_d,
+ 'fieldvalue', 'text', 'NULL', '',
+ ],
+ 'primary_key' => 'fieldnum',
+ 'unique' => [ [ 'sessionnum', 'fieldname' ] ],
+ 'index' => [],
},
);