[freeside-commits] freeside/FS/FS Schema.pm, 1.202, 1.203 cust_attachment.pm, 1.1, 1.2 cust_credit.pm, 1.39, 1.40 cust_main.pm, 1.499, 1.500 cust_main_note.pm, 1.1, 1.2 cust_pay_void.pm, 1.7, 1.8 cust_pkg.pm, 1.160, 1.161 cust_pkg_reason.pm, 1.7, 1.8 cust_pkg_discount.pm, 1.5, 1.6 cust_refund.pm, 1.33, 1.34 banned_pay.pm, 1.1, 1.2 Upgrade.pm, 1.34, 1.35 otaker_Mixin.pm, NONE, 1.1 access_user.pm, 1.25, 1.26

Ivan,,, ivan at wavetail.420.am
Sun Mar 28 17:23:10 PDT 2010


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv15993

Modified Files:
	Schema.pm cust_attachment.pm cust_credit.pm cust_main.pm 
	cust_main_note.pm cust_pay_void.pm cust_pkg.pm 
	cust_pkg_reason.pm cust_pkg_discount.pm cust_refund.pm 
	banned_pay.pm Upgrade.pm access_user.pm 
Added Files:
	otaker_Mixin.pm 
Log Message:
move from otaker to proper usernum FK

Index: cust_refund.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_refund.pm,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -w -d -r1.33 -r1.34
--- cust_refund.pm	1 Jun 2008 22:48:14 -0000	1.33
+++ cust_refund.pm	29 Mar 2010 00:23:07 -0000	1.34
@@ -1,19 +1,17 @@
 package FS::cust_refund;
 
 use strict;
-use vars qw( @ISA @encrypted_fields );
+use base qw( FS::otaker_Mixin FS::payinfo_transaction_Mixin FS::cust_main_Mixin
+             FS::Record );
+use vars qw( @encrypted_fields );
 use Business::CreditCard;
 use FS::UID qw(getotaker);
 use FS::Record qw( qsearch qsearchs dbh );
-use FS::cust_main_Mixin;
-use FS::payinfo_transaction_Mixin;
 use FS::cust_credit;
 use FS::cust_credit_refund;
 use FS::cust_pay_refund;
 use FS::cust_main;
 
- at ISA = qw( FS::payinfo_transaction_Mixin FS::cust_main_Mixin FS::Record );
-
 @encrypted_fields = ('payinfo');
 
 =head1 NAME
@@ -43,28 +41,50 @@
 
 =over 4
 
-=item refundnum - primary key (assigned automatically for new refunds)
+=item refundnum
 
-=item custnum - customer (see L<FS::cust_main>)
+primary key (assigned automatically for new refunds)
 
-=item refund - Amount of the refund
+=item custnum
 
-=item reason - Reason for the refund
+customer (see L<FS::cust_main>)
 
-=item _date - specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
+=item refund
+
+Amount of the refund
+
+=item reason
+
+Reason for the refund
+
+=item _date
+
+specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
 L<Time::Local> and L<Date::Parse> for conversion functions.
 
-=item payby - Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
+=item payby
 
-=item payinfo - Payment Information (See L<FS::payinfo_Mixin> for data format)
+Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
 
-=item paymask - Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
+=item payinfo
 
-=item paybatch - text field for tracking card processing
+Payment Information (See L<FS::payinfo_Mixin> for data format)
 
-=item otaker - order taker (assigned automatically, see L<FS::UID>)
+=item paymask
 
-=item closed - books closed flag, empty or `Y'
+Masked payinfo (See L<FS::payinfo_Mixin> for how this works)
+
+=item paybatch
+
+text field for tracking card processing
+
+=item usernum
+
+order taker (see L<FS::access_user>
+
+=item closed
+
+books closed flag, empty or `Y'
 
 =back
 
