1 <% include( 'elements/search.html',
5 'count_query' => $count_query,
6 'count_addl' => [ '$%.2f total credited (gross)', ],
8 'header' => [ 'Amount',
12 FS::UI::Web::cust_header(),
16 sub { sprintf('$%.2f', shift->amount ) },
17 sub { time2str('%b %d %Y', shift->_date ) },
20 \&FS::UI::Web::cust_fields,
22 #'align' => 'rrrllll',
23 'align' => 'rrll'.FS::UI::Web::cust_aligns(),
29 ( map { $_ ne 'Cust. Status' ? $clink : '' }
30 FS::UI::Web::cust_header()
38 FS::UI::Web::cust_colors(),
45 FS::UI::Web::cust_styles(),
52 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
54 my $title = 'Credit Search Results';
55 #my( $count_query, $sql_query );
59 if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
60 push @search, "cust_credit.otaker = '$1'";
63 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
64 push @search, "agentnum = $1";
65 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
66 die "unknown agentnum $1" unless $agent;
67 $title = $agent->agent. " $title";
70 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
71 push @search, "_date >= $beginning ",
74 push @search, FS::UI::Web::parse_lt_gt($cgi, 'amount' );
76 #here is the agent virtualization
77 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
79 my $where = 'WHERE '. join(' AND ', @search);
81 my $count_query = 'SELECT COUNT(*), SUM(amount) '.
82 'FROM cust_credit LEFT JOIN cust_main USING ( custnum ) '.
86 'table' => 'cust_credit',
87 'select' => join(', ',
89 'cust_main.custnum as cust_main_custnum',
90 FS::UI::Web::cust_sql_fields(),
93 'extra_sql' => $where,
94 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
98 my $cust_bill = shift;
99 $cust_bill->cust_main_custnum
100 ? [ "${p}view/cust_main.cgi?", 'custnum' ]