1 <& elements/search.html,
2 'title' => emt('Invoice Search Results'),
3 'html_init' => $html_init,
7 'count_query' => $count_query,
8 'count_addl' => $count_addl,
10 'header' => [ emt('Invoice #'),
11 emt($invoiced ? 'Charged' : 'Gross Amount'),
17 FS::UI::Web::cust_header(),
21 $invoiced ? 'charged' : 'gross',
26 sub { time2str('%b %d %Y', shift->_date ) },
27 \&FS::UI::Web::cust_fields,
30 'COALESCE( agent_invid, invnum )',
31 $invoiced ? 'charged' : 'gross',
47 'align' => 'rrrrrrl'.FS::UI::Web::cust_aligns(),
56 ( map { $_ ne 'Cust. Status' ? $clink : '' }
57 FS::UI::Web::cust_header()
68 FS::UI::Web::cust_colors(),
78 FS::UI::Web::cust_styles(),
84 unless $FS::CurrentUser::CurrentUser->access_right('List invoices');
86 my( $count_query, $sql_query );
90 # show invoiced amount (charged) instead of gross sales
91 my $invoiced = $cgi->param('invoiced') ? 1 : 0;
93 if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
95 my $join_cust_main = FS::UI::Web::join_cust_main('cust_bill');
96 #here is the agent virtualization
97 my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
99 my $invnum_or_invid = "( invnum = $2 OR agent_invid = $2 )";
100 my $where = "WHERE $invnum_or_invid AND $agentnums_sql";
102 $count_query = "SELECT COUNT(*) FROM cust_bill $join_cust_main $where";
105 'table' => 'cust_bill',
106 'addl_from' => $join_cust_main,
108 'extra_sql' => $where,
111 if ( FS::Record->scalar_sql($count_query) == 0 ) {
113 # check for a voided invoice
114 $count_query =~ s/cust_bill/cust_bill_void/g;
115 if ( FS::Record->scalar_sql($count_query) > 0 ) {
116 # Redirect to the void search.
117 my $url = $cgi->self_url;
118 $url =~ s(search/cust_bill)(search/cust_bill_void);
120 $m->print($cgi->redirect($url));
127 #deal with some old-style URLs
128 my($query) = $cgi->keywords;
129 if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
130 $search{'open'} = 1 if $1;
131 ($search{'days'}, my $field) = ($2, $3);
132 $field = "_date" if $field eq 'date';
133 $search{'order_by'} = "cust_bill.$field";
137 for (qw( agentnum custnum cust_status refnum invnum_min invnum_max
138 open net newest_percust invoiced
142 $search{$_} = $cgi->param($_) if length($cgi->param($_));
146 for my $param (qw( cust_classnum )) {
147 $search{$param} = [ $cgi->param($param) ]
148 if grep { $_ eq $param } $cgi->param;
152 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
153 foreach qw( charged owed );
155 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
156 $search{'_date'} = [ $beginning, $ending ]
157 unless $beginning == 0 && $ending == 4294967295;
160 my $start_of_day = timelocal(0, 0, 0, (localtime(time))[3,4,5]);
161 foreach ( $cgi->param('promised_date') ) {
162 # only if at least one box is checked
163 $search{promised_date} ||= [ $start_of_day, $start_of_day, 0 ];
165 # accept everything before today
166 $search{promised_date}[0] = 0;
168 elsif ( $_ eq 'future' ) {
169 # accept everything after today
170 $search{promised_date}[1] = 4294967295;
172 elsif ( $_ eq 'null' ) {
174 $search{promised_date}[2] = 1;
178 $sql_query = FS::cust_bill->search(\%search);
179 $count_query = delete( $sql_query->{'count_query'} );
180 $count_addl = delete( $sql_query->{'count_addl'} );
184 my $link = [ "${p}view/cust_bill.cgi?", 'invnum', ];
186 my $cust_bill = shift;
187 $cust_bill->cust_main_custnum
188 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
192 my $conf = new FS::Conf;
193 my $money_char = $conf->config('money_char') || '$';
195 my $html_init = join("\n", map {
196 ( my $action = $_ ) =~ s/_$//;
197 include('/elements/progress-init.html',
199 [ sort keys %search ],
200 "../misc/${_}invoices.cgi",
201 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
204 qq!<FORM NAME="${_}form">!,
206 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
207 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
212 } qw( print_ email_ fax_ ftp_ spool_ ) ).
214 '<SCRIPT TYPE="text/javascript">
216 function confirm_print_process() {
217 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
222 function confirm_email_process() {
223 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
228 function confirm_fax_process() {
229 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
234 function confirm_ftp_process() {
235 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
240 function confirm_spool_process() {
241 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
251 if ( $FS::CurrentUser::CurrentUser->access_right('Resend invoices') ) {
253 push @$menubar, emt('Print these invoices') =>
254 "javascript:confirm_print_process()",
255 emt('Email these invoices') =>
256 "javascript:confirm_email_process()";
258 push @$menubar, emt('Fax these invoices') =>
259 "javascript:confirm_fax_process()"
260 if $conf->exists('hylafax');
262 push @$menubar, emt('FTP these invoices') =>
263 "javascript:confirm_ftp_process()"
264 if $conf->exists('cust_bill-ftpformat');
266 push @$menubar, emt('Spool these invoices') =>
267 "javascript:confirm_spool_process()"
268 if $conf->exists('cust_bill-spoolformat');