@@ -236,13 +256,13 @@
 sub check {
   my $self = shift;
 
-  $self->otaker(getotaker) unless ($self->otaker);
+  $self->otaker(getotaker) unless $self->otaker;
 
   my $error =
     $self->ut_numbern('refundnum')
     || $self->ut_numbern('custnum')
     || $self->ut_money('refund')
-    || $self->ut_alpha('otaker')
+    || $self->ut_alphan('otaker')
     || $self->ut_text('reason')
     || $self->ut_numbern('_date')
     || $self->ut_textn('paybatch')
@@ -273,6 +293,7 @@
 
 sub cust_credit_refund {
   my $self = shift;
+  map { $_ } #return $self->num_cust_credit_refund unless wantarray;
   sort { $a->_date <=> $b->_date }
     qsearch( 'cust_credit_refund', { 'refundnum' => $self->refundnum } )
   ;
@@ -287,6 +308,7 @@
 
 sub cust_pay_refund {
   my $self = shift;
+  map { $_ } #return $self->num_cust_pay_refund unless wantarray;
   sort { $a->_date <=> $b->_date }
     qsearch( 'cust_pay_refund', { 'refundnum' => $self->refundnum } )
   ;
@@ -338,6 +360,12 @@
 
 }
 
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data {  # class method
+  my ($class, %opts) = @_;
+  $class->_upgrade_otaker(%opts);
+}
+
 =back
 
 =head1 BUGS

Index: cust_main_note.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main_note.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- cust_main_note.pm	3 Oct 2006 22:44:26 -0000	1.1
+++ cust_main_note.pm	29 Mar 2010 00:23:07 -0000	1.2
@@ -1,11 +1,9 @@
 package FS::cust_main_note;
 
 use strict;
-use vars qw( @ISA );
+use base qw( FS::otaker_Mixin FS::Record );
 use FS::Record qw( qsearch qsearchs );
 
- at ISA = qw(FS::Record);
-
 =head1 NAME
 
 FS::cust_main_note - Object methods for cust_main_note records
@@ -33,16 +31,17 @@
 
 =over 4
 
-=item notenum - primary key
+=item notenum
 
-=item custnum - 
+primary key
 
-=item _date - 
+=item custnum
 
-=item otaker - 
+=item _date
 
-=item comments - 
+=item usernum
 
+=item comments
 
 =back
 
@@ -107,7 +106,7 @@
     $self->ut_numbern('notenum')
     || $self->ut_number('custnum')
     || $self->ut_numbern('_date')
-    || $self->ut_text('otaker')
+    || $self->ut_alphan('otaker')
     || $self->ut_anything('comments')
   ;
   return $error if $error;
@@ -115,6 +114,12 @@
   $self->SUPER::check;
 }
 
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data {  # class method
+  my ($class, %opts) = @_;
+  $class->_upgrade_otaker(%opts);
+}
+
 =back
 
 =head1 BUGS

Index: Upgrade.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Upgrade.pm,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -w -d -r1.34 -r1.35
--- Upgrade.pm	27 Mar 2010 04:37:26 -0000	1.34
+++ Upgrade.pm	29 Mar 2010 00:23:07 -0000	1.35
@@ -140,6 +140,19 @@
     #cdrbatch fixes
     'cdr' => [],
 
+    #otaker->usernum
+    'cust_attachment' => [],
+    #'cust_credit' => [],
+    #'cust_main' => [],
+    'cust_main_note' => [],
+    #'cust_pay' => [],
+    'cust_pay_void' => [],
+    'cust_pkg' => [],
+    #'cust_pkg_reason' => [],
+    'cust_pkg_discount' => [],
+    'cust_refund' => [],
+    'banned_pay' => [],
+
   ;
 
   \%hash;

Index: cust_attachment.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_attachment.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- cust_attachment.pm	9 Aug 2009 09:05:37 -0000	1.1
+++ cust_attachment.pm	29 Mar 2010 00:23:07 -0000	1.2
@@ -1,7 +1,7 @@
 package FS::cust_attachment;
 
 use strict;
-use base qw( FS::Record );
+use base qw( FS::otaker_Mixin FS::Record );
 use FS::Record qw( qsearch qsearchs );
 use FS::Conf;
 
@@ -44,9 +44,9 @@
 
 The date the record was last updated.
 
-=item otaker
+=item usernum
 
-Order taker (assigned automatically; see L<FS::UID>).
+Order taker (see L<FS::access_user>)
 
 =item filename
 
@@ -128,7 +128,7 @@
     $self->ut_numbern('attachnum')
     || $self->ut_number('custnum')
     || $self->ut_numbern('_date')
-    || $self->ut_text('otaker')
+    || $self->ut_alphan('otaker')
     || $self->ut_text('filename')
     || $self->ut_text('mime_type')
     || $self->ut_numbern('disabled')
@@ -154,6 +154,12 @@
   return length($self->body);
 }
 
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data {  # class method
+  my ($class, %opts) = @_;
+  $class->_upgrade_otaker(%opts);
+}
+
 =back
 
 =head1 BUGS

--- NEW FILE: otaker_Mixin.pm ---
package FS::otaker_Mixin;

