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");
11 if ($use_popup_windows)
12 $js .= get_js_open_window(900, 500);
14 $js .= get_js_date_picker();
15 page(_("Customer Inquiry"), false, false, "", $js);
18 if (isset($_GET['customer_id']))
20 $_POST['customer_id'] = $_GET['customer_id'];
23 //------------------------------------------------------------------------------------------------
27 if (!isset($_POST['customer_id']))
28 $_POST['customer_id'] = get_global_customer();
30 start_table("class='tablestyle_noborder'");
32 customer_list_cells(_("Select a customer: "), 'customer_id', $_POST['customer_id'], true);
34 date_cells(_("From:"), 'TransAfterDate', null, -30);
35 date_cells(_("To:"), 'TransToDate', null, 1);
37 if (!isset($_POST['filterType']))
38 $_POST['filterType'] = 0;
40 cust_allocations_list_cells(null, 'filterType', $_POST['filterType']);
42 submit_cells('Refresh Inquiry', _("Search"));
48 set_global_customer($_POST['customer_id']);
50 //------------------------------------------------------------------------------------------------
52 function display_customer_summary($customer_record)
56 $past1 = get_company_pref('past_due_days');
58 if ($customer_record["dissallow_invoices"] != 0)
60 echo "<center><font color=red size=4><b>" . _("CUSTOMER ACCOUNT IS ON HOLD") . "</font></b></center>";
63 $nowdue = "1-" . $past1 . " " . _('Days');
64 $pastdue1 = $past1 + 1 . "-" . $past2 . " " . _('Days');
65 $pastdue2 = _('Over') . " " . $past2 . " " . _('Days');
67 start_table("width=80% $table_style");
68 $th = array(_("Currency"), _("Terms"), _("Current"), $nowdue,
69 $pastdue1, $pastdue2, _("Total Balance"));
73 label_cell($customer_record["curr_code"]);
74 label_cell($customer_record["terms"]);
75 amount_cell($customer_record["Balance"] - $customer_record["Due"]);
76 amount_cell($customer_record["Due"] - $customer_record["Overdue1"]);
77 amount_cell($customer_record["Overdue1"] - $customer_record["Overdue2"]);
78 amount_cell($customer_record["Overdue2"]);
79 amount_cell($customer_record["Balance"]);
85 //------------------------------------------------------------------------------------------------
87 function get_transactions()
89 $date_after = date2sql($_POST['TransAfterDate']);
90 $date_to = date2sql($_POST['TransToDate']);
92 $sql = "SELECT ".TB_PREF."debtor_trans.*,
93 ".TB_PREF."debtors_master.name AS CustName, ".TB_PREF."debtors_master.curr_code AS CustCurrCode,
94 (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount)
95 AS TotalAmount, ".TB_PREF."debtor_trans.alloc AS Allocated,
96 ((".TB_PREF."debtor_trans.type = 10)
97 AND ".TB_PREF."debtor_trans.due_date < '" . date2sql(Today()) . "') AS OverDue
98 FROM ".TB_PREF."debtor_trans, ".TB_PREF."debtors_master
99 WHERE ".TB_PREF."debtors_master.debtor_no = ".TB_PREF."debtor_trans.debtor_no
100 AND ".TB_PREF."debtor_trans.tran_date >= '$date_after'
101 AND ".TB_PREF."debtor_trans.tran_date <= '$date_to'";
103 if ($_POST['customer_id'] != reserved_words::get_all())
104 $sql .= " AND ".TB_PREF."debtor_trans.debtor_no = '" . $_POST['customer_id'] . "'";
106 if ($_POST['filterType'] != reserved_words::get_all())
108 if ($_POST['filterType'] == '1')
110 $sql .= " AND (".TB_PREF."debtor_trans.type = 10 OR ".TB_PREF."debtor_trans.type = 1) ";
112 elseif ($_POST['filterType'] == '2')
114 $sql .= " AND (".TB_PREF."debtor_trans.type = 10) ";
116 elseif ($_POST['filterType'] == '3')
118 $sql .= " AND (".TB_PREF."debtor_trans.type = " . systypes::cust_payment() . " OR ".TB_PREF."debtor_trans.type = 2) ";
120 elseif ($_POST['filterType'] == '4')
122 $sql .= " AND ".TB_PREF."debtor_trans.type = 11 ";
125 if ($_POST['filterType'] == '2')
127 $today = date2sql(Today());
128 $sql .= " AND ".TB_PREF."debtor_trans.due_date < '$today'
129 AND (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount - ".TB_PREF."debtor_trans.alloc > 0) ";
133 $sql .= " ORDER BY ".TB_PREF."debtor_trans.tran_date";
135 return db_query($sql,"No transactions were returned");
138 //------------------------------------------------------------------------------------------------
140 if (($_POST['customer_id'] != "") && ($_POST['customer_id'] != reserved_words::get_all()))
142 $customer_record = get_customer_details($_POST['customer_id']);
143 display_customer_summary($customer_record);
147 //------------------------------------------------------------------------------------------------
149 $result = get_transactions();
151 if (db_num_rows($result) == 0)
153 display_note(_("The selected customer has no transactions for the given dates."), 0, 2);
158 //------------------------------------------------------------------------------------------------
160 start_table("$table_style width='80%'");
162 if ($_POST['customer_id'] == reserved_words::get_all())
163 $th = array(_("Type"), _("#"), _("Order"), _("Reference"), _("Date"), _("Due Date"),
164 _("Customer"), _("Branch"), _("Currency"), _("Debit"), _("Credit"), "", "");
166 $th = array(_("Type"), _("#"), _("Order"), _("Reference"), _("Date"), _("Due Date"),
167 _("Branch"), _("Debit"), _("Credit"), "", "");
172 $k = 0; //row colour counter
174 while ($myrow = db_fetch($result))
177 if ($myrow['OverDue'] == 1)
179 start_row("class='overduebg'");
183 alt_table_row_color($k);
185 $date = sql2date($myrow["tran_date"]);
187 if ($myrow["order_"] > 0)
188 $preview_order_str = get_customer_trans_view_str(systypes::sales_order(), $myrow["order_"]);
190 $preview_order_str = "";
192 $gl_trans_str = get_gl_view_str_cell($myrow["type"], $myrow["trans_no"]);
196 $credit_invoice_str = "<a href='$path_to_root/sales/customer_credit_invoice.php?InvoiceNumber=" . $myrow["trans_no"] . "'>" . _("Credit This") . "</a>";
200 if ($myrow["type"] == 10)
201 $due_date_str = sql2date($myrow["due_date"]);
203 if ($myrow["type"] == 10)
205 /*Show a link to allow an invoice to be credited */
206 // only allow crediting if it's not been totally allocated
207 if ($myrow["TotalAmount"] - $myrow["Allocated"] > 0)
208 $credit_me_str = $credit_invoice_str;
212 if ($myrow["branch_code"] > 0)
214 $branch_name = get_branch_name($myrow["branch_code"]);
217 $preview_trans_str = get_trans_view_str($myrow["type"], $myrow["trans_no"]);
219 label_cell(systypes::name($myrow["type"]));
221 label_cell($preview_trans_str);
222 label_cell($preview_order_str);
223 label_cell($myrow["reference"]);
224 label_cell($date, "nowrap");
225 label_cell($due_date_str, "nowrap");
226 if ($_POST['customer_id'] == reserved_words::get_all())
227 label_cell($myrow["CustName"]);
228 label_cell($branch_name);
229 if ($_POST['customer_id'] == reserved_words::get_all())
230 label_cell($myrow["CustCurrCode"]);
231 display_debit_or_credit_cells($myrow["TotalAmount"]);
233 if ($credit_me_str != "")
234 label_cell($credit_me_str, "nowrap");
245 //end of page full new headings if
252 display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'");