X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpay_batch.pm;h=c57c554984de1aaa5c0669afb38be5ebf1c2f688;hp=d0ed7ae2d3e3f7d7abfab542cf80a564f2451658;hb=f1d04f65cbacc2d5f4a286ef2a4c3f1b6b3943c2;hpb=bb201b08e3f48784cd77979dd4e31e866aa4f15d diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm index d0ed7ae2d..c57c55498 100644 --- a/FS/FS/pay_batch.pm +++ b/FS/FS/pay_batch.pm @@ -1257,43 +1257,49 @@ sub _upgrade_data { 'extra_sql' => $extrasql, }); - warn "found ".scalar @batch_refunds." batch refunds.\n"; - warn "Searching for their cust refunds...\n" if (scalar @batch_refunds > 0); - - my $oldAutoCommit = $FS::UID::AutoCommit; - local $FS::UID::AutoCommit = 0; - my $dbh = dbh; - - ## move refund to credit batch. - my %pay_batch = ( - 'status' => 'O', - 'payby' => 'CHEK', - 'type' => 'CREDIT', - ); + my $replace_error; - my $pay_batch = qsearchs( 'pay_batch', \%pay_batch ); + if (@batch_refunds) { + warn "found ".scalar @batch_refunds." batch refunds.\n"; + warn "Searching for their cust refunds...\n" if (scalar @batch_refunds > 0); - unless ( $pay_batch ) { - $pay_batch = new FS::pay_batch \%pay_batch; - my $error = $pay_batch->insert; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - warn "error creating a credit batch: $error\n"; - } - } + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; - my $replace_error; - foreach my $cust_pay_batch (@batch_refunds) { - $cust_pay_batch->batchnum($pay_batch->batchnum); - $replace_error = $cust_pay_batch->replace(); - if ( $replace_error ) { - $dbh->rollback if $oldAutoCommit; - warn "Unable o move credit to a credit batch: $replace_error"; - } - else { - warn "Moved cust pay credit ".$cust_pay_batch->paybatchnum." to credit batch ".$cust_pay_batch->batchnum."\n"; + ## move refund to credit batch. + foreach my $cust_pay_batch (@batch_refunds) { + my $payby = $cust_pay_batch->payby eq "CARD" ? "CARD" : "CHEK"; + + my %pay_batch = ( + 'status' => 'O', + 'payby' => $payby, + 'type' => 'CREDIT', + ); + + my $pay_batch = qsearchs( 'pay_batch', \%pay_batch ); + + unless ( $pay_batch ) { + $pay_batch = new FS::pay_batch \%pay_batch; + my $error = $pay_batch->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + warn "error creating a $payby credit batch: $error\n"; + } + } + + $cust_pay_batch->batchnum($pay_batch->batchnum); + $replace_error = $cust_pay_batch->replace(); + if ( $replace_error ) { + $dbh->rollback if $oldAutoCommit; + warn "Unable to move credit to a credit batch: $replace_error"; + } + else { + warn "Moved cust pay credit ".$cust_pay_batch->paybatchnum." to ".$cust_pay_batch->payby." credit batch ".$cust_pay_batch->batchnum."\n"; + } } - } + } #end @batch_refunds + else { warn "No batch refunds found\n"; } FS::upgrade_journal->set_done('removed_refunds_nodownload_format') unless $replace_error; }