From: ivan Date: Thu, 19 Aug 2010 11:55:33 +0000 (+0000) Subject: fix batching protection against transactions settled in the meantime, RT#7905 X-Git-Tag: TORRUS_1_0_9~371 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=bb617fa9977d6886ac930d7a97e9221b33899474 fix batching protection against transactions settled in the meantime, RT#7905 --- diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm index 3abb06d2a..0b8c9f79b 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";