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_ITEM";
7 $path_to_root = "../..";
8 include_once($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/ui.inc");
11 $mode = get_company_pref('no_item_list');
13 $js = get_js_set_combo_item();
15 $js = get_js_select_combo_item();
17 page(_($help_context = "Items"), true, false, "", $js);
19 if (isset($SysPrefs->max_rows_in_search))
20 $limit = $SysPrefs->max_rows_in_search;
24 // Activate Ajax on form submit
25 if(get_post("search")) {
26 $Ajax->activate("item_tbl");
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']);
33 start_table(TABLESTYLE_NOBORDER);
37 text_cells(_("Description"), "description");
38 submit_cells("search", _("Search"), "", _("Search items"), "default");
47 // BEGIN: Link to add new item
48 // hyperlink_params($path_to_root . "/inventory/manage/items.php", _("Add new"), "popup=1");
49 // END: Link to add new item
52 div_start("item_tbl");
54 start_table(TABLESTYLE);
56 $th = array("", _("Item Code"), _("Description"), _("Category"));
60 // Query based on function sales_items_list in includes/ui/ui_lists.inc.
61 $sql = "SELECT COUNT(i.item_code) AS kit, i.item_code, i.description, c.description category
63 ".TB_PREF."stock_master s,
64 ".TB_PREF."item_codes i
66 ".TB_PREF."stock_category c
67 ON i.category_id=c.category_id
68 WHERE i.stock_id=s.stock_id
69 AND !i.inactive AND !s.inactive
70 AND ( i.item_code LIKE " . db_escape("%" . get_post("description"). "%") . " OR
71 i.description LIKE " . db_escape("%" . get_post("description"). "%") . " OR
72 c.description LIKE " . db_escape("%" . get_post("description"). "%") . ") ";
75 if (isset($_GET['type'])) {
76 $type = $_GET['type'];
78 //_vd("type = $type");
81 $sql .= " AND !s.no_sale AND mb_flag != 'F'";
84 $sql .= " AND mb_flag = 'M'";
87 $sql .= " AND NOT no_purchase AND mb_flag != 'F' AND i.item_code=i.stock_id";
90 $sql .= " AND mb_flag != 'D' AND mb_flag != 'F' AND i.item_code=i.stock_id";
93 $sql .= " AND mb_flag = 'F'";
96 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id AND mb_flag != 'F'";
99 $sql .= " AND mb_flag != 'F' AND i.item_code=i.stock_id";
104 $sql .= " GROUP BY i.item_code ORDER BY i.description LIMIT 0, $limit"; // We only display 10 items.
106 $result = db_query($sql, "Failed in retreiving item list.");
108 $k = 0; //row colour counter
109 $name = $_GET["client_id"];
110 while ($myrow = db_fetch_assoc($result)) {
111 alt_table_row_color($k);
112 $value = $myrow['item_code'];
114 $text = $myrow['description'];
115 ahref_cell(_("Select"), 'javascript:void(0)', '', 'setComboItem(window.opener.document, "'.$name.'", "'.$value.'", "'.$text.'")');
118 ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
120 label_cell($myrow["item_code"]);
121 label_cell($myrow["description"]);
122 label_cell($myrow["category"]);