1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
<& email-customers.html,
'form_action' => 'email-customer-statement.html',
'title' => 'Send statement to customer',
'no_search_fields' => [ 'start_date', 'end_date' ],
'alternate_form' => $alternate_form,
'post_search_hook' => $post_search_hook,
'acl' => $acl,
'process_url' => 'process/email-customer-statement.html',
&>
<%init>
my $acl = 'Resend invoices';
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right($acl);
my $alternate_form = sub {
# this could maaaybe be a separate element, for cleanliness
# but it's really only for use by this page, and it's not overly complicated
my $noinit = 0;
return join("\n",
'<TABLE BORDER="0">',
(
map {
my $label = ucfirst($_);
$label =~ s/_/ /;
include('/elements/tr-input-date-field.html',{
'name' => $_,
'value' => $cgi->param($_) || '',
'label' => $label,
'noinit' => $noinit++
});
}
qw( start_date end_date )
),
'</TABLE>',
'<INPUT TYPE="hidden" NAME="preview" VALUE="1">',
'<INPUT TYPE="submit" VALUE="Preview notice">',
);
};
my $post_search_hook = sub {
my %opt = @_;
return unless $cgi->param('preview');
my $cust_main = qsearchs('cust_main',$opt{'search'})
or die "Could not find customer";
# so that the statement indicates the latest date
my $date_format = $opt{'conf'}->config('date_format') || '%m/%d/%Y';
$cgi->param('end_date', time2str($date_format, time))
unless $cgi->param('end_date');
# set from/subject/html_body based on date range
$cgi->param('from',
$opt{'conf'}->config('invoice_from')
);
# shortcut for common text
my $summary_text = $cust_main->name_short .
($cgi->param('start_date') ? ' from ' : '') .
$cgi->param('start_date') .
($cgi->param('end_date') ? ' through ' : '') .
$cgi->param('end_date');
$cgi->param('subject',
$opt{'conf'}->config('company_name') .
' statement for ' .
$summary_text
);
$cgi->param('body',
'<P>' .
$opt{'conf'}->config('company_name') .
' statement of charges and payments for ' .
$summary_text .
"</P>" .
include('/elements/customer-statement.html',
'history' => [
$cust_main->payment_history(
map {
$_ => parse_datetime(scalar($cgi->param($_)))
}
qw( start_date end_date ),
),
],
)
);
};
</%init>
|