X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fsearch%2Funearned_detail.html;h=b87a7477e730009993b6e4e3e05066b6327b7ed3;hp=285fb50a7ee6a349874b483421a2091e04a5069c;hb=1fc8addc56f8daf12397da568eb1ac1b27fd3984;hpb=63973c641c4be00765fa27e55c57cc5b9aa4da19 diff --git a/httemplate/search/unearned_detail.html b/httemplate/search/unearned_detail.html index 285fb50a7..b87a7477e 100644 --- a/httemplate/search/unearned_detail.html +++ b/httemplate/search/unearned_detail.html @@ -105,6 +105,10 @@ my $agentnums_sql = my @where = ( $agentnums_sql ); +if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { + push @where, "cust_main.agentnum = $1"; +} + my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi); if ( $cgi->param('status') =~ /^([a-z]+)$/ ) { @@ -191,12 +195,16 @@ push @select, "$unearned_sql AS unearned_revenue"; # last payment/credit date my %t = (pay => 'cust_bill_pay', credit => 'cust_credit_bill'); foreach my $x (qw(pay credit)) { - my $table = $t{$x}; - my $link = $table.'_pkg'; - my $pkey = dbdef->table($table)->primary_key; - my $last_date_sql = "SELECT MAX(_date) - FROM $table JOIN $link USING ($pkey) - WHERE $link.billpkgnum = cust_bill_pkg.billpkgnum + my $table = "cust_$x"; + my $link_bill = $t{$x}; + my $link_pkg = $link_bill.'_pkg'; + my %pkey = map { $_ => dbdef->table($_)->primary_key } + ( $table, $link_bill ); + + my $last_date_sql = "SELECT MAX($table._date) + FROM $table JOIN $link_bill USING ($pkey{$table}) + JOIN $link_pkg USING ($pkey{$link_bill}) + WHERE $link_pkg.billpkgnum = cust_bill_pkg.billpkgnum AND $table._date <= $unearned"; push @select, "($last_date_sql) AS last_$x"; }