From: Mark Wells Date: Fri, 28 Feb 2014 01:06:41 +0000 (-0800) Subject: fix payment voiding, fallout from #13971 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=beff2bed3d06a91072427a15efef08b24c7cc8df fix payment voiding, fallout from #13971 --- diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 295ddbdec..321fb3f07 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2235,6 +2235,7 @@ sub tables_hashref { 'gatewaynum', 'int', 'NULL', '', '', '', #'cust_balance', @money_type, '', '', 'paynum', 'int', 'NULL', '', '', '', + 'void_paynum', 'int', 'NULL', '', '', '', 'jobnum', 'bigint', 'NULL', '', '', '', 'invnum', 'int', 'NULL', '', '', '', 'manual', 'char', 'NULL', 1, '', '', @@ -2257,6 +2258,10 @@ sub tables_hashref { { columns => [ 'paynum' ], table => 'cust_pay', }, + { columns => [ 'void_paynum' ], + table => 'cust_pay_void', + references => [ 'paynum' ], + }, { columns => [ 'jobnum' ], table => 'queue', }, diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 63d7c4835..0f643c9ae 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -414,12 +414,17 @@ sub void { } ); $cust_pay_void->reason(shift) if scalar(@_); my $error = $cust_pay_void->insert; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; + + my $cust_pay_pending = + qsearchs('cust_pay_pending', { paynum => $self->paynum }); + if ( $cust_pay_pending ) { + $cust_pay_pending->set('void_paynum', $self->paynum); + $cust_pay_pending->set('paynum', ''); + $error ||= $cust_pay_pending->replace; } - $error = $self->delete; + $error ||= $self->delete; + if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; diff --git a/FS/FS/cust_pay_pending.pm b/FS/FS/cust_pay_pending.pm index f5de73dbe..63274b184 100644 --- a/FS/FS/cust_pay_pending.pm +++ b/FS/FS/cust_pay_pending.pm @@ -135,6 +135,10 @@ L id. Payment number (L) of the completed payment. +=item void_paynum + +Payment number of the payment if it's been voided. + =item invnum Invoice number (L) to try to apply this payment to. @@ -224,6 +228,7 @@ sub check { || $self->ut_foreign_keyn('paynum', 'cust_pay', 'paynum' ) || $self->ut_foreign_keyn('pkgnum', 'cust_pkg', 'pkgnum') || $self->ut_foreign_keyn('invnum', 'cust_bill', 'invnum') + || $self->ut_foreign_keyn('void_paynum', 'cust_pay_void', 'paynum' ) || $self->ut_flag('manual') || $self->ut_numbern('discount_term') || $self->payinfo_check() #payby/payinfo/paymask/paydate diff --git a/FS/FS/cust_pay_void.pm b/FS/FS/cust_pay_void.pm index 55b6c6743..b2f777b32 100644 --- a/FS/FS/cust_pay_void.pm +++ b/FS/FS/cust_pay_void.pm @@ -133,12 +133,16 @@ sub unvoid { map { $_ => $self->get($_) } fields('cust_pay') } ); my $error = $cust_pay->insert; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; + + my $cust_pay_pending = + qsearchs('cust_pay_pending', { void_paynum => $self->paynum }); + if ( $cust_pay_pending ) { + $cust_pay_pending->set('paynum', $cust_pay->paynum); + $cust_pay_pending->set('void_paynum', ''); + $error ||= $cust_pay_pending->replace; } - $error = $self->delete; + $error ||= $self->delete; if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error;