- my $payby_sql = '';
- $payby_sql = ' AND (' .
- join(' OR ', map { "cust_main.payby = '$_'" } $cgi->param('payby') ) .
- ')'
- if $cgi->param('payby');
-
- my $extra_sql = ' WHERE '.
- FS::cust_bill->search_sql_where( \%search ).
- $payby_sql;
-
- unless ( $count_query ) {
- $count_query = 'SELECT COUNT(*), '. join(', ',
- map "SUM($_)",
- ( 'charged',
- FS::cust_bill->net_sql,
- FS::cust_bill->owed_sql,
- )
- );
- $count_addl = [ '$%.2f invoiced (gross)',
- '$%.2f invoiced (net)',
- '$%.2f outstanding balance',
- ];
- }
- $count_query .= " FROM cust_bill $join_cust_main $extra_sql";
-
- $sql_query = {
- 'table' => 'cust_bill',
- 'addl_from' => $join_cust_main,
- 'hashref' => {},
- 'select' => join(', ',
- 'cust_bill.*',
- #( map "cust_main.$_", qw(custnum last first company) ),
- 'cust_main.custnum as cust_main_custnum',
- FS::UI::Web::cust_sql_fields(),
- FS::cust_bill->owed_sql. ' AS owed',
- FS::cust_bill->net_sql. ' AS net',
- ),
- 'extra_sql' => $extra_sql,
- 'order_by' => $orderby,
- };