- 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";
+ }