1d1c5890b6f67bbbac1cc035da1649a827497f30
[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
63     ".TB_PREF."stock_master s,
64     ".TB_PREF."item_codes i
65   LEFT JOIN
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"). "%") . ") ";
73
74 $type = "";
75 if (isset($_GET['type'])) {
76   $type = $_GET['type'];
77 }
78 //_vd("type = $type");
79 switch ($type) {
80   case "sales":
81     $sql .= " AND !s.no_sale AND mb_flag != 'F'";
82     break;
83   case "manufactured":
84     $sql .= " AND mb_flag = 'M'";
85     break;
86   case "purchasable":
87     $sql .= " AND NOT no_purchase AND mb_flag != 'F' AND i.item_code=i.stock_id";
88     break;
89   case "costable":
90     $sql .= " AND mb_flag != 'D' AND mb_flag != 'F' AND  i.item_code=i.stock_id";
91     break;
92   case "assets":
93     $sql .= " AND mb_flag = 'F'";
94     break;
95   case "kits":
96         $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id AND mb_flag != 'F'";
97         break;
98   case "all":
99     $sql .= " AND mb_flag != 'F' AND i.item_code=i.stock_id";
100     // NOTHING TO DO.
101     break;
102 }
103
104 $sql .= " GROUP BY i.item_code ORDER BY i.description LIMIT 0, $limit"; // We only display 10 items.
105 //_vd($sql);
106 $result = db_query($sql, "Failed in retreiving item list.");
107
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'];
113         if ($mode != 0) {
114                 $text = $myrow['description'];
115                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'setComboItem(window.opener.document, "'.$name.'",  "'.$value.'", "'.$text.'")');
116         }
117         else {
118                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
119         }
120         label_cell($myrow["item_code"]);
121         label_cell($myrow["description"]);
122         label_cell($myrow["category"]);
123         end_row();
124 }
125
126 end_table(1);
127
128 div_end();
129 // END: Item list
130
131 end_page(true);