- } else {
- # only gather up non-taxable transactions
- $query =
- qq|SELECT a.id, '0' AS invoice, $transdate AS transdate, a.invnumber, n.name, a.netamount
- FROM acc_trans ac
- JOIN ${arap} a ON (a.id = ac.trans_id)
- JOIN $table n ON (n.id = a.${table}_id)
- WHERE
- $where
- AND (a.invoice = '0')
- AND (a.netamount = a.amount)
-
- UNION
-
- SELECT a.id, '1' AS invoice, $transdate AS transdate, a.invnumber, n.name, i.sellprice * i.qty AS netamount
- FROM acc_trans ac
- JOIN ${arap} a ON (a.id = ac.trans_id)
- JOIN $table n ON (n.id = a.${table}_id)
- JOIN invoice i ON (i.trans_id = a.id)
- WHERE
- $where
- AND (a.invoice = '1')
- AND (
- a.${table}_id NOT IN (SELECT ${table}_id FROM ${table}tax t (${table}_id))
- OR
- i.parts_id NOT IN (SELECT parts_id FROM partstax p (parts_id))
- )
- GROUP BY a.id, a.invnumber, $transdate, n.name, i.sellprice, i.qty
- ORDER by $sortorder|;
- }