diff options
author | Mark Wells <mark@freeside.biz> | 2014-02-27 17:06:41 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-02-27 17:06:41 -0800 |
commit | beff2bed3d06a91072427a15efef08b24c7cc8df (patch) | |
tree | 766f67c17b70af25083bbebdfc9ea549d8ce5247 | |
parent | 07644a5463751fdaeb0dcd9cc3caf2d19eb877df (diff) |
fix payment voiding, fallout from #13971
-rw-r--r-- | FS/FS/Schema.pm | 5 | ||||
-rw-r--r-- | FS/FS/cust_pay.pm | 13 | ||||
-rw-r--r-- | FS/FS/cust_pay_pending.pm | 5 | ||||
-rw-r--r-- | FS/FS/cust_pay_void.pm | 12 |
4 files changed, 27 insertions, 8 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 295ddbd..321fb3f 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 63d7c48..0f643c9 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 f5de73d..63274b1 100644 --- a/FS/FS/cust_pay_pending.pm +++ b/FS/FS/cust_pay_pending.pm @@ -135,6 +135,10 @@ L<FS::payment_gateway> id. Payment number (L<FS::cust_pay>) of the completed payment. +=item void_paynum + +Payment number of the payment if it's been voided. + =item invnum Invoice number (L<FS::cust_bill>) 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 55b6c67..b2f777b 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; |