X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Fcust_bill.html;h=be7406ec62aca6544ffc50bbe23dda03eb58df4d;hb=b91bcdff200acb281c58c4ba5ef8482b335ecdbc;hp=7b9386ec683a4b95294a80740d0f3fa9e59174dc;hpb=eb4ff7f73c5d4bdf74a3472448b5a195598ff4cd;p=freeside.git diff --git a/httemplate/search/cust_bill.html b/httemplate/search/cust_bill.html index 7b9386ec6..be7406ec6 100755 --- a/httemplate/search/cust_bill.html +++ b/httemplate/search/cust_bill.html @@ -58,11 +58,13 @@ my $join_cust_main = 'LEFT JOIN cust_main USING ( custnum )'; my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql; my( $count_query, $sql_query ); -my( $count_addl ) = ( '' ); -my( $distinct ) = ( '' ); +my $count_addl = ''; +#my $distinct = ''; my($begin, $end) = ( '', '' ); -my($agentnum) = ( '' ); +my $agentnum = ''; my($open, $days) = ( '', '' ); +my($invnum_min, $invnum_max) = ( '', '' ); +my $newest_percust = ''; if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) { $count_query = "SELECT COUNT(*) FROM cust_bill $join_cust_main". @@ -106,9 +108,11 @@ if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) { } if ( $cgi->param('invnum_min') =~ /^\s*(\d+)\s*$/ ) { + $invnum_min = $1; push @where, "cust_bill.invnum >= $1"; } if ( $cgi->param('invnum_max') =~ /^\s*(\d+)\s*$/ ) { + $invnum_max = $1; push @where, "cust_bill.invnum <= $1"; } @@ -137,17 +141,34 @@ if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) { push @where, "cust_bill._date < ". (time-86400*$days) if $days; } - #here is the agent virtualization - push @where, $agentnums_sql; - my $extra_sql = scalar(@where) ? 'WHERE '. join(' AND ', @where) : ''; - if ( $cgi->param('newest_percust') ) { - $distinct = 'DISTINCT ON ( cust_bill.custnum )'; - $orderby = 'ORDER BY cust_bill.custnum ASC, cust_bill._date DESC'; + $newest_percust = 1; + + #$distinct = 'DISTINCT ON ( cust_bill.custnum )'; + #$orderby = 'ORDER BY cust_bill.custnum ASC, cust_bill._date DESC'; #$count_query = "SELECT 'N/A', 'N/A', 'N/A'"; #XXXXXXX fix + + my @newest_where = map { s/\bcust_bill\./newest_cust_bill./g; } + grep ! /^cust_main./, @where; + my $newest_where = scalar(@newest_where) + ? ' AND '. join(' AND ', @newest_where) + : ''; + + push @where, "cust_bill._date = ( + SELECT(MAX(newest_cust_bill._date)) FROM cust_bill AS newest_cust_bill + WHERE newest_cust_bill.custnum = cust_bill.custnum + $newest_where + )"; + + $count_query = "SELECT COUNT(DISTINCT cust_bill.custnum), 'N/A', 'N/A'"; } + #here is the agent virtualization + push @where, $agentnums_sql; + + my $extra_sql = scalar(@where) ? 'WHERE '. join(' AND ', @where) : ''; + unless ( $count_query ) { $count_query = "SELECT COUNT(*), sum(charged), sum($owed)"; $count_addl = [ '$%.2f total invoiced', @@ -160,7 +181,8 @@ if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) { 'table' => 'cust_bill', 'addl_from' => $join_cust_main, 'hashref' => {}, - 'select' => "$distinct ". join(', ', + #'select' => "$distinct ". join(', ', + 'select' => join(', ', 'cust_bill.*', #( map "cust_main.$_", qw(custnum last first company) ), 'cust_main.custnum as cust_main_custnum', @@ -187,17 +209,22 @@ my $html_init = join("\n", map { ( my $action = $_ ) =~ s/_$//; include('/elements/progress-init.html', $_.'form', - [ 'begin', 'end', 'agentnum', 'open', 'days', 'newest_percust' ], + [ 'begin', 'end', 'agentnum', 'open', 'days', + 'invnum_min', 'invnum_max', 'newest_percust', + ], "../misc/${_}invoices.cgi", { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but... $_, #key ), qq!
!, - qq!!, - qq!!, - qq!!, - qq!!, - qq!!, + qq!!, + qq!!, + qq!!, + qq!!, + qq!!, + qq!!, + qq!!, + qq!!, qq!
! } qw( print_ email_ fax_ ) ).