summaryrefslogtreecommitdiff
path: root/FS/FS/pay_batch.pm
diff options
context:
space:
mode:
authorivan <ivan>2010-08-19 11:55:33 +0000
committerivan <ivan>2010-08-19 11:55:33 +0000
commitbb617fa9977d6886ac930d7a97e9221b33899474 (patch)
treed37f71f64308f7a5ccda67d51c3c8e2088607d22 /FS/FS/pay_batch.pm
parent3f4c9d34c4a031ca061f2f53f6ec4d893b5c3d40 (diff)
fix batching protection against transactions settled in the meantime, RT#7905
Diffstat (limited to 'FS/FS/pay_batch.pm')
-rw-r--r--FS/FS/pay_batch.pm39
1 files changed, 22 insertions, 17 deletions
diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm
index 3abb06d..0b8c9f7 100644
--- a/FS/FS/pay_batch.pm
+++ b/FS/FS/pay_batch.pm
@@ -478,29 +478,34 @@ sub export_batch {
$batch .= $h . "\n";
}
foreach my $cust_pay_batch (@cust_pay_batch) {
- if($first_download) {
+
+ if ($first_download) {
my $balance = $cust_pay_batch->cust_main->balance;
- my $error = '';
- if($balance <= 0) { # then don't charge this customer
- $error = $cust_pay_batch->delete;
- undef $cust_pay_batch;
- }
- elsif($balance < $cust_pay_batch->amount) { # then reduce the charge to the remaining balance
+ if ($balance <= 0) { # then don't charge this customer
+ my $error = $cust_pay_batch->delete;
+ if ( $error ) {
+ $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
+ die $error;
+ }
+ next;
+ } elsif ($balance < $cust_pay_batch->amount) {
+ # reduce the charge to the remaining balance
$cust_pay_batch->amount($balance);
- $error = $cust_pay_batch->replace;
+ my $error = $cust_pay_batch->replace;
+ if ( $error ) {
+ $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
+ die $error;
+ }
}
# else $balance >= $cust_pay_batch->amount
- if($error) {
- $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
- die $error;
- }
- }
- if($cust_pay_batch) { # that is, it wasn't deleted
- $batchcount++;
- $batchtotal += $cust_pay_batch->amount;
- $batch .= &{$info->{'row'}}($cust_pay_batch, $self, $batchcount, $batchtotal) . "\n";
}
+
+ $batchcount++;
+ $batchtotal += $cust_pay_batch->amount;
+ $batch .= &{$info->{'row'}}($cust_pay_batch, $self, $batchcount, $batchtotal) . "\n";
+
}
+
my $f = $info->{'footer'};
if(ref($f) eq 'CODE') {
$batch .= &$f($self, $batchcount, $batchtotal) . "\n";