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 #'),
17 FS::UI::Web::cust_header(),
26 sub { time2str('%b %d %Y', shift->_date ) },
27 \&FS::UI::Web::cust_fields,
30 'COALESCE( agent_invid, invnum )',
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 if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
92 my $join_cust_main = FS::UI::Web::join_cust_main('cust_bill');
93 #here is the agent virtualization
94 my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
96 my $invnum_or_invid = "( invnum = $2 OR agent_invid = $2 )";
97 my $where = "WHERE $invnum_or_invid AND $agentnums_sql";
99 $count_query = "SELECT COUNT(*) FROM cust_bill $join_cust_main $where";
102 'table' => 'cust_bill',
103 'addl_from' => $join_cust_main,
105 'extra_sql' => $where,
108 if ( FS::Record->scalar_sql($count_query) == 0 ) {
110 # check for a voided invoice
111 $count_query =~ s/cust_bill/cust_bill_void/g;
112 if ( FS::Record->scalar_sql($count_query) > 0 ) {
113 # Redirect to the void search.
114 my $url = $cgi->self_url;
115 $url =~ s(search/cust_bill)(search/cust_bill_void);
117 $m->print($cgi->redirect($url));
124 #deal with some old-style URLs
125 my($query) = $cgi->keywords;
126 if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
127 $search{'open'} = 1 if $1;
128 ($search{'days'}, my $field) = ($2, $3);
129 $field = "_date" if $field eq 'date';
130 $search{'order_by'} = "cust_bill.$field";
134 for (qw( agentnum custnum cust_status refnum invnum_min invnum_max
135 open net newest_percust
139 $search{$_} = $cgi->param($_) if length($cgi->param($_));
143 for my $param (qw( cust_classnum payby )) {
144 $search{$param} = [ $cgi->param($param) ]
145 if grep { $_ eq $param } $cgi->param;
149 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
150 foreach qw( charged owed );
152 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
153 $search{'_date'} = [ $beginning, $ending ]
154 unless $beginning == 0 && $ending == 4294967295;
157 my $start_of_day = timelocal(0, 0, 0, (localtime(time))[3,4,5]);
158 foreach ( $cgi->param('promised_date') ) {
159 # only if at least one box is checked
160 $search{promised_date} ||= [ $start_of_day, $start_of_day, 0 ];
162 # accept everything before today
163 $search{promised_date}[0] = 0;
165 elsif ( $_ eq 'future' ) {
166 # accept everything after today
167 $search{promised_date}[1] = 4294967295;
169 elsif ( $_ eq 'null' ) {
171 $search{promised_date}[2] = 1;
175 $sql_query = FS::cust_bill->search(\%search);
176 $count_query = delete( $sql_query->{'count_query'} );
177 $count_addl = delete( $sql_query->{'count_addl'} );
181 my $link = [ "${p}view/cust_bill.cgi?", 'invnum', ];
183 my $cust_bill = shift;
184 $cust_bill->cust_main_custnum
185 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
189 my $conf = new FS::Conf;
190 my $money_char = $conf->config('money_char') || '$';
192 my $html_init = join("\n", map {
193 ( my $action = $_ ) =~ s/_$//;
194 include('/elements/progress-init.html',
197 "../misc/${_}invoices.cgi",
198 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
201 qq!<FORM NAME="${_}form">!,
203 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
204 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
209 } qw( print_ email_ fax_ ftp_ spool_ ) ).
211 '<SCRIPT TYPE="text/javascript">
213 function confirm_print_process() {
214 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
219 function confirm_email_process() {
220 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
225 function confirm_fax_process() {
226 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
231 function confirm_ftp_process() {
232 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
237 function confirm_spool_process() {
238 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
248 if ( $FS::CurrentUser::CurrentUser->access_right('Resend invoices') ) {
250 push @$menubar, emt('Print these invoices') =>
251 "javascript:confirm_print_process()",
252 emt('Email these invoices') =>
253 "javascript:confirm_email_process()";
255 push @$menubar, emt('Fax these invoices') =>
256 "javascript:confirm_fax_process()"
257 if $conf->exists('hylafax');
259 push @$menubar, emt('FTP these invoices') =>
260 "javascript:confirm_ftp_process()"
261 if $conf->exists('cust_bill-ftpformat');
263 push @$menubar, emt('Spool these invoices') =>
264 "javascript:confirm_spool_process()"
265 if $conf->exists('cust_bill-spoolformat');