1 <& elements/search.html,
3 'name' => 'net payments',
5 'count_query' => $count_query,
6 'count_addl' => [ '$%.2f total paid (net)', ],
7 'header' => [ 'Net applied',
15 FS::UI::Web::cust_header(),
18 sub { $money_char.sprintf('%.2f', shift->amount ) },
20 sub { $money_char.sprintf('%.2f', shift->cust_bill_charged)},
21 sub { time2str('%b %d %Y', shift->cust_bill_date ) },
22 sub { shift->cust_pay->payby_payinfo_pretty },
23 sub { $money_char.sprintf('%.2f', shift->cust_pay_paid)},
24 sub { time2str('%b %d %Y', shift->cust_pay_date ) },
25 sub { shift->cust_pay_otaker },
26 \&FS::UI::Web::cust_fields,
38 'align' => 'rrrrlrrl'.FS::UI::Web::cust_aligns(),
48 ( map { $_ ne 'Cust. Status' ? $cust_link : '' }
49 FS::UI::Web::cust_header()
61 FS::UI::Web::cust_colors(),
72 FS::UI::Web::cust_styles(),
79 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
81 my $conf = new FS::Conf;
82 my $money_char = $conf->config('money_char') || '$';
84 my $title = 'Net Payment Search Results';
88 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
89 push @search, "agentnum = $1";
90 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
91 die "unknown agentnum $1" unless $agent;
92 $title = $agent->agent. " $title";
95 if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) {
96 push @search, "refnum = $1";
97 my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } );
98 die "unknown refnum $1" unless $part_referral;
99 $title = $part_referral->referral. " $title";
102 if ( $cgi->param('cust_classnum') ) {
103 my @classnums = grep /^\d+$/, $cgi->param('cust_classnum');
104 push @search, 'cust_main.classnum IN('.join(',',@classnums).')'
109 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
110 push @search, "cust_bill._date >= $beginning ",
111 "cust_bill._date <= $ending";
113 #here is the agent virtualization
114 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
116 my $where = 'WHERE '. join(' AND ', @search);
118 my $count_query = 'SELECT COUNT(*), SUM(amount)
120 LEFT JOIN cust_bill USING ( invnum ) '.
121 FS::UI::Web::join_cust_main('cust_bill') .
125 'table' => 'cust_bill_pay',
126 'select' => join(', ',
128 'cust_bill._date AS cust_bill_date',
129 'cust_bill.charged AS cust_bill_charged',
130 'cust_pay.paid AS cust_pay_paid',
131 'cust_pay._date AS cust_pay_date',
132 'cust_pay.otaker AS cust_pay_otaker',
133 'cust_pay.custnum AS custnum',
134 'cust_main.custnum AS cust_main_custnum',
135 FS::UI::Web::cust_sql_fields(),
138 'extra_sql' => $where,
139 'addl_from' => 'LEFT JOIN cust_bill USING ( invnum )
140 LEFT JOIN cust_pay USING ( paynum ) '.
141 FS::UI::Web::join_cust_main('cust_bill')
144 my $cust_bill_link = sub {
145 my $cust_bill_pay = shift;
146 $cust_bill_pay->invnum
147 ? [ "${p}view/cust_bill.cgi?", 'invnum' ]
151 my $cust_pay_link = sub {
152 my $cust_bill_pay = shift;
153 $cust_bill_pay->paynum
154 ? [ "${p}view/cust_pay.html?paynum=", 'paynum' ]
158 my $cust_link = sub {
159 my $cust_credit_bill = shift;
160 $cust_credit_bill->cust_main_custnum
161 ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]