2 <% include('email-customers.html',
3 'form_action' => 'email-customer-statement.html',
4 'title' => 'Send statement to customer',
5 'no_search_fields' => [ 'start_date', 'end_date' ],
6 'alternate_form' => $alternate_form,
7 'post_search_hook' => $post_search_hook,
14 unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
16 my $alternate_form = sub {
17 # this could maaaybe be a separate element, for cleanliness
18 # but it's really only for use by this page, and it's not overly complicated
24 my $label = ucfirst($_);
26 include('/elements/tr-input-date-field.html',{
28 'value' => $cgi->param($_) || '',
33 qw( start_date end_date )
36 '<INPUT TYPE="hidden" NAME="action" VALUE="preview">',
37 '<INPUT TYPE="submit" VALUE="Preview notice">',
41 my $post_search_hook = sub {
43 return unless $cgi->param('action') eq 'preview';
44 my $cust_main = qsearchs('cust_main',$opt{'search'})
45 or die "Could not find customer";
47 # so that the statement indicates the latest date
48 my $date_format = $opt{'conf'}->config('date_format') || '%m/%d/%Y';
49 $cgi->param('end_date', time2str($date_format, time))
50 unless $cgi->param('end_date');
52 # set from/subject/html_body based on date range
55 $opt{'conf'}->config('invoice_from')
58 # shortcut for common text
59 my $summary_text = $cust_main->name_short .
60 ($cgi->param('start_date') ? ' from ' : '') .
61 $cgi->param('start_date') .
62 ($cgi->param('end_date') ? ' through ' : '') .
63 $cgi->param('end_date');
65 $cgi->param('subject',
66 $opt{'conf'}->config('company_name') .
71 $cgi->param('html_body',
73 $opt{'conf'}->config('company_name') .
74 ' statement of charges and payments for ' .
77 include('/elements/customer-statement.html',
79 $cust_main->payment_history(
81 $_ => parse_datetime($cgi->param($_))
83 qw( start_date end_date ),