Removed fixed assets from list item search and popup search.
[fa-stable.git] / inventory / inquiry / stock_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_ITEM";
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_item_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 = "Items"), 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("item_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(_("Description"), "description");
38 submit_cells("search", _("Search"), "", _("Search items"), "default");
39
40 end_row();
41
42 end_table();
43
44 end_form();
45 // END: Filter form
46
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
50
51 // BEGIN: Item list
52 div_start("item_tbl");
53
54 start_table(TABLESTYLE);
55
56 $th = array("", _("Item Code"), _("Description"), _("Category"));
57
58 table_header($th);
59
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"). "%") . ") ";
70
71 $type = "";
72 if (isset($_GET['type'])) {
73   $type = $_GET['type'];
74 }
75
76 switch ($type) {
77   case "sales":
78     $sql .= " AND !s.no_sale AND mb_flag <> 'F'";
79     break;
80   case "manufactured":
81     $sql .= " AND mb_flag = 'M'";
82     break;
83   case "purchasable":
84     $sql .= " AND NOT no_purchase AND mb_flag <> 'F' AND i.item_code=i.stock_id";
85     break;
86   case "costable":
87     $sql .= " AND mb_flag <> 'D' AND mb_flag <> 'F' AND  i.item_code=i.stock_id";
88     break;
89   case "component":
90         $parent = $_GET['parent'];
91     $sql .= " AND  i.item_code=i.stock_id AND i.stock_id <> '$parent' AND mb_flag <> 'F' ";
92     break;
93   case "kits":
94         $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id AND mb_flag <> 'F'";
95         break;
96   case "all":
97     $sql .= " AND mb_flag <> 'F' AND i.item_code=i.stock_id";
98     // NOTHING TO DO.
99     break;
100 }
101
102 $sql .= " GROUP BY i.item_code ORDER BY i.description LIMIT 0, $limit"; // We only display 10 items.
103
104 $result = db_query($sql, "Failed in retreiving item list.");
105
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'];
111         if ($mode != 0) {
112                 $text = $myrow['description'];
113                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'setComboItem(window.opener.document, "'.$name.'",  "'.$value.'", "'.$text.'")');
114         }
115         else {
116                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
117         }
118         label_cell($myrow["item_code"]);
119         label_cell($myrow["description"]);
120         label_cell($myrow["category"]);
121         end_row();
122 }
123
124 end_table(1);
125
126 div_end();
127 // END: Item list
128
129 end_page(true);