- global $db;
-
- $date_after = date2sql($_POST['TransAfterDate']);
- $date_to = date2sql($_POST['TransToDate']);
-
- // Sherifoz 22.06.03 Also get the description
- $sql = "SELECT ".TB_PREF."supp_trans.type, ".TB_PREF."supp_trans.trans_no,
- ".TB_PREF."supp_trans.tran_date, ".TB_PREF."supp_trans.reference, ".TB_PREF."supp_trans.supp_reference,
- (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount) AS TotalAmount, ".TB_PREF."supp_trans.alloc AS Allocated,
- ((".TB_PREF."supp_trans.type = 20 OR ".TB_PREF."supp_trans.type = 21) AND ".TB_PREF."supp_trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
- (ABS(".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount - ".TB_PREF."supp_trans.alloc) <= 0.005) AS Settled,
- ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.supp_name, ".TB_PREF."supp_trans.due_date
- FROM ".TB_PREF."supp_trans, ".TB_PREF."suppliers
- WHERE ".TB_PREF."suppliers.supplier_id = ".TB_PREF."supp_trans.supplier_id
- AND ".TB_PREF."supp_trans.tran_date >= '$date_after'
- AND ".TB_PREF."supp_trans.tran_date <= '$date_to'";
- if ($_POST['supplier_id'] != reserved_words::get_all())
- $sql .= " AND ".TB_PREF."supp_trans.supplier_id = '" . $_POST['supplier_id'] . "'";
- if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
- {
- if (($_POST['filterType'] == '1'))
- {
- $sql .= " AND (".TB_PREF."supp_trans.type = 20 OR ".TB_PREF."supp_trans.type = 2)";
- }
- elseif (($_POST['filterType'] == '2'))
- {
- $sql .= " AND ".TB_PREF."supp_trans.type = 20 ";
- }
- elseif ($_POST['filterType'] == '3')
- {
- $sql .= " AND (".TB_PREF."supp_trans.type = 22 OR ".TB_PREF."supp_trans.type = 1) ";
- }
- elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
- {
- $sql .= " AND ".TB_PREF."supp_trans.type = 21 ";
- }
-
- if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
- {
- $today = date2sql(Today());
- $sql .= " AND ".TB_PREF."supp_trans.due_date < '$today' ";
- }
- }
-
- $sql .= " ORDER BY ".TB_PREF."supp_trans.tran_date";
-
- return db_query($sql,"No supplier transactions were returned");