Added foreign/alias item codes and sales kits support.
[fa-stable.git] / inventory / manage / item_codes.php
1 <?php
2 $page_security = 11;
3 $path_to_root="../..";
4 include_once($path_to_root . "/includes/session.inc");
5
6 page(_("Foreign Item Codes"));
7
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");
12
13 check_db_has_purchasable_items(_("There are no inventory items defined in the system."));
14
15 simple_page_mode(true);
16 //--------------------------------------------------------------------------------------------------
17
18 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
19 {
20
21         $input_error = 0;
22         if ($_POST['stock_id'] == "" || !isset($_POST['stock_id']))
23         {
24         $input_error = 1;
25         display_error( _("There is no item selected."));
26                 set_focus('stock_id');
27         }
28         elseif (!check_num('quantity', 0))
29         {
30         $input_error = 1;
31         display_error( _("The price entered was not numeric."));
32                 set_focus('quantity');
33         }
34         elseif ($_POST['description'] == '')
35         {
36         $input_error = 1;
37         display_error( _("Item code description cannot be empty."));
38                 set_focus('description');
39         }
40         elseif($selected_id == -1)
41         {
42                 $kit = get_item_kit($_POST['item_code']);
43         if (db_num_rows($kit)) {
44                         $input_error = 1;
45                 display_error( _("This item code is already assigned to stock item or sale kit."));
46                         set_focus('item_code');
47                 }
48         }
49         
50         if ($input_error == 0)
51         {
52         if ($Mode == 'ADD_ITEM') 
53         {
54                         add_item_code($_POST['item_code'], $_POST['stock_id'],
55                                 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1); 
56
57                 display_notification(_("New item code has been added."));
58         } else
59         {
60                         update_item_code($selected_id, $_POST['item_code'], $_POST['stock_id'],
61                                 $_POST['description'], $_POST['category_id'], $_POST['quantity'], 1); 
62
63                 display_notification(_("Item code has been updated."));
64         }
65                 $Mode = 'RESET';
66         }
67 }
68
69 //--------------------------------------------------------------------------------------------------
70
71 if ($Mode == 'Delete')
72 {
73         delete_item_code($selected_id);
74         
75         display_notification(_("The purchasing data item has been sucessfully deleted."));
76         $Mode = 'RESET';
77 }
78
79 if ($Mode == 'RESET')
80 {
81         $selected_id = -1;
82         unset($_POST);
83 }
84
85 if (list_updated('stock_id')) 
86         $Ajax->activate('_page_body');
87
88 //--------------------------------------------------------------------------------------------------
89
90 start_form(false, true);
91
92 if (!isset($_POST['stock_id']))
93         $_POST['stock_id'] = get_global_stock_item();
94
95 echo "<center>" . _("Item:"). "&nbsp;";
96 stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
97
98 echo "<hr></center>";
99
100 set_global_stock_item($_POST['stock_id']);
101
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'];
107
108 $result = get_all_item_codes($_POST['stock_id']);
109 div_start('code_table');
110         start_table("$table_style width=60%");
111
112         $th = array(_("EAN/UPC Code"), _("Quantity"), _("Units"), 
113                 _("Description"),_("Category"), "", "");
114
115         table_header($th);
116
117         $k = $j = 0; //row colour counter
118
119         while ($myrow = db_fetch($result))
120         {
121                         alt_table_row_color($k);
122
123             label_cell($myrow["item_code"]);
124             qty_cell($myrow["quantity"], $dec);
125             label_cell($units);
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"));
130             end_row();
131
132             $j++;
133             If ($j == 12)
134             {
135                 $j = 1;
136                         table_header($th);
137             } //end of page full new headings
138         } //end of while loop
139
140         end_table();
141 div_end();
142
143 //-----------------------------------------------------------------------------------------------
144
145 if ($Mode =='Edit')
146 {
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"];
152 }
153  else {
154     $_POST['quantity'] = 1;
155     $_POST['description'] = $dflt_desc;
156     $_POST['category_id'] = $dflt_cat;
157 }
158
159 echo "<br>";
160 hidden('selected_id', $selected_id);
161 start_table($table_style2);
162
163 hidden('code_id', $selected_id);
164
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);
169
170 end_table(1);
171
172 submit_add_or_update_center($selected_id == -1, '', true);
173
174 end_form();
175 end_page();
176
177 ?>