summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIrina Todeva <itodeva@hostgator.com>2015-09-28 13:48:20 -0600
committerMark Wells <mark@freeside.biz>2015-11-03 12:28:13 -0800
commit55c7e3cc18a45620f48ae62d3bc044a830bd8c95 (patch)
treeada1a14fc07a00421d1693b845fb673bff7d619f
parenta87e91ee19d14a6fc3da62f4b44a9628d32bb6a3 (diff)
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
-rw-r--r--FS/FS/Schema.pm4
-rw-r--r--FS/FS/cust_pay.pm19
-rw-r--r--FS/FS/cust_pay_void.pm15
-rw-r--r--httemplate/view/cust_main/payment_history/voided_payment.html2
4 files changed, 34 insertions, 6 deletions
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<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;
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 %>
</I>