1 <& elements/search.html,
3 'name' => emt('credits'),
5 'count_query' => $count_query,
8 'sort_fields' => \@sort_fields,
17 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
19 my $money_char = FS::Conf->new->config('money_char') || '$';
21 my $title = emt('Voided Credit Search Results');
24 my $cust_bill = shift;
25 $cust_bill->cust_main_custnum
26 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
30 my %void_access_users;
32 my (@header, @fields, @sort_fields, $align, @links, @color, @style);
36 push @header, emt('Amount');
37 push @fields, sub { $money_char .sprintf('%.2f', shift->amount) };
38 push @sort_fields, 'amount';
44 push @header, emt('Void Date'),
50 FS::UI::Web::cust_header(),
52 push @fields, sub { time2str('%b %d %Y', shift->void_date ) },
53 'void_access_user_name',
55 sub { time2str('%b %d %Y', shift->_date ) },
58 \&FS::UI::Web::cust_fields,
60 push @sort_fields, 'void_date',
61 'void_usernum', #not ideal, but at least groups them together
62 'void_reasonnum, void_reason', #ditto
65 'reasonnum, reason', #ditto
66 FS::UI::Web::cust_sort_fields();
67 $align .= 'rllrll'.FS::UI::Web::cust_aligns();
74 ( map { $_ ne 'Cust. Status' ? $clink : '' }
75 FS::UI::Web::cust_header()
84 FS::UI::Web::cust_colors(),
92 FS::UI::Web::cust_styles(),
98 # note that cgi field is usernum, but we're actually searching void_usernum
99 # because true laziness with tr-select-user in report_cust_credit_void.html
100 if ( $cgi->param('usernum') =~ /^(\d+)$/ ) {
101 push @search, "cust_credit_void.void_usernum = $1";
104 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
105 push @search, "agentnum = $1";
106 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
107 die "unknown agentnum $1" unless $agent;
108 $title = $agent->agent. " $title";
111 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
112 push @search, "void_date >= $beginning ",
113 "void_date <= $ending";
115 push @search, FS::UI::Web::parse_lt_gt($cgi, 'amount' );
117 #here is the agent virtualization
118 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql(table=>'cust_main');
121 'cust_credit_void.*',
122 'cust_main.custnum as cust_main_custnum',
123 FS::UI::Web::cust_sql_fields(),
126 my $where = 'WHERE '. join(' AND ', @search);
128 my $count_query = 'SELECT COUNT(*), SUM(amount) ';
129 $count_query .= 'FROM cust_credit_void'.
130 $addl_from. FS::UI::Web::join_cust_main('cust_credit_void').
134 'table' => 'cust_credit_void',
135 'select' => join(', ',@select),
137 'extra_sql' => $where,
138 'addl_from' => $addl_from. FS::UI::Web::join_cust_main('cust_credit_void')