4 include_once($path_to_root . "/includes/session.inc");
6 page(_("Foreign Item Codes"));
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/includes/manufacturing.inc");
11 include_once($path_to_root . "/includes/data_checks.inc");
13 check_db_has_purchasable_items(_("There are no inventory items defined in the system."));
15 simple_page_mode(true);
16 //--------------------------------------------------------------------------------------------------
18 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
22 if ($_POST['stock_id'] == "" || !isset($_POST['stock_id']))
25 display_error( _("There is no item selected."));
26 set_focus('stock_id');
28 elseif (!check_num('quantity', 0))
31 display_error( _("The price entered was not numeric."));
32 set_focus('quantity');
34 elseif ($_POST['description'] == '')
37 display_error( _("Item code description cannot be empty."));
38 set_focus('description');
40 elseif($selected_id == -1)
42 $kit = get_item_kit($_POST['item_code']);
43 if (db_num_rows($kit)) {
45 display_error( _("This item code is already assigned to stock item or sale kit."));
46 set_focus('item_code');
50 if ($input_error == 0)
52 if ($Mode == 'ADD_ITEM')
54 add_item_code($_POST['item_code'], $_POST['stock_id'],
55 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1);
57 display_notification(_("New item code has been added."));
60 update_item_code($selected_id, $_POST['item_code'], $_POST['stock_id'],
61 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1);
63 display_notification(_("Item code has been updated."));
69 //--------------------------------------------------------------------------------------------------
71 if ($Mode == 'Delete')
73 delete_item_code($selected_id);
75 display_notification(_("The purchasing data item has been sucessfully deleted."));
85 if (list_updated('stock_id'))
86 $Ajax->activate('_page_body');
88 //--------------------------------------------------------------------------------------------------
90 start_form(false, true);
92 if (!isset($_POST['stock_id']))
93 $_POST['stock_id'] = get_global_stock_item();
95 echo "<center>" . _("Item:"). " ";
96 stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
100 set_global_stock_item($_POST['stock_id']);
102 $result = get_item_code_dflts($_POST['stock_id']);
103 $dec = $result['decimals'];
104 $units = $result['units'];
105 $dflt_desc = $result['description'];
106 $dflt_cat = $result['category_id'];
108 $result = get_all_item_codes($_POST['stock_id']);
109 div_start('code_table');
110 start_table("$table_style width=60%");
112 $th = array(_("EAN/UPC Code"), _("Quantity"), _("Units"),
113 _("Description"),_("Category"), "", "");
117 $k = $j = 0; //row colour counter
119 while ($myrow = db_fetch($result))
121 alt_table_row_color($k);
123 label_cell($myrow["item_code"]);
124 qty_cell($myrow["quantity"], $dec);
126 label_cell($myrow["description"]);
127 label_cell($myrow["cat_name"]);
128 edit_button_cell("Edit".$myrow['id'], _("Edit"));
129 edit_button_cell("Delete".$myrow['id'], _("Delete"));
137 } //end of page full new headings
138 } //end of while loop
143 //-----------------------------------------------------------------------------------------------
147 $myrow = get_item_code($selected_id);
148 $_POST['item_code'] = $myrow["item_code"];
149 $_POST['quantity'] = $myrow["quantity"];
150 $_POST['description'] = $myrow["description"];
151 $_POST['category_id'] = $myrow["category_id"];
154 $_POST['quantity'] = 1;
155 $_POST['description'] = $dflt_desc;
156 $_POST['category_id'] = $dflt_cat;
160 hidden('selected_id', $selected_id);
161 start_table($table_style2);
163 hidden('code_id', $selected_id);
165 text_row(_("UPC/EAN code:"), 'item_code', null, 20, 21);
166 qty_row(_("Quantity:"), 'quantity', null, '', $units, $dec);
167 text_row(_("Description:"), 'description', null, 50, 200);
168 stock_categories_list_row(_("Category:"), 'category_id', null);
172 submit_add_or_update_center($selected_id == -1, '', true);