5 include($path_to_root . "/includes/db_pager.inc");
6 include($path_to_root . "/includes/session.inc");
8 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
11 if ($use_popup_windows)
12 $js .= get_js_open_window(900, 500);
14 $js .= get_js_date_picker();
15 page(_("Supplier Inquiry"), false, false, "", $js);
17 if (isset($_GET['supplier_id'])){
18 $_POST['supplier_id'] = $_GET['supplier_id'];
20 if (isset($_GET['FromDate'])){
21 $_POST['TransAfterDate'] = $_GET['FromDate'];
23 if (isset($_GET['ToDate'])){
24 $_POST['TransToDate'] = $_GET['ToDate'];
27 //------------------------------------------------------------------------------------------------
29 start_form(false, true);
31 if (!isset($_POST['supplier_id']))
32 $_POST['supplier_id'] = get_global_supplier();
34 start_table("class='tablestyle_noborder'");
37 supplier_list_cells(_("Select a supplier:"), 'supplier_id', null, true);
39 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
40 date_cells(_("To:"), 'TransToDate');
42 supp_allocations_list_cell("filterType", null);
44 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), true);
51 set_global_supplier($_POST['supplier_id']);
53 //------------------------------------------------------------------------------------------------
55 function display_supplier_summary($supplier_record)
59 $past1 = get_company_pref('past_due_days');
61 $nowdue = "1-" . $past1 . " " . _('Days');
62 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
63 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
66 start_table("width=80% $table_style");
67 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
68 $pastdue1, $pastdue2, _("Total Balance"));
72 label_cell($supplier_record["curr_code"]);
73 label_cell($supplier_record["terms"]);
74 amount_cell($supplier_record["Balance"] - $supplier_record["Due"]);
75 amount_cell($supplier_record["Due"] - $supplier_record["Overdue1"]);
76 amount_cell($supplier_record["Overdue1"] - $supplier_record["Overdue2"]);
77 amount_cell($supplier_record["Overdue2"]);
78 amount_cell($supplier_record["Balance"]);
82 //------------------------------------------------------------------------------------------------
84 div_start('totals_tbl');
85 if (($_POST['supplier_id'] != "") && ($_POST['supplier_id'] != reserved_words::get_all()))
87 $supplier_record = get_supplier_details($_POST['supplier_id']);
88 display_supplier_summary($supplier_record);
92 if(get_post('RefreshInquiry'))
94 $Ajax->activate('totals_tbl');
97 //------------------------------------------------------------------------------------------------
98 function systype_name($dummy, $type)
100 return systypes::name($type);
103 function trans_view($trans)
105 return get_trans_view_str($trans["type"], $trans["trans_no"]);
108 function due_date($row)
110 return ($row["type"]== 20) || ($row["type"]== 21)
111 ? $row["due_date"] : '';
114 function gl_view($row)
116 return get_gl_view_str($row["type"], $row["trans_no"]);
119 function fmt_debit($row)
121 $value = $row["TotalAmount"];
122 return $value>=0 ? price_format($value) : '';
126 function fmt_credit($row)
128 $value = -$row["TotalAmount"];
129 return $value>0 ? price_format($value) : '';
132 function prt_link($row)
134 return print_document_link($row['trans_no'], _("Print"), true, $row['type']);
137 function check_overdue($row)
139 return $row['OverDue'] == 1
140 && (abs($row["TotalAmount"]) - $row["Allocated"] != 0);
142 //------------------------------------------------------------------------------------------------
144 $date_after = date2sql($_POST['TransAfterDate']);
145 $date_to = date2sql($_POST['TransToDate']);
147 // Sherifoz 22.06.03 Also get the description
148 $sql = "SELECT trans.type,
152 trans.supp_reference,
156 (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS TotalAmount,
157 trans.alloc AS Allocated,
158 ((trans.type = 20 OR trans.type = 21) AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue,
159 (ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc) <= 0.005) AS Settled
160 FROM ".TB_PREF."supp_trans as trans, ".TB_PREF."suppliers as supplier
161 WHERE supplier.supplier_id = trans.supplier_id
162 AND trans.tran_date >= '$date_after'
163 AND trans.tran_date <= '$date_to'";
164 if ($_POST['supplier_id'] != reserved_words::get_all())
165 $sql .= " AND trans.supplier_id = '" . $_POST['supplier_id'] . "'";
166 if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
168 if (($_POST['filterType'] == '1'))
170 $sql .= " AND (trans.type = 20 OR trans.type = 2)";
172 elseif (($_POST['filterType'] == '2'))
174 $sql .= " AND trans.type = 20 ";
176 elseif ($_POST['filterType'] == '3')
178 $sql .= " AND (trans.type = 22 OR trans.type = 1) ";
180 elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
182 $sql .= " AND trans.type = 21 ";
185 if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
187 $today = date2sql(Today());
188 $sql .= " AND trans.due_date < '$today' ";
193 _("Type") => array('fun'=>'systype_name', 'ord'=>''),
194 _("#") => array('fun'=>'trans_view', 'ord'=>''),
197 _("Supplier's Reference"),
198 _("Date") => array('type'=>'date', 'ord'=>'desc'),
199 _("Due Date") => array('type'=>'date', 'fun'=>'due_date'),
200 _("Currency") => array('align'=>'center'),
201 _("Debit") => array('align'=>'right', 'fun'=>'fmt_debit'),
202 _("Credit") => array('align'=>'right', 'insert'=>true,'fun'=>'fmt_credit'),
203 array('insert'=>true, 'fun'=>'gl_view'),
206 if ($_POST['supplier_id'] != reserved_words::get_all())
208 $cols[_("Supplier")] = 'skip';
209 $cols[_("Currency")] = 'skip';
211 //------------------------------------------------------------------------------------------------
214 /*show a table of the transactions returned by the sql */
215 $table =& new_db_pager('trans_tbl', $sql, $cols);
216 $table->set_marker('check_overdue', _("Marked items are overdue."));
220 display_db_pager($table);