1 <% include( 'elements/search.html',
2 'title' => 'Invoice Search Results',
3 'html_init' => $html_init,
7 'count_query' => $count_query,
8 'count_addl' => $count_addl,
10 'header' => [ '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,
25 'align' => 'rrrr'.FS::UI::Web::cust_aligns(),
32 ( map { $_ ne 'Cust. Status' ? $clink : '' }
33 FS::UI::Web::cust_header()
42 FS::UI::Web::cust_colors(),
50 FS::UI::Web::cust_styles(),
59 unless $FS::CurrentUser::CurrentUser->access_right('List invoices');
61 my $join_cust_main = 'LEFT JOIN cust_main USING ( custnum )';
62 #here is the agent virtualization
63 my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
65 my( $count_query, $sql_query );
70 if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
73 "SELECT COUNT(*) FROM cust_bill $join_cust_main".
74 " WHERE invnum = $2 AND $agentnums_sql"; #agent virtualization
76 'table' => 'cust_bill',
77 'addl_from' => $join_cust_main,
78 'hashref' => { 'invnum' => $2 },
80 'extra_sql' => " AND $agentnums_sql", #agent virtualization
85 #some false laziness w/cust_bill::re_X
87 my $orderby = 'ORDER BY cust_bill._date';
89 if ( $cgi->param('beginning')
90 && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
91 $search{'begin'} = str2time($1);
93 if ( $cgi->param('ending')
94 && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
95 $search{'end'} = str2time($1) + 86399;
98 if ( $cgi->param('begin') =~ /^(\d+)$/ ) {
99 $search{'begin'} = $1;
101 if ( $cgi->param('end') =~ /^(\d+)$/ ) {
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;
112 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
113 $search{'agentnum'} = $1;
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'";
132 my $extra_sql = ' WHERE '. FS::cust_bill->search_sql( \%search );
134 unless ( $count_query ) {
135 $count_query = 'SELECT COUNT(*), '. join(', ',
138 FS::cust_bill->net_sql,
139 FS::cust_bill->owed_sql,
142 $count_addl = [ '$%.2f invoiced (gross)',
143 '$%.2f invoiced (net)',
144 '$%.2f outstanding balance',
147 $count_query .= " FROM cust_bill $join_cust_main $extra_sql";
150 'table' => 'cust_bill',
151 'addl_from' => $join_cust_main,
153 #'select' => "$distinct ". join(', ',
154 'select' => join(', ',
156 #( map "cust_main.$_", qw(custnum last first company) ),
157 'cust_main.custnum as cust_main_custnum',
158 FS::UI::Web::cust_sql_fields(),
159 FS::cust_bill->owed_sql. ' AS owed',
160 FS::cust_bill->net_sql. ' AS net',
162 'extra_sql' => $extra_sql,
163 'order_by' => $orderby,
168 my $link = [ "${p}view/cust_bill.cgi?", 'invnum', ];
170 my $cust_bill = shift;
171 $cust_bill->cust_main_custnum
172 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
176 my $conf = new FS::Conf;
177 my $money_char = $conf->config('money_char') || '$';
179 my $html_init = join("\n", map {
180 ( my $action = $_ ) =~ s/_$//;
181 include('/elements/progress-init.html',
184 "../misc/${_}invoices.cgi",
185 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
188 qq!<FORM NAME="${_}form">!,
189 ( map qq!<INPUT TYPE="hidden" NAME="$_" VALUE="$search{$_}">!, keys %search ),
191 } qw( print_ email_ fax_ ftp_ spool_ ) ).
193 '<SCRIPT TYPE="text/javascript">
195 function confirm_print_process() {
196 if ( ! confirm("Are you sure you want to reprint these invoices?") ) {
201 function confirm_email_process() {
202 if ( ! confirm("Are you sure you want to re-email these invoices?") ) {
207 function confirm_fax_process() {
208 if ( ! confirm("Are you sure you want to re-fax these invoices?") ) {
213 function confirm_ftp_process() {
214 if ( ! confirm("Are you sure you want to re-FTP these invoices?") ) {
219 function confirm_spool_process() {
220 if ( ! confirm("Are you sure you want to re-spool these invoices?") ) {
230 if ( $FS::CurrentUser::CurrentUser->access_right('Resend invoices') ) {
232 push @$menubar, 'Print these invoices' =>
233 "javascript:confirm_print_process()",
234 'Email these invoices' =>
235 "javascript:confirm_email_process()";
237 push @$menubar, 'Fax these invoices' =>
238 "javascript:confirm_fax_process()"
239 if $conf->exists('hylafax');
241 push @$menubar, 'FTP these invoices' =>
242 "javascript:confirm_ftp_process()"
243 if $conf->exists('cust_bill-ftpformat');
245 push @$menubar, 'Spool these invoices' =>
246 "javascript:confirm_spool_process()"
247 if $conf->exists('cust_bill-spoolformat');