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
62 FROM ".TB_PREF."stock_master s, ".TB_PREF."item_codes i
63 LEFT JOIN ".TB_PREF."stock_category c
64 ON i.category_id=c.category_id
65 WHERE i.stock_id=s.stock_id
66 AND !i.inactive AND !s.inactive
67 AND ( i.item_code LIKE " . db_escape("%" . get_post("description"). "%") . " OR
68 i.description LIKE " . db_escape("%" . get_post("description"). "%") . " OR
69 c.description LIKE " . db_escape("%" . get_post("description"). "%") . ") ";
72 if (isset($_GET['type'])) {
73 $type = $_GET['type'];
78 $sql .= " AND !s.no_sale AND mb_flag <> 'F'";
81 $sql .= " AND mb_flag = 'M'";
84 $sql .= " AND NOT no_purchase AND mb_flag <> 'F' AND i.item_code=i.stock_id";
87 $sql .= " AND mb_flag <> 'D' AND mb_flag <> 'F' AND i.item_code=i.stock_id";
90 $parent = $_GET['parent'];
91 $sql .= " AND i.item_code=i.stock_id AND i.stock_id <> '$parent' AND mb_flag <> 'F' ";
94 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id AND mb_flag <> 'F'";
97 $sql .= " AND mb_flag <> 'F' AND i.item_code=i.stock_id";
102 $sql .= " GROUP BY i.item_code ORDER BY i.description LIMIT 0, $limit"; // We only display 10 items.
104 $result = db_query($sql, "Failed in retreiving item list.");
106 $k = 0; //row colour counter
107 $name = $_GET["client_id"];
108 while ($myrow = db_fetch_assoc($result)) {
109 alt_table_row_color($k);
110 $value = $myrow['item_code'];
112 $text = $myrow['description'];
113 ahref_cell(_("Select"), 'javascript:void(0)', '', 'setComboItem(window.opener.document, "'.$name.'", "'.$value.'", "'.$text.'")');
116 ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
118 label_cell($myrow["item_code"]);
119 label_cell($myrow["description"]);
120 label_cell($myrow["category"]);