First fix of PHP 8.2 deprecated errors. Not seen with $go_debug = 0, but error.log...
[fa-stable.git] / purchasing / inquiry / supplier_inquiry.php
1 <?php
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_once($path_to_root . "/includes/db_pager.inc");
15 include_once($path_to_root . "/includes/session.inc");
16
17 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
18 include_once($path_to_root . "/reporting/includes/reporting.inc");
19
20 $js = "";
21 if ($SysPrefs->use_popup_windows)
22         $js .= get_js_open_window(900, 500);
23 if (user_use_date_picker())
24         $js .= get_js_date_picker();
25 page(_($help_context = "Supplier Inquiry"), isset($_GET['supplier_id']), false, "", $js);
26
27 if (isset($_GET['supplier_id'])){
28         $_POST['supplier_id'] = $_GET['supplier_id'];
29 }
30
31 if (isset($_GET['FromDate'])){
32         $_POST['TransAfterDate'] = $_GET['FromDate'];
33 }
34 if (isset($_GET['ToDate'])){
35         $_POST['TransToDate'] = $_GET['ToDate'];
36 }
37
38 //------------------------------------------------------------------------------------------------
39
40 function display_supplier_summary($supplier_record)
41 {
42         $past1 = get_company_pref('past_due_days');
43         $past2 = 2 * $past1;
44         $nowdue = "1-" . $past1 . " " . _('Days');
45         $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
46         $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
47         
48
49     start_table(TABLESTYLE, "width='80%'");
50     $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
51         $pastdue1, $pastdue2, _("Total Balance"));
52
53         table_header($th);
54         if ($supplier_record != false)
55         {
56             start_row();
57                 label_cell($supplier_record["curr_code"]);
58             label_cell($supplier_record["terms"]);
59             amount_cell($supplier_record["Balance"] - $supplier_record["Due"]);
60             amount_cell($supplier_record["Due"] - $supplier_record["Overdue1"]);
61             amount_cell($supplier_record["Overdue1"] - $supplier_record["Overdue2"]);
62             amount_cell($supplier_record["Overdue2"]);
63             amount_cell($supplier_record["Balance"]);
64             end_row();
65         }
66     end_table(1);
67 }
68 //------------------------------------------------------------------------------------------------
69 function systype_name($dummy, $type)
70 {
71         global $systypes_array;
72         return $systypes_array[$type];
73 }
74
75 function trans_view($trans)
76 {
77         return get_trans_view_str($trans["type"], $trans["trans_no"]);
78 }
79
80 function due_date($row)
81 {
82         return ($row["type"]== ST_SUPPINVOICE) || ($row["type"]== ST_SUPPCREDIT) ? $row["due_date"] : '';
83 }
84
85 function gl_view($row)
86 {
87         if ($row['type'] == ST_SUPPRECEIVE && get_voided_entry(ST_SUPPRECEIVE, $row['trans_no']))
88                 return set_icon(ICON_REMOVE, _("Voided."));
89         return get_gl_view_str($row["type"], $row["trans_no"]);
90 }
91
92 function credit_link($row)
93 {
94         global $page_nested;
95
96         if ($page_nested)
97                 return '';
98         return $row['type'] == ST_SUPPINVOICE && $row["TotalAmount"] - $row["Allocated"] > 0 ?
99                 pager_link(_("Credit This"),
100                         "/purchasing/supplier_credit.php?New=1&invoice_no=".
101                         $row['trans_no'], ICON_CREDIT)
102                         : '';
103 }
104
105 function fmt_amount($row)
106 {
107         $value = $row["TotalAmount"];
108         return price_format($value);
109 }
110
111 function prt_link($row)
112 {
113         if ($row['type'] == ST_SUPPAYMENT || $row['type'] == ST_BANKPAYMENT || $row['type'] == ST_SUPPCREDIT) 
114                 return print_document_link($row['trans_no']."-".$row['type'], _("Print Remittance"), true, ST_SUPPAYMENT, ICON_PRINT);
115 }
116
117 function check_overdue($row)
118 {
119         return $row['OverDue'] == 1
120                 && (abs($row["TotalAmount"]) - $row["Allocated"] != 0);
121 }
122
123 function edit_link($row)
124 {
125         global $page_nested;
126
127         if ($page_nested)
128                 return '';
129         return trans_editor_link($row['type'], $row['trans_no']);
130 }
131 //------------------------------------------------------------------------------------------------
132
133 start_form();
134
135 if (!isset($_POST['supplier_id']))
136         $_POST['supplier_id'] = get_global_supplier();
137
138 start_table(TABLESTYLE_NOBORDER);
139 start_row();
140
141 if (!$page_nested)
142         supplier_list_cells(_("Select a supplier:"), 'supplier_id', null, true, true, false, true);
143
144 supp_transactions_list_cell("filterType", null, true);
145
146 if ($_POST['filterType'] != '2')
147 {
148         date_cells(_("From:"), 'TransAfterDate', '', null, -user_transaction_days());
149         date_cells(_("To:"), 'TransToDate');
150 }
151
152 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), 'default');
153
154 end_row();
155 end_table();
156 set_global_supplier($_POST['supplier_id']);
157
158 //------------------------------------------------------------------------------------------------
159
160 div_start('totals_tbl');
161
162 if ($_POST['supplier_id'] != "" && $_POST['supplier_id'] != ALL_TEXT)
163 {
164         $supplier_record = get_supplier_details(get_post('supplier_id'), get_post('TransToDate'), true);
165     display_supplier_summary($supplier_record);
166 }
167 div_end();
168
169 if (get_post('RefreshInquiry') || list_updated('filterType'))
170 {
171         $Ajax->activate('_page_body');
172 }
173
174 //------------------------------------------------------------------------------------------------
175
176 $sql = get_sql_for_supplier_inquiry(get_post('filterType'), get_post('TransAfterDate'), get_post('TransToDate'), get_post('supplier_id'));
177
178 $cols = array(
179                         _("Type") => array('fun'=>'systype_name', 'ord'=>''), 
180                         _("#") => array('fun'=>'trans_view', 'ord'=>'', 'align'=>'right'), 
181                         _("Reference"), 
182                         _("Supplier"),
183                         _("Supplier's Reference"), 
184                         _("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'desc'), 
185                         _("Due Date") => array('type'=>'date', 'fun'=>'due_date'), 
186                         _("Currency") => array('align'=>'center'),
187                         _("Amount") => array('align'=>'right', 'fun'=>'fmt_amount'), 
188                         _("Balance") => array('align'=>'right', 'type'=>'amount'),
189                         array('insert'=>true, 'fun'=>'gl_view'),
190                         array('insert'=>true, 'fun'=>'edit_link'),
191                         array('insert'=>true, 'fun'=>'credit_link'),
192                         array('insert'=>true, 'fun'=>'prt_link')
193                         );
194
195 if ($_POST['supplier_id'] != ALL_TEXT)
196 {
197         $cols[_("Supplier")] = 'skip';
198         $cols[_("Currency")] = 'skip';
199 }
200 if ($_POST['filterType'] != '2')
201         $cols[_("Balance")] = 'skip';
202
203 /*show a table of the transactions returned by the sql */
204 $table =& new_db_pager('trans_tbl', $sql, $cols);
205 $table->set_marker('check_overdue', _("Marked items are overdue."));
206
207 $table->width = "85%";
208
209 display_db_pager($table);
210
211 end_form();
212 end_page();
213