From cfd6a2219e498ec70d30b207b7a82037347ca7b0 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Mon, 23 Feb 2015 15:26:11 -0800 Subject: [PATCH] specify invoice mode for post-payment statements, #33152 --- FS/FS/Conf.pm | 29 +++++++++++++++++++++++++++-- FS/FS/cust_bill.pm | 4 ++++ FS/FS/cust_pay.pm | 15 ++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 92136813f..c4e5af4e0 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -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 : ''; diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 8d6966161..a65154ec4 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -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 ); diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index e8f9aee8e..8274b3d7a 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -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; -- 2.11.0