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'),
51 FS::UI::Web::cust_header(),
53 push @fields, sub { time2str('%b %d %Y', shift->void_date ) },
54 'void_access_user_name',
56 sub { time2str('%b %d %Y', shift->_date ) },
60 \&FS::UI::Web::cust_fields,
62 push @sort_fields, 'void_date',
63 'void_usernum', #not ideal, but at least groups them together
64 'void_reasonnum, void_reason', #ditto
67 'reasonnum, reason', #ditto
69 FS::UI::Web::cust_sort_fields();
70 $align .= 'rllrlll'.FS::UI::Web::cust_aligns();
78 ( map { $_ ne 'Cust. Status' ? $clink : '' }
79 FS::UI::Web::cust_header()
89 FS::UI::Web::cust_colors(),
98 FS::UI::Web::cust_styles(),
104 # note that cgi field is usernum, but we're actually searching void_usernum
105 # because true laziness with tr-select-user in report_cust_credit_void.html
106 if ( $cgi->param('usernum') =~ /^(\d+)$/ ) {
107 push @search, "cust_credit_void.void_usernum = $1";
110 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
111 push @search, "agentnum = $1";
112 my $agent = qsearchs('agent', { 'agentnum' => $1 } );
113 die "unknown agentnum $1" unless $agent;
114 $title = $agent->agent. " $title";
117 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
118 push @search, "void_date >= $beginning ",
119 "void_date <= $ending";
121 push @search, FS::UI::Web::parse_lt_gt($cgi, 'amount' );
123 #here is the agent virtualization
124 push @search, $FS::CurrentUser::CurrentUser->agentnums_sql(table=>'cust_main');
127 'cust_credit_void.*',
128 'cust_main.custnum as cust_main_custnum',
129 FS::UI::Web::cust_sql_fields(),
132 my $where = 'WHERE '. join(' AND ', @search);
134 my $count_query = 'SELECT COUNT(*), SUM(amount) ';
135 $count_query .= 'FROM cust_credit_void'.
136 $addl_from. FS::UI::Web::join_cust_main('cust_credit_void').
140 'table' => 'cust_credit_void',
141 'select' => join(', ',@select),
143 'extra_sql' => $where,
144 'addl_from' => $addl_from. FS::UI::Web::join_cust_main('cust_credit_void')