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' => 'rrrrl'.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*$/ ) {
72 my $invnum_or_invid = "( invnum = $2 OR agent_invid = $2 )";
73 my $where = "WHERE $invnum_or_invid AND $agentnums_sql";
75 $count_query = "SELECT COUNT(*) FROM cust_bill $join_cust_main $where";
79 'table' => 'cust_bill',
80 'addl_from' => $join_cust_main,
82 'extra_sql' => $where,
87 #some false laziness w/cust_bill::re_X
88 my $orderby = 'ORDER BY cust_bill._date';
90 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
91 $search{'agentnum'} = $1;
94 # begin/end/beginning/ending
95 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
96 $search{'_date'} = [ $beginning, $ending ]
97 unless $beginning == 0 && $ending == 4294967295;
99 if ( $cgi->param('invnum_min') =~ /^\s*(\d+)\s*$/ ) {
100 $search{'invnum_min'} = $1;
102 if ( $cgi->param('invnum_max') =~ /^\s*(\d+)\s*$/ ) {
103 $search{'invnum_max'} = $1;
107 $search{$_} = [ FS::UI::Web::parse_lt_gt($cgi, $_) ]
108 foreach qw( charged owed );
110 $search{'open'} = 1 if $cgi->param('open');
111 $search{'net'} = 1 if $cgi->param('net' );
113 my($query) = $cgi->keywords;
114 if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
115 $search{'open'} = 1 if $1;
116 ($search{'days'}, my $field) = ($2, $3);
117 $field = "_date" if $field eq 'date';
118 $orderby = "ORDER BY cust_bill.$field";
121 if ( $cgi->param('newest_percust') ) {
122 $search{'newest_percust'} = 1;
123 $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'";
126 my $extra_sql = ' WHERE '. FS::cust_bill->search_sql_where( \%search );
128 unless ( $count_query ) {
129 $count_query = 'SELECT COUNT(*), '. join(', ',
132 FS::cust_bill->net_sql,
133 FS::cust_bill->owed_sql,
136 $count_addl = [ '$%.2f invoiced (gross)',
137 '$%.2f invoiced (net)',
138 '$%.2f outstanding balance',
141 $count_query .= " FROM cust_bill $join_cust_main $extra_sql";
144 'table' => 'cust_bill',
145 'addl_from' => $join_cust_main,
147 #'select' => "$distinct ". join(', ',
148 'select' => join(', ',
150 #( map "cust_main.$_", qw(custnum last first company) ),
151 'cust_main.custnum as cust_main_custnum',
152 FS::UI::Web::cust_sql_fields(),
153 FS::cust_bill->owed_sql. ' AS owed',
154 FS::cust_bill->net_sql. ' AS net',
156 'extra_sql' => $extra_sql,
157 'order_by' => $orderby,
162 my $link = [ "${p}view/cust_bill.cgi?", 'invnum', ];
164 my $cust_bill = shift;
165 $cust_bill->cust_main_custnum
166 ? [ "${p}view/cust_main.cgi?", 'custnum' ]
170 my $conf = new FS::Conf;
171 my $money_char = $conf->config('money_char') || '$';
173 my $html_init = join("\n", map {
174 ( my $action = $_ ) =~ s/_$//;
175 include('/elements/progress-init.html',
178 "../misc/${_}invoices.cgi",
179 { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
182 qq!<FORM NAME="${_}form">!,
184 my @values = ref($search{$f}) ? @{ $search{$f} } : $search{$f};
185 map qq!<INPUT TYPE="hidden" NAME="$f" VALUE="$_">!, @values;
190 } qw( print_ email_ fax_ ftp_ spool_ ) ).
192 '<SCRIPT TYPE="text/javascript">
194 function confirm_print_process() {
195 if ( ! confirm("Are you sure you want to reprint these invoices?") ) {
200 function confirm_email_process() {
201 if ( ! confirm("Are you sure you want to re-email these invoices?") ) {
206 function confirm_fax_process() {
207 if ( ! confirm("Are you sure you want to re-fax these invoices?") ) {
212 function confirm_ftp_process() {
213 if ( ! confirm("Are you sure you want to re-FTP these invoices?") ) {
218 function confirm_spool_process() {
219 if ( ! confirm("Are you sure you want to re-spool these invoices?") ) {
229 if ( $FS::CurrentUser::CurrentUser->access_right('Resend invoices') ) {
231 push @$menubar, 'Print these invoices' =>
232 "javascript:confirm_print_process()",
233 'Email these invoices' =>
234 "javascript:confirm_email_process()";
236 push @$menubar, 'Fax these invoices' =>
237 "javascript:confirm_fax_process()"
238 if $conf->exists('hylafax');
240 push @$menubar, 'FTP these invoices' =>
241 "javascript:confirm_ftp_process()"
242 if $conf->exists('cust_bill-ftpformat');
244 push @$menubar, 'Spool these invoices' =>
245 "javascript:confirm_spool_process()"
246 if $conf->exists('cust_bill-spoolformat');