5 include_once($path_to_root . "/includes/session.inc");
7 include_once($path_to_root . "/sales/includes/sales_ui.inc");
8 include_once($path_to_root . "/sales/includes/sales_db.inc");
9 include_once($path_to_root . "/reporting/includes/reporting.inc");
12 if ($use_popup_windows)
13 $js .= get_js_open_window(900, 500);
15 $js .= get_js_date_picker();
16 page(_("Customer Transactions"), false, false, "", $js);
19 if (isset($_GET['customer_id']))
21 $_POST['customer_id'] = $_GET['customer_id'];
24 //------------------------------------------------------------------------------------------------
28 if (!isset($_POST['customer_id']))
29 $_POST['customer_id'] = get_global_customer();
31 start_table("class='tablestyle_noborder'");
33 customer_list_cells(_("Select a customer: "), 'customer_id', $_POST['customer_id'], true);
35 date_cells(_("From:"), 'TransAfterDate', null, -30);
36 date_cells(_("To:"), 'TransToDate', null, 1);
38 if (!isset($_POST['filterType']))
39 $_POST['filterType'] = 0;
41 cust_allocations_list_cells(null, 'filterType', $_POST['filterType'], true);
43 submit_cells('Refresh Inquiry', _("Search"));
49 set_global_customer($_POST['customer_id']);
51 //------------------------------------------------------------------------------------------------
53 function display_customer_summary($customer_record)
57 $past1 = get_company_pref('past_due_days');
59 if ($customer_record["dissallow_invoices"] != 0)
61 echo "<center><font color=red size=4><b>" . _("CUSTOMER ACCOUNT IS ON HOLD") . "</font></b></center>";
64 $nowdue = "1-" . $past1 . " " . _('Days');
65 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
66 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
68 start_table("width=80% $table_style");
69 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
70 $pastdue1, $pastdue2, _("Total Balance"));
74 label_cell($customer_record["curr_code"]);
75 label_cell($customer_record["terms"]);
76 amount_cell($customer_record["Balance"] - $customer_record["Due"]);
77 amount_cell($customer_record["Due"] - $customer_record["Overdue1"]);
78 amount_cell($customer_record["Overdue1"] - $customer_record["Overdue2"]);
79 amount_cell($customer_record["Overdue2"]);
80 amount_cell($customer_record["Balance"]);
86 //------------------------------------------------------------------------------------------------
88 function get_transactions()
90 $date_after = date2sql($_POST['TransAfterDate']);
91 $date_to = date2sql($_POST['TransToDate']);
93 $sql = "SELECT ".TB_PREF."debtor_trans.*,
94 ".TB_PREF."debtors_master.name AS CustName, ".TB_PREF."debtors_master.curr_code AS CustCurrCode,
95 (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
96 .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + ".TB_PREF."debtor_trans.ov_discount)
97 AS TotalAmount, ".TB_PREF."debtor_trans.alloc AS Allocated,
98 ((".TB_PREF."debtor_trans.type = 10)
99 AND ".TB_PREF."debtor_trans.due_date < '" . date2sql(Today()) . "') AS OverDue
100 FROM ".TB_PREF."debtor_trans, ".TB_PREF."debtors_master
101 WHERE ".TB_PREF."debtors_master.debtor_no = ".TB_PREF."debtor_trans.debtor_no
102 AND ".TB_PREF."debtor_trans.tran_date >= '$date_after'
103 AND ".TB_PREF."debtor_trans.tran_date <= '$date_to'";
105 if ($_POST['customer_id'] != reserved_words::get_all())
106 $sql .= " AND ".TB_PREF."debtor_trans.debtor_no = '" . $_POST['customer_id'] . "'";
108 if ($_POST['filterType'] != reserved_words::get_all())
110 if ($_POST['filterType'] == '1')
112 $sql .= " AND (".TB_PREF."debtor_trans.type = 10 OR ".TB_PREF."debtor_trans.type = 1) ";
114 elseif ($_POST['filterType'] == '2')
116 $sql .= " AND (".TB_PREF."debtor_trans.type = 10) ";
118 elseif ($_POST['filterType'] == '3')
120 $sql .= " AND (".TB_PREF."debtor_trans.type = " . systypes::cust_payment() . " OR ".TB_PREF."debtor_trans.type = 2) ";
122 elseif ($_POST['filterType'] == '4')
124 $sql .= " AND ".TB_PREF."debtor_trans.type = 11 ";
126 elseif ($_POST['filterType'] == '5')
128 $sql .= " AND ".TB_PREF."debtor_trans.type = 13 ";
131 if ($_POST['filterType'] == '2')
133 $today = date2sql(Today());
134 $sql .= " AND ".TB_PREF."debtor_trans.due_date < '$today'
135 AND (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
136 .TB_PREF."debtor_trans.ov_freight_tax + ".TB_PREF."debtor_trans.ov_freight + "
137 .TB_PREF."debtor_trans.ov_discount - ".TB_PREF."debtor_trans.alloc > 0) ";
141 $sql .= " ORDER BY ".TB_PREF."debtor_trans.tran_date DESC,
142 ".TB_PREF."debtor_trans.type,".TB_PREF."debtor_trans.trans_no ";
144 return db_query($sql,"No transactions were returned");
147 //------------------------------------------------------------------------------------------------
149 if (($_POST['customer_id'] != "") && ($_POST['customer_id'] != reserved_words::get_all()))
151 $customer_record = get_customer_details($_POST['customer_id']);
152 display_customer_summary($customer_record);
156 //------------------------------------------------------------------------------------------------
158 $result = get_transactions();
160 if (db_num_rows($result) == 0)
162 display_note(_("The selected customer has no transactions for the given dates."), 0, 2);
167 //------------------------------------------------------------------------------------------------
169 start_table("$table_style width='80%'");
171 $th = array(_("Type"), _("#"), _("Order"), _("Reference"), _("Date"), _("Due Date"),
172 _("Customer"), _("Branch"), _("Currency"), _("Debit"), _("Credit"), "", "",""
175 if ($_POST['customer_id'] != reserved_words::get_all()) {
176 unset($th[6], $th[8]);
183 $k = 0; //row colour counter
185 while ($myrow = db_fetch($result))
188 if ($myrow['OverDue'] == 1)
190 start_row("class='overduebg'");
194 alt_table_row_color($k);
200 switch($myrow['type']) {
202 $due_date_str = sql2date($myrow["due_date"]);
203 /*Show a link to allow an invoice to be credited */
204 // only allow crediting if it's not been totally allocated
205 if ($myrow["TotalAmount"] - $myrow["Allocated"] > 0)
206 $credit_me_str = "<a href='$path_to_root/sales/customer_credit_invoice.php?InvoiceNumber=" . $myrow["trans_no"] . "'>" . _("Credit This") . "</a>";
207 $edit_page= $path_to_root.'/sales/customer_invoice.php?ModifyInvoice='
208 . $myrow['trans_no'];
212 if ($myrow['order_']==0) // free-hand credit note
213 $edit_page= $path_to_root.'/sales/credit_note_entry.php?ModifyCredit='
214 . $myrow['trans_no'];
215 else // credit invoice
216 $edit_page= $path_to_root.'/sales/customer_credit_invoice.php?ModifyCredit='
217 . $myrow['trans_no'];
221 $edit_page= $path_to_root.'/sales/customer_delivery.php?ModifyDelivery='
222 . $myrow['trans_no']; break;
225 $date = sql2date($myrow["tran_date"]);
227 if ($myrow["order_"] > 0)
228 $preview_order_str = get_customer_trans_view_str(systypes::sales_order(), $myrow["order_"]);
230 $preview_order_str = "";
232 $gl_trans_str = get_gl_view_str_cell($myrow["type"], $myrow["trans_no"]);
234 // $print_str = "<a href='$path_to_root/reporting/print_invoice.php?InvoiceNumber=" . $myrow["trans_no"] . "'>" . _("Print") . "</a>";
238 if ($myrow["branch_code"] > 0)
240 $branch_name = get_branch_name($myrow["branch_code"]);
243 $preview_trans_str = get_trans_view_str($myrow["type"], $myrow["trans_no"]);
245 label_cell(systypes::name($myrow["type"]));
247 label_cell($preview_trans_str);
248 label_cell($preview_order_str);
249 label_cell($myrow["reference"]);
250 label_cell($date, "nowrap");
251 label_cell($due_date_str, "nowrap");
252 if ($_POST['customer_id'] == reserved_words::get_all())
253 label_cell($myrow["CustName"]);
254 label_cell($branch_name);
255 if ($_POST['customer_id'] == reserved_words::get_all())
256 label_cell($myrow["CustCurrCode"]);
257 display_debit_or_credit_cells(
258 $myrow['type']==11 || $myrow['type']==12 ?
259 -$myrow["TotalAmount"] : $myrow["TotalAmount"]);
263 label_cell($edit_page=='' ? '' : "<a href='$edit_page'>" . _('Edit') . '</a>');
264 // label_cell(print_document_link($myrow['trans_no'], _("Print")));
266 if ($credit_me_str != "")
267 label_cell($credit_me_str, "nowrap");
271 // if ($myrow["type"] == 10)
272 // label_cell($print_str, 'nowrap');
283 } //end of page full new headings if
284 } //end of transaction while loop
289 display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'");