5 include($path_to_root . "/includes/db_pager.inc");
6 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/sales/includes/sales_ui.inc");
9 include_once($path_to_root . "/sales/includes/sales_db.inc");
10 include_once($path_to_root . "/reporting/includes/reporting.inc");
13 if ($use_popup_windows)
14 $js .= get_js_open_window(900, 500);
16 $js .= get_js_date_picker();
17 page(_("Customer Transactions"), false, false, "", $js);
20 if (isset($_GET['customer_id']))
22 $_POST['customer_id'] = $_GET['customer_id'];
25 //------------------------------------------------------------------------------------------------
29 if (!isset($_POST['customer_id']))
30 $_POST['customer_id'] = get_global_customer();
32 start_table("class='tablestyle_noborder'");
35 customer_list_cells(_("Select a customer: "), 'customer_id', null, true);
37 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
38 date_cells(_("To:"), 'TransToDate', '', null, 1);
40 if (!isset($_POST['filterType']))
41 $_POST['filterType'] = 0;
43 cust_allocations_list_cells(null, 'filterType', $_POST['filterType'], true);
45 submit_cells('RefreshInquiry', _("Search"),'',_('Refresh Inquiry'), true);
51 set_global_customer($_POST['customer_id']);
53 //------------------------------------------------------------------------------------------------
55 function display_customer_summary($customer_record)
59 $past1 = get_company_pref('past_due_days');
61 if ($customer_record["dissallow_invoices"] != 0)
63 echo "<center><font color=red size=4><b>" . _("CUSTOMER ACCOUNT IS ON HOLD") . "</font></b></center>";
66 $nowdue = "1-" . $past1 . " " . _('Days');
67 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
68 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
70 start_table("width=80% $table_style");
71 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
72 $pastdue1, $pastdue2, _("Total Balance"));
76 label_cell($customer_record["curr_code"]);
77 label_cell($customer_record["terms"]);
78 amount_cell($customer_record["Balance"] - $customer_record["Due"]);
79 amount_cell($customer_record["Due"] - $customer_record["Overdue1"]);
80 amount_cell($customer_record["Overdue1"] - $customer_record["Overdue2"]);
81 amount_cell($customer_record["Overdue2"]);
82 amount_cell($customer_record["Balance"]);
87 //------------------------------------------------------------------------------------------------
89 div_start('totals_tbl');
90 if ($_POST['customer_id'] != "" && $_POST['customer_id'] != reserved_words::get_all())
92 $customer_record = get_customer_details($_POST['customer_id'], $_POST['TransToDate']);
93 display_customer_summary($customer_record);
99 //------------------------------------------------------------------------------------------------
100 function systype_name($dummy, $type)
102 return systypes::name($type);
105 function order_view($row)
107 return $row['order_']>0 ?
108 get_customer_trans_view_str(systypes::sales_order(), $row['order_'])
112 function trans_view($trans)
114 return get_trans_view_str($trans["type"], $trans["trans_no"]);
117 function due_date($row)
119 return ($row["type"]==20 || $row["type"]==21)? sql2date($row["due_date"]) : '';
122 function fmt_balance($row)
124 return price_format($row["TotalAmount"] - $row["Allocated"]);
127 function gl_view($row)
129 return get_gl_view_str($row["type"], $row["trans_no"]);
132 function fmt_debit($row)
135 $row['type']==11 || $row['type']==12 || $row['type']==2 ?
136 -$row["TotalAmount"] : $row["TotalAmount"];
137 return $value>=0 ? price_format($value) : '';
141 function fmt_credit($row)
144 !($row['type']==11 || $row['type']==12 || $row['type']==2) ?
145 -$row["TotalAmount"] : $row["TotalAmount"];
146 return $value>0 ? price_format($value) : '';
149 function alloc_link($row)
151 if ($row['type'] == 10)
152 if ($row["TotalAmount"] - $row["Allocated"] > 0)
153 return pager_link(_("Allocation"),
154 "/sales/allocations/customer_allocate.php"
155 ."?trans_no={$row['trans_no']}&trans_type="
160 function credit_link($row)
162 return $row['type'] == 10 ?
163 pager_link(_("Credit This"),
164 "/sales/customer_credit_invoice.php?InvoiceNumber=".
169 function edit_link($row)
173 switch($row['type']) {
175 $str = "/sales/customer_invoice.php?ModifyInvoice=".$row['trans_no'];
178 if ($row['order_']==0) // free-hand credit note
179 $str = "/sales/credit_note_entry.php?ModifyCredit=".$row['trans_no'];
180 else // credit invoice
181 $str = "/sales/customer_credit_invoice.php?ModifyCredit=".$row['trans_no'];
184 $str = "/sales/customer_delivery.php?ModifyDelivery=".$row['trans_no'];
187 return pager_link(_('Edit'), $str);
190 function prt_link($row)
192 if ($row['type'] != 12) // customer payment printout not defined yet.
193 return print_document_link($row['trans_no'], _("Print"), true, $row['type']);
196 function check_overdue($row)
198 return $row['OverDue'] == 1
199 && (abs($row["TotalAmount"]) - $row["Allocated"] != 0);
201 //------------------------------------------------------------------------------------------------
202 $date_after = date2sql($_POST['TransAfterDate']);
203 $date_to = date2sql($_POST['TransToDate']);
215 (trans.ov_amount + trans.ov_gst + trans.ov_freight
216 + trans.ov_freight_tax + trans.ov_discount) AS TotalAmount,
217 trans.alloc AS Allocated,
219 AND trans.due_date < '" . date2sql(Today()) . "') AS OverDue
221 .TB_PREF."debtor_trans as trans, "
222 .TB_PREF."debtors_master as debtor, "
223 .TB_PREF."cust_branch as branch
224 WHERE debtor.debtor_no = trans.debtor_no
225 AND trans.tran_date >= '$date_after'
226 AND trans.tran_date <= '$date_to'";
228 if ($_POST['customer_id'] != reserved_words::get_all())
229 $sql .= " AND trans.debtor_no = '" . $_POST['customer_id'] . "'";
231 if ($_POST['filterType'] != reserved_words::get_all())
233 if ($_POST['filterType'] == '1')
235 $sql .= " AND (trans.type = 10 OR trans.type = 1) ";
237 elseif ($_POST['filterType'] == '2')
239 $sql .= " AND (trans.type = 10) ";
241 elseif ($_POST['filterType'] == '3')
243 $sql .= " AND (trans.type = " . systypes::cust_payment()
244 ." OR trans.type = 2) ";
246 elseif ($_POST['filterType'] == '4')
248 $sql .= " AND trans.type = 11 ";
250 elseif ($_POST['filterType'] == '5')
252 $sql .= " AND trans.type = 13 ";
255 if ($_POST['filterType'] == '2')
257 $today = date2sql(Today());
258 $sql .= " AND trans.due_date < '$today'
259 AND (trans.ov_amount + trans.ov_gst + trans.ov_freight_tax +
260 trans.ov_freight + trans.ov_discount - trans.alloc > 0) ";
264 //------------------------------------------------------------------------------------------------
267 _("Type") => array('type'=>'spec', 'fun'=>'systype_name', 'ord'=>''),
268 _("#") => array('type'=>'spec', 'fun'=>'trans_view', 'ord'=>''),
269 _("Order") => array('type'=>'spec', 'fun'=>'order_view'),
271 _("Date") => array('type'=>'date', 'ord'=>'desc'),
272 _("Due Date") => array('type'=>'spec', 'fun'=>'due_date'),
273 _("Customer") => array('ord'=>''),
274 _("Branch") => array('ord'=>''),
275 _("Currency") => 'text',
276 _("Debit") => array('type'=>'spec', 'fun'=>'fmt_debit'),
277 _("Credit") => array('type'=>'insert', 'fun'=>'fmt_credit'),
278 array('type'=>'insert', 'fun'=>'gl_view'),
279 array('type'=>'insert', 'fun'=>'alloc_link'),
280 array('type'=>'insert', 'fun'=>'credit_link'),
281 array('type'=>'insert', 'fun'=>'edit_link'),
282 array('type'=>'insert', 'fun'=>'prt_link')
285 if ($_POST['customer_id'] != reserved_words::get_all()) {
286 $cols[_("Customer")] = 'skip';
287 $cols[_("Currency")] = 'skip';
291 $table =& new_db_pager('trans_tbl', $sql, $cols);
292 $table->set_marker('check_overdue', _("Marked items are overdue."));
295 if(get_post('RefreshInquiry'))
297 $table->set_sql($sql);
298 $table->set_columns($cols);
299 $Ajax->activate('trans_tbl');
300 $Ajax->activate('totals_tbl');
304 display_db_pager($table);