2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_SUPPTRANSVIEW';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/db_pager.inc");
15 include($path_to_root . "/includes/session.inc");
17 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
20 if ($use_popup_windows)
21 $js .= get_js_open_window(900, 500);
23 $js .= get_js_date_picker();
24 page(_("Supplier Inquiry"), false, false, "", $js);
26 if (isset($_GET['supplier_id'])){
27 $_POST['supplier_id'] = $_GET['supplier_id'];
29 if (isset($_GET['FromDate'])){
30 $_POST['TransAfterDate'] = $_GET['FromDate'];
32 if (isset($_GET['ToDate'])){
33 $_POST['TransToDate'] = $_GET['ToDate'];
36 //------------------------------------------------------------------------------------------------
40 if (!isset($_POST['supplier_id']))
41 $_POST['supplier_id'] = get_global_supplier();
43 start_table("class='tablestyle_noborder'");
46 supplier_list_cells(_("Select a supplier:"), 'supplier_id', null, true);
48 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
49 date_cells(_("To:"), 'TransToDate');
51 supp_allocations_list_cell("filterType", null);
53 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), 'default');
58 set_global_supplier($_POST['supplier_id']);
60 //------------------------------------------------------------------------------------------------
62 function display_supplier_summary($supplier_record)
66 $past1 = get_company_pref('past_due_days');
68 $nowdue = "1-" . $past1 . " " . _('Days');
69 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
70 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
73 start_table("width=80% $table_style");
74 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
75 $pastdue1, $pastdue2, _("Total Balance"));
79 label_cell($supplier_record["curr_code"]);
80 label_cell($supplier_record["terms"]);
81 amount_cell($supplier_record["Balance"] - $supplier_record["Due"]);
82 amount_cell($supplier_record["Due"] - $supplier_record["Overdue1"]);
83 amount_cell($supplier_record["Overdue1"] - $supplier_record["Overdue2"]);
84 amount_cell($supplier_record["Overdue2"]);
85 amount_cell($supplier_record["Balance"]);
89 //------------------------------------------------------------------------------------------------
91 div_start('totals_tbl');
92 if (($_POST['supplier_id'] != "") && ($_POST['supplier_id'] != ALL_TEXT))
94 $supplier_record = get_supplier_details($_POST['supplier_id']);
95 display_supplier_summary($supplier_record);
99 if(get_post('RefreshInquiry'))
101 $Ajax->activate('totals_tbl');
104 //------------------------------------------------------------------------------------------------
105 function systype_name($dummy, $type)
107 global $systypes_array;
108 return $systypes_array[$type];
111 function trans_view($trans)
113 return get_trans_view_str($trans["type"], $trans["trans_no"]);
116 function due_date($row)
118 return ($row["type"]== 20) || ($row["type"]== 21) ? $row["due_date"] : '';
121 function gl_view($row)
123 return get_gl_view_str($row["type"], $row["trans_no"]);
126 function credit_link($row)
128 return $row['type'] == 20 && $row["TotalAmount"] - $row["Allocated"] > 0 ?
129 pager_link(_("Credit This"),
130 "/purchasing/supplier_credit.php?New=1&invoice_no=".
131 $row['trans_no'], ICON_CREDIT)
135 function fmt_debit($row)
137 $value = $row["TotalAmount"];
138 return $value>=0 ? price_format($value) : '';
142 function fmt_credit($row)
144 $value = -$row["TotalAmount"];
145 return $value>0 ? price_format($value) : '';
148 function prt_link($row)
150 return print_document_link($row['trans_no'], _("Print"), true, $row['type']);
153 function check_overdue($row)
155 return $row['OverDue'] == 1
156 && (abs($row["TotalAmount"]) - $row["Allocated"] != 0);
158 //------------------------------------------------------------------------------------------------
160 $date_after = date2sql($_POST['TransAfterDate']);
161 $date_to = date2sql($_POST['TransToDate']);
163 // Sherifoz 22.06.03 Also get the description
164 $sql = "SELECT trans.type,
168 trans.supp_reference,
172 (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount,
173 trans.alloc AS Allocated,
174 ((trans.type = 20 OR trans.type = 21) AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
175 (ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc) <= 0.005) AS Settled
176 FROM ".TB_PREF."supp_trans as trans, ".TB_PREF."suppliers as supplier
177 WHERE supplier.supplier_id = trans.supplier_id
178 AND trans.tran_date >= '$date_after'
179 AND trans.tran_date <= '$date_to'
180 AND trans.ov_amount != 0"; // exclude voided transactions
181 if ($_POST['supplier_id'] != ALL_TEXT)
182 $sql .= " AND trans.supplier_id = '" . $_POST['supplier_id'] . "'";
183 if (isset($_POST['filterType']) && $_POST['filterType'] != ALL_TEXT)
185 if (($_POST['filterType'] == '1'))
187 $sql .= " AND (trans.type = 20 OR trans.type = 2)";
189 elseif (($_POST['filterType'] == '2'))
191 $sql .= " AND trans.type = 20 ";
193 elseif ($_POST['filterType'] == '3')
195 $sql .= " AND (trans.type = 22 OR trans.type = 1) ";
197 elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
199 $sql .= " AND trans.type = 21 ";
202 if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
204 $today = date2sql(Today());
205 $sql .= " AND trans.due_date < '$today' ";
210 _("Type") => array('fun'=>'systype_name', 'ord'=>''),
211 _("#") => array('fun'=>'trans_view', 'ord'=>''),
214 _("Supplier's Reference"),
215 _("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'desc'),
216 _("Due Date") => array('type'=>'date', 'fun'=>'due_date'),
217 _("Currency") => array('align'=>'center'),
218 _("Debit") => array('align'=>'right', 'fun'=>'fmt_debit'),
219 _("Credit") => array('align'=>'right', 'insert'=>true,'fun'=>'fmt_credit'),
220 array('insert'=>true, 'fun'=>'gl_view'),
221 array('insert'=>true, 'fun'=>'credit_link')
224 if ($_POST['supplier_id'] != ALL_TEXT)
226 $cols[_("Supplier")] = 'skip';
227 $cols[_("Currency")] = 'skip';
229 //------------------------------------------------------------------------------------------------
232 /*show a table of the transactions returned by the sql */
233 $table =& new_db_pager('trans_tbl', $sql, $cols);
234 $table->set_marker('check_overdue', _("Marked items are overdue."));
236 if (get_post('RefreshInquiry')) {
237 $table->set_sql($sql);
238 $table->set_columns($cols);
240 $table->width = "85%";
243 display_db_pager($table);