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);
12 page(_("Supplier Inquiry"), false, false, "", $js);
14 if (isset($_GET['supplier_id'])){
15 $_POST['supplier_id'] = $_GET['supplier_id'];
17 if (isset($_GET['FromDate'])){
18 $_POST['TransAfterDate'] = $_GET['FromDate'];
20 if (isset($_GET['ToDate'])){
21 $_POST['TransToDate'] = $_GET['ToDate'];
24 //------------------------------------------------------------------------------------------------
26 start_form(false, true);
28 if (!isset($_POST['supplier_id']))
29 $_POST['supplier_id'] = get_global_supplier();
31 start_table("class='tablestyle_noborder'");
34 supplier_list_cells(_("Select a supplier:"), 'supplier_id', null, true);
36 date_cells(_("From:"), 'TransAfterDate', null, -30);
37 date_cells(_("To:"), 'TransToDate');
39 supp_allocations_list_cells("filterType", null);
41 submit_cells('Refresh Inquiry', _("Search"));
48 set_global_supplier($_POST['supplier_id']);
50 //------------------------------------------------------------------------------------------------
52 function display_supplier_summary($supplier_record)
56 $past1 = get_company_pref('past_due_days');
58 $nowdue = "1-" . $past1 . " " . _('Days');
59 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
60 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
63 start_table("width=80% $table_style");
64 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
65 $pastdue1, $pastdue2, _("Total Balance"));
69 label_cell($supplier_record["curr_code"]);
70 label_cell($supplier_record["terms"]);
71 amount_cell($supplier_record["Balance"] - $supplier_record["Due"]);
72 amount_cell($supplier_record["Due"] - $supplier_record["Overdue1"]);
73 amount_cell($supplier_record["Overdue1"] - $supplier_record["Overdue2"]);
74 amount_cell($supplier_record["Overdue2"]);
75 amount_cell($supplier_record["Balance"]);
80 //------------------------------------------------------------------------------------------------
82 function get_transactions()
86 $date_after = date2sql($_POST['TransAfterDate']);
87 $date_to = date2sql($_POST['TransToDate']);
89 // Sherifoz 22.06.03 Also get the description
90 $sql = "SELECT ".TB_PREF."supp_trans.type, ".TB_PREF."supp_trans.trans_no,
91 ".TB_PREF."supp_trans.tran_date, ".TB_PREF."supp_trans.reference, ".TB_PREF."supp_trans.supp_reference,
92 (".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,
93 ((".TB_PREF."supp_trans.type = 20 OR ".TB_PREF."supp_trans.type = 21) AND ".TB_PREF."supp_trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
94 (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,
95 ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.supp_name, ".TB_PREF."supp_trans.due_date
96 FROM ".TB_PREF."supp_trans, ".TB_PREF."suppliers
97 WHERE ".TB_PREF."suppliers.supplier_id = ".TB_PREF."supp_trans.supplier_id
98 AND ".TB_PREF."supp_trans.tran_date >= '$date_after'
99 AND ".TB_PREF."supp_trans.tran_date <= '$date_to'";
100 if ($_POST['supplier_id'] != reserved_words::get_all())
101 $sql .= " AND ".TB_PREF."supp_trans.supplier_id = '" . $_POST['supplier_id'] . "'";
102 if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
104 if (($_POST['filterType'] == '1'))
106 $sql .= " AND (".TB_PREF."supp_trans.type = 20 OR ".TB_PREF."supp_trans.type = 2)";
108 elseif (($_POST['filterType'] == '2'))
110 $sql .= " AND ".TB_PREF."supp_trans.type = 20 ";
112 elseif ($_POST['filterType'] == '3')
114 $sql .= " AND (".TB_PREF."supp_trans.type = 22 OR ".TB_PREF."supp_trans.type = 1) ";
116 elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
118 $sql .= " AND ".TB_PREF."supp_trans.type = 21 ";
121 if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
123 $today = date2sql(Today());
124 $sql .= " AND ".TB_PREF."supp_trans.due_date < '$today' ";
128 $sql .= " ORDER BY ".TB_PREF."supp_trans.tran_date";
130 return db_query($sql,"No supplier transactions were returned");
133 //------------------------------------------------------------------------------------------------
135 if (($_POST['supplier_id'] != "") && ($_POST['supplier_id'] != reserved_words::get_all()))
137 $supplier_record = get_supplier_details($_POST['supplier_id']);
138 display_supplier_summary($supplier_record);
141 //------------------------------------------------------------------------------------------------
143 $result = get_transactions();
145 if (db_num_rows($result) == 0)
147 display_note(_("There are no transactions to display for the given dates."), 1, 1);
152 //------------------------------------------------------------------------------------------------
154 /*show a table of the transactions returned by the sql */
156 start_table("$table_style width=80%");
157 if ($_POST['supplier_id'] == reserved_words::get_all())
158 $th = array(_("Type"), _("#"), _("Reference"), _("Supplier"),
159 _("Supplier's Reference"), _("Date"), _("Due Date"), _("Currency"),
160 _("Debit"), _("Credit"), "");
162 $th = array(_("Type"), _("#"), _("Reference"),
163 _("Supplier's Reference"), _("Date"), _("Due Date"),
164 _("Debit"), _("Credit"), "");
168 $k = 0; //row colour counter
170 while ($myrow = db_fetch($result))
173 if ($myrow['OverDue'] == 1)
175 start_row("class='overduebg'");
180 alt_table_row_color($k);
183 $date = sql2date($myrow["tran_date"]);
185 $duedate = ((($myrow["type"]== 20) || ($myrow["type"]== 21))?sql2date($myrow["due_date"]):"");
188 label_cell(systypes::name($myrow["type"]));
189 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
190 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"], $myrow["reference"]));
191 if ($_POST['supplier_id'] == reserved_words::get_all())
192 label_cell($myrow["supp_name"]);
193 label_cell($myrow["supp_reference"]);
195 label_cell($duedate);
196 if ($_POST['supplier_id'] == reserved_words::get_all())
197 label_cell($myrow["curr_code"]);
198 if ($myrow["TotalAmount"] >= 0)
200 amount_cell(abs($myrow["TotalAmount"]));
201 if ($myrow["TotalAmount"] < 0)
204 label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
214 //end of page full new headings if
220 display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'");