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