use strict;
use Carp qw( croak ); #confess );
use FS::Record qw( qsearch qsearchs );
use FS::access_user;

sub otaker {
  my $self = shift;
  if ( scalar(@_) ) { #set
    my $otaker = shift;
    my $access_user = qsearchs('access_user', { 'username' => $otaker } )
      or croak "can't set otaker: $otaker not found!"; #confess?
    $self->usernum( $access_user->usernum );
    $otaker; #not sure return is used anywhere, but just in case
  } else { #get
    if ( $self->usernum ) {
      $self->access_user->username;
    } elsif ( length($self->get('otaker')) ) {
      $self->get('otaker');
    } else {
      '';
    }
  }
}

sub access_user {
  my $self = shift;
  qsearchs('access_user', { 'usernum' => $self->usernum } );
}

sub _upgrade_otaker {
  my $class = shift;
  my $table = $class->table;

  while ( 1 ) {
    my @records = qsearch({
                    'table'     => $table,
                    'hashref'   => {},
                    'extra_sql' => 'WHERE otaker IS NOT NULL LIMIT 1000',
                  });
    last unless @records;

    foreach my $record (@records) {
      eval { $record->otaker($record->otaker) };
      if ( $@ ) {
        my $access_user = new FS::access_user {
          'username'  => $record->otaker,
          '_password' => 'CHANGEME',
          'first'     => 'Legacy',
          'last'      => 'User',
          'disabled'  => 'Y',
        };
        my $error = $access_user->insert;
        die $error if $error;
        $record->otaker($record->otaker);
      }
      $record->set('otaker', '');
      my $error = $record->replace;
      die $error if $error;
    }

  }

}

1;

Index: cust_pkg_discount.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg_discount.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -d -r1.5 -r1.6
--- cust_pkg_discount.pm	6 Feb 2010 02:57:12 -0000	1.5
+++ cust_pkg_discount.pm	29 Mar 2010 00:23:07 -0000	1.6
@@ -1,7 +1,7 @@
 package FS::cust_pkg_discount;
 
 use strict;
-use base qw( FS::cust_main_Mixin FS::Record );
+use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::Record );
 use FS::Record qw( dbh qsearchs ); # qsearch );
 use FS::cust_pkg;
 use FS::discount;
@@ -53,9 +53,9 @@
 
 end_date
 
-=item otaker
+=item usernum
 
-otaker
+order taker, see L<FS::access_user>
 
 
 =back
@@ -164,7 +164,7 @@
     || $self->ut_foreign_key('discountnum', 'discount', 'discountnum' )
     || $self->ut_float('months_used') #actually decimal, but this will do
     || $self->ut_numbern('end_date')
-    || $self->ut_text('otaker')
+    || $self->ut_alphan('otaker')
     || $self->ut_enum('disabled', [ '', 'Y' ] )
   ;
   return $error if $error;
@@ -226,6 +226,12 @@
   }
 }
 
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data {  # class method
+  my ($class, %opts) = @_;
+  $class->_upgrade_otaker(%opts);
+}
+
 =back
 
 =head1 BUGS

Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.160
retrieving revision 1.161
diff -u -w -d -r1.160 -r1.161
--- cust_pkg.pm	26 Mar 2010 21:43:45 -0000	1.160
+++ cust_pkg.pm	29 Mar 2010 00:23:07 -0000	1.161
@@ -1,10 +1,9 @@
 package FS::cust_pkg;
 
 use strict;
-use base qw( FS::cust_main_Mixin FS::location_Mixin
-             FS::m2m_Common FS::option_Common FS::Record
-           );
-use vars qw(@ISA $disable_agentcheck $DEBUG $me);
+use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::location_Mixin
+             FS::m2m_Common FS::option_Common FS::Record );
+use vars qw($disable_agentcheck $DEBUG $me);
 use Carp qw(cluck);
 use Scalar::Util qw( blessed );
 use List::Util qw(max);
@@ -157,9 +156,9 @@
 
 date
 
-=item otaker
+=item usernum
 
-order taker (assigned automatically if null, see L<FS::UID>)
+order taker (see L<FS::access_user>)
 
 =item manual_flag
 
@@ -425,7 +424,7 @@
       : { @_ };
 
   #return "Can't (yet?) change pkgpart!" if $old->pkgpart != $new->pkgpart;
-  return "Can't change otaker!" if $old->otaker ne $new->otaker;
+  #return "Can't change otaker!" if $old->otaker ne $new->otaker;
 
   #allow this *sigh*
   #return "Can't change setup once it exists!"
