From: Irina Todeva Date: Mon, 28 Sep 2015 19:48:20 +0000 (-0600) Subject: Changes to add classified reasons for payment void X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=55c7e3cc18a45620f48ae62d3bc044a830bd8c95 Changes to add classified reasons for payment void - 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 --- diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 447302b36..c9ab5bcc5 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -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' ], diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index d9ae0d39e..4d06862d6 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -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; ## diff --git a/FS/FS/cust_pay_void.pm b/FS/FS/cust_pay_void.pm index b2f777b32..8fd539616 100644 --- a/FS/FS/cust_pay_void.pm +++ b/FS/FS/cust_pay_void.pm @@ -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) =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) 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; diff --git a/httemplate/view/cust_main/payment_history/voided_payment.html b/httemplate/view/cust_main/payment_history/voided_payment.html index 5c43c91e5..e295f9b3b 100644 --- a/httemplate/view/cust_main/payment_history/voided_payment.html +++ b/httemplate/view/cust_main/payment_history/voided_payment.html @@ -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 %>