[freeside-commits] branch FREESIDE_3_BRANCH updated. 8b8ebd929229c8376bb81076071c5e76d2baa0ee
Mark Wells
mark at 420.am
Wed Apr 23 11:22:52 PDT 2014
The branch, FREESIDE_3_BRANCH has been updated
via 8b8ebd929229c8376bb81076071c5e76d2baa0ee (commit)
from 980c48cf66eebdf43fa4238aed16fdaa583cdcb2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 8b8ebd929229c8376bb81076071c5e76d2baa0ee
Author: Mark Wells <mark at freeside.biz>
Date: Wed Apr 23 11:16:55 2014 -0700
fix foreign keys to voided payments in advance of 4.x upgrade, #13971
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index f225658..f97495d 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1645,6 +1645,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, '', '',
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index d36bae6..3cdbdb3 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -416,12 +416,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 22c9293..b61635d 100644
--- a/FS/FS/cust_pay_pending.pm
+++ b/FS/FS/cust_pay_pending.pm
@@ -133,6 +133,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.
@@ -221,6 +225,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
@@ -459,6 +464,20 @@ sub _upgrade_data { #class method
my $sth = dbh->prepare($sql) or die dbh->errstr;
$sth->execute or die $sth->errstr;
+ # For cust_pay_pending records linked to voided payments, move the paynum
+ # to void_paynum.
+ $sql =
+ "UPDATE cust_pay_pending SET void_paynum = paynum, paynum = NULL
+ WHERE paynum IS NOT NULL AND void_paynum IS NULL AND EXISTS(
+ SELECT 1 FROM cust_pay_void
+ WHERE cust_pay_void.paynum = cust_pay_pending.paynum
+ ) AND NOT EXISTS(
+ SELECT 1 FROM cust_pay
+ WHERE cust_pay.paynum = cust_pay_pending.paynum
+ )";
+ $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute or die $sth->errstr;
+
}
=back
diff --git a/FS/FS/cust_pay_void.pm b/FS/FS/cust_pay_void.pm
index e6e2159..fdb7c7f 100644
--- a/FS/FS/cust_pay_void.pm
+++ b/FS/FS/cust_pay_void.pm
@@ -135,12 +135,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;
-----------------------------------------------------------------------
Summary of changes:
FS/FS/Schema.pm | 1 +
FS/FS/cust_pay.pm | 13 +++++++++----
FS/FS/cust_pay_pending.pm | 19 +++++++++++++++++++
FS/FS/cust_pay_void.pm | 12 ++++++++----
4 files changed, 37 insertions(+), 8 deletions(-)
More information about the freeside-commits
mailing list