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($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
22 if ($use_popup_windows)
\r
23 $js .= get_js_open_window(900, 500);
\r
24 if ($use_date_picker)
\r
25 $js .= get_js_date_picker();
\r
26 page(_($help_context = "Customer Transactions"), isset($_GET['customer_id']), false, "", $js);
\r
29 if (isset($_GET['customer_id']))
\r
31 $_POST['customer_id'] = $_GET['customer_id'];
\r
34 //------------------------------------------------------------------------------------------------
\r
38 if (!isset($_POST['customer_id']))
\r
39 $_POST['customer_id'] = get_global_customer();
\r
41 start_table(TABLESTYLE_NOBORDER);
\r
44 customer_list_cells(_("Select a customer: "), 'customer_id', null, true, false, false, !@$_REQUEST['popup']);
\r
46 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
\r
47 date_cells(_("To:"), 'TransToDate', '', null, 1);
\r
49 if (!isset($_POST['filterType']))
\r
50 $_POST['filterType'] = 0;
\r
52 cust_allocations_list_cells(null, 'filterType', $_POST['filterType'], true);
\r
54 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), 'default');
\r
58 set_global_customer($_POST['customer_id']);
\r
60 //------------------------------------------------------------------------------------------------
\r
62 function display_customer_summary($customer_record)
\r
64 $past1 = get_company_pref('past_due_days');
\r
65 $past2 = 2 * $past1;
\r
66 if ($customer_record["dissallow_invoices"] != 0)
\r
68 echo "<center><font color=red size=4><b>" . _("CUSTOMER ACCOUNT IS ON HOLD") . "</font></b></center>";
\r
71 $nowdue = "1-" . $past1 . " " . _('Days');
\r
72 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
\r
73 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
\r
75 start_table(TABLESTYLE, "width=80%");
\r
76 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
\r
77 $pastdue1, $pastdue2, _("Total Balance"));
\r
81 label_cell($customer_record["curr_code"]);
\r
82 label_cell($customer_record["terms"]);
\r
83 amount_cell($customer_record["Balance"] - $customer_record["Due"]);
\r
84 amount_cell($customer_record["Due"] - $customer_record["Overdue1"]);
\r
85 amount_cell($customer_record["Overdue1"] - $customer_record["Overdue2"]);
\r
86 amount_cell($customer_record["Overdue2"]);
\r
87 amount_cell($customer_record["Balance"]);
\r
92 //------------------------------------------------------------------------------------------------
\r
94 div_start('totals_tbl');
\r
95 if ($_POST['customer_id'] != "" && $_POST['customer_id'] != ALL_TEXT)
\r
97 $customer_record = get_customer_details($_POST['customer_id'], $_POST['TransToDate']);
\r
98 display_customer_summary($customer_record);
\r
103 if(get_post('RefreshInquiry'))
\r
105 $Ajax->activate('totals_tbl');
\r
107 //------------------------------------------------------------------------------------------------
\r
109 function systype_name($dummy, $type)
\r
111 global $systypes_array;
\r
113 return $systypes_array[$type];
\r
116 function order_view($row)
\r
118 return $row['order_']>0 ?
\r
119 get_customer_trans_view_str(ST_SALESORDER, $row['order_'])
\r
123 function trans_view($trans)
\r
125 return get_trans_view_str($trans["type"], $trans["trans_no"]);
\r
128 function due_date($row)
\r
130 return $row["type"] == ST_SALESINVOICE ? $row["due_date"] : '';
\r
133 function gl_view($row)
\r
135 return get_gl_view_str($row["type"], $row["trans_no"]);
\r
138 function fmt_debit($row)
\r
141 $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT ?
\r
142 -$row["TotalAmount"] : $row["TotalAmount"];
\r
143 return $value>=0 ? price_format($value) : '';
\r
147 function fmt_credit($row)
\r
150 !($row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT) ?
\r
151 -$row["TotalAmount"] : $row["TotalAmount"];
\r
152 return $value>0 ? price_format($value) : '';
\r
155 function credit_link($row)
\r
157 return $row['type'] == ST_SALESINVOICE && $row["Outstanding"] > 0 ?
\r
158 pager_link(_("Credit This") ,
\r
159 "/sales/customer_credit_invoice.php?InvoiceNumber=". $row['trans_no'], ICON_CREDIT):'';
\r
162 function edit_link($row)
\r
166 switch($row['type']) {
\r
167 case ST_SALESINVOICE:
\r
168 if (get_voided_entry(ST_SALESINVOICE, $row["trans_no"]) === false && $row['Allocated'] == 0)
\r
169 $str = "/sales/customer_invoice.php?ModifyInvoice=".$row['trans_no'];
\r
171 case ST_CUSTCREDIT:
\r
172 if (get_voided_entry(ST_CUSTCREDIT, $row["trans_no"]) === false && $row['Allocated'] == 0) // 2008-11-19 Joe Hunt
\r
174 if ($row['order_']==0) // free-hand credit note
\r
175 $str = "/sales/credit_note_entry.php?ModifyCredit=".$row['trans_no'];
\r
176 else // credit invoice
\r
177 $str = "/sales/customer_credit_invoice.php?ModifyCredit=".$row['trans_no'];
\r
180 case ST_CUSTDELIVERY:
\r
181 if (get_voided_entry(ST_CUSTDELIVERY, $row["trans_no"]) === false)
\r
182 $str = "/sales/customer_delivery.php?ModifyDelivery=".$row['trans_no'];
\r
184 case ST_CUSTPAYMENT:
\r
185 if (get_voided_entry(ST_CUSTPAYMENT, $row["trans_no"]) === false)
\r
186 $str = "/sales/customer_payments.php?trans_no=".$row['trans_no'];
\r
189 if ($str != "" && !is_closed_trans($row['type'], $row["trans_no"]))
\r
190 return pager_link(_('Edit'), $str, ICON_EDIT);
\r
194 function prt_link($row)
\r
196 if ($row['type'] == ST_CUSTPAYMENT || $row['type'] == ST_BANKDEPOSIT)
\r
197 return print_document_link($row['trans_no']."-".$row['type'], _("Print Receipt"), true, ST_CUSTPAYMENT, ICON_PRINT);
\r
198 elseif ($row['type'] == ST_BANKPAYMENT) // bank payment printout not defined yet.
\r
201 return print_document_link($row['trans_no']."-".$row['type'], _("Print"), true, $row['type'], ICON_PRINT);
\r
204 function check_overdue($row)
\r
206 return $row['OverDue'] == 1
\r
207 && (abs($row["TotalAmount"]) - $row["Allocated"] != 0);
\r
209 //------------------------------------------------------------------------------------------------
\r
210 $sql = get_sql_for_customer_inquiry();
\r
212 //------------------------------------------------------------------------------------------------
\r
213 db_query("set @bal:=0");
\r
216 _("Type") => array('fun'=>'systype_name', 'ord'=>''),
\r
217 _("#") => array('fun'=>'trans_view', 'ord'=>''),
\r
218 _("Order") => array('fun'=>'order_view'),
\r
220 _("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'desc'),
\r
221 _("Due Date") => array('type'=>'date', 'fun'=>'due_date'),
\r
222 _("Customer") => array('ord'=>''),
\r
223 _("Branch") => array('ord'=>''),
\r
224 _("Currency") => array('align'=>'center'),
\r
225 _("Debit") => array('align'=>'right', 'fun'=>'fmt_debit'),
\r
226 _("Credit") => array('align'=>'right','insert'=>true, 'fun'=>'fmt_credit'),
\r
227 _("RB") => array('align'=>'right', 'type'=>'amount'),
\r
228 array('insert'=>true, 'fun'=>'gl_view'),
\r
229 array('insert'=>true, 'fun'=>'credit_link'),
\r
230 array('insert'=>true, 'fun'=>'edit_link'),
\r
231 array('insert'=>true, 'fun'=>'prt_link')
\r
235 if ($_POST['customer_id'] != ALL_TEXT) {
\r
236 $cols[_("Customer")] = 'skip';
\r
237 $cols[_("Currency")] = 'skip';
\r
239 if ($_POST['filterType'] == ALL_TEXT)
\r
240 $cols[_("RB")] = 'skip';
\r
242 $table =& new_db_pager('trans_tbl', $sql, $cols);
\r
243 $table->set_marker('check_overdue', _("Marked items are overdue."));
\r
245 $table->width = "85%";
\r
247 display_db_pager($table);
\r
249 hidden('popup', @$_REQUEST['popup']);
\r
252 end_page(@$_REQUEST['popup'], false, false);
\r