From: Irina Todeva Date: Wed, 30 Sep 2015 20:35:07 +0000 (-0600) Subject: Changes to add classified reasons for invoice void X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=6d34c5060a4e5e9338ebc0d04459861a5c45e812 Changes to add classified reasons for invoice void - Added reasonnum and a corresponding foreign key in cust_bill_void and cust_bill_pkg_void tables (Schema.pm) - Used the FS::reason_Mixin::reason as the override of the cust_bill_void->reason to handle legacy and classified reasons - Changes in voided_invoice.html template to handle classified reasons for void invoices --- diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index c9ab5bcc5..6b5d6586c 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -735,8 +735,9 @@ sub tables_hashref { #void fields 'void_date', @date_type, '', '', - 'reason', 'varchar', 'NULL', $char_d, '', '', - 'void_usernum', 'int', 'NULL', '', '', '', + 'reason', 'varchar', 'NULL', $char_d, '', '', + 'reasonnum', 'int', 'NULL', '', '', '', + 'void_usernum', 'int', 'NULL', '', '', '', ], 'primary_key' => 'invnum', 'unique' => [ [ 'custnum', 'agent_invid' ] ], #agentnum? huh @@ -750,6 +751,9 @@ sub tables_hashref { { columns => [ 'statementnum' ], table => 'cust_statement', #_void? both? }, + { columns => [ 'reasonnum' ], + table => 'reason', + }, { columns => [ 'void_usernum' ], table => 'access_user', references => [ 'usernum' ], @@ -1197,8 +1201,9 @@ sub tables_hashref { 'feepart', 'int', 'NULL', '', '', '', #void fields 'void_date', @date_type, '', '', - 'reason', 'varchar', 'NULL', $char_d, '', '', - 'void_usernum', 'int', 'NULL', '', '', '', + 'reason', 'varchar', 'NULL', $char_d, '', '', + 'reasonnum', 'int', 'NULL', '', '', '', + 'void_usernum', 'int', 'NULL', '', '', '', ], 'primary_key' => 'billpkgnum', 'unique' => [], @@ -1209,6 +1214,9 @@ sub tables_hashref { { columns => [ 'invnum' ], table => 'cust_bill_void', }, + { columns => [ 'reasonnum' ], + table => 'reason', + }, #pkgnum 0 and -1 are used for special things #{ columns => [ 'pkgnum' ], # table => 'cust_pkg', diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 6546bfa95..138d0fab8 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -37,6 +37,8 @@ use FS::cust_bill_pay_pkg; use FS::cust_credit_bill_pkg; use FS::discount_plan; use FS::cust_bill_void; +use FS::reason; +use FS::reason_type; use FS::L10N; $DEBUG = 0; @@ -212,7 +214,7 @@ sub insert { } -=item void +=item void [ REASON ] Voids this invoice: deletes the invoice and adds a record of the voided invoice to the FS::cust_bill_void table (and related tables starting from @@ -224,6 +226,14 @@ sub void { my $self = shift; my $reason = scalar(@_) ? shift : ''; + unless (ref($reason) || !$reason) { + $reason = FS::reason->new_or_existing( + 'class' => 'X', + 'type' => 'Void invoice', + 'reason' => $reason + ); + } + local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; local $SIG{QUIT} = 'IGNORE'; @@ -238,7 +248,7 @@ sub void { my $cust_bill_void = new FS::cust_bill_void ( { map { $_ => $self->get($_) } $self->fields } ); - $cust_bill_void->reason($reason); + $cust_bill_void->reasonnum($reason->reasonnum) if $reason; my $error = $cust_bill_void->insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 5861ee47f..aea776a80 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -26,6 +26,8 @@ use FS::cust_bill_pkg_tax_location_void; use FS::cust_bill_pkg_tax_rate_location_void; use FS::cust_tax_exempt_pkg_void; use FS::cust_bill_pkg_fee_void; +use FS::reason; +use FS::reason_type; use FS::Cursor; @@ -322,7 +324,7 @@ sub insert { } -=item void +=item void [ REASON ] Voids this line item: deletes the line item and adds a record of the voided line item to the FS::cust_bill_pkg_void table (and related tables). @@ -333,6 +335,14 @@ sub void { my $self = shift; my $reason = scalar(@_) ? shift : ''; + unless (ref($reason) || !$reason) { + $reason = FS::reason->new_or_existing( + 'class' => 'X', + 'type' => 'Void invoice', + 'reason' => $reason + ); + } + local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; local $SIG{QUIT} = 'IGNORE'; @@ -347,7 +357,7 @@ sub void { my $cust_bill_pkg_void = new FS::cust_bill_pkg_void ( { map { $_ => $self->get($_) } $self->fields } ); - $cust_bill_pkg_void->reason($reason); + $cust_bill_pkg_void->reasonnum($reason->reasonnum) if $reason; my $error = $cust_bill_pkg_void->insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; diff --git a/FS/FS/cust_bill_pkg_void.pm b/FS/FS/cust_bill_pkg_void.pm index 080452e19..4b9cffd4e 100644 --- a/FS/FS/cust_bill_pkg_void.pm +++ b/FS/FS/cust_bill_pkg_void.pm @@ -1,5 +1,5 @@ package FS::cust_bill_pkg_void; -use base qw( FS::TemplateItem_Mixin FS::Record ); +use base qw( FS::TemplateItem_Mixin FS::reason_Mixin FS::Record ); use strict; use FS::Record qw( qsearch qsearchs dbh fields ); @@ -104,6 +104,13 @@ unitrecur hidden +=item reason + +freeform string (deprecated) + +=item reasonnum + +reason for voiding the payment (see L) =back @@ -134,6 +141,10 @@ sub discount_table { 'cust_bill_pkg_discount_void'; } Adds this record to the database. If there is an error, returns the error, otherwise returns false. +=item reason + +Returns the text of the associated void reason (see L) for this. + =item unvoid "Un-void"s this line item: Deletes the voided line item from the database and @@ -242,6 +253,8 @@ sub check { || $self->ut_moneyn('unitrecur') || $self->ut_enum('hidden', [ '', 'Y' ]) || $self->ut_numbern('feepart') + || $self->ut_textn('reason') + || $self->ut_foreign_keyn('reasonnum', 'reason', 'reasonnum') ; return $error if $error; diff --git a/FS/FS/cust_bill_void.pm b/FS/FS/cust_bill_void.pm index f3dba9081..04c69d4bb 100644 --- a/FS/FS/cust_bill_void.pm +++ b/FS/FS/cust_bill_void.pm @@ -1,5 +1,6 @@ package FS::cust_bill_void; -use base qw( FS::Template_Mixin FS::cust_main_Mixin FS::otaker_Mixin FS::Record ); +use base qw( FS::Template_Mixin FS::cust_main_Mixin FS::otaker_Mixin + FS::reason_Mixin FS::Record ); use strict; use FS::Record qw( qsearch qsearchs dbh fields ); @@ -82,9 +83,13 @@ promised_date void_date -=item reason +=item reason + +freeform string (deprecated) + +=item reasonnum -reason +reason for voiding the payment (see L) =item void_usernum @@ -216,6 +221,7 @@ sub check { || $self->ut_numbern('void_date') || $self->ut_textn('reason') || $self->ut_numbern('void_usernum') + || $self->ut_foreign_keyn('reasonnum', 'reason', 'reasonnum') ; return $error if $error; @@ -259,6 +265,10 @@ sub void_access_user { =item cust_bill_pkg +=item reason + +Returns the text of the associated void reason (see L) for this. + =cut sub cust_bill_pkg { #actually cust_bill_pkg_void objects diff --git a/httemplate/view/cust_main/payment_history/voided_invoice.html b/httemplate/view/cust_main/payment_history/voided_invoice.html index ea61f8446..ff4d12f58 100644 --- a/httemplate/view/cust_main/payment_history/voided_invoice.html +++ b/httemplate/view/cust_main/payment_history/voided_invoice.html @@ -6,7 +6,7 @@ % } % my $reason = $cust_bill_void->reason; % if ($reason) { - (<% $reason %>) + (<% $reason |h %>) % } <% mt("on [_1]", time2str($date_format, $cust_bill_void->void_date) ) |h %>