@@ -565,8 +564,6 @@
   }
 
   $self->otaker(getotaker) unless $self->otaker;
-  $self->otaker =~ /^(\w{1,32})$/ or return "Illegal otaker";
-  $self->otaker($1);
 
   if ( $self->dbdef_table->column('manual_flag') ) {
     $self->manual_flag('') if $self->manual_flag eq ' ';
@@ -3127,6 +3124,12 @@
   '';
 }
 
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data {  # class method
+  my ($class, %opts) = @_;
+  $class->_upgrade_otaker(%opts);
+}
+
 =back
 
 =head1 BUGS

Index: cust_pkg_reason.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg_reason.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -d -r1.7 -r1.8
--- cust_pkg_reason.pm	15 Mar 2009 19:42:33 -0000	1.7
+++ cust_pkg_reason.pm	29 Mar 2010 00:23:07 -0000	1.8
@@ -1,11 +1,9 @@
 package FS::cust_pkg_reason;
 
 use strict;
-use vars qw( @ISA );
+use base qw( FS::otaker_Mixin FS::Record );
 use FS::Record qw( qsearch qsearchs );
 
- at ISA = qw(FS::Record);
-
 =head1 NAME
 
 FS::cust_pkg_reason - Object methods for cust_pkg_reason records
@@ -34,16 +32,17 @@
 
 =over 4
 
-=item num - primary key
+=item num
 
-=item pkgnum - 
+primary key
 
-=item reasonnum - 
+=item pkgnum
 
-=item otaker - 
+=item reasonnum
 
-=item date - 
+=item usernum
 
+=item date
 
 =back
 
@@ -99,7 +98,7 @@
     || $self->ut_number('pkgnum')
     || $self->ut_number('reasonnum')
     || $self->ut_enum('action', [ 'A', 'C', 'E', 'S' ])
-    || $self->ut_text('otaker')
+    || $self->ut_alphan('otaker')
     || $self->ut_numbern('date')
   ;
   return $error if $error;
@@ -307,8 +306,7 @@
     }
   }
 
-  '';
-
+  $class->_upgrade_otaker(%opts);
 }
 
 =back

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.202
retrieving revision 1.203
diff -u -w -d -r1.202 -r1.203
--- Schema.pm	26 Mar 2010 05:02:51 -0000	1.202
+++ Schema.pm	29 Mar 2010 00:23:07 -0000	1.203
@@ -391,7 +391,8 @@
         'attachnum', 'serial', '', '', '', '',
         'custnum',   'int', '', '', '', '',
         '_date',     @date_type, '', '',
-        'otaker',    'varchar', '', 32, '', '',
+        'otaker',    'varchar', 'NULL', 32, '', '',
+        'usernum',   'int', 'NULL', '', '', '',
         'filename',  'varchar', '', 255, '', '',
         'mime_type', 'varchar', '', $char_d, '', '',
         'title',     'varchar', 'NULL', $char_d, '', '',
@@ -400,7 +401,7 @@
       ],
       'primary_key' => 'attachnum',
       'unique'      => [],
-      'index'       => [ ['custnum'] ],
+      'index'       => [ ['custnum'], ['usernum'], ],
     },
 
     'cust_bill' => {
@@ -650,7 +651,8 @@
         'custnum',  'int', '', '', '', '', 
         '_date',    @date_type, '', '', 
         'amount',   @money_type, '', '', 
-        'otaker',   'varchar', '', 32, '', '', 
+        'otaker',   'varchar', 'NULL', 32, '', '', 
+        'usernum',   'int', 'NULL', '', '', '',
         'reason',   'text', 'NULL', '', '', '', 
         'reasonnum', 'int', 'NULL', '', '', '', 
         'addlinfo', 'text', 'NULL', '', '', '',
@@ -659,7 +661,7 @@
       ],
       'primary_key' => 'crednum',
       'unique' => [],
