X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpay_batch.pm;h=0b8c9f79b0353d8495c5300365388693d4f0ca4c;hb=b94239735e6daf996cc3c24808e38318126569b4;hp=3abb06d2a0289da95082a691e212709f79c3d906;hpb=6dc850028dbd122e60e2ffd7a5be74451f9c687e;p=freeside.git 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";