5 include($path_to_root . "/includes/session.inc");
7 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
10 if ($use_popup_windows)
11 $js .= get_js_open_window(900, 500);
13 $js .= get_js_date_picker();
14 page(_("Supplier Inquiry"), false, false, "", $js);
16 if (isset($_GET['supplier_id'])){
17 $_POST['supplier_id'] = $_GET['supplier_id'];
19 if (isset($_GET['FromDate'])){
20 $_POST['TransAfterDate'] = $_GET['FromDate'];
22 if (isset($_GET['ToDate'])){
23 $_POST['TransToDate'] = $_GET['ToDate'];
26 //------------------------------------------------------------------------------------------------
28 start_form(false, true);
30 if (!isset($_POST['supplier_id']))
31 $_POST['supplier_id'] = get_global_supplier();
33 start_table("class='tablestyle_noborder'");
36 supplier_list_cells(_("Select a supplier:"), 'supplier_id', null, true);
38 date_cells(_("From:"), 'TransAfterDate', null, -30);
39 date_cells(_("To:"), 'TransToDate');
41 supp_allocations_list_cells("filterType", null);
43 submit_cells('Refresh Inquiry', _("Search"));
50 set_global_supplier($_POST['supplier_id']);
52 //------------------------------------------------------------------------------------------------
54 function display_supplier_summary($supplier_record)
58 $past1 = get_company_pref('past_due_days');
60 $nowdue = "1-" . $past1 . " " . _('Days');
61 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
62 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
65 start_table("width=80% $table_style");
66 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
67 $pastdue1, $pastdue2, _("Total Balance"));
71 label_cell($supplier_record["curr_code"]);
72 label_cell($supplier_record["terms"]);
73 amount_cell($supplier_record["Balance"] - $supplier_record["Due"]);
74 amount_cell($supplier_record["Due"] - $supplier_record["Overdue1"]);
75 amount_cell($supplier_record["Overdue1"] - $supplier_record["Overdue2"]);
76 amount_cell($supplier_record["Overdue2"]);
77 amount_cell($supplier_record["Balance"]);
82 //------------------------------------------------------------------------------------------------
84 function get_transactions()
88 $date_after = date2sql($_POST['TransAfterDate']);
89 $date_to = date2sql($_POST['TransToDate']);
91 // Sherifoz 22.06.03 Also get the description
92 $sql = "SELECT ".TB_PREF."supp_trans.type, ".TB_PREF."supp_trans.trans_no,
93 ".TB_PREF."supp_trans.tran_date, ".TB_PREF."supp_trans.reference, ".TB_PREF."supp_trans.supp_reference,
94 (".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,
95 ((".TB_PREF."supp_trans.type = 20 OR ".TB_PREF."supp_trans.type = 21) AND ".TB_PREF."supp_trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
96 (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,
97 ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.supp_name, ".TB_PREF."supp_trans.due_date
98 FROM ".TB_PREF."supp_trans, ".TB_PREF."suppliers
99 WHERE ".TB_PREF."suppliers.supplier_id = ".TB_PREF."supp_trans.supplier_id
100 AND ".TB_PREF."supp_trans.tran_date >= '$date_after'
101 AND ".TB_PREF."supp_trans.tran_date <= '$date_to'";
102 if ($_POST['supplier_id'] != reserved_words::get_all())
103 $sql .= " AND ".TB_PREF."supp_trans.supplier_id = '" . $_POST['supplier_id'] . "'";
104 if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
106 if (($_POST['filterType'] == '1'))
108 $sql .= " AND (".TB_PREF."supp_trans.type = 20 OR ".TB_PREF."supp_trans.type = 2)";
110 elseif (($_POST['filterType'] == '2'))
112 $sql .= " AND ".TB_PREF."supp_trans.type = 20 ";
114 elseif ($_POST['filterType'] == '3')
116 $sql .= " AND (".TB_PREF."supp_trans.type = 22 OR ".TB_PREF."supp_trans.type = 1) ";
118 elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
120 $sql .= " AND ".TB_PREF."supp_trans.type = 21 ";
123 if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
125 $today = date2sql(Today());
126 $sql .= " AND ".TB_PREF."supp_trans.due_date < '$today' ";
130 $sql .= " ORDER BY ".TB_PREF."supp_trans.tran_date";
132 return db_query($sql,"No supplier transactions were returned");
135 //------------------------------------------------------------------------------------------------
137 if (($_POST['supplier_id'] != "") && ($_POST['supplier_id'] != reserved_words::get_all()))
139 $supplier_record = get_supplier_details($_POST['supplier_id']);
140 display_supplier_summary($supplier_record);
143 //------------------------------------------------------------------------------------------------
145 $result = get_transactions();
147 if (db_num_rows($result) == 0)
149 display_note(_("There are no transactions to display for the given dates."), 1, 1);
154 //------------------------------------------------------------------------------------------------
156 /*show a table of the transactions returned by the sql */
158 start_table("$table_style width=80%");
159 if ($_POST['supplier_id'] == reserved_words::get_all())
160 $th = array(_("Type"), _("#"), _("Reference"), _("Supplier"),
161 _("Supplier's Reference"), _("Date"), _("Due Date"), _("Currency"),
162 _("Debit"), _("Credit"), "");
164 $th = array(_("Type"), _("#"), _("Reference"),
165 _("Supplier's Reference"), _("Date"), _("Due Date"),
166 _("Debit"), _("Credit"), "");
170 $k = 0; //row colour counter
172 while ($myrow = db_fetch($result))
175 if ($myrow['OverDue'] == 1)
177 start_row("class='overduebg'");
182 alt_table_row_color($k);
185 $date = sql2date($myrow["tran_date"]);
187 $duedate = ((($myrow["type"]== 20) || ($myrow["type"]== 21))?sql2date($myrow["due_date"]):"");
190 label_cell(systypes::name($myrow["type"]));
191 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
192 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"], $myrow["reference"]));
193 if ($_POST['supplier_id'] == reserved_words::get_all())
194 label_cell($myrow["supp_name"]);
195 label_cell($myrow["supp_reference"]);
197 label_cell($duedate);
198 if ($_POST['supplier_id'] == reserved_words::get_all())
199 label_cell($myrow["curr_code"]);
200 if ($myrow["TotalAmount"] >= 0)
202 amount_cell(abs($myrow["TotalAmount"]));
203 if ($myrow["TotalAmount"] < 0)
206 label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
216 //end of page full new headings if
222 display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'");