[freeside-commits] freeside/FS/FS cust_pay.pm, 1.57, 1.58 Schema.pm, 1.78, 1.79 Upgrade.pm, 1.3, 1.4

Ivan,,, ivan at wavetail.420.am
Wed Feb 13 19:52:38 PST 2008


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

Modified Files:
	cust_pay.pm Schema.pm Upgrade.pm 
Log Message:
add cust_pay.otaker field; populate it based on history on upgrades, and show the order taker on all payments (on customer view and payment search)  closes: #2953

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- Schema.pm	20 Jan 2008 23:24:54 -0000	1.78
+++ Schema.pm	14 Feb 2008 03:52:36 -0000	1.79
@@ -695,8 +695,9 @@
       'columns' => [
         'paynum',   'serial',    '',   '', '', '',
         'custnum',  'int',    '',   '', '', '', 
-        'paid',     @money_type, '', '', 
         '_date',    @date_type, '', '', 
+        'paid',     @money_type, '', '', 
+        'otaker',   'varchar', 'NULL', 32, '', '',  #NULL for the upgrade so we can create & populate the field
         'payby',    'char',   '',     4, '', '', # CARD/BILL/COMP, should be
                                                  # index into payby table
                                                  # eventually

Index: cust_pay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pay.pm,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- cust_pay.pm	25 Jan 2008 18:29:04 -0000	1.57
+++ cust_pay.pm	14 Feb 2008 03:52:36 -0000	1.58
@@ -1,11 +1,14 @@
 package FS::cust_pay;
 
 use strict;
-use vars qw( @ISA $conf $unsuspendauto $ignore_noapply @encrypted_fields );
+use vars qw( @ISA $DEBUG $me $conf @encrypted_fields
+             $unsuspendauto $ignore_noapply 
+           );
 use Date::Format;
 use Business::CreditCard;
 use Text::Template;
-use FS::Misc qw(send_email);
+use FS::UID qw( getotaker );
+use FS::Misc qw( send_email );
 use FS::Record qw( dbh qsearch qsearchs );
 use FS::payby;
 use FS::cust_main_Mixin;
@@ -18,6 +21,10 @@
 
 @ISA = qw(FS::Record FS::cust_main_Mixin FS::payinfo_Mixin  );
 
+$DEBUG = 0;
+
+$me = '[FS::cust_pay]';
+
 $ignore_noapply = 0;
 
 #ask FS::UID to run this stuff for us later
@@ -59,11 +66,13 @@
 
 =item custnum - customer (see L<FS::cust_main>)
 
-=item paid - Amount of this payment
-
 =item _date - specified as a UNIX timestamp; see L<perlfunc/"time">.  Also see
 L<Time::Local> and L<Date::Parse> for conversion functions.
 
+=item paid - Amount of this payment
+
+=item otaker - order taker (assigned automatically, see L<FS::UID>)
+
 =item payby - Payment Type (See L<FS::payinfo_Mixin> for valid payby values)
 
 =item payinfo - Payment Information (See L<FS::payinfo_Mixin> for data format)
@@ -389,11 +398,14 @@
 sub check {
   my $self = shift;
 
+  $self->otaker(getotaker) unless ($self->otaker);
+
   my $error =
     $self->ut_numbern('paynum')
     || $self->ut_numbern('custnum')
-    || $self->ut_money('paid')
     || $self->ut_numbern('_date')
+    || $self->ut_money('paid')
+    || $self->ut_alpha('otaker')
     || $self->ut_textn('paybatch')
     || $self->ut_textn('payunique')
     || $self->ut_enum('closed', [ '', 'Y' ])
@@ -420,6 +432,8 @@
 #           " already exists";
 #  }
 
+  $self->otaker(getotaker);
+
   $self->SUPER::check;
 }
 
@@ -648,6 +662,56 @@
 
 }
 
+# _upgrade_data
+#
+# Used by FS::Upgrade to migrate to a new database.
+
+use FS::h_cust_pay;
+
+sub _upgrade_data {  #class method
+  my ($class, %opts) = @_;
+
+  warn "$me upgrading $class\n" if $DEBUG;
+
+  #not the most efficient, but hey, it only has to run once
+
+  my $count_sql =
+    "SELECT COUNT(*) FROM cust_pay WHERE otaker IS NULL OR otaker = ''";
+
+  my $sth = dbh->prepare($count_sql) or die dbh->errstr;
+  $sth->execute or die $sth->errstr;
+  my $total = $sth->fetchrow_arrayref->[0];
+
+  local($DEBUG) = 2 if $total > 1000; #could be a while, force progress info
+
+  my $count = 0;
+  my $lastprog = 0;
+  while (1) {
+
+    my $cust_pay = qsearchs( {
+      'table'     => 'cust_pay',
+      'hashref'   => {},
+      'extra_sql' => "WHERE otaker IS NULL OR otaker = ''",
+      'order_by'  => 'ORDER BY paynum LIMIT 1',
+    } );
+
+    return unless $cust_pay;
+
+    my $h_cust_pay = $cust_pay->h_search('insert');
+    $cust_pay->otaker($h_cust_pay->history_user);
+    my $error = $cust_pay->replace;
+    die $error if $error;
+
+    $count++;
+    if ( $DEBUG > 1 && $lastprog + 30 < time ) {
+      warn "$me $count/$total (". sprintf('%.2f',100*$count/$total). '%)'. "\n";
+      $lastprog = time;
+    }
+
+  }
+
+}
+
 =back
 
 =head1 SUBROUTINES

Index: Upgrade.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Upgrade.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Upgrade.pm	11 Feb 2008 02:36:52 -0000	1.3
+++ Upgrade.pm	14 Feb 2008 03:52:36 -0000	1.4
@@ -84,8 +84,10 @@
     'cust_credit' => [],
 
     #duplicate history records
-    'h_cust_svc' => [],
+    'h_cust_svc'  => [],
 
+    #populate cust_pay.otaker
+    'cust_pay'    => [],
   ;
 
   \%hash;



More information about the freeside-commits mailing list