11bb108f52ff6d5f6cf29923cfd3d2a2ea713866
[fa-stable.git] / purchasing / inquiry / suppliers_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_PURCHASEORDER";
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_supplier_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 = "Suppliers"), 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("supplier_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(_("Supplier"), "supplier");
38 submit_cells("search", _("Search"), "", _("Search suppliers"), "default");
39
40 end_row();
41
42 end_table();
43
44 end_form();
45 // END: Filter form
46
47 // BEGIN: Link to add new supplier
48 // hyperlink_params($path_to_root . "/purchasing/manage/suppliers.php", _("Add new"), "popup=1");
49 // END: Link to add new supplier
50
51 // BEGIN: Supplier list
52 div_start("supplier_tbl");
53
54 start_table(TABLESTYLE);
55
56 $th = array("", _("Supplier"), _("Short Name"), _("Address"), _("Tax ID"));
57
58 table_header($th);
59
60 // Query based on function supplier_list in includes/ui/ui_lists.inc.
61 $sql = "SELECT supplier_id, supp_name, supp_ref, address, gst_no FROM ".TB_PREF."suppliers
62   WHERE (supp_name LIKE " . db_escape("%" . get_post("supplier"). "%") . " OR 
63           supp_ref LIKE " . db_escape("%" . get_post("supplier"). "%") . " OR 
64            address LIKE " . db_escape("%" . get_post("supplier"). "%") . " OR 
65             gst_no LIKE " . db_escape("%" . get_post("supplier"). "%") . ")
66   ORDER BY supp_name LIMIT 0, $limit"; // We only display 10 items.
67 $result = db_query($sql, "Failed in retreiving supplier list.");
68
69 $k = 0; //row colour counter
70 $name = $_GET["client_id"];
71 while ($myrow = db_fetch_assoc($result)) {
72         alt_table_row_color($k);
73         $value = $myrow['supplier_id'];
74         if ($mode != 0) {
75                 $text = $myrow['supp_name'];
76                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'setComboItem(window.opener.document, "'.$name.'",  "'.$value.'", "'.$text.'")');
77         }
78         else {
79                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
80         }
81         label_cell($myrow["supp_name"]);
82         label_cell($myrow["supp_ref"]);
83         label_cell($myrow["address"]);
84         label_cell($myrow["gst_no"]);
85         end_row();
86 }
87
88 end_table(1);
89
90 div_end();
91 // END: Supplier list
92
93 end_page(true);