[freeside-commits] branch FREESIDE_3_BRANCH updated. 44576664ce3cb013a563bad7926d5b7d04657368

Christopher Burger burgerc at freeside.biz
Fri Mar 15 12:27:21 PDT 2019


The branch, FREESIDE_3_BRANCH has been updated
       via  44576664ce3cb013a563bad7926d5b7d04657368 (commit)
       via  7023b257301d73ea36eb21579fff9476e7971c17 (commit)
       via  4021a65b46491615b8577335ab93d4a2eab34c46 (commit)
      from  30ec7432f51aad8bf7bf1cf4281d40d10c86139c (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 44576664ce3cb013a563bad7926d5b7d04657368
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Fri Mar 15 15:26:33 2019 -0400

    RT# 83044 - V3 fix

diff --git a/httemplate/edit/process/cust_refund.cgi b/httemplate/edit/process/cust_refund.cgi
index 89994eb30..bea81bc12 100755
--- a/httemplate/edit/process/cust_refund.cgi
+++ b/httemplate/edit/process/cust_refund.cgi
@@ -97,6 +97,10 @@ if ( $cgi->param('paynum') > 0) {
       $_, scalar($cgi->param($_))
     } fields('cust_refund');
 
+    $hash{'payinfo'} = $cust_main->payinfo;
+    $hash{'paymask'} = $cust_main->paymask;
+    $hash{'paycardtype'} = $cust_main->paycardtype;
+
     ## unapply payment before creating refund.
     while ( $cust_pay && $cust_pay->unapplied < $refund ) {
       my @cust_bill_pay = $cust_pay->cust_bill_pay;

commit 7023b257301d73ea36eb21579fff9476e7971c17
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 7580b1c82..aac7fffc0 100644
--- a/FS/FS/pay_batch.pm
+++ b/FS/FS/pay_batch.pm
@@ -1251,61 +1251,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;
   }

commit 4021a65b46491615b8577335ab93d4a2eab34c46
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Fri Mar 15 11:29:50 2019 -0400

    RT# 83044 - fixed cc refund issues
    
    Conflicts:
            httemplate/edit/process/cust_refund.cgi
            httemplate/misc/download-batch.cgi

diff --git a/FS/FS/cust_main/Billing_Batch.pm b/FS/FS/cust_main/Billing_Batch.pm
index c1bb35f04..c8292cd1b 100644
--- a/FS/FS/cust_main/Billing_Batch.pm
+++ b/FS/FS/cust_main/Billing_Batch.pm
@@ -151,7 +151,7 @@ sub batch_card {
                   ),
     'exp'      => $options{paydate}  || $cust_payby->paydate,
     'payname'  => $options{payname}  || $cust_payby->payname,
-    'paytype'  => $options{paytype}  || $cust_payby->paytype,
+    'paytype'  => $options{paytype}  || $cust_payby->{'Hash'}->{'paytype'},
     'amount'   => $amount,                         # consolidating
     'paycode'  => $options{paycode}  || '',
   } );
