add pkey to batch payments and fix a doc typo
[freeside.git] / bin / fs-setup
index 8fbc67e..476b84d 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -Tw
 #
 #!/usr/bin/perl -Tw
 #
-# $Id: fs-setup,v 1.46 2001-09-01 21:52:20 jeff Exp $
+# $Id: fs-setup,v 1.60 2001-10-02 16:00:30 jeff Exp $
 
 #to delay loading dbdef until we're ready
 BEGIN { $FS::Record::setup_hack = 1; }
 
 #to delay loading dbdef until we're ready
 BEGIN { $FS::Record::setup_hack = 1; }
@@ -15,9 +15,13 @@ use DBIx::DBSchema::ColGroup::Index;
 use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets);
 use FS::Record;
 use FS::cust_main_county;
 use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets);
 use FS::Record;
 use FS::cust_main_county;
+use FS::raddb;
 
 die "Not running uid freeside!" unless checkeuid();
 
 
 die "Not running uid freeside!" unless checkeuid();
 
+my %attrib2db =
+  map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib;
+
 my $user = shift or die &usage;
 getsecrets($user);
 
 my $user = shift or die &usage;
 getsecrets($user);
 
@@ -35,13 +39,15 @@ reply attribute Framed-IP-Address for each user.  You can specify additional
 check and reply attributes.  First enter any additional RADIUS check attributes
 you need to track for each user, separated by whitespace.
 END
 check and reply attributes.  First enter any additional RADIUS check attributes
 you need to track for each user, separated by whitespace.
 END
-my @check_attributes = map { s/\-/_/g; $_; } split(" ",&getvalue);
+my @check_attributes = map { $attrib2db{lc($_)} or die "unknown attribute $_"; }
+                         split(" ",&getvalue);
 
 print "\n\n", <<END, ":";
 Now enter any additional reply attributes you need to track for each user,
 separated by whitespace.
 END
 
 print "\n\n", <<END, ":";
 Now enter any additional reply attributes you need to track for each user,
 separated by whitespace.
 END
-my @attributes = map { s/\-/_/g; $_; } split(" ",&getvalue);
+my @attributes = map { $attrib2db{lc($_)} or die "unknown attribute $_"; }
+                   split(" ",&getvalue);
 
 print "\n\n", <<END, ":";
 Do you wish to enable the tracking of a second, separate shipping/service
 
 print "\n\n", <<END, ":";
 Do you wish to enable the tracking of a second, separate shipping/service
@@ -122,32 +128,32 @@ foreach $attribute (@check_attributes) {
   ));
 }
 
   ));
 }
 
-#make part_svc table (but now as object)
-
-my($part_svc)=$dbdef->table('part_svc');
-
-#because of svc_acct_pop
-#foreach (grep /^svc_/, $dbdef->tables) { 
-#foreach (qw(svc_acct svc_acct_sm svc_charge svc_domain svc_wo)) {
-foreach (qw(svc_acct svc_domain svc_forward svc_www)) {
-  my($table)=$dbdef->table($_);
-  my($col);
-  foreach $col ( $table->columns ) {
-    next if $col =~ /^svcnum$/;
-    $part_svc->addcolumn( new DBIx::DBSchema::Column (
-      $table->name. '__' . $table->column($col)->name,
-      'varchar', #$table->column($col)->type, 
-      'NULL',
-      $char_d, #$table->column($col)->length,
-    ));
-    $part_svc->addcolumn ( new DBIx::DBSchema::Column (
-      $table->name. '__'. $table->column($col)->name . "_flag",
-      'char',
-      'NULL',
-      1,
-    ));
-  }
-}
+##make part_svc table (but now as object)
+#
+#my($part_svc)=$dbdef->table('part_svc');
+#
+##because of svc_acct_pop
+##foreach (grep /^svc_/, $dbdef->tables) { 
+##foreach (qw(svc_acct svc_acct_sm svc_charge svc_domain svc_wo)) {
+#foreach (qw(svc_acct svc_domain svc_forward svc_www)) {
+#  my($table)=$dbdef->table($_);
+#  my($col);
+#  foreach $col ( $table->columns ) {
+#    next if $col =~ /^svcnum$/;
+#    $part_svc->addcolumn( new DBIx::DBSchema::Column (
+#      $table->name. '__' . $table->column($col)->name,
+#      'varchar', #$table->column($col)->type, 
+#      'NULL',
+#      $char_d, #$table->column($col)->length,
+#    ));
+#    $part_svc->addcolumn ( new DBIx::DBSchema::Column (
+#      $table->name. '__'. $table->column($col)->name . "_flag",
+#      'char',
+#      'NULL',
+#      1,
+#    ));
+#  }
+#}
 
 #important
 $dbdef->save($dbdef_file);
 
 #important
 $dbdef->save($dbdef_file);
