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