Improvements to dashboard. All titles are outside the tables/graphics for better...
[fa-stable.git] / inventory / inquiry / stock_list.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 /**********************************************************************
13   Page for searching item list and select it to item selection
14   in pages that have the item dropdown lists.
15   Author: bogeyman2007 from Discussion Forum. Modified by Joe Hunt
16 ***********************************************************************/
17 $page_security = "SA_ITEM";
18 $path_to_root = "../..";
19 include_once($path_to_root . "/includes/session.inc");
20 include_once($path_to_root . "/includes/ui.inc");
21
22 $mode = get_company_pref('no_item_list');
23 if ($mode != 0)
24         $js = get_js_set_combo_item();
25 else
26         $js = get_js_select_combo_item();
27
28 page(_($help_context = "Items"), true, false, "", $js);
29
30 if (isset($SysPrefs->max_rows_in_search))
31         $limit = $SysPrefs->max_rows_in_search;
32 else
33         $limit = 10;
34
35 // Activate Ajax on form submit
36 if(get_post("search")) {
37   $Ajax->activate("item_tbl");
38 }
39
40 // BEGIN: Filter form. Use query string so the client_id will not disappear
41 // after ajax form post.
42 start_form(false, false, $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);
43
44 start_table(TABLESTYLE_NOBORDER);
45
46 start_row();
47
48 text_cells(_("Description"), "description");
49 submit_cells("search", _("Search"), "", _("Search items"), "default");
50
51 end_row();
52
53 end_table();
54
55 end_form();
56 // END: Filter form
57
58 // BEGIN: Link to add new item
59 // hyperlink_params($path_to_root . "/inventory/manage/items.php", _("Add new"), "popup=1");
60 // END: Link to add new item
61
62 // BEGIN: Item list
63 div_start("item_tbl");
64
65 start_table(TABLESTYLE);
66
67 $th = array("", _("Item Code"), _("Description"), _("Category"));
68
69 table_header($th);
70
71 // Query based on function sales_items_list in includes/ui/ui_lists.inc.
72 $sql = "SELECT COUNT(i.item_code) AS kit, i.item_code, i.description, c.description category
73   FROM ".TB_PREF."stock_master s, ".TB_PREF."item_codes i
74   LEFT JOIN ".TB_PREF."stock_category c
75     ON i.category_id=c.category_id
76   WHERE i.stock_id=s.stock_id
77     AND !i.inactive AND !s.inactive
78     AND (  i.item_code LIKE " . db_escape("%" . get_post("description"). "%") . " OR 
79          i.description LIKE " . db_escape("%" . get_post("description"). "%") . " OR 
80          c.description LIKE " . db_escape("%" . get_post("description"). "%") . ") ";
81
82 $type = "";
83 if (isset($_GET['type'])) {
84   $type = $_GET['type'];
85 }
86
87 switch ($type) {
88   case "sales":
89     $sql .= " AND !s.no_sale AND mb_flag <> 'F'";
90     break;
91   case "manufactured":
92     $sql .= " AND mb_flag = 'M'";
93     break;
94   case "purchasable":
95     $sql .= " AND NOT no_purchase AND mb_flag <> 'F' AND i.item_code=i.stock_id";
96     break;
97   case "costable":
98     $sql .= " AND mb_flag <> 'D' AND mb_flag <> 'F' AND  i.item_code=i.stock_id";
99     break;
100   case "component":
101         $parent = $_GET['parent'];
102     $sql .= " AND  i.item_code=i.stock_id AND i.stock_id <> '$parent' AND mb_flag <> 'F' ";
103     break;
104   case "kits":
105         $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id AND mb_flag <> 'F'";
106         break;
107   case "all":
108     $sql .= " AND mb_flag <> 'F' AND i.item_code=i.stock_id";
109     // NOTHING TO DO.
110     break;
111 }
112
113 $sql .= " GROUP BY i.item_code ORDER BY i.description LIMIT 0, $limit"; // We only display 10 items.
114
115 $result = db_query($sql, "Failed in retreiving item list.");
116
117 $k = 0; //row colour counter
118 $name = $_GET["client_id"];
119 while ($myrow = db_fetch_assoc($result)) {
120         alt_table_row_color($k);
121         $value = $myrow['item_code'];
122         if ($mode != 0) {
123                 $text = $myrow['description'];
124                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'setComboItem(window.opener.document, "'.$name.'",  "'.$value.'", "'.$text.'")');
125         }
126         else {
127                 ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
128         }
129         label_cell($myrow["item_code"]);
130         label_cell($myrow["description"]);
131         label_cell($myrow["category"]);
132         end_row();
133 }
134
135 end_table(1);
136
137 div_end();
138 // END: Item list
139
140 end_page(true);