2 /**********************************************************************
\r
3 Copyright (C) FrontAccounting, LLC.
\r
4 Released under the terms of the GNU General Public License, GPL,
\r
5 as published by the Free Software Foundation, either version 3
\r
6 of the License, or (at your option) any later version.
\r
7 This program is distributed in the hope that it will be useful,
\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
\r
11 ***********************************************************************/
\r
12 $page_security = 'SA_SALESTRANSVIEW';
\r
13 $path_to_root = "../..";
\r
14 include_once($path_to_root . "/includes/db_pager.inc");
\r
15 include_once($path_to_root . "/includes/session.inc");
\r
17 include_once($path_to_root . "/sales/includes/sales_ui.inc");
\r
18 include_once($path_to_root . "/sales/includes/sales_db.inc");
\r
19 include_once($path_to_root . "/reporting/includes/reporting.inc");
\r
21 if (!@$_GET['popup'])
\r
24 if ($use_popup_windows)
\r
25 $js .= get_js_open_window(900, 500);
\r
26 if ($use_date_picker)
\r
27 $js .= get_js_date_picker();
\r
28 page(_($help_context = "Customer Transactions"), isset($_GET['customer_id']), false, "", $js);
\r
31 if (isset($_GET['customer_id']))
\r
33 $_POST['customer_id'] = $_GET['customer_id'];
\r
36 //------------------------------------------------------------------------------------------------
\r
38 if (!@$_GET['popup'])
\r
41 if (!isset($_POST['customer_id']))
\r
42 $_POST['customer_id'] = get_global_customer();
\r
44 start_table(TABLESTYLE_NOBORDER);
\r
47 if (!@$_GET['popup'])
\r
48 customer_list_cells(_("Select a customer: "), 'customer_id', null, true, false, false, !@$_GET['popup']);
\r
50 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
\r
51 date_cells(_("To:"), 'TransToDate', '', null, 1);
\r
53 if (!isset($_POST['filterType']))
\r
54 $_POST['filterType'] = 0;
\r
56 cust_allocations_list_cells(null, 'filterType', $_POST['filterType'], true);
\r
58 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), 'default');
\r
62 set_global_customer($_POST['customer_id']);
\r
64 //------------------------------------------------------------------------------------------------
\r
66 function display_customer_summary($customer_record)
\r
68 $past1 = get_company_pref('past_due_days');
\r
69 $past2 = 2 * $past1;
\r
70 if ($customer_record["dissallow_invoices"] != 0)
\r
72 echo "<center><font color=red size=4><b>" . _("CUSTOMER ACCOUNT IS ON HOLD") . "</font></b></center>";
\r
75 $nowdue = "1-" . $past1 . " " . _('Days');
\r
76 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
\r
77 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
\r
79 start_table(TABLESTYLE, "width=80%");
\r
80 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
\r
81 $pastdue1, $pastdue2, _("Total Balance"));
\r
85 label_cell($customer_record["curr_code"]);
\r
86 label_cell($customer_record["terms"]);
\r
87 amount_cell($customer_record["Balance"] - $customer_record["Due"]);
\r
88 amount_cell($customer_record["Due"] - $customer_record["Overdue1"]);
\r
89 amount_cell($customer_record["Overdue1"] - $customer_record["Overdue2"]);
\r
90 amount_cell($customer_record["Overdue2"]);
\r
91 amount_cell($customer_record["Balance"]);
\r
96 //------------------------------------------------------------------------------------------------
\r
98 div_start('totals_tbl');
\r
99 if ($_POST['customer_id'] != "" && $_POST['customer_id'] != ALL_TEXT)
\r
101 $customer_record = get_customer_details($_POST['customer_id'], $_POST['TransToDate']);
\r
102 display_customer_summary($customer_record);
\r
107 if(get_post('RefreshInquiry'))
\r
109 $Ajax->activate('totals_tbl');
\r
111 //------------------------------------------------------------------------------------------------
\r
113 function systype_name($dummy, $type)
\r
115 global $systypes_array;
\r
117 return $systypes_array[$type];
\r
120 function order_view($row)
\r
122 return $row['order_']>0 ?
\r
123 get_customer_trans_view_str(ST_SALESORDER, $row['order_'])
\r
127 function trans_view($trans)
\r
129 return get_trans_view_str($trans["type"], $trans["trans_no"]);
\r
132 function due_date($row)
\r
134 return $row["type"] == ST_SALESINVOICE ? $row["due_date"] : '';
\r
137 function gl_view($row)
\r
139 return get_gl_view_str($row["type"], $row["trans_no"]);
\r
142 function fmt_debit($row)
\r
145 $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT ?
\r
146 -$row["TotalAmount"] : $row["TotalAmount"];
\r
147 return $value>=0 ? price_format($value) : '';
\r
151 function fmt_credit($row)
\r
154 !($row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT) ?
\r
155 -$row["TotalAmount"] : $row["TotalAmount"];
\r
156 return $value>0 ? price_format($value) : '';
\r
159 function credit_link($row)
\r
161 if (@$_GET['popup'])
\r
163 return $row['type'] == ST_SALESINVOICE && $row["Outstanding"] > 0 ?
\r
164 pager_link(_("Credit This") ,
\r
165 "/sales/customer_credit_invoice.php?InvoiceNumber=". $row['trans_no'], ICON_CREDIT):'';
\r
168 function edit_link($row)
\r
172 if (@$_GET['popup'])
\r
174 switch($row['type']) {
\r
175 case ST_SALESINVOICE:
\r
176 if (get_voided_entry(ST_SALESINVOICE, $row["trans_no"]) === false && $row['Allocated'] == 0)
\r
177 $str = "/sales/customer_invoice.php?ModifyInvoice=".$row['trans_no'];
\r
179 case ST_CUSTCREDIT:
\r
180 if (get_voided_entry(ST_CUSTCREDIT, $row["trans_no"]) === false && $row['Allocated'] == 0) // 2008-11-19 Joe Hunt
\r
182 if ($row['order_']==0) // free-hand credit note
\r
183 $str = "/sales/credit_note_entry.php?ModifyCredit=".$row['trans_no'];
\r
184 else // credit invoice
\r
185 $str = "/sales/customer_credit_invoice.php?ModifyCredit=".$row['trans_no'];
\r
188 case ST_CUSTDELIVERY:
\r
189 if (get_voided_entry(ST_CUSTDELIVERY, $row["trans_no"]) === false)
\r
190 $str = "/sales/customer_delivery.php?ModifyDelivery=".$row['trans_no'];
\r
192 case ST_CUSTPAYMENT:
\r
193 if (get_voided_entry(ST_CUSTPAYMENT, $row["trans_no"]) === false)
\r
194 $str = "/sales/customer_payments.php?trans_no=".$row['trans_no'];
\r
197 if ($str != "" && !is_closed_trans($row['type'], $row["trans_no"]))
\r
198 return pager_link(_('Edit'), $str, ICON_EDIT);
\r
202 function prt_link($row)
\r
204 if ($row['type'] == ST_CUSTPAYMENT || $row['type'] == ST_BANKDEPOSIT)
\r
205 return print_document_link($row['trans_no']."-".$row['type'], _("Print Receipt"), true, ST_CUSTPAYMENT, ICON_PRINT);
\r
206 elseif ($row['type'] == ST_BANKPAYMENT) // bank payment printout not defined yet.
\r
209 return print_document_link($row['trans_no']."-".$row['type'], _("Print"), true, $row['type'], ICON_PRINT);
\r
212 function check_overdue($row)
\r
214 return $row['OverDue'] == 1
\r
215 && (abs($row["TotalAmount"]) - $row["Allocated"] != 0);
\r
217 //------------------------------------------------------------------------------------------------
\r
218 $sql = get_sql_for_customer_inquiry();
\r
220 //------------------------------------------------------------------------------------------------
\r
221 db_query("set @bal:=0");
\r
224 _("Type") => array('fun'=>'systype_name', 'ord'=>''),
\r
225 _("#") => array('fun'=>'trans_view', 'ord'=>''),
\r
226 _("Order") => array('fun'=>'order_view'),
\r
228 _("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'desc'),
\r
229 _("Due Date") => array('type'=>'date', 'fun'=>'due_date'),
\r
230 _("Customer") => array('ord'=>''),
\r
231 _("Branch") => array('ord'=>''),
\r
232 _("Currency") => array('align'=>'center'),
\r
233 _("Debit") => array('align'=>'right', 'fun'=>'fmt_debit'),
\r
234 _("Credit") => array('align'=>'right','insert'=>true, 'fun'=>'fmt_credit'),
\r
235 _("RB") => array('align'=>'right', 'type'=>'amount'),
\r
236 array('insert'=>true, 'fun'=>'gl_view'),
\r
237 array('insert'=>true, 'fun'=>'credit_link'),
\r
238 array('insert'=>true, 'fun'=>'edit_link'),
\r
239 array('insert'=>true, 'fun'=>'prt_link')
\r
243 if ($_POST['customer_id'] != ALL_TEXT) {
\r
244 $cols[_("Customer")] = 'skip';
\r
245 $cols[_("Currency")] = 'skip';
\r
247 if ($_POST['filterType'] == ALL_TEXT)
\r
248 $cols[_("RB")] = 'skip';
\r
250 $table =& new_db_pager('trans_tbl', $sql, $cols);
\r
251 $table->set_marker('check_overdue', _("Marked items are overdue."));
\r
253 $table->width = "85%";
\r
255 display_db_pager($table);
\r
257 if (!@$_GET['popup'])
\r
260 end_page(@$_GET['popup'], false, false);
\r