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_SALESTRANSVIEW';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/db_pager.inc");
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/sales/includes/sales_ui.inc");
18 include_once($path_to_root . "/sales/includes/sales_db.inc");
19 include_once($path_to_root . "/reporting/includes/reporting.inc");
22 if ($SysPrefs->use_popup_windows)
23 $js .= get_js_open_window(900, 500);
24 if (user_use_date_picker())
25 $js .= get_js_date_picker();
26 page(_($help_context = "Customer Transactions"), isset($_GET['customer_id']), false, "", $js);
28 //------------------------------------------------------------------------------------------------
30 function systype_name($dummy, $type)
32 global $systypes_array;
34 return $systypes_array[$type];
37 function order_view($row)
39 return $row['order_']>0 ?
40 get_customer_trans_view_str(ST_SALESORDER, $row['order_'])
44 function trans_view($trans)
46 return get_trans_view_str($trans["type"], $trans["trans_no"]);
49 function due_date($row)
51 return $row["type"] == ST_SALESINVOICE ? $row["due_date"] : '';
54 function gl_view($row)
56 return get_gl_view_str($row["type"], $row["trans_no"]);
59 function fmt_amount($row)
62 $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT ?
63 -$row["TotalAmount"] : $row["TotalAmount"];
64 return price_format($value);
67 function credit_link($row)
73 return $row['type'] == ST_SALESINVOICE && $row["Outstanding"] > 0 ?
74 pager_link(_("Credit This") ,
75 "/sales/customer_credit_invoice.php?InvoiceNumber=". $row['trans_no'], ICON_CREDIT):'';
78 function edit_link($row)
86 return $row['type'] == ST_CUSTCREDIT && $row['order_'] ? '' : // allow only free hand credit notes edition
87 trans_editor_link($row['type'], $row['trans_no']);
90 function prt_link($row)
92 if ($row['type'] == ST_CUSTPAYMENT || $row['type'] == ST_BANKDEPOSIT)
93 return print_document_link($row['trans_no']."-".$row['type'], _("Print Receipt"), true, ST_CUSTPAYMENT, ICON_PRINT);
94 elseif ($row['type'] == ST_BANKPAYMENT) // bank payment printout not defined yet.
97 return print_document_link($row['trans_no']."-".$row['type'], _("Print"), true, $row['type'], ICON_PRINT);
100 function check_overdue($row)
102 return $row['OverDue'] == 1
103 && floatcmp($row["TotalAmount"], $row["Allocated"]) != 0;
105 //------------------------------------------------------------------------------------------------
107 function display_customer_summary($customer_record)
109 $past1 = get_company_pref('past_due_days');
111 if ($customer_record["dissallow_invoices"] != 0)
113 echo "<center><font color=red size=4><b>" . _("CUSTOMER ACCOUNT IS ON HOLD") . "</font></b></center>";
116 $nowdue = "1-" . $past1 . " " . _('Days');
117 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
118 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
120 start_table(TABLESTYLE, "width='80%'");
121 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
122 $pastdue1, $pastdue2, _("Total Balance"));
126 label_cell($customer_record["curr_code"]);
127 label_cell($customer_record["terms"]);
128 amount_cell($customer_record["Balance"] - $customer_record["Due"]);
129 amount_cell($customer_record["Due"] - $customer_record["Overdue1"]);
130 amount_cell($customer_record["Overdue1"] - $customer_record["Overdue2"]);
131 amount_cell($customer_record["Overdue2"]);
132 amount_cell($customer_record["Balance"]);
138 if (isset($_GET['customer_id']))
140 $_POST['customer_id'] = $_GET['customer_id'];
143 //------------------------------------------------------------------------------------------------
147 if (!isset($_POST['customer_id']))
148 $_POST['customer_id'] = get_global_customer();
150 start_table(TABLESTYLE_NOBORDER);
154 customer_list_cells(_("Select a customer: "), 'customer_id', null, true, true, false, true);
156 cust_allocations_list_cells(null, 'filterType', null, true, true);
158 if ($_POST['filterType'] != '2')
160 date_cells(_("From:"), 'TransAfterDate', '', null, -user_transaction_days());
161 date_cells(_("To:"), 'TransToDate', '', null);
164 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), 'default');
168 set_global_customer($_POST['customer_id']);
170 //------------------------------------------------------------------------------------------------
172 div_start('totals_tbl');
173 if ($_POST['customer_id'] != "" && $_POST['customer_id'] != ALL_TEXT)
175 $customer_record = get_customer_details(get_post('customer_id'), get_post('TransToDate'));
176 display_customer_summary($customer_record);
181 if (get_post('RefreshInquiry') || list_updated('filterType'))
183 $Ajax->activate('_page_body');
185 //------------------------------------------------------------------------------------------------
186 $sql = get_sql_for_customer_inquiry(get_post('TransAfterDate'), get_post('TransToDate'),
187 get_post('customer_id'), get_post('filterType'));
189 //------------------------------------------------------------------------------------------------
190 //db_query("set @bal:=0");
193 _("Type") => array('fun'=>'systype_name', 'ord'=>''),
194 _("#") => array('fun'=>'trans_view', 'ord'=>'', 'align'=>'right'),
195 _("Order") => array('fun'=>'order_view', 'align'=>'right'),
197 _("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'desc'),
198 _("Due Date") => array('type'=>'date', 'fun'=>'due_date'),
199 _("Customer") => array('ord'=>''),
200 _("Branch") => array('ord'=>''),
201 _("Currency") => array('align'=>'center'),
202 _("Amount") => array('align'=>'right', 'fun'=>'fmt_amount'),
203 _("Balance") => array('align'=>'right', 'type'=>'amount'),
204 array('insert'=>true, 'fun'=>'gl_view'),
205 array('insert'=>true, 'fun'=>'credit_link'),
206 array('insert'=>true, 'fun'=>'edit_link'),
207 array('insert'=>true, 'fun'=>'prt_link')
211 if ($_POST['customer_id'] != ALL_TEXT) {
212 $cols[_("Customer")] = 'skip';
213 $cols[_("Currency")] = 'skip';
215 if ($_POST['filterType'] != '2')
216 $cols[_("Balance")] = 'skip';
218 $table =& new_db_pager('trans_tbl', $sql, $cols);
219 $table->set_marker('check_overdue', _("Marked items are overdue."));
221 $table->width = "85%";
223 display_db_pager($table);