All *_list() functions now does not display html directly - added echo when needed.
[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 (!check_num('quantity', 0))
39         {
40         $input_error = 1;
41         display_error( _("The price entered was not numeric."));
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 echo stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
107
108 echo "<hr></center>";
109
110 set_global_stock_item($_POST['stock_id']);
111
112 $result = get_item_code_dflts($_POST['stock_id']);
113 $dec = $result['decimals'];
114 $units = $result['units'];
115 $dflt_desc = $result['description'];
116 $dflt_cat = $result['category_id'];
117
118 $result = get_all_item_codes($_POST['stock_id']);
119 div_start('code_table');
120         start_table("$table_style width=60%");
121
122         $th = array(_("EAN/UPC Code"), _("Quantity"), _("Units"), 
123                 _("Description"),_("Category"), "", "");
124
125         table_header($th);
126
127         $k = $j = 0; //row colour counter
128
129         while ($myrow = db_fetch($result))
130         {
131                         alt_table_row_color($k);
132
133             label_cell($myrow["item_code"]);
134             qty_cell($myrow["quantity"], $dec);
135             label_cell($units);
136             label_cell($myrow["description"]);
137             label_cell($myrow["cat_name"]);
138                         edit_button_cell("Edit".$myrow['id'], _("Edit"));
139                         edit_button_cell("Delete".$myrow['id'], _("Delete"));
140             end_row();
141
142             $j++;
143             If ($j == 12)
144             {
145                 $j = 1;
146                         table_header($th);
147             } //end of page full new headings
148         } //end of while loop
149
150         end_table();
151 div_end();
152
153 //-----------------------------------------------------------------------------------------------
154
155 if ($Mode =='Edit')
156 {
157         $myrow = get_item_code($selected_id);
158         $_POST['item_code'] = $myrow["item_code"];
159     $_POST['quantity'] = $myrow["quantity"];
160     $_POST['description'] = $myrow["description"];
161     $_POST['category_id'] = $myrow["category_id"];
162 }
163  else {
164     $_POST['quantity'] = 1;
165     $_POST['description'] = $dflt_desc;
166     $_POST['category_id'] = $dflt_cat;
167 }
168
169 echo "<br>";
170 hidden('selected_id', $selected_id);
171 start_table($table_style2);
172
173 hidden('code_id', $selected_id);
174
175 text_row(_("UPC/EAN code:"), 'item_code', null, 20, 21);
176 qty_row(_("Quantity:"), 'quantity', null, '', $units, $dec);
177 text_row(_("Description:"), 'description', null, 50, 200);
178 stock_categories_list_row(_("Category:"), 'category_id', null);
179
180 end_table(1);
181
182 submit_add_or_update_center($selected_id == -1, '', 'both');
183
184 end_form();
185 end_page();
186
187 ?>