-      'index' => [ ['custnum'], ['_date'] ],
+      'index' => [ ['custnum'], ['_date'], ['usernum'] ],
     },
 
     'cust_credit_bill' => {
@@ -755,7 +757,8 @@
         'geocode',  'varchar', 'NULL', 20,  '', '',
         'censustract', 'varchar', 'NULL', 20,  '', '', # 7 to save space?
         'tax',      'char', 'NULL', 1, '', '', 
-        'otaker',   'varchar', '',    32, '', '', 
+        'otaker',   'varchar', 'NULL',    32, '', '', 
+        'usernum',   'int', 'NULL', '', '', '',
         'refnum',   'int',  '',     '', '', '', 
         'referral_custnum', 'int',  'NULL', '', '', '', 
         'comments', 'text', 'NULL', '', '', '', 
@@ -770,7 +773,7 @@
       'unique' => [ [ 'agentnum', 'agent_custid' ] ],
       #'index' => [ ['last'], ['company'] ],
       'index' => [
-                   [ 'agentnum' ], [ 'refnum' ], [ 'classnum' ],
+                   [ 'agentnum' ], [ 'refnum' ], [ 'classnum' ], [ 'usernum' ],
                    [ 'custbatch' ],
                    [ 'referral_custnum' ],
                    [ 'payby' ], [ 'paydate' ],
@@ -924,12 +927,13 @@
         'notenum',  'serial',  '',     '', '', '', 
         'custnum',  'int',  '',     '', '', '', 
         '_date',    @date_type, '', '', 
-        'otaker',   'varchar', '',    32, '', '', 
+        'otaker',   'varchar', 'NULL',    32, '', '', 
+        'usernum',   'int', 'NULL', '', '', '',
         'comments', 'text', 'NULL', '', '', '', 
       ],
       'primary_key' => 'notenum',
       'unique' => [],
-      'index' => [ [ 'custnum' ], [ '_date' ], ],
+      'index' => [ [ 'custnum' ], [ '_date' ], [ 'usernum' ], ],
     },
 
     'cust_category' => {
@@ -1127,7 +1131,8 @@
         'custnum',  'int',    '',   '', '', '', 
         '_date',    @date_type, '', '', 
         'paid',     @money_type, '', '', 
-        'otaker',   'varchar', 'NULL', 32, '', '',  #NULL for the upgrade so we can create & populate the field
+        'otaker',   'varchar', 'NULL', 32, '', '',
+        'usernum',   'int', 'NULL', '', '', '',
         'payby',    'char',   '',     4, '', '', # CARD/BILL/COMP, should be
                                                  # index into payby table
                                                  # eventually
@@ -1141,7 +1146,7 @@
       ],
       'primary_key' => 'paynum',
       #i guess not now, with cust_pay_pending, if we actually make it here, we _do_ want to record it# 'unique' => [ [ 'payunique' ] ],
-      'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ] ],
+      'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ], [ 'usernum' ] ],
     },
 
     'cust_pay_void' => {
@@ -1161,10 +1166,11 @@
         'void_date', @date_type, '', '', 
         'reason',    'varchar',   'NULL', $char_d, '', '', 
         'otaker',   'varchar', '', 32, '', '', 
+        'usernum',   'int', 'NULL', '', '', '',
       ],
       'primary_key' => 'paynum',
       'unique' => [],
-      'index' => [ [ 'custnum' ] ],
+      'index' => [ [ 'custnum' ], [ 'usernum' ], ],
     },
 
     'cust_bill_pay' => {
@@ -1259,7 +1265,8 @@
         'custnum',             'int',     '', '', '', '', 
         'pkgpart',             'int',     '', '', '', '', 
         'locationnum',         'int', 'NULL', '', '', '',
-        'otaker',          'varchar',     '', 32, '', '', 
+        'otaker',          'varchar', 'NULL', 32, '', '', 
+        'usernum',             'int', 'NULL', '', '', '',
         'start_date',     @date_type,             '', '', 
         'setup',          @date_type,             '', '', 
         'bill',           @date_type,             '', '', 
@@ -1278,7 +1285,7 @@
       ],
       'primary_key' => 'pkgnum',
       'unique' => [],
-      'index' => [ ['custnum'], ['pkgpart'], [ 'locationnum' ],
+      'index' => [ ['custnum'], ['pkgpart'], [ 'locationnum' ], [ 'usernum' ],
                    [ 'start_date' ], ['setup'], ['last_bill'], ['bill'],
                    ['susp'], ['adjourn'], ['expire'], ['cancel'],
                    ['change_date'],
@@ -1316,12 +1323,13 @@
         'pkgnum',   'int',    '',   '', '', '', 
         'reasonnum','int',    '',   '', '', '', 
         'action',   'char', 'NULL', 1, '', '',     #should not be nullable
-        'otaker',   'varchar', '', 32, '', '', 
+        'otaker',   'varchar', 'NULL', 32, '', '', 
+        'usernum',   'int', 'NULL', '', '', '',
         'date',     @date_type, '', '', 
       ],
       'primary_key' => 'num',
       'unique' => [],
-      'index' => [ [ 'pkgnum' ], [ 'reasonnum' ], ['action'], ],
+      'index' => [ [ 'pkgnum' ], [ 'reasonnum' ], ['action'], [ 'usernum' ], ],
     },
 
     'cust_pkg_discount' => {
@@ -1331,12 +1339,13 @@
         'discountnum',       'int', '',     '', '', '',
         'months_used',   'decimal', 'NULL', '', '', '',
         'end_date',     @date_type,             '', '',
-        'otaker',        'varchar', '',     32, '', '', 
+        'otaker',        'varchar', 'NULL', 32, '', '', 
+        'usernum',           'int', 'NULL', '', '', '',
         'disabled',         'char', 'NULL',  1, '', '', 
       ],
       'primary_key' => 'pkgdiscountnum',
       'unique' => [],
