- $date_after = date2sql($_POST['TransAfterDate']);
- $date_to = date2sql($_POST['TransToDate']);
-
- // Sherifoz 22.06.03 Also get the description
- $sql = "SELECT trans.type,
- trans.trans_no,
- trans.reference,
- supplier.supp_name,
- trans.supp_reference,
- trans.tran_date,
- trans.due_date,
- supplier.curr_code,
- (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount,
- trans.alloc AS Allocated,
- ((trans.type = 20 OR trans.type = 21) AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
- (ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc) <= 0.005) AS Settled
- FROM ".TB_PREF."supp_trans as trans, ".TB_PREF."suppliers as supplier
- WHERE supplier.supplier_id = trans.supplier_id
- AND trans.tran_date >= '$date_after'
- AND trans.tran_date <= '$date_to'";
- if ($_POST['supplier_id'] != reserved_words::get_all())
- $sql .= " AND trans.supplier_id = '" . $_POST['supplier_id'] . "'";
- if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
- {
- if (($_POST['filterType'] == '1'))
- {
- $sql .= " AND (trans.type = 20 OR trans.type = 2)";
- }
- elseif (($_POST['filterType'] == '2'))
- {
- $sql .= " AND trans.type = 20 ";
- }
- elseif ($_POST['filterType'] == '3')
- {
- $sql .= " AND (trans.type = 22 OR trans.type = 1) ";
- }
- elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
- {
- $sql .= " AND trans.type = 21 ";
- }
-
- if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
- {
- $today = date2sql(Today());
- $sql .= " AND trans.due_date < '$today' ";
- }
- }
+start_form();
+
+if (!isset($_POST['supplier_id']))
+ $_POST['supplier_id'] = get_global_supplier();
+
+start_table(TABLESTYLE_NOBORDER);
+start_row();
+
+if (!$page_nested)
+ supplier_list_cells(_("Select a supplier:"), 'supplier_id', null, true, true, false, true);
+
+supp_transactions_list_cell("filterType", null, true);
+
+if ($_POST['filterType'] != '2')
+{
+ date_cells(_("From:"), 'TransAfterDate', '', null, -user_transaction_days());
+ date_cells(_("To:"), 'TransToDate');
+}
+
+submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), 'default');
+
+end_row();
+end_table();
+set_global_supplier($_POST['supplier_id']);
+
+//------------------------------------------------------------------------------------------------
+
+div_start('totals_tbl');
+if ($_POST['supplier_id'] != "" && $_POST['supplier_id'] != ALL_TEXT)
+{
+ $supplier_record = get_supplier_details(get_post('supplier_id'), get_post('TransToDate'));
+ display_supplier_summary($supplier_record);
+}
+div_end();
+
+if (get_post('RefreshInquiry') || list_updated('filterType'))
+{
+ $Ajax->activate('_page_body');
+}
+
+//------------------------------------------------------------------------------------------------
+
+$sql = get_sql_for_supplier_inquiry(get_post('filterType'), get_post('TransAfterDate'), get_post('TransToDate'), get_post('supplier_id'));