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 #'),
15 FS::UI::Web::cust_header(),
19 sub { sprintf($money_char.'%.2f', shift->get('owed') ) },
20 sub { sprintf($money_char.'%.2f', shift->get('net') ) },
21 sub { sprintf($money_char.'%.2f', shift->charged ) },
22 sub { time2str('%b %d %Y', shift->_date ) },
23 \&FS::UI::Web::cust_fields,
26 'COALESCE( agent_invid, invnum )',
27 FS::cust_bill->owed_sql,
28 FS::cust_bill->net_sql,
32 'align' => 'rrrrl'.FS::UI::Web::cust_aligns(),
39 ( map { $_ ne 'Cust. Status' ? $clink : '' }
40 FS::UI::Web::cust_header()
49 FS::UI::Web::cust_colors(),
57 FS::UI::Web::cust_styles(),
63 unless $FS::CurrentUser::CurrentUser->access_right('List invoices');
65 my( $count_query, $sql_query );
69 if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
71 my $join_cust_main = FS::UI::Web::join_cust_main('cust_bill');
72 #here is the agent virtualization
73 my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
75 my $invnum_or_invid = "( invnum = $2 OR agent_invid = $2 )";
76 my $where = "WHERE $invnum_or_invid AND $agentnums_sql";
78 $count_query = "SELECT COUNT(*) FROM cust_bill $join_cust_main $where";
81 'table' => 'cust_bill',
82 'addl_from' => $join_cust_main,
84 'extra_sql' => $where,
87 if ( FS::Record->scalar_sql($count_query) == 0 ) {
89 # check for a voided invoice
90 $count_query =~ s/cust_bill/cust_bill_void/g;
91 if ( FS::Record->scalar_sql($count_query) > 0 ) {
92 # Redirect to the void search.
93 my $url = $cgi->self_url;
94 $url =~ s(search/cust_bill)(search/cust_bill_void);
96 $m->print($cgi->redirect($url));
103 #deal with some old-style URLs
104 my($query) = $cgi->keywords;
105 if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
106 $search{'open'} = 1 if $1;
107 ($search{'days'}, my $field) = ($2, $3);
108 $field = "_date" if $field eq 'date';
109 $search{'order_by'} = "cust_bill.$field";
113 for (qw( agentnum custnum cust_status refnum invnum_min invnum_max
114 open net newest_percust
118 $search{$_} = $cgi->param($_) if length($cgi->param($_));
122 for my $param (qw( cust_classnum payby )) {
123 $search{$param} = [ $cgi->param($param) ]
124 if grep { $_ eq $param } $cgi->param;
128 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
129 foreach qw( charged owed );
131 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
132 $search{'_date'} = [ $beginning, $ending ]
133 unless $beginning == 0 && $ending == 4294967295;
136 my $start_of_day = timelocal(0, 0, 0, (localtime(time))[3,4,5]);
137 foreach ( $cgi->param('promised_date') ) {
138 # only if at least one box is checked
139 $search{promised_date} ||= [ $start_of_day, $start_of_day, 0 ];
141 # accept everything before today
142 $search{promised_date}[0] = 0;
144 elsif ( $_ eq 'future' ) {
145 # accept everything after today
146 $search{promised_date}[1] = 4294967295;
148 elsif ( $_ eq 'null' ) {
150 $search{promised_date}[2] = 1;
154 $sql_query = FS::cust_bill->search(\%search);
155 $count_query = delete( $sql_query->{'count_query'} );
156 $count_addl = delete( $sql_query->{'count_addl'} );
160 my $link = [ "${p}view/cust_bill.cgi?", 'invnum', ];
162 my $cust_bill = shift;
163 $cust_bill->cust_main_custnum
164 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
168 my $conf = new FS::Conf;
169 my $money_char = $conf->config('money_char') || '$';
171 my $html_init = join("\n", map {
172 ( my $action = $_ ) =~ s/_$//;
173 include('/elements/progress-init.html',
176 "../misc/${_}invoices.cgi",
177 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
180 qq!<FORM NAME="${_}form">!,
182 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
183 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
188 } qw( print_ email_ fax_ ftp_ spool_ ) ).
190 '<SCRIPT TYPE="text/javascript">
192 function confirm_print_process() {
193 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
198 function confirm_email_process() {
199 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
204 function confirm_fax_process() {
205 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
210 function confirm_ftp_process() {
211 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
216 function confirm_spool_process() {
217 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
227 if ( $FS::CurrentUser::CurrentUser->access_right('Resend invoices') ) {
229 push @$menubar, emt('Print these invoices') =>
230 "javascript:confirm_print_process()",
231 emt('Email these invoices') =>
232 "javascript:confirm_email_process()";
234 push @$menubar, emt('Fax these invoices') =>
235 "javascript:confirm_fax_process()"
236 if $conf->exists('hylafax');
238 push @$menubar, emt('FTP these invoices') =>
239 "javascript:confirm_ftp_process()"
240 if $conf->exists('cust_bill-ftpformat');
242 push @$menubar, emt('Spool these invoices') =>
243 "javascript:confirm_spool_process()"
244 if $conf->exists('cust_bill-spoolformat');