1 <% include( 'elements/search.html',
3 'name' => 'net payments',
5 'count_query' => $count_query,
6 'count_addl' => [ '$%.2f total paid (net)', ],
7 'header' => [ 'Net applied',
11 FS::UI::Web::cust_header(),
14 sub { $money_char. sprintf('%.2f', shift->amount ) },
15 sub { my $cbp = shift;
16 '#'.$cbp->invnum. ' '.
17 time2str('%b %d %Y', $cbp->cust_bill_date ).
19 sprintf('%.2f', $cbp->cust_bill_amount).
22 sub { my $cbp = shift;
23 $cbp->cust_pay->payby_payinfo_pretty. ' '.
24 time2str('%b %d %Y', $cbp->_date ).
26 sprintf('%.2f', $cbp->cust_pay_paid ).
29 sub { shift->cust_pay->otaker },
30 \&FS::UI::Web::cust_fields,
32 'align' => 'rrrl'.FS::UI::Web::cust_aligns(),
38 ( map { $_ ne 'Cust. Status' ? $cust_link : '' }
39 FS::UI::Web::cust_header()
47 FS::UI::Web::cust_colors(),
54 FS::UI::Web::cust_styles(),
61 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
63 my $conf = new FS::Conf;
64 my $money_char = $conf->config('money_char') || '$';
66 my $title = 'Net Payment Search Results';
70 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
71 push @search, "agentnum = $1";
72 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
73 die "unknown agentnum $1" unless $agent;
74 $title = $agent->agent. " $title";
77 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
78 push @search, "cust_bill._date >= $beginning ",
79 "cust_bill._date <= $ending";
81 #here is the agent virtualization
82 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
84 my $where = 'WHERE '. join(' AND ', @search);
86 my $count_query = 'SELECT COUNT(*), SUM(amount)
88 LEFT JOIN cust_bill USING ( invnum )
89 LEFT JOIN cust_main USING ( custnum ) '.
93 'table' => 'cust_bill_pay',
94 'select' => join(', ',
96 'cust_pay.paid AS cust_pay_paid',
97 'cust_bill._date AS cust_bill_date',
98 #'cust_bill.charged AS cust_bill_charged',
99 'cust_pay.custnum AS custnum',
100 'cust_main.custnum AS cust_main_custnum',
101 FS::UI::Web::cust_sql_fields(),
104 'extra_sql' => $where,
105 'addl_from' => 'LEFT JOIN cust_bill USING ( invnum )
106 LEFT JOIN cust_pay USING ( paynum )
107 LEFT JOIN cust_main ON ( cust_bill.custnum = cust_main.custnum )',
110 my $cust_bill_link = sub {
111 my $cust_bill_pay = shift;
112 $cust_bill_pay->invnum
113 ? [ "${p}view/cust_bill.cgi?", 'invnum' ]
117 my $cust_pay_link = sub {
118 my $cust_bill_pay = shift;
119 $cust_bill_pay->paynum
120 ? [ "${p}view/cust_pay.html?paynum=", 'paynum' ]
124 my $cust_link = sub {
125 my $cust_credit_bill = shift;
126 $cust_credit_bill->cust_main_custnum
127 ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]