1 <% include( 'elements/search.html',
3 'name' => 'net refunds',
5 'count_query' => $count_query,
6 'count_addl' => [ '$%.2f total refunded (net)', ],
7 'header' => [ 'Net applied',
11 FS::UI::Web::cust_header(),
14 sub { $money_char. sprintf('%.2f', shift->amount ) },
15 sub { my $ccr = shift;
16 '#'.$ccr->crednum. ' '.
17 time2str('%b %d %Y', $ccr->cust_credit_date ).
19 sprintf('%.2f', $ccr->cust_credit_amount).
22 sub { my $ccr = shift;
23 time2str('%b %d %Y', $ccr->_date ).
25 sprintf('%.2f', $ccr->cust_refund_refund ).
28 sub { shift->cust_refund->otaker },
29 \&FS::UI::Web::cust_fields,
33 '', #cust_credit_amount? cust_credit_date? prolly split field
34 '', #_date? cust_refund_refund? also split
36 'align' => 'rrrl'.FS::UI::Web::cust_aligns(),
42 ( map { $_ ne 'Cust. Status' ? $cust_link : '' }
43 FS::UI::Web::cust_header()
51 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 Refund 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 if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) {
82 push @search, "refnum = $1";
83 my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } );
84 die "unknown refnum $1" unless $part_referral;
85 $title = $part_referral->referral. " $title";
88 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
89 push @search, "cust_credit._date >= $beginning ",
90 "cust_credit._date <= $ending";
92 #here is the agent virtualization
93 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
95 my $where = 'WHERE '. join(' AND ', @search);
97 my $count_query = 'SELECT COUNT(*), SUM(cust_credit_refund.amount)
98 FROM cust_credit_refund
99 LEFT JOIN cust_credit USING ( crednum )
100 LEFT JOIN cust_main USING ( custnum ) '.
104 'table' => 'cust_credit_refund',
105 'select' => join(', ',
106 'cust_credit_refund.*',
107 'cust_refund.refund AS cust_refund_refund',
108 'cust_credit._date AS cust_credit_date',
109 'cust_credit.amount AS cust_credit_amnount',
110 'cust_refund.custnum AS custnum',
111 'cust_main.custnum AS cust_main_custnum',
112 FS::UI::Web::cust_sql_fields(),
115 'extra_sql' => $where,
116 'addl_from' => 'LEFT JOIN cust_credit USING ( crednum )
117 LEFT JOIN cust_refund USING ( refundnum )
118 LEFT JOIN cust_main ON ( cust_credit.custnum = cust_main.custnum )',
121 #my $cust_credit_link = sub {
122 # my $cust_credit_refund = shift;
123 # $cust_credit_refund->crednum
124 # ? [ "${p}view/cust_credit.cgi?", 'credum' ]
128 #my $cust_refund_link = sub {
129 # my $cust_credit_refund = shift;
130 # $cust_credit_refund->refundnum
131 # ? [ "${p}view/cust_refund.cgi?", 'refundnum' ]
135 my $cust_link = sub {
136 my $cust_credit_refund = shift;
137 $cust_credit_refund->cust_main_custnum
138 ? [ "${p}view/cust_main.cgi?", 'cust_main_custnum' ]