Changes to add classified reasons for payment void
authorIrina Todeva <itodeva@hostgator.com>
Mon, 28 Sep 2015 19:48:20 +0000 (13:48 -0600)
committerMark Wells <mark@freeside.biz>
Tue, 3 Nov 2015 20:28:13 +0000 (12:28 -0800)
 - Added reasonnum in cust_pay_void and a foreign key in Schema.pm
 - Added an override of the cust_pay_void_reason to handle legacy and
   classified reasons
 - Added usage of FS::reason_Mixin::_upgrade_reasonnum in
   cust_pay->_upgrade_data
 - Changes in voided_payment.html template to handle classified reasons for
   void payemnts

FS/FS/Schema.pm
FS/FS/cust_pay.pm
FS/FS/cust_pay_void.pm
httemplate/view/cust_main/payment_history/voided_payment.html

index 447302b..c9ab5bc 100644 (file)
@@ -2523,6 +2523,7 @@ sub tables_hashref {
         #void fields
         'void_date',  @date_type,                  '', '', 
         'reason',      'varchar', 'NULL', $char_d, '', '', 
+        'reasonnum',       'int', 'NULL',      '', '', '', 
         'void_usernum',    'int', 'NULL',      '', '', '',
       ],
       'primary_key'  => 'paynum',
@@ -2544,6 +2545,9 @@ sub tables_hashref {
                           { columns    => [ 'gatewaynum' ],
                             table      => 'payment_gateway',
                           },
+                          { columns    => [ 'reasonnum' ],
+                            table      => 'reason',
+                          },
                           { columns    => [ 'void_usernum' ],
                             table      => 'access_user',
                             references => [ 'usernum' ],
index d9ae0d3..4d06862 100644 (file)
@@ -2,9 +2,9 @@ package FS::cust_pay;
 
 use strict;
 use base qw( FS::otaker_Mixin FS::payinfo_transaction_Mixin FS::cust_main_Mixin
-             FS::Record );
+             FS::reason_Mixin FS::Record);
 use vars qw( $DEBUG $me $conf @encrypted_fields
-             $unsuspendauto $ignore_noapply 
+             $unsuspendauto $ignore_noapply
            );
 use Date::Format;
 use Business::CreditCard;
@@ -24,6 +24,8 @@ use FS::cust_pkg;
 use FS::cust_pay_void;
 use FS::upgrade_journal;
 use FS::Cursor;
+use FS::reason;
+use FS::reason_type;
 
 $DEBUG = 0;
 
@@ -438,6 +440,15 @@ adds a record of the voided payment to the FS::cust_pay_void table.
 
 sub void {
   my $self = shift;
+  my $reason = shift;
+
+  unless (ref($reason) || !$reason) {
+    $reason = FS::reason->new_or_existing(
+      'class'  => 'X',
+      'type'   => 'Void payment',
+      'reason' => $reason
+    );
+  }
 
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
@@ -453,7 +464,7 @@ sub void {
   my $cust_pay_void = new FS::cust_pay_void ( {
     map { $_ => $self->get($_) } $self->fields
   } );
-  $cust_pay_void->reason(shift) if scalar(@_);
+  $cust_pay_void->reasonnum($reason->reasonnum) if $reason;
   my $error = $cust_pay_void->insert;
 
   my $cust_pay_pending =
@@ -1023,6 +1034,8 @@ sub _upgrade_data {  #class method
 
   warn "$me upgrading $class\n" if $DEBUG;
 
+  $class->_upgrade_reasonnum(%opt);
+
   local $FS::payinfo_Mixin::ignore_masked_payinfo = 1;
 
   ##
index b2f777b..8fd5396 100644 (file)
@@ -1,6 +1,6 @@
 package FS::cust_pay_void; 
 use base qw( FS::otaker_Mixin FS::payinfo_transaction_Mixin FS::cust_main_Mixin
-             FS::Record );
+             FS::reason_Mixin FS::Record );
 
 use strict;
 use vars qw( @encrypted_fields $otaker_upgrade_kludge );
@@ -88,7 +88,9 @@ Desired pkgnum when using experimental package balances.
 
 =item void_date
 
-=item reason
+=item reason - a freeform string (deprecated)
+
+=item reasonnum - Reason for voiding the payment (see L<FS::reson>)
 
 =back
 
@@ -189,6 +191,7 @@ sub check {
     || $self->ut_numbern('void_date')
     || $self->ut_textn('reason')
     || $self->payinfo_check
+    || $self->ut_foreign_keyn('reasonnum', 'reason', 'reasonnum')
   ;
   return $error if $error;
 
@@ -221,10 +224,18 @@ sub void_access_user {
   qsearchs('access_user', { 'usernum' => $self->void_usernum } );
 }
 
+=item reason
+
+Returns the text of the associated void reason (see L<FS::reason>) for this.
+
+=cut
+
 # Used by FS::Upgrade to migrate to a new database.
 sub _upgrade_data {  # class method
   my ($class, %opts) = @_;
 
+  $class->_upgrade_reasonnum(%opts);
+
   my $sql = "SELECT usernum FROM access_user WHERE username = ( SELECT history_user FROM h_cust_pay_void WHERE paynum = ? AND history_action = 'insert' ORDER BY history_date LIMIT 1 ) ";
   my $sth = dbh->prepare($sql) or die dbh->errstr;
 
index 5c43c91..e295f9b 100644 (file)
@@ -6,7 +6,7 @@
 % }
 % my $reason = $cust_pay_void->reason;
 % if ($reason) {
-     (<% $reason %>)
+     (<% $reason |h %>)
 % }
 <% mt("on [_1]", time2str($date_format, $cust_pay_void->void_date) ) |h %> 
 </I>