-      'index'  => [ [ 'pkgnum' ], [ 'discountnum' ] ],
+      'index'  => [ [ 'pkgnum' ], [ 'discountnum' ], [ 'usernum' ], ],
     },
 
     'cust_bill_pkg_discount' => {
@@ -1373,7 +1382,8 @@
         'custnum',  'int',    '',   '', '', '', 
         '_date',        @date_type, '', '', 
         'refund',       @money_type, '', '', 
-        'otaker',       'varchar',   '',   32, '', '', 
+        'otaker',       'varchar',   'NULL',   32, '', '', 
+        'usernum',   'int', 'NULL', '', '', '',
         'reason',       'varchar',   '',   $char_d, '', '', 
         'payby',        'char',   '',     4, '', '', # CARD/BILL/COMP, should
                                                      # be index into payby
@@ -1385,7 +1395,7 @@
       ],
       'primary_key' => 'refundnum',
       'unique' => [],
-      'index' => [ ['custnum'], ['_date'] ],
+      'index' => [ ['custnum'], ['_date'], [ 'usernum' ], ],
     },
 
     'cust_credit_refund' => {
@@ -2286,12 +2296,13 @@
         'payinfo', 'varchar',  '',     128, '', '', #say, a 512-big digest _hex encoded
 	#'paymask', 'varchar',  'NULL', $char_d, '', ''
         '_date',   @date_type, '', '', 
-        'otaker',  'varchar',  '',     32, '', '', 
+        'otaker',  'varchar',  'NULL',     32, '', '', 
+        'usernum',   'int', 'NULL', '', '', '',
         'reason',  'varchar',  'NULL', $char_d, '', '', 
       ],
       'primary_key' => 'bannum',
       'unique'      => [ [ 'payby', 'payinfo' ] ],
-      'index'       => [],
+      'index'       => [ [ 'usernum' ] ],
     },
 
     'pkg_category' => {
@@ -2537,11 +2548,12 @@
         '_password', 'varchar', '', $char_d, '', '',
         'last',      'varchar', '', $char_d, '', '', 
         'first',     'varchar', '', $char_d, '', '', 
+        'user_custnum',  'int', 'NULL',  '', '', '',
         'disabled',     'char', 'NULL',   1, '', '', 
       ],
       'primary_key' => 'usernum',
       'unique' => [ [ 'username' ] ],
-      'index'  => [],
+      'index'  => [ [ 'user_custnum' ] ],
     },
 
     'access_user_pref' => {

Index: access_user.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/access_user.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -w -d -r1.25 -r1.26
--- access_user.pm	22 Jun 2009 10:39:48 -0000	1.25
+++ access_user.pm	29 Mar 2010 00:23:07 -0000	1.26
@@ -10,6 +10,7 @@
 use FS::access_user_pref;
 use FS::access_usergroup;
 use FS::agent;
+use FS::cust_main;
 
 @ISA = qw( FS::m2m_Common FS::option_Common FS::Record );
 #@ISA = qw( FS::m2m_Common FS::option_Common );
@@ -220,6 +221,9 @@
       $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
       return $error;
     }
+  } elsif ( $old->disabled && !$new->disabled
+              && $new->_password =~ /changeme/i ) {
+    return "Must change password when enabling this account";
   }
 
   my $error = $new->SUPER::replace($old, @_);
@@ -254,6 +258,7 @@
     || $self->ut_text('_password')
     || $self->ut_text('last')
     || $self->ut_text('first')
+    || $self->ut_foreign_keyn('user_custnum', 'cust_main', 'custnum')
     || $self->ut_enum('disabled', [ '', 'Y' ] )
   ;
   return $error if $error;
