Fixed warnings related to empty item/customer/supplier selector in search modes.
[fa-stable.git] / inventory / manage / item_codes.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 $page_security = 'SA_FORITEMCODE';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
15
16 $js = "";
17 if ($SysPrefs->use_popup_windows && $SysPrefs->use_popup_search)
18         $js .= get_js_open_window(900, 500);
19
20 page(_($help_context = "Foreign Item Codes"), false, false, "", $js);
21
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/ui.inc");
24 include_once($path_to_root . "/includes/data_checks.inc");
25
26 check_db_has_purchasable_items(_("There are no inventory items defined in the system."));
27
28 simple_page_mode(true);
29 //--------------------------------------------------------------------------------------------------
30
31 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
32 {
33
34         $input_error = 0;
35         if ($_POST['stock_id'] == "" || !isset($_POST['stock_id']))
36         {
37         $input_error = 1;
38         display_error( _("There is no item selected."));
39                 set_focus('stock_id');
40         }
41         elseif (!input_num('quantity'))
42         {
43         $input_error = 1;
44         display_error( _("The quantity entered was not positive number."));
45                 set_focus('quantity');
46         }
47         elseif ($_POST['description'] == '')
48         {
49         $input_error = 1;
50         display_error( _("Item code description cannot be empty."));
51                 set_focus('description');
52         }
53         elseif($selected_id == -1)
54         {
55                 $kit = get_item_kit($_POST['item_code']);
56         if (db_num_rows($kit)) {
57                         $input_error = 1;
58                 display_error( _("This item code is already assigned to stock item or sale kit."));
59                         set_focus('item_code');
60                 }
61         }
62         
63         if ($input_error == 0)
64         {
65         if ($Mode == 'ADD_ITEM') 
66         {
67                         add_item_code($_POST['item_code'], $_POST['stock_id'],
68                                 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1); 
69
70                 display_notification(_("New item code has been added."));
71         } else
72         {
73                         update_item_code($selected_id, $_POST['item_code'], $_POST['stock_id'],
74                                 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1); 
75
76                 display_notification(_("Item code has been updated."));
77         }
78                 $Mode = 'RESET';
79         }
80 }
81
82 //--------------------------------------------------------------------------------------------------
83
84 if ($Mode == 'Delete')
85 {
86         delete_item_code($selected_id);
87         
88         display_notification(_("Item code has been sucessfully deleted."));
89         $Mode = 'RESET';
90 }
91
92 if ($Mode == 'RESET')
93 {
94         $selected_id = -1;
95         unset($_POST);
96 }
97
98 if (list_updated('stock_id')) 
99         $Ajax->activate('_page_body');
100
101 //--------------------------------------------------------------------------------------------------
102
103 start_form();
104
105 if (!isset($_POST['stock_id']))
106         $_POST['stock_id'] = get_global_stock_item();
107
108 echo "<center>" . _("Item:"). "&nbsp;";
109 //Manufcatured item visible
110 echo stock_items_list('stock_id', $_POST['stock_id'], false, true);
111
112 echo "<hr></center>";
113
114 set_global_stock_item($_POST['stock_id']);
115
116 $units = $dec = '';
117 $result = get_item_code_dflts($_POST['stock_id']);
118 if ($result) {
119         $dec = $result['decimals'];
120         $units = $result['units'];
121         $dflt_desc = $result['description'];
122         $dflt_cat = $result['category_id'];
123 }
124
125
126 $result = get_all_item_codes($_POST['stock_id']);
127 div_start('code_table');
128         start_table(TABLESTYLE, "width='60%'");
129
130         $th = array(_("EAN/UPC Code"), _("Quantity"), _("Units"), 
131                 _("Description"),_("Category"), "", "");
132
133         table_header($th);
134
135         $k = $j = 0; //row colour counter
136
137         while ($myrow = db_fetch($result))
138         {
139                         alt_table_row_color($k);
140
141             label_cell($myrow["item_code"]);
142             qty_cell($myrow["quantity"], $dec);
143             label_cell($units);
144             label_cell($myrow["description"]);
145             label_cell($myrow["cat_name"]);
146                         edit_button_cell("Edit".$myrow['id'], _("Edit"));
147                         edit_button_cell("Delete".$myrow['id'], _("Delete"));
148             end_row();
149
150             $j++;
151             If ($j == 12)
152             {
153                 $j = 1;
154                         table_header($th);
155             } //end of page full new headings
156         } //end of while loop
157
158         end_table();
159 div_end();
160
161 //-----------------------------------------------------------------------------------------------
162
163 if ($selected_id != '') {
164         if ($Mode =='Edit')
165         {
166                 $myrow = get_item_code($selected_id);
167                 $_POST['item_code'] = $myrow["item_code"];
168                 $_POST['quantity'] = $myrow["quantity"];
169                 $_POST['description'] = $myrow["description"];
170                 $_POST['category_id'] = $myrow["category_id"];
171         }
172         hidden('selected_id', $selected_id);
173 } else {
174         $_POST['quantity'] = 1;
175         $_POST['description'] = $dflt_desc;
176         $_POST['category_id'] = $dflt_cat;
177 }
178
179 echo "<br>";
180 start_table(TABLESTYLE2);
181
182 hidden('code_id', $selected_id);
183
184 text_row(_("UPC/EAN code:"), 'item_code', null, 20, 20);
185 qty_row(_("Quantity:"), 'quantity', null, '', $units, $dec);
186 text_row(_("Description:"), 'description', null, 50, 200);
187 stock_categories_list_row(_("Category:"), 'category_id', null);
188
189 end_table(1);
190
191 submit_add_or_update_center($selected_id == -1, '', 'both');
192
193 end_form();
194 end_page();
195