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 $join_cust_main = 'LEFT JOIN cust_main USING ( custnum )';
66 #here is the agent virtualization
67 my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
69 my( $count_query, $sql_query );
73 if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
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,
89 #some false laziness w/cust_bill::re_X
90 my $orderby = 'ORDER BY cust_bill._date';
92 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
93 $search{'agentnum'} = $1;
96 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
97 $search{'custnum'} = $1;
100 # begin/end/beginning/ending
101 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
102 $search{'_date'} = [ $beginning, $ending ]
103 unless $beginning == 0 && $ending == 4294967295;
105 if ( $cgi->param('invnum_min') =~ /^\s*(\d+)\s*$/ ) {
106 $search{'invnum_min'} = $1;
108 if ( $cgi->param('invnum_max') =~ /^\s*(\d+)\s*$/ ) {
109 $search{'invnum_max'} = $1;
113 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
114 foreach qw( charged owed );
116 $search{'open'} = 1 if $cgi->param('open');
117 $search{'net'} = 1 if $cgi->param('net' );
119 my($query) = $cgi->keywords;
120 if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
121 $search{'open'} = 1 if $1;
122 ($search{'days'}, my $field) = ($2, $3);
123 $field = "_date" if $field eq 'date';
124 $orderby = "ORDER BY cust_bill.$field";
127 if ( $cgi->param('newest_percust') ) {
128 $search{'newest_percust'} = 1;
129 $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
133 $payby_sql = ' AND (' .
134 join(' OR ', map { "cust_main.payby = '$_'" } $cgi->param('payby') ) .
136 if $cgi->param('payby');
138 my $extra_sql = ' WHERE '.
139 FS::cust_bill->search_sql_where( \%search ).
142 unless ( $count_query ) {
143 $count_query = 'SELECT COUNT(*), '. join(', ',
146 FS::cust_bill->net_sql,
147 FS::cust_bill->owed_sql,
150 $count_addl = [ '$%.2f invoiced (gross)',
151 '$%.2f invoiced (net)',
152 '$%.2f outstanding balance',
155 $count_query .= " FROM cust_bill $join_cust_main $extra_sql";
158 'table' => 'cust_bill',
159 'addl_from' => $join_cust_main,
161 'select' => join(', ',
163 #( map "cust_main.$_", qw(custnum last first company) ),
164 'cust_main.custnum as cust_main_custnum',
165 FS::UI::Web::cust_sql_fields(),
166 FS::cust_bill->owed_sql. ' AS owed',
167 FS::cust_bill->net_sql. ' AS net',
169 'extra_sql' => $extra_sql,
170 'order_by' => $orderby,
175 my $link = [ "${p}view/cust_bill.cgi?", 'invnum', ];
177 my $cust_bill = shift;
178 $cust_bill->cust_main_custnum
179 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
183 my $conf = new FS::Conf;
184 my $money_char = $conf->config('money_char') || '$';
186 my $html_init = join("\n", map {
187 ( my $action = $_ ) =~ s/_$//;
188 include('/elements/progress-init.html',
191 "../misc/${_}invoices.cgi",
192 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
195 qq!<FORM NAME="${_}form">!,
197 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
198 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
203 } qw( print_ email_ fax_ ftp_ spool_ ) ).
205 '<SCRIPT TYPE="text/javascript">
207 function confirm_print_process() {
208 if ( ! confirm('.js_mt("Are you sure you want to reprint these invoices?").') ) {
213 function confirm_email_process() {
214 if ( ! confirm('.js_mt("Are you sure you want to re-email these invoices?").') ) {
219 function confirm_fax_process() {
220 if ( ! confirm('.js_mt("Are you sure you want to re-fax these invoices?").') ) {
225 function confirm_ftp_process() {
226 if ( ! confirm('.js_mt("Are you sure you want to re-FTP these invoices?").') ) {
231 function confirm_spool_process() {
232 if ( ! confirm('.js_mt("Are you sure you want to re-spool these invoices?").') ) {
242 if ( $FS::CurrentUser::CurrentUser->access_right('Resend invoices') ) {
244 push @$menubar, emt('Print these invoices') =>
245 "javascript:confirm_print_process()",
246 emt('Email these invoices') =>
247 "javascript:confirm_email_process()";
249 push @$menubar, emt('Fax these invoices') =>
250 "javascript:confirm_fax_process()"
251 if $conf->exists('hylafax');
253 push @$menubar, emt('FTP these invoices') =>
254 "javascript:confirm_ftp_process()"
255 if $conf->exists('cust_bill-ftpformat');
257 push @$menubar, emt('Spool these invoices') =>
258 "javascript:confirm_spool_process()"
259 if $conf->exists('cust_bill-spoolformat');