Enabling popup search in Customers, branches, suppliers, inventory, fixed assets...
[fa-stable.git] / sales / inquiry / customers_list.php
1 <?php
2 /**********************************************************************
3   Page for searching item list and select it to item selection
4   in sales order and purchase order.
5 ***********************************************************************/
6 $page_security = "SA_SALESORDER";
7 $path_to_root = "../..";
8 include_once($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10
11 $mode = get_company_pref('no_customer_list');
12 if ($mode != 0)
13         $js = get_js_set_combo_item();
14 else
15         $js = get_js_select_combo_item();
16
17 page(_($help_context = "Customers"), true, false, "", $js);
18
19 if (isset($SysPrefs->max_rows_in_search))
20         $limit = $SysPrefs->max_rows_in_search;
21 else
22         $limit = 10;
23
24 // Activate Ajax on form submit
25 if(get_post("search")) {
26   $Ajax->activate("customer_tbl");
27 }
28
29 // BEGIN: Filter form. Use query string so the client_id will not disappear
30 // after ajax form post.
31 start_form(false, false, $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);
32
33 start_table(TABLESTYLE_NOBORDER);
34
35 start_row();
36
37 text_cells(_("Customer"), "customer");
38 submit_cells("search", _("Search"), "", _("Search customers"), "default");
39
40 end_row();
41
42 end_table();
43
44 end_form();
45 // END: Filter form
46
47 // BEGIN: Link to add new customer
48 // hyperlink_params($path_to_root . "/sales/manage/customers.php", _("Add new"), "popup=1");
49 // END: Link to add new customer
50
51 // BEGIN: Customer list
52 div_start("customer_tbl");
53
54 start_table(TABLESTYLE);
55
56 $th = array("", _("Customer"), _("Short Name"), _("Address"), _("Tax ID"));
57
58 table_header($th);
59
60 // Query based on function customer_list in includes/ui/ui_lists.inc.
61
62 $sql = "SELECT debtor_no, name, debtor_ref, address, tax_id FROM ".TB_PREF."debtors_master 
63   WHERE (  name LIKE " . db_escape("%" . get_post("customer"). "%") . " OR 
64      debtor_ref LIKE " . db_escape("%" . get_post("customer"). "%") . " OR 
65         address LIKE " . db_escape("%" . get_post("customer"). "%") . " OR 
66          tax_id LIKE " . db_escape("%" . get_post("customer") . "%").")
67   ORDER BY name LIMIT 0, $limit"; // We only display 10 items.
68 $result = db_query($sql, "Failed in retreiving customer list.");
69
70 $k = 0; //row colour counter
71 $name = $_GET["client_id"];
72 while ($myrow = db_fetch_assoc($result)) {
73         alt_table_row_color($k);
74         $value = $myrow['debtor_no'];
75         if ($mode != 0) {
76                 $text = $myrow['name'];
77                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'setComboItem(window.opener.document, "'.$name.'",  "'.$value.'", "'.$text.'")');
78         }
79         else {
80                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
81         }
82         label_cell($myrow["name"]);
83         label_cell($myrow["debtor_ref"]);
84         label_cell($myrow["address"]);
85         label_cell($myrow["tax_id"]);
86         end_row();
87 }
88
89 end_table(1);
90
91 div_end();
92 // END: Customer list
93
94 end_page(true);