1 <% include( 'elements/search.html',
3 'name' => 'net credits',
5 'count_query' => $count_query,
6 'count_addl' => [ '$%.2f total credited (net)', ],
7 'header' => [ 'Net applied',
12 FS::UI::Web::cust_header(),
15 sub { $money_char. sprintf('%.2f', shift->amount ) },
16 sub { my $ccb = shift;
17 '#'.$ccb->invnum. ' '.
18 time2str('%b %d %Y', $ccb->cust_bill_date ).
20 sprintf('%.2f', $ccb->cust_bill_amount).
23 sub { my $ccb = shift;
24 time2str('%b %d %Y', $ccb->_date ).
26 sprintf('%.2f', $ccb->cust_credit_amount ).
29 sub { shift->cust_credit->otaker },
30 sub { shift->cust_credit->reason },
31 \&FS::UI::Web::cust_fields,
33 'align' => 'rrrll'.FS::UI::Web::cust_aligns(),
40 ( map { $_ ne 'Cust. Status' ? $cust_link : '' }
41 FS::UI::Web::cust_header()
50 FS::UI::Web::cust_colors(),
58 FS::UI::Web::cust_styles(),
65 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
67 my $conf = new FS::Conf;
68 my $money_char = $conf->config('money_char') || '$';
70 my $title = 'Net Credit Search Results';
74 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
75 push @search, "agentnum = $1";
76 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
77 die "unknown agentnum $1" unless $agent;
78 $title = $agent->agent. " $title";
81 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
82 push @search, "cust_bill._date >= $beginning ",
83 "cust_bill._date <= $ending";
85 #here is the agent virtualization
86 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
88 my $where = 'WHERE '. join(' AND ', @search);
90 my $count_query = 'SELECT COUNT(*), SUM(amount)
92 LEFT JOIN cust_bill USING ( invnum )
93 LEFT JOIN cust_main USING ( custnum ) '.
97 'table' => 'cust_credit_bill',
98 'select' => join(', ',
100 'cust_credit.amount AS cust_credit_amount',
101 'cust_bill._date AS cust_bill_date',
102 'cust_bill.charged AS cust_bill_charged',
103 'cust_credit.custnum AS custnum',
104 'cust_main.custnum AS cust_main_custnum',
105 FS::UI::Web::cust_sql_fields(),
108 'extra_sql' => $where,
109 'addl_from' => 'LEFT JOIN cust_bill USING ( invnum )
110 LEFT JOIN cust_credit USING ( crednum )
111 LEFT JOIN cust_main ON ( cust_bill.custnum = cust_main.custnum )',
114 my $cust_bill_link = sub {
115 my $cust_credit_bill = shift;
116 $cust_credit_bill->invnum
117 ? [ "${p}view/cust_bill.cgi?", 'invnum' ]
121 #my $cust_credit_link = sub {
122 # my $cust_credit_bill = shift;
123 # $cust_credit_bill->crednum
124 # ? [ "${p}view/cust_credit.cgi?", 'crednum' ]
128 my $cust_link = sub {
129 my $cust_credit_bill = shift;
130 $cust_credit_bill->cust_main_custnum
131 ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]