@@ -272,6 +277,18 @@
   $self->get('last'). ', '. $self->first;
 }
 
+=item user_cust_main
+
+Returns the FS::cust_main object (see L<FS::cust_main>), if any, for this
+user.
+
+=cut
+
+sub user_cust_main {
+  my $self = shift;
+  qsearchs( 'cust_main', { 'custnum' => $self->user_custnum } );
+}
+
 =item access_usergroup
 
 Returns links to the the groups this user is a part of, as FS::access_usergroup

Index: cust_credit.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_credit.pm,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -w -d -r1.39 -r1.40
--- cust_credit.pm	28 Oct 2009 19:01:18 -0000	1.39
+++ cust_credit.pm	29 Mar 2010 00:23:07 -0000	1.40
@@ -1,12 +1,12 @@
 package FS::cust_credit;
 
 use strict;
-use vars qw( @ISA $conf $unsuspendauto $me $DEBUG );
+use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::Record );
+use vars qw( $conf $unsuspendauto $me $DEBUG );
 use Date::Format;
 use FS::UID qw( dbh getotaker );
 use FS::Misc qw(send_email);
 use FS::Record qw( qsearch qsearchs dbdef );
-use FS::cust_main_Mixin;
 use FS::cust_main;
 use FS::cust_pkg;
 use FS::cust_refund;
@@ -15,7 +15,6 @@
 use FS::reason_type;
 use FS::reason;
 
- at ISA = qw( FS::cust_main_Mixin FS::Record );
 $me = '[ FS::cust_credit ]';
 $DEBUG = 0;
 
@@ -76,9 +75,9 @@
 Specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
 L<Time::Local> and L<Date::Parse> for conversion functions.
 
-=item otaker
+=item usernum
 
-Order taker (assigned automatically, see L<FS::UID>)
+Order taker (see L<FS::access_user>)
 
 =item reason
 
@@ -152,7 +151,7 @@
                               );
     unless($result) {
       $dbh->rollback if $oldAutoCommit;
-      return "failed to set reason for $me: ". $dbh->errstr;
+      return "failed to set reason for $me"; #: ". $dbh->errstr;
     }
   }
 
@@ -295,7 +294,7 @@
     || $self->ut_number('custnum')
     || $self->ut_numbern('_date')
     || $self->ut_money('amount')
-    || $self->ut_alpha('otaker')
+    || $self->ut_alphan('otaker')
     || $self->ut_textn('reason')
     || $self->ut_foreign_key('reasonnum', 'reason', 'reasonnum')
     || $self->ut_textn('addlinfo')
@@ -325,6 +324,7 @@
 
 sub cust_credit_refund {
   my $self = shift;
+  map { $_ } #return $self->num_cust_credit_refund unless wantarray;
   sort { $a->_date <=> $b->_date }
     qsearch( 'cust_credit_refund', { 'crednum' => $self->crednum } )
   ;
@@ -339,6 +339,7 @@
 
 sub cust_credit_bill {
   my $self = shift;
+  map { $_ } #return $self->num_cust_credit_bill unless wantarray;
   sort { $a->_date <=> $b->_date }
     qsearch( 'cust_credit_bill', { 'crednum' => $self->crednum } )
   ;
@@ -416,7 +417,11 @@
                                   'reason' => $value,
                                   'disabled' => 'Y', 
                               } );
-      $reason->insert and $reason = undef;
+      my $error = $reason->insert;
+      if ( $error ) {
+        warn "error inserting reason: $error\n";
+        $reason = undef;
+      }
     }
 
     $self->reasonnum($reason ? $reason->reasonnum : '') ;
@@ -541,7 +546,7 @@
     }
   }
 
-  '';
+  $class->_upgrade_otaker(%opts);
 
 }
 

Index: banned_pay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/banned_pay.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- banned_pay.pm	27 Aug 2005 08:46:57 -0000	1.1
+++ banned_pay.pm	29 Mar 2010 00:23:07 -0000	1.2
@@ -1,12 +1,10 @@
 package FS::banned_pay;
 
 use strict;
-use vars qw( @ISA );
+use base qw( FS::otaker_Mixin FS::Record );
 use FS::Record qw( qsearch qsearchs );
 use FS::UID qw( getotaker );
 
- at ISA = qw(FS::Record);
-
 =head1 NAME
 
 FS::banned_pay - Object methods for banned_pay records
@@ -117,11 +115,17 @@
 
   $self->_date(time) unless $self->_date;
 
