[freeside-commits] branch master updated. f1d04f65cbacc2d5f4a286ef2a4c3f1b6b3943c2

Christopher Burger burgerc at freeside.biz
Fri Mar 15 10:10:26 PDT 2019


The branch, master has been updated
       via  f1d04f65cbacc2d5f4a286ef2a4c3f1b6b3943c2 (commit)
      from  38f5c59a6a3b92881c0f60bc8dccc9acd0feef41 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f1d04f65cbacc2d5f4a286ef2a4c3f1b6b3943c2
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Fri Mar 15 13:09:21 2019 -0400

    RT# 83044 - fixed so open empty batches not created on upgrade

diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm
index 0df9c7a23..c57c55498 100644
--- a/FS/FS/pay_batch.pm
+++ b/FS/FS/pay_batch.pm
@@ -1257,61 +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 check credit batch: $error\n";
-      }
-    }
+      my $oldAutoCommit = $FS::UID::AutoCommit;
+      local $FS::UID::AutoCommit = 0;
+      my $dbh = dbh;
 
-    my %card_pay_batch = (
-      'status' => 'O',
-      'payby'  => 'CARD',
-      'type'   => 'CREDIT',
-    );
+      ## move refund to credit batch.
+      foreach my $cust_pay_batch (@batch_refunds) {
+        my $payby = $cust_pay_batch->payby eq "CARD" ? "CARD" : "CHEK";
 
-    my $card_pay_batch = qsearchs( 'pay_batch', \%card_pay_batch );
+        my %pay_batch = (
+          'status' => 'O',
+          'payby'  => $payby,
+          'type'   => 'CREDIT',
+        );
 
-    unless ( $card_pay_batch ) {
-      $card_pay_batch = new FS::pay_batch \%card_pay_batch;
-      my $error = $card_pay_batch->insert;
-      if ( $error ) {
-        $dbh->rollback if $oldAutoCommit;
-          warn "error creating a card credit batch: $error\n";
-      }
-    }
+        my $pay_batch = qsearchs( 'pay_batch', \%pay_batch );
 
-    my $replace_error;
-    foreach my $cust_pay_batch (@batch_refunds) {
-      if ($cust_pay_batch->payby eq "CARD") { $cust_pay_batch->batchnum($card_pay_batch->batchnum); }
-      else { $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 ".$cust_pay_batch->payby." credit batch ".$cust_pay_batch->batchnum."\n";
+        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;
   }

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/pay_batch.pm | 84 +++++++++++++++++++++++-------------------------------
 1 file changed, 36 insertions(+), 48 deletions(-)




More information about the freeside-commits mailing list