From 06f4ee7c977486d06aa1e638e0e2a4a29518a2c7 Mon Sep 17 00:00:00 2001 From: Justin DeVuyst Date: Wed, 22 Feb 2017 15:39:41 -0500 Subject: [PATCH] Agent virtualize the attachment report. See RT#24899. --- httemplate/browse/cust_attachment.html | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/httemplate/browse/cust_attachment.html b/httemplate/browse/cust_attachment.html index f81ec1b6b..268bd4a0a 100755 --- a/httemplate/browse/cust_attachment.html +++ b/httemplate/browse/cust_attachment.html @@ -11,10 +11,7 @@ ! , - 'query' => { 'table' => 'cust_attachment', - 'hashref' => $hashref, - 'order_by' => 'ORDER BY '.$orderby, - }, + 'query' => $query, 'count_query' => $count_query, 'header' => [ selflink('#',orderby => 'attachnum'), selflink('Customer',orderby => 'custnum'), @@ -90,15 +87,25 @@ else { } } -my $hashref = $disabled ? - { disabled => { op => '>', value => 0 } } : - { disabled => '' }; - -my $count_query = 'SELECT COUNT(*) FROM cust_attachment WHERE '. ($disabled ? - 'disabled > 0' : 'disabled IS NULL'); - my $orderby = $cgi->param('orderby') || 'custnum'; +my ( $query, $count_query, ) = do { + my @agentnums = $curuser->agentnums; + { + table => 'cust_attachment', + hashref + => { disabled => $disabled ? { op => '>', value => 0 } : undef, }, + order_by => "ORDER BY $orderby", + addl_from => 'JOIN cust_main USING (custnum)', + extra_sql + => 'AND agentnum IN (' . join( ',', @agentnums, 'NULL', ) . ')', + }, + 'SELECT COUNT(*) FROM cust_attachment' + . ' JOIN cust_main USING (custnum)' + . ' WHERE agentnum in (' . join( ',', @agentnums, 'NULL', ) . ')' + . ( $disabled ? 'and disabled > 0' : '' ); +}; + my $sub_cust = sub { my $c = qsearchs('cust_main', { custnum => shift->custnum } ); return $c ? encode_entities($c->name) : '(not found)'; -- 2.11.0