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");
17 if ($SysPrefs->use_popup_windows && $SysPrefs->use_popup_search)
18 $js .= get_js_open_window(900, 500);
20 page(_($help_context = "Foreign Item Codes"), false, false, "", $js);
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");
26 check_db_has_purchasable_items(_("There are no inventory items defined in the system."));
28 simple_page_mode(true);
29 //--------------------------------------------------------------------------------------------------
31 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
35 if ($_POST['stock_id'] == "" || !isset($_POST['stock_id']))
38 display_error( _("There is no item selected."));
39 set_focus('stock_id');
41 elseif (!input_num('quantity'))
44 display_error( _("The quantity entered was not positive number."));
45 set_focus('quantity');
47 elseif ($_POST['description'] == '')
50 display_error( _("Item code description cannot be empty."));
51 set_focus('description');
53 elseif($selected_id == -1)
55 $kit = get_item_kit($_POST['item_code']);
56 if (db_num_rows($kit)) {
58 display_error( _("This item code is already assigned to stock item or sale kit."));
59 set_focus('item_code');
63 if ($input_error == 0)
65 if ($Mode == 'ADD_ITEM')
67 add_item_code($_POST['item_code'], $_POST['stock_id'],
68 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1);
70 display_notification(_("New item code has been added."));
73 update_item_code($selected_id, $_POST['item_code'], $_POST['stock_id'],
74 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1);
76 display_notification(_("Item code has been updated."));
82 //--------------------------------------------------------------------------------------------------
84 if ($Mode == 'Delete')
86 delete_item_code($selected_id);
88 display_notification(_("Item code has been sucessfully deleted."));
98 if (list_updated('stock_id'))
99 $Ajax->activate('_page_body');
101 //--------------------------------------------------------------------------------------------------
105 if (!isset($_POST['stock_id']))
106 $_POST['stock_id'] = get_global_stock_item();
108 echo "<center>" . _("Item:"). " ";
109 //Manufcatured item visible
110 echo stock_items_list('stock_id', $_POST['stock_id'], false, true);
112 echo "<hr></center>";
114 set_global_stock_item($_POST['stock_id']);
117 $result = get_item_code_dflts($_POST['stock_id']);
119 $dec = $result['decimals'];
120 $units = $result['units'];
121 $dflt_desc = $result['description'];
122 $dflt_cat = $result['category_id'];
126 $result = get_all_item_codes($_POST['stock_id']);
127 div_start('code_table');
128 start_table(TABLESTYLE, "width='60%'");
130 $th = array(_("EAN/UPC Code"), _("Quantity"), _("Units"),
131 _("Description"),_("Category"), "", "");
135 $k = $j = 0; //row colour counter
137 while ($myrow = db_fetch($result))
139 alt_table_row_color($k);
141 label_cell($myrow["item_code"]);
142 qty_cell($myrow["quantity"], $dec);
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"));
155 } //end of page full new headings
156 } //end of while loop
161 //-----------------------------------------------------------------------------------------------
163 if ($selected_id != '') {
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"];
172 hidden('selected_id', $selected_id);
174 $_POST['quantity'] = 1;
175 $_POST['description'] = $dflt_desc;
176 $_POST['category_id'] = $dflt_cat;
180 start_table(TABLESTYLE2);
182 hidden('code_id', $selected_id);
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);
191 submit_add_or_update_center($selected_id == -1, '', 'both');