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");
16 page(_("Foreign Item Codes"));
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");
23 check_db_has_purchasable_items(_("There are no inventory items defined in the system."));
25 simple_page_mode(true);
26 //--------------------------------------------------------------------------------------------------
28 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
32 if ($_POST['stock_id'] == "" || !isset($_POST['stock_id']))
35 display_error( _("There is no item selected."));
36 set_focus('stock_id');
38 elseif (!check_num('quantity', 0))
41 display_error( _("The price entered was not numeric."));
42 set_focus('quantity');
44 elseif ($_POST['description'] == '')
47 display_error( _("Item code description cannot be empty."));
48 set_focus('description');
50 elseif($selected_id == -1)
52 $kit = get_item_kit($_POST['item_code']);
53 if (db_num_rows($kit)) {
55 display_error( _("This item code is already assigned to stock item or sale kit."));
56 set_focus('item_code');
60 if ($input_error == 0)
62 if ($Mode == 'ADD_ITEM')
64 add_item_code($_POST['item_code'], $_POST['stock_id'],
65 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1);
67 display_notification(_("New item code has been added."));
70 update_item_code($selected_id, $_POST['item_code'], $_POST['stock_id'],
71 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1);
73 display_notification(_("Item code has been updated."));
79 //--------------------------------------------------------------------------------------------------
81 if ($Mode == 'Delete')
83 delete_item_code($selected_id);
85 display_notification(_("Item code has been sucessfully deleted."));
95 if (list_updated('stock_id'))
96 $Ajax->activate('_page_body');
98 //--------------------------------------------------------------------------------------------------
102 if (!isset($_POST['stock_id']))
103 $_POST['stock_id'] = get_global_stock_item();
105 echo "<center>" . _("Item:"). " ";
106 stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
108 echo "<hr></center>";
110 set_global_stock_item($_POST['stock_id']);
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'];
118 $result = get_all_item_codes($_POST['stock_id']);
119 div_start('code_table');
120 start_table("$table_style width=60%");
122 $th = array(_("EAN/UPC Code"), _("Quantity"), _("Units"),
123 _("Description"),_("Category"), "", "");
127 $k = $j = 0; //row colour counter
129 while ($myrow = db_fetch($result))
131 alt_table_row_color($k);
133 label_cell($myrow["item_code"]);
134 qty_cell($myrow["quantity"], $dec);
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"));
147 } //end of page full new headings
148 } //end of while loop
153 //-----------------------------------------------------------------------------------------------
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"];
164 $_POST['quantity'] = 1;
165 $_POST['description'] = $dflt_desc;
166 $_POST['category_id'] = $dflt_cat;
170 hidden('selected_id', $selected_id);
171 start_table($table_style2);
173 hidden('code_id', $selected_id);
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);
182 submit_add_or_update_center($selected_id == -1, '', 'both');