[freeside-commits] branch FREESIDE_3_BRANCH updated. 01625315547278cbf15ad5e96c218b5cd4bf10cc

Christopher Burger burgerc at freeside.biz
Wed May 16 15:54:25 PDT 2018


The branch, FREESIDE_3_BRANCH has been updated
       via  01625315547278cbf15ad5e96c218b5cd4bf10cc (commit)
       via  0bc6f2a95309807cc9372a6be3a36d5e8b3485d8 (commit)
      from  8286d9921bf88afd0ddd367f3894f12fc2347f09 (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 01625315547278cbf15ad5e96c218b5cd4bf10cc
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Wed May 16 12:39:59 2018 -0400

    RT# 78131 - added documentation for new method.
    
    Conflicts:
            FS/FS/cust_pay.pm

diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 285ab3f3c..67f4b297d 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -664,6 +664,7 @@ sub send_receipt {
        || ! $cust_bill
      )
   {
+
     $error = $self->send_message_receipt(
         'cust_main'      => $cust_main,
         'cust_bill'      => $opt->{cust_bill},
@@ -716,7 +717,13 @@ sub send_receipt {
 =item send_message_receipt
 
 sends out a message receipt.
-send_message_receipt($cust_main, $msgnum);
+$error = $self->send_message_receipt(
+        'cust_main'      => $cust_main,
+        'cust_bill'      => $opt->{cust_bill},
+        'cust_pkg'       => $opt->{cust_pkg},
+        'invoicing_list' => @invoicing_list,
+        'msgnum'         => $conf->config('payment_receipt_msgnum', $cust_main->agentnum)
+      );
 
 =cut
 
@@ -734,6 +741,11 @@ sub send_message_receipt {
       my %substitutions = ();
       $substitutions{invnum} = $cust_bill->invnum if $cust_bill;
 
+      my $msg_template = qsearchs('msg_template',{ msgnum => $msgnum});
+      unless ($msg_template) {
+        return "send_receipt could not load msg_template";
+      }
+
       my $queue = new FS::queue {
         'job'     => 'FS::Misc::process_send_email',
         'paynum'  => $self->paynum,
@@ -754,8 +766,7 @@ sub send_message_receipt {
         TYPE   => 'ARRAY',
         SOURCE => [ map "$_\n", $conf->config('payment_receipt_email') ],
       ) or do {
-        warn "can't create payment receipt template: $Text::Template::ERROR";
-        return '';
+        return "can't create payment receipt template: $Text::Template::ERROR";
       };
 
       my $payby = $self->payby;
@@ -800,8 +811,7 @@ sub send_message_receipt {
         'body'    => [ $receipt_template->fill_in( HASH => \%fill_in ) ],
       );  
     } else {
-      warn "payment_receipt is on, but no payment_receipt_msgnum\n";
-      $error = "payment_receipt is on, but no payment_receipt_msgnum";
+      $error = "payment_receipt is on, but no payment_receipt_msgnum\n";
     }
 
   return $error;

commit 0bc6f2a95309807cc9372a6be3a36d5e8b3485d8
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue May 15 13:32:46 2018 -0400

    RT78131 - Created new method to send message receipts so code does not have to be duplicated. Updated for V3 backport
    
    Conflicts:
            FS/FS/cust_pay.pm

diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 7739203c4..285ab3f3c 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -664,11 +664,75 @@ sub send_receipt {
        || ! $cust_bill
      )
   {
-    my $msgnum = $conf->config('payment_receipt_msgnum', $cust_main->agentnum);
+    $error = $self->send_message_receipt(
+        'cust_main'      => $cust_main,
+        'cust_bill'      => $opt->{cust_bill},
+        'cust_pkg'       => $opt->{cust_pkg},
+        'invoicing_list' => @invoicing_list,
+        'msgnum'         => $conf->config('payment_receipt_msgnum', $cust_main->agentnum)
+    );
+
+  } elsif ( ! $cust_main->invoice_noemail ) { #not manual
+
+    # check to see if they want to send specific message template as receipt for auto payments
+    if ( $conf->config('payment_receipt_msgnum_auto', $cust_main->agentnum) ) {
+      $error = $self->send_message_receipt(
+        'cust_main' => $cust_main,
+        'cust_bill' => $opt->{cust_bill},
+        'msgnum'    => $conf->config('payment_receipt_msgnum_auto', $cust_main->agentnum),
+      );
+    }
+    else {
+      my $queue = new FS::queue {
+        'job'     => 'FS::cust_bill::queueable_email',
+        'paynum'  => $self->paynum,
+        'custnum' => $cust_main->custnum,
+      };
+
+      my %opt = (
+        'invnum'      => $cust_bill->invnum,
+        'no_coupon'   => 1,
+      );
+
+      if ( my $mode = $conf->config('payment_receipt_statement_mode') ) {
+        $opt{'mode'} = $mode;
+      } else {
+        # backward compatibility, no good fix for this yet as some people may
+        # still have "invoice_latex_statement" and such options
+        $opt{'template'} = 'statement';
+        $opt{'notice_name'} = 'Statement';
+      }
+
+      $error = $queue->insert(%opt);
+    }
+
+
+
+  }
+
+  warn "send_receipt: $error\n" if $error;
+}
+
+=item send_message_receipt
+
+sends out a message receipt.
+send_message_receipt($cust_main, $msgnum);
+
+=cut
+
+sub send_message_receipt {
+  my ($self, %opt) = @_;
+  my $cust_main      = $opt{'cust_main'};
+  my $cust_bill      = $opt{'cust_bill'};
+  my $cust_pkg       = $opt{'cust_pkg'};
+  my @invoicing_list = $opt{'invoicing_list'};
+  my $msgnum         = $opt{'msgnum'};
+  my $error = '';
+
     if ( $msgnum ) {
 
       my %substitutions = ();
-      $substitutions{invnum} = $opt->{cust_bill}->invnum if $opt->{cust_bill};
+      $substitutions{invnum} = $cust_bill->invnum if $cust_bill;
 
       my $queue = new FS::queue {
         'job'     => 'FS::Misc::process_send_email',
@@ -684,7 +748,6 @@ sub send_receipt {
         ),
         'msgtype' => 'receipt', # override msg_template's default
       );
-
     } elsif ( $conf->exists('payment_receipt_email') ) {
 
       my $receipt_template = new Text::Template (
@@ -716,13 +779,13 @@ sub send_receipt {
         'company_name' => $conf->config('company_name', $cust_main->agentnum),
       );
 
-      $fill_in{'invnum'} = $opt->{cust_bill}->invnum if $opt->{cust_bill};
+      $fill_in{'invnum'} = $cust_bill->invnum if $cust_bill;
 
-      if ( $opt->{'cust_pkg'} ) {
-        $fill_in{'pkg'} = $opt->{'cust_pkg'}->part_pkg->pkg;
+      if ( $cust_pkg ) {
+        $fill_in{'pkg'} = $cust_pkg->part_pkg->pkg;
         #setup date, other things?
       }
-
+      
       my $queue = new FS::queue {
         'job'     => 'FS::Misc::process_send_generated_email',
         'paynum'  => $self->paynum,
@@ -735,69 +798,13 @@ sub send_receipt {
         'to'      => \@invoicing_list,
         'subject' => 'Payment receipt',
         'body'    => [ $receipt_template->fill_in( HASH => \%fill_in ) ],
-      );
-
+      );  
     } else {
-
       warn "payment_receipt is on, but no payment_receipt_msgnum\n";
-
-    }
-
-  } elsif ( ! $cust_main->invoice_noemail ) { #not manual
-
-    # check to see if they want to send specific message template as receipt for auto payments
-    my $msgnum = $conf->config('payment_receipt_msgnum_auto', $cust_main->agentnum);
-    if ( $msgnum ) {
-
-      my %substitutions = ();
-      $substitutions{invnum} = $opt->{cust_bill}->invnum if $opt->{cust_bill};
-
-      my $queue = new FS::queue {
-        'job'     => 'FS::Misc::process_send_email',
-        'paynum'  => $self->paynum,
-        'custnum' => $cust_main->custnum,
-      };
-
-      $error = $queue->insert(
-        FS::msg_template->by_key($msgnum)->prepare(
-          'cust_main'     => $cust_main,
-          'object'        => $self,
-          'from_config'   => 'payment_receipt_from',
-          'substitutions' => \%substitutions,
-        ),
-        'msgtype' => 'receipt', # override msg_template's default
-      );
-
-    }
-    else {
-      my $queue = new FS::queue {
-        'job'     => 'FS::cust_bill::queueable_email',
-        'paynum'  => $self->paynum,
-        'custnum' => $cust_main->custnum,
-      };
-
-      my %opt = (
-        'invnum'      => $cust_bill->invnum,
-        'no_coupon'   => 1,
-      );
-
-      if ( my $mode = $conf->config('payment_receipt_statement_mode') ) {
-        $opt{'mode'} = $mode;
-      } else {
-        # backward compatibility, no good fix for this yet as some people may
-        # still have "invoice_latex_statement" and such options
-        $opt{'template'} = 'statement';
-        $opt{'notice_name'} = 'Statement';
-      }
-
-      $error = $queue->insert(%opt);
+      $error = "payment_receipt is on, but no payment_receipt_msgnum";
     }
 
-
-
-  }
-  
-  warn "send_receipt: $error\n" if $error;
+  return $error;
 }
 
 =item cust_bill_pay

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

Summary of changes:
 FS/FS/cust_pay.pm | 155 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 86 insertions(+), 69 deletions(-)




More information about the freeside-commits mailing list