@@ -319,14 +325,15 @@ sub tables_hash_hack {
 
     'cust_credit_bill' => {
       'columns' => [
 
     'cust_credit_bill' => {
       'columns' => [
+        'creditbillnum', 'int', '', '',
         'crednum',  'int', '', '',
         'invnum',  'int', '', '',
         '_date',    @date_type,
         'amount',   @money_type,
       ],
         'crednum',  'int', '', '',
         'invnum',  'int', '', '',
         '_date',    @date_type,
         'amount',   @money_type,
       ],
-      'primary_key' => 'crednum',
+      'primary_key' => 'creditbillnum',
       'unique' => [ [] ],
       'unique' => [ [] ],
-      'index' => [ ['invnum'] ],
+      'index' => [ ['crednum'], ['invnum'] ],
     },
 
     'cust_main' => {
     },
 
     'cust_main' => {
@@ -411,6 +418,7 @@ sub tables_hash_hack {
       'columns' => [
         'paynum',   'int',    '',   '',
         #now cust_bill_pay #'invnum',   'int',    '',   '',
       'columns' => [
         'paynum',   'int',    '',   '',
         #now cust_bill_pay #'invnum',   'int',    '',   '',
+        'custnum',  'int',    '',   '',
         'paid',     @money_type,
         '_date',    @date_type,
         'payby',    'char',   '',     4, # CARD/BILL/COMP, should be index into
         'paid',     @money_type,
         '_date',    @date_type,
         'payby',    'char',   '',     4, # CARD/BILL/COMP, should be index into
@@ -420,18 +428,18 @@ sub tables_hash_hack {
       ],
       'primary_key' => 'paynum',
       'unique' => [ [] ],
       ],
       'primary_key' => 'paynum',
       'unique' => [ [] ],
-      'index' => [ ['invnum'] ],
+      'index' => [ [] ],
     },
 
     'cust_bill_pay' => {
     },
 
     'cust_bill_pay' => {
-      'column' => [
+      'columns' => [
         'billpaynum', 'int',     '',   '',
         'invnum',  'int',     '',   '',
         'paynum',  'int',     '',   '',
         'amount',  @money_type,
         '_date',   @date_type
       ],
         'billpaynum', 'int',     '',   '',
         'invnum',  'int',     '',   '',
         'paynum',  'int',     '',   '',
         'amount',  @money_type,
         '_date',   @date_type
       ],
-      'primary_key' => 'billpaynum'
+      'primary_key' => 'billpaynum',
       'unique' => [ [] ],
       'index' => [ [ 'paynum', 'invnum' ] ],
     },
       'unique' => [ [] ],
       'index' => [ [ 'paynum', 'invnum' ] ],
     },
@@ -439,6 +447,7 @@ sub tables_hash_hack {
     'cust_pay_batch' => { #what's this used for again?  list of customers
                           #in current CARD batch? (necessarily CARD?)
       'columns' => [
     'cust_pay_batch' => { #what's this used for again?  list of customers
                           #in current CARD batch? (necessarily CARD?)
       'columns' => [
+        'paybatchnum',   'int',    '',   '',
         'invnum',   'int',    '',   '',
         'custnum',   'int',    '',   '',
         'last',     'varchar', '',     $char_d,
         'invnum',   'int',    '',   '',
         'custnum',   'int',    '',   '',
         'last',     'varchar', '',     $char_d,
@@ -456,7 +465,7 @@ sub tables_hash_hack {
         'payname',  'varchar', 'NULL', $char_d,
         'amount',   @money_type,
       ],
         'payname',  'varchar', 'NULL', $char_d,
         'amount',   @money_type,
       ],
-      'primary_key' => '',
+      'primary_key' => 'paybatchnum',
       'unique' => [ [] ],
       'index' => [ ['invnum'], ['custnum'] ],
     },
       'unique' => [ [] ],
       'index' => [ ['invnum'], ['custnum'] ],
     },
@@ -482,6 +491,7 @@ sub tables_hash_hack {
       'columns' => [
         'refundnum',    'int',    '',   '',
         #now cust_credit_refund #'crednum',      'int',    '',   '',
       'columns' => [
         'refundnum',    'int',    '',   '',
         #now cust_credit_refund #'crednum',      'int',    '',   '',
+        'custnum',  'int',    '',   '',
         '_date',        @date_type,
         'refund',       @money_type,
         'otaker',       'varchar',   '',   8,
         '_date',        @date_type,
         'refund',       @money_type,
         'otaker',       'varchar',   '',   8,
@@ -493,18 +503,18 @@ sub tables_hash_hack {
       ],
       'primary_key' => 'refundnum',
       'unique' => [ [] ],
       ],
       'primary_key' => 'refundnum',
       'unique' => [ [] ],
-      'index' => [ ['crednum'] ],
+      'index' => [ [] ],
     },
 
     'cust_credit_refund' => {
     },
 
     'cust_credit_refund' => {
-      'column' => [
+      'columns' => [
         'creditrefundnum', 'int',     '',   '',
         'crednum',  'int',     '',   '',
         'refundnum',  'int',     '',   '',
         'amount',  @money_type,
         '_date',   @date_type
       ],
         'creditrefundnum', 'int',     '',   '',
         'crednum',  'int',     '',   '',
         'refundnum',  'int',     '',   '',
         'amount',  @money_type,
         '_date',   @date_type
       ],
-      'primary_key' => 'creditrefundnum'
+      'primary_key' => 'creditrefundnum',
       'unique' => [ [] ],
       'index' => [ [ 'crednum', 'refundnum' ] ],
     },
       'unique' => [ [] ],
       'index' => [ [ 'crednum', 'refundnum' ] ],
     },
@@ -577,6 +587,19 @@ sub tables_hash_hack {
       'index' => [ [] ],
     },
 
       'index' => [ [] ],
     },
 
+    'part_svc_column' => {
+      'columns' => [
+        'columnnum',   'int',         '', '',
+        'svcpart',     'int',         '', '',
+        'columnname',  'varchar',     '', 64,
+        'columnvalue', 'varchar', 'NULL', $char_d,
+        'columnflag',  'char',    'NULL', 1, 
+      ],
+      'primary_key' => 'columnnum',
+      'unique' => [ [ 'svcpart', 'columnname' ] ],
+      'index' => [ [ 'svcpart' ] ],
+    },
+
     #(this should be renamed to part_pop)
     'svc_acct_pop' => {
       'columns' => [
     #(this should be renamed to part_pop)
     'svc_acct_pop' => {
       'columns' => [
@@ -589,7 +612,21 @@ sub tables_hash_hack {
       ],
       'primary_key' => 'popnum',
       'unique' => [ [] ],
       ],
       'primary_key' => 'popnum',
       'unique' => [ [] ],
-      'index' => [ [] ],
+      'index' => [ [ 'state' ] ],
+    },
+
+    'part_pop_local' => {
+      'columns' => [
+        'localnum',  'int',     '',     '',
+        'popnum',    'int',     '',     '',
+        'city',      'varchar', 'NULL', $char_d,
+        'state',     'char',    'NULL', 2,
+        'npa',       'char',    '',     3,
+        'nxx',       'char',    '',     3,
+      ],
+      'primary_key' => 'popnum',
+      'unique' => [ [] ],
+      'index' => [ [ 'npa', 'nxx' ] ],
     },
 
     'svc_acct' => {
     },
 
     'svc_acct' => {
@@ -746,6 +783,28 @@ sub tables_hash_hack {
       'index'       => [ [ 'portnum' ] ],
     },
 
       'index'       => [ [ 'portnum' ] ],
     },
 
+    'queue' => {
+      'columns' => [
+        'jobnum', 'int', '', '',
+        'job', 'varchar', '', '',
+        '_date', 'int', '', '',
+        'status', 'varchar', '', $char_d,
+      ],
+      'primary_key' => 'jobnum',
+      'unique'      => [],
+      'index'       => [],
+    },
+
+    'queue_arg' => {
+      'columns' => [
+        'argnum', 'int', '', '',
+        'jobnum', 'int', '', '',
+        'arg', 'varchar', 'NULL', '',
+      ],
+      'primary_key' => 'argnum',
+      'unique'      => [],
+      'index'       => [ [ 'jobnum' ] ],
+    },
   );
 
   %tables;
   );
 
   %tables;