display both original usernum and void usernum vfor voided payments, RT#10280
authorivan <ivan>
Fri, 22 Oct 2010 06:14:24 +0000 (06:14 +0000)
committerivan <ivan>
Fri, 22 Oct 2010 06:14:24 +0000 (06:14 +0000)
FS/FS/Schema.pm
FS/FS/cust_pay_void.pm
httemplate/view/cust_main/payment_history/voided_payment.html

index a4c12aa..1838036 100644 (file)
@@ -1194,10 +1194,11 @@ sub tables_hashref {
         'reason',    'varchar',   'NULL', $char_d, '', '', 
         'otaker',   'varchar', 'NULL', 32, '', '', 
         'usernum',   'int', 'NULL', '', '', '',
+        'void_usernum',   'int', 'NULL', '', '', '',
       ],
       'primary_key' => 'paynum',
       'unique' => [],
-      'index' => [ [ 'custnum' ], [ 'usernum' ], ],
+      'index' => [ [ 'custnum' ], [ 'usernum' ], [ 'void_usernum' ] ],
     },
 
     'cust_bill_pay' => {
@@ -2969,7 +2970,18 @@ sub tables_hashref {
       'index'       => [ ['agentnum'], ]
     },
 
-
+    'svc_cert' => {
+      'columns' => [
+        'svcnum',            'int',     '',            '', '', '', 
+        'recnum',   'int',      '',  '', '', '', 
+        'something', 'text', '', '', '', '',
+        #XXX more fields
+      ],
+      'primary_key' => 'svcnum',
+      'unique' => [],
+      'index'  => [], #recnum
+    },
+   
 
     # name type nullability length default local
 
index 45287a4..1a298ba 100644 (file)
@@ -1,12 +1,14 @@
 package FS::cust_pay_void; 
 
 use strict;
-use base qw( FS::otaker_Mixin FS::payinfo_Mixin FS::Record );
+use base qw( FS::otaker_Mixin FS::payinfo_Mixin FS::cust_main_Mixin
+             FS::Record );
 use vars qw( @encrypted_fields $otaker_upgrade_kludge );
 use Business::CreditCard;
 use FS::UID qw(getotaker);
-use FS::Record qw(qsearchs dbh fields); # qsearch );
+use FS::Record qw(qsearch qsearchs dbh fields);
 use FS::CurrentUser;
+use FS::access_user;
 use FS::cust_pay;
 #use FS::cust_bill;
 #use FS::cust_bill_pay;
@@ -219,7 +221,8 @@ sub check {
     return $error if $error;
   }
 
-  $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum;
+  $self->void_usernum($FS::CurrentUser::CurrentUser->usernum)
+    unless $self->void_usernum;
 
   $self->SUPER::check;
 }
@@ -235,11 +238,41 @@ sub cust_main {
   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
 }
 
+=item void_access_user
+
+Returns the voiding employee object (see L<FS::access_user>).
+
+=cut
+
+sub void_access_user {
+  my $self = shift;
+  qsearchs('access_user', { 'usernum' => $self->void_usernum } );
+}
+
 # Used by FS::Upgrade to migrate to a new database.
 sub _upgrade_data {  # class method
   my ($class, %opts) = @_;
+
+  my $sql = "SELECT usernum FROM access_user WHERE username = ( SELECT history_user FROM h_cust_pay_void WHERE paynum = ? AND history_action = 'insert' ) ";
+  my $sth = dbh->prepare($sql) or die dbh->errstr;
+
+  foreach my $cust_pay_void (qsearch('cust_pay_void', {'void_usernum' => ''})) {
+    $sth->execute($cust_pay_void->paynum) or die $sth->errstr;
+    my $usernum = $sth->fetchrow_arrayref->[0] or next;
+    if ( $usernum ) {
+      $cust_pay_void->void_usernum($usernum);
+      my $error = $cust_pay_void->replace;
+      die $error if $error;
+    } else {
+      warn "cust_pay_void upgrade: can't find access_user record for ". $cust_pay_void->paynum. "\n";
+    }
+  }
+
   local($otaker_upgrade_kludge) = 1;
   $class->_upgrade_otaker(%opts);
+
+  #XXX look for the h_cust_pay delete records and when that's a different
+  # usernum, set usernum
 }
 
 =back
index be68ff0..5d7f60c 100644 (file)
@@ -1,6 +1,10 @@
-<DEL>Payment <% $info %></DEL>
+<DEL>Payment <% $info %> by <% $cust_pay_void->otaker %></DEL>
 <I>voided <% time2str($date_format, $cust_pay_void->void_date) %>
-by <% $cust_pay_void->otaker %></I><% $unvoid %>
+% my $void_user = $cust_pay_void->void_access_user;
+% if ($void_user) {
+    by <% $void_user->username %></I>
+% }
+<% $unvoid %>
 <%init>
 
 my( $cust_pay_void, %opt ) = @_;