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";
134 $search{'invoiced'} = 1; # preserve old behavior under 3.x
138 for (qw( agentnum custnum cust_status refnum invnum_min invnum_max
139 open net newest_percust invoiced
143 $search{$_} = $cgi->param($_) if length($cgi->param($_));
147 for my $param (qw( cust_classnum payby )) {
148 $search{$param} = [ $cgi->param($param) ]
149 if grep { $_ eq $param } $cgi->param;
153 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
154 foreach qw( charged owed );
156 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
157 $search{'_date'} = [ $beginning, $ending ]
158 unless $beginning == 0 && $ending == 4294967295;
161 my $start_of_day = timelocal(0, 0, 0, (localtime(time))[3,4,5]);
162 foreach ( $cgi->param('promised_date') ) {
163 # only if at least one box is checked
164 $search{promised_date} ||= [ $start_of_day, $start_of_day, 0 ];
166 # accept everything before today
167 $search{promised_date}[0] = 0;
169 elsif ( $_ eq 'future' ) {
170 # accept everything after today
171 $search{promised_date}[1] = 4294967295;
173 elsif ( $_ eq 'null' ) {
175 $search{promised_date}[2] = 1;
179 $sql_query = FS::cust_bill->search(\%search);
180 $count_query = delete( $sql_query->{'count_query'} );
181 $count_addl = delete( $sql_query->{'count_addl'} );
185 my $link = [ "${p}view/cust_bill.cgi?", 'invnum', ];
187 my $cust_bill = shift;
188 $cust_bill->cust_main_custnum
189 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
193 my $conf = new FS::Conf;
194 my $money_char = $conf->config('money_char') || '$';
196 my $html_init = join("\n", map {
197 ( my $action = $_ ) =~ s/_$//;
198 include('/elements/progress-init.html',
200 [ sort keys %search ],
201 "../misc/${_}invoices.cgi",
202 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
205 qq!<FORM NAME="${_}form">!,
207 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
208 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
213 } qw( print_ email_ fax_ ftp_ spool_ ) ).
215 '<SCRIPT TYPE="text/javascript">
217 function confirm_print_process() {
218 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
223 function confirm_email_process() {
224 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
229 function confirm_fax_process() {
230 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
235 function confirm_ftp_process() {
236 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
241 function confirm_spool_process() {
242 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
252 if ( $FS::CurrentUser::CurrentUser->access_right('Resend invoices') ) {
254 push @$menubar, emt('Print these invoices') =>
255 "javascript:confirm_print_process()",
256 emt('Email these invoices') =>
257 "javascript:confirm_email_process()";
259 push @$menubar, emt('Fax these invoices') =>
260 "javascript:confirm_fax_process()"
261 if $conf->exists('hylafax');
263 push @$menubar, emt('FTP these invoices') =>
264 "javascript:confirm_ftp_process()"
265 if $conf->exists('cust_bill-ftpformat');
267 push @$menubar, emt('Spool these invoices') =>
268 "javascript:confirm_spool_process()"
269 if $conf->exists('cust_bill-spoolformat');