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(_($help_context = "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 (!input_num('quantity'))
41 display_error( _("The price entered was not positive number."));
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 //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);
110 echo "<hr></center>";
112 set_global_stock_item($_POST['stock_id']);
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'];
120 $result = get_all_item_codes($_POST['stock_id']);
121 div_start('code_table');
122 start_table(TABLESTYLE, "width='60%'");
124 $th = array(_("EAN/UPC Code"), _("Quantity"), _("Units"),
125 _("Description"),_("Category"), "", "");
129 $k = $j = 0; //row colour counter
131 while ($myrow = db_fetch($result))
133 alt_table_row_color($k);
135 label_cell($myrow["item_code"]);
136 qty_cell($myrow["quantity"], $dec);
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"));
149 } //end of page full new headings
150 } //end of while loop
155 //-----------------------------------------------------------------------------------------------
157 if ($selected_id != '') {
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"];
166 hidden('selected_id', $selected_id);
168 $_POST['quantity'] = 1;
169 $_POST['description'] = $dflt_desc;
170 $_POST['category_id'] = $dflt_cat;
174 start_table(TABLESTYLE2);
176 hidden('code_id', $selected_id);
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);
185 submit_add_or_update_center($selected_id == -1, '', 'both');