specify invoice mode for post-payment statements, #33152
authorMark Wells <mark@freeside.biz>
Mon, 23 Feb 2015 23:26:11 +0000 (15:26 -0800)
committerMark Wells <mark@freeside.biz>
Mon, 23 Feb 2015 23:26:11 +0000 (15:26 -0800)
FS/FS/Conf.pm
FS/FS/cust_bill.pm
FS/FS/cust_pay.pm

index 9213681..c4e5af4 100644 (file)
@@ -1,6 +1,7 @@
 package FS::Conf;
 
 use vars qw($base_dir @config_items @base_items @card_types $DEBUG);
+use strict;
 use Carp;
 use IO::File;
 use File::Basename;
@@ -733,6 +734,23 @@ my %batch_gateway_options = (
   },
 );
 
+my %invoice_mode_options = (
+  'type'        => 'select-sub',
+  'options_sub' => sub { 
+    my @modes = qsearch({
+        'table' => 'invoice_mode', 
+        'extra_sql' => ' WHERE '.
+          $FS::CurrentUser::CurrentUser->agentnums_sql(null => 1),
+        });
+    map { $_->modenum, $_->modename } @modes;
+  },
+  'option_sub'  => sub { 
+                         my $mode = FS::invoice_mode->by_key(shift);
+                         $mode ? $mode->modename : '',
+                       },
+  'per_agent' => 1,
+);
+
 my @cdr_formats = (
   '' => '',
   'default' => 'Default',
@@ -1721,9 +1739,16 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'payment_receipt_statement_mode',
+    'section'     => 'notification',
+    'description' => 'Automatic payments will cause a post-payment statement to be sent to the customer. Select the invoice mode to use for this statement. If unspecified, it will use the "_statement" versions of invoice configuration settings, and have the notice name "Statement".',
+    %invoice_mode_options,
+  },
+
+  {
     'key'         => 'payment_receipt_msgnum',
     'section'     => 'notification',
-    'description' => 'Template to use for payment receipts.',
+    'description' => 'Template to use for manual payment receipts.',
     %msg_template_options,
   },
   
@@ -3054,7 +3079,7 @@ and customer address. Include units.',
                         },
     'option_sub'  => sub { require FS::Record;
                            require FS::agent_type;
-                          my $agent = FS::Record::qsearchs(
+                          my $agent_type = FS::Record::qsearchs(
                             'agent_type', { 'typenum'=>shift }
                           );
                            $agent_type ? $agent_type->atype : '';
index 8d69661..a65154e 100644 (file)
@@ -1086,6 +1086,10 @@ sub queueable_email {
   my $self = qsearchs('cust_bill', { 'invnum' => $opt{invnum} } )
     or die "invalid invoice number: " . $opt{invnum};
 
+  if ( $opt{mode} ) {
+    $self->set('mode', $opt{mode});
+  }
+
   my %args = map {$_ => $opt{$_}} 
              grep { $opt{$_} }
               qw( from notice_name no_coupon template );
index e8f9aee..8274b3d 100644 (file)
@@ -716,13 +716,22 @@ sub send_receipt {
        'custnum' => $cust_main->custnum,
     };
 
-    $error = $queue->insert(
+    my %opt = (
       'invnum'      => $cust_bill->invnum,
-      'template'    => 'statement',
-      'notice_name' => 'Statement',
       '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;