1 <& elements/search.html,
2 'title' => emt('Voided Invoice Search Results'),
3 'name' => 'voided invoices',
5 'count_query' => $count_query,
6 'count_addl' => $count_addl,
8 'header' => [ emt('Invoice #'),
11 FS::UI::Web::cust_header(),
18 sub { sprintf($money_char.'%.2f', shift->charged ) },
19 sub { time2str('%b %d %Y', shift->_date ) },
20 \&FS::UI::Web::cust_fields,
22 sub { time2str('%b %d %Y', shift->void_date) },
26 'COALESCE( agent_invid, invnum )',
29 FS::UI::Web::cust_sort_fields(),
34 'align' => 'rrl'.FS::UI::Web::cust_aligns().'lll',
39 ( map { $_ ne 'Cust. Status' ? $clink : '' }
40 FS::UI::Web::cust_header()
49 FS::UI::Web::cust_colors(),
55 FS::UI::Web::cust_styles(),
61 unless $FS::CurrentUser::CurrentUser->access_right('List invoices');
64 my $conf = new FS::Conf;
65 my $money_char = $conf->config('money_char') || '$';
68 ' LEFT JOIN access_user ON (cust_bill_void.void_usernum = access_user.usernum) '.
69 FS::UI::Web::join_cust_main('cust_bill_void');
70 #here is the agent virtualization
71 my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
73 my( $count_query, $sql_query );
77 if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
79 my $invnum_or_invid = "( invnum = $2 OR agent_invid = $2 )";
80 my $where = "WHERE $invnum_or_invid AND $agentnums_sql";
82 $count_query = "SELECT COUNT(*) FROM cust_bill_void $addl_from $where";
85 'table' => 'cust_bill_void',
86 'addl_from' => $addl_from,
88 'extra_sql' => $where,
93 #some false laziness w/cust_bill::re_X
94 my $orderby = 'ORDER BY cust_bill_void._date';
96 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
97 $search{'agentnum'} = $1;
100 if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
101 $search{'refnum'} = $1;
104 if ( grep { $_ eq 'cust_classnum' } $cgi->param ) {
105 $search{'cust_classnum'} = [ $cgi->param('cust_classnum') ];
108 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
109 $search{'custnum'} = $1;
112 # begin/end/beginning/ending
113 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
114 $search{'_date'} = [ $beginning, $ending ]
115 unless $beginning == 0 && $ending == 4294967295;
117 ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, 'void_');
118 $search{'void_date'} = [ $beginning, $ending ]
119 unless $beginning == 0 && $ending == 4294967295;
121 if ( $cgi->param('invnum_min') =~ /^\s*(\d+)\s*$/ ) {
122 $search{'invnum_min'} = $1;
124 if ( $cgi->param('invnum_max') =~ /^\s*(\d+)\s*$/ ) {
125 $search{'invnum_max'} = $1;
129 $search{'charged'} = [ FS::UI::Web::parse_lt_gt($cgi, 'charged') ];
131 my $extra_sql = FS::cust_bill_void->search_sql_where( \%search );
132 $extra_sql = "WHERE $extra_sql" if $extra_sql;
134 unless ( $count_query ) {
135 $count_query = 'SELECT COUNT(*), SUM(charged)';
136 $count_addl = [ $money_char . '%.2f voided' ];
138 $count_query .= " FROM cust_bill_void $addl_from $extra_sql";
141 'table' => 'cust_bill_void',
142 'addl_from' => $addl_from,
144 'select' => join(', ',
146 #( map "cust_main.$_", qw(custnum last first company) ),
147 'cust_main.custnum as cust_main_custnum',
148 FS::UI::Web::cust_sql_fields(),
149 'access_user.username',
151 'extra_sql' => $extra_sql,
152 'order_by' => $orderby,
156 my $link = [ "${p}view/cust_bill_void.html?", 'invnum', ];
158 my $cust_bill = shift;
159 $cust_bill->cust_main_custnum
160 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
164 # really don't want the ability to print/spool/email voided invoices