+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' : '' );
+};
+