-  $self->otaker(getotaker);
+  $self->otaker(getotaker) unless $self->otaker;
 
   $self->SUPER::check;
 }
 
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data {  # class method
+  my ($class, %opts) = @_;
+  $class->_upgrade_otaker(%opts);
+}
+
 =back
 
 =head1 BUGS

Index: cust_pay_void.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pay_void.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -d -r1.7 -r1.8
--- cust_pay_void.pm	30 Jul 2009 06:42:31 -0000	1.7
+++ cust_pay_void.pm	29 Mar 2010 00:23:07 -0000	1.8
@@ -1,6 +1,8 @@
 package FS::cust_pay_void; 
+
 use strict;
-use vars qw( @ISA @encrypted_fields );
+use base qw( FS::otaker_Mixin FS::payinfo_Mixin FS::Record );
+use vars qw( @encrypted_fields );
 use Business::CreditCard;
 use FS::UID qw(getotaker);
 use FS::Record qw(qsearchs dbh fields); # qsearch );
@@ -11,8 +13,6 @@
 #use FS::cust_main;
 use FS::cust_pkg;
 
- at ISA = qw( FS::Record FS::payinfo_Mixin );
-
 @encrypted_fields = ('payinfo');
 
 =head1 NAME
@@ -58,6 +58,10 @@
 specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
 L<Time::Local> and L<Date::Parse> for conversion functions.
 
+=item otaker
+
+order taker (see L<FS::access_user>)
+
 =item payby
 
 `CARD' (credit cards), `CHEK' (electronic check/ACH),
@@ -215,7 +219,7 @@
     return $error if $error;
   }
 
-  $self->otaker(getotaker);
+  $self->otaker(getotaker) unless $self->otaker;
 
   $self->SUPER::check;
 }
@@ -231,6 +235,12 @@
   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
 }
 
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data {  # class method
+  my ($class, %opts) = @_;
+  $class->_upgrade_otaker(%opts);
+}
+
 =back
 
 =head1 BUGS

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.499
retrieving revision 1.500
diff -u -w -d -r1.499 -r1.500
--- cust_main.pm	18 Mar 2010 07:59:51 -0000	1.499
+++ cust_main.pm	29 Mar 2010 00:23:07 -0000	1.500
@@ -2,7 +2,8 @@
 
 require 5.006;
 use strict;
-use vars qw( @ISA @EXPORT_OK $DEBUG $me $conf
+use base qw( FS::otaker_Mixin FS::payinfo_Mixin FS::Record );
+use vars qw( @EXPORT_OK $DEBUG $me $conf
              @encrypted_fields
              $import $ignore_expired_card
              $skip_fuzzyfiles @fuzzyfields
@@ -25,7 +26,7 @@
 use Business::CreditCard 0.28;
 use Locale::Country;
 use FS::UID qw( getotaker dbh driver_name );
-use FS::Record qw( qsearchs qsearch dbdef );
+use FS::Record qw( qsearchs qsearch dbdef regexp_sql );
 use FS::Misc qw( generate_email send_email generate_ps do_print );
 use FS::Msgcat qw(gettext);
 use FS::payby;
@@ -66,11 +67,8 @@
 use FS::payment_gateway;
 use FS::agent_payment_gateway;
 use FS::banned_pay;
-use FS::payinfo_Mixin;
 use FS::TicketSystem;
 
- at ISA = qw( FS::payinfo_Mixin FS::Record );
-
 @EXPORT_OK = qw( smart_search );
 
 $realtime_bop_decline_quiet = 0;
@@ -304,9 +302,9 @@
 
 Tax exempt, empty or `Y'
 
-=item otaker
+=item usernum
 
-Order taker (assigned automatically, see L<FS::UID>)
+Order taker (see L<FS::access_user>)
 
 =item comments
 
@@ -9710,14 +9708,7 @@
   
   my $agentnum = $self->agentnum;
 
-  my $regexp = '';
-  if ( driver_name =~ /^Pg/i ) {
-    $regexp = '~';
-  } elsif ( driver_name =~ /^mysql/i ) {
-    $regexp = 'REGEXP';
-  } else {
-    die "don't know how to use regular expressions in ". driver_name. " databases";
-  }
+  my $regexp = regexp_sql();
 
   my $part_event_option =
     qsearchs({
@@ -9783,6 +9774,8 @@
   my $sth = dbh->prepare($sql) or die dbh->errstr;
   $sth->execute or die $sth->errstr;
 
+  $class->_upgrade_otaker(%opts);
+
 }
 
 =back



More information about the freeside-commits mailing list