- ON trans.trans_no=line.debtor_trans_no AND trans.type=line.debtor_trans_type,"
- .TB_PREF."debtors_master as debtor, "
- .TB_PREF."cust_branch as branch
- WHERE debtor.debtor_no = trans.debtor_no
- AND trans.tran_date >= '$date_after'
- AND trans.tran_date <= '$date_to'
- AND trans.branch_code = branch.branch_code";
-
- if ($_POST['customer_id'] != ALL_TEXT)
- $sql .= " AND trans.debtor_no = ".db_escape($_POST['customer_id']);
-
- if ($_POST['filterType'] != ALL_TEXT)
+ ON trans.trans_no=line.debtor_trans_no AND trans.type=line.debtor_trans_type
+ LEFT JOIN ".TB_PREF."voided as v
+ ON trans.trans_no=v.id AND trans.type=v.type
+ LEFT JOIN ".TB_PREF."audit_trail as audit ON (trans.type=audit.type AND trans.trans_no=audit.trans_no)
+ LEFT JOIN ".TB_PREF."users as user ON (audit.user=user.id)
+ LEFT JOIN ".TB_PREF."cust_branch as branch ON trans.branch_code=branch.branch_code,"
+ .TB_PREF."debtors_master as debtor
+ WHERE debtor.debtor_no = trans.debtor_no"; // exclude voided transactions and self-balancing (journal) transactions:
+ if (!$show_voided)
+ $sql .= " AND ISNULL(v.date_) AND (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount) != 0";
+ if ($ref) {
+ $sql .= " AND trans.reference LIKE ". db_escape("%$ref%");
+ }
+ if ($filter == '2')
+ $sql .= " AND ABS(IF(prep_amount, prep_amount, ABS(trans.ov_amount) + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount)-trans.alloc)>"
+ .FLOAT_COMP_DELTA;
+ else {
+ $sql .= " AND trans.tran_date >= '$date_after'
+ AND trans.tran_date <= '$date_to'";
+ }
+
+ if ($cust_id != ALL_TEXT)
+ $sql .= " AND trans.debtor_no = ".db_escape($cust_id);
+
+ if ($filter != ALL_TEXT)