diff --git a/FS/FS/cust_pay_batch.pm b/FS/FS/cust_pay_batch.pm
index 3cc8a7c93..153fc921b 100644
--- a/FS/FS/cust_pay_batch.pm
+++ b/FS/FS/cust_pay_batch.pm
@@ -328,6 +328,9 @@ sub approve {
   if ( $error ) {
     return "error approving paybatchnum $paybatchnum: $error\n";
   }
+
+  return if $new->paycode eq "C";
+
   my $cust_pay = new FS::cust_pay ( {
       'custnum'   => $new->custnum,
       'payby'     => $new->payby,
diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm
index 0fb358917..7580b1c82 100644
--- a/FS/FS/pay_batch.pm
+++ b/FS/FS/pay_batch.pm
@@ -1272,20 +1272,38 @@ sub _upgrade_data {
       my $error = $pay_batch->insert;
       if ( $error ) {
         $dbh->rollback if $oldAutoCommit;
-          warn "error creating a credit batch: $error\n";
+          warn "error creating a check credit batch: $error\n";
+      }
+    }
+
+    my %card_pay_batch = (
+      'status' => 'O',
+      'payby'  => 'CARD',
+      'type'   => 'CREDIT',
+    );
+
+    my $card_pay_batch = qsearchs( 'pay_batch', \%card_pay_batch );
+
+    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 $replace_error;
     foreach my $cust_pay_batch (@batch_refunds) {
-      $cust_pay_batch->batchnum($pay_batch->batchnum);
+      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 credit batch ".$cust_pay_batch->batchnum."\n";
+        warn "Moved cust pay credit ".$cust_pay_batch->paybatchnum." to ".$cust_pay_batch->payby." credit batch ".$cust_pay_batch->batchnum."\n";
       }
     }
 
diff --git a/FS/bin/freeside-paymentech-upload b/FS/bin/freeside-paymentech-upload
index 8e504d259..b243c90fa 100755
--- a/FS/bin/freeside-paymentech-upload
+++ b/FS/bin/freeside-paymentech-upload
@@ -41,8 +41,17 @@ my @batches;
 if($opt_a) {
   my %criteria = (status => 'O');
   $criteria{'payby'} = uc($opt_p) if $opt_p;
-  $criteria{'type'} = 'DEBIT' unless FS::pay_batch->can_handle_electronic_refunds('paymentech');
-  @batches = qsearch('pay_batch', \%criteria);
+
+  my $extra_sql;
+  $extra_sql = " AND ((payby = 'CHEK' AND type != 'CREDIT') OR (payby != 'CHEK'))" unless FS::pay_batch->can_handle_electronic_refunds('paymentech');
+
+  my %hash = (
+    table => 'pay_batch',
+    hashref   => \%criteria,
+    extra_sql => $extra_sql,
+  );
+
+  @batches = qsearch(\%hash);
   log_and_die("No open batches found".($opt_p ? " of type '$opt_p'" : '').".\n")
     if !@batches;
 }
diff --git a/FS/bin/freeside-rbc-upload b/FS/bin/freeside-rbc-upload
index 5be31aeee..7c53a391d 100755
--- a/FS/bin/freeside-rbc-upload
+++ b/FS/bin/freeside-rbc-upload
@@ -33,8 +33,17 @@ my @batches;
 if($opt_a) {
   my %criteria = (status => 'O');
   $criteria{'payby'} = uc($opt_p) if $opt_p;
-  $criteria{'type'} = 'DEBIT' unless FS::pay_batch->can_handle_electronic_refunds('RBC');
-  @batches = qsearch('pay_batch', \%criteria);
+
+  my $extra_sql;
+  $extra_sql = " AND ((payby = 'CHEK' AND type != 'CREDIT') OR (payby != 'CHEK'))" unless FS::pay_batch->can_handle_electronic_refunds('RBC');
+
+  my %hash = (
+    table => 'pay_batch',
+    hashref   => \%criteria,
+    extra_sql => $extra_sql,
+  );
+
+  @batches = qsearch(\%hash);
   die "No open batches found".($opt_p ? " of type '$opt_p'" : '').".\n" 
     if !@batches;
 }
@@ -45,7 +54,7 @@ else {
   die "Can't find payment batch '$batchnum'\n" if !@batches;
   if ($batches[0]->type eq "CREDIT") {
     warn "running credit\n";
-    log_and_die( "Batch number $batchnum is a credit (batch refund) batch, and this format can not handle batch refunds.\n" )
+    die( "Batch number $batchnum is a credit (batch refund) batch, and this format can not handle batch refunds.\n" )
       unless FS::pay_batch->can_handle_electronic_refunds('RBC');
   }
 }
diff --git a/httemplate/edit/process/cust_refund.cgi b/httemplate/edit/process/cust_refund.cgi
index 3a175ea35..89994eb30 100755
--- a/httemplate/edit/process/cust_refund.cgi
+++ b/httemplate/edit/process/cust_refund.cgi
@@ -55,7 +55,7 @@ if ( $error ) {
              'CHEK' => 'electronic check (ACH)',
              );
 
-my( $cust_pay, $cust_payby, $payinfo, $paycvv, $month, $year, $payname );
+my( $cust_pay, $cust_payby, $payinfo, $paycvv, $month, $year, $payname, $paycardtype );
 my $paymask = '';
 
 ## get cust pay info if paynum exists
diff --git a/httemplate/misc/download-batch.cgi b/httemplate/misc/download-batch.cgi
index 5db563a43..c59ba9d37 100644
--- a/httemplate/misc/download-batch.cgi
+++ b/httemplate/misc/download-batch.cgi
@@ -28,9 +28,4 @@ my $pay_batch = qsearchs({ 'select'    => "*, $credit_transactions",
                          });
 die "Batch not found: '$batchnum'" if !$pay_batch;
 
-if ($pay_batch->{Hash}->{arecredits}) {
-  my $export_format = "FS::pay_batch::".$opt{'format'};
-  die "You are trying to download a credit (batch refund) batch and The format ".$opt{'format'}." can not handle refunds.\n" unless $export_format->can('can_handle_credits');
-}
-
 </%init>
diff --git a/httemplate/search/elements/cust_pay_batch_top.html b/httemplate/search/elements/cust_pay_batch_top.html
index 90fc9e449..d29e487b2 100644
--- a/httemplate/search/elements/cust_pay_batch_top.html
+++ b/httemplate/search/elements/cust_pay_batch_top.html
@@ -146,7 +146,7 @@ tie my %upload_formats, 'Tie::IxHash', (
 delete $upload_formats{'td_eft1464'};
 $upload_formats{'PAP'} = '264 byte results for TD Canada Trust PAP Batch';
 
-if ($pay_batch->type eq "CREDIT") {
+if ($pay_batch->type eq "CREDIT" && $pay_batch->payby eq "CHEK") {
   foreach my $key (keys %download_formats) {
     delete $download_formats{$key} unless FS::pay_batch->can_handle_electronic_refunds($key);
     ## remove default format if unable to handle electronic refunds

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

Summary of changes:
 FS/FS/cust_main/Billing_Batch.pm                   |  2 +-
 FS/FS/cust_pay_batch.pm                            |  3 +
 FS/FS/pay_batch.pm                                 | 72 ++++++++++++----------
 FS/bin/freeside-paymentech-upload                  | 13 +++-
 FS/bin/freeside-rbc-upload                         | 15 ++++-
 httemplate/edit/process/cust_refund.cgi            |  6 +-
 httemplate/misc/download-batch.cgi                 |  5 --
 httemplate/search/elements/cust_pay_batch_top.html |  2 +-
 8 files changed, 72 insertions(+), 46 deletions(-)




More information about the freeside-commits mailing list