5 include_once($path_to_root . "/includes/session.inc");
7 page(_("Sales Kits & Alias Codes"));
9 include_once($path_to_root . "/includes/date_functions.inc");
10 include_once($path_to_root . "/includes/ui.inc");
11 include_once($path_to_root . "/includes/data_checks.inc");
13 include_once($path_to_root . "/includes/manufacturing.inc");
15 check_db_has_stock_items(_("There are no items defined in the system."));
17 simple_page_mode(true);
19 if (isset($_GET['item_code']))
21 $_POST['item_code'] = $_GET['item_code'];
22 $selected_kit = $_GET['item_code'];
25 //--------------------------------------------------------------------------------------------------
26 function display_kit_items($selected_kit)
30 $result = get_item_kit($selected_kit);
32 start_table("$table_style width=60%");
33 $th = array(_("Stock Item"), _("Description"), _("Quantity"), _("Units"),
38 while ($myrow = db_fetch($result))
41 alt_table_row_color($k);
43 label_cell($myrow["stock_id"]);
44 label_cell($myrow["comp_name"]);
45 qty_cell($myrow["quantity"], false,
46 $myrow["units"] == '' ? 0 : get_qty_dec($myrow["comp_name"]));
47 label_cell($myrow["units"] == '' ? _('kit') : $myrow["units"]);
48 edit_button_cell("Edit".$myrow['id'], _("Edit"));
49 edit_button_cell("Delete".$myrow['id'], _("Delete"));
52 } //END WHILE LIST LOOP
57 //--------------------------------------------------------------------------------------------------
59 function update_component($kit_code, $selected_item)
61 global $Mode, $Ajax, $selected_kit;
63 if (!check_num('quantity', 0))
65 display_error(_("The quantity entered must be numeric and greater than zero."));
66 set_focus('quantity');
69 elseif ($_POST['description'] == '')
71 display_error( _("Item code description cannot be empty."));
72 set_focus('description');
75 elseif ($selected_item == -1) // adding new item or new alias/kit
77 if (get_post('item_code') == '') { // New kit/alias definition
78 $kit = get_item_kit($_POST['item_code']);
79 if (db_num_rows($kit)) {
81 display_error( _("This item code is already assigned to stock item or sale kit."));
82 set_focus('kit_code');
85 if (get_post('kit_code') == '') {
86 display_error( _("Kit/alias code cannot be empty."));
87 set_focus('kit_code');
93 if (check_item_in_kit($selected_item, $kit_code, $_POST['component'], true)) {
94 display_error(_("The selected component contains directly or on any lower level the kit under edition. Recursive kits are not allowed."));
95 set_focus('component');
99 /*Now check to see that the component is not already in the kit */
100 if (check_item_in_kit($selected_item, $kit_code, $_POST['component'])) {
101 display_error(_("The selected component is already in this kit. You can modify it's quantity but it cannot appear more than once in the same kit."));
102 set_focus('component');
105 if ($selected_item == -1) { // new item alias/kit
106 if ($_POST['item_code']=='') {
107 $kit_code = $_POST['kit_code'];
108 $selected_kit = $_POST['item_code'] = $kit_code;
109 $msg = _("New alias code has been created.");
112 $msg =_("New component has been added to selected kit.");
114 add_item_code( $kit_code, get_post('component'), get_post('description'),
115 get_post('category'), input_num('quantity'), 0);
116 display_notification($msg);
119 $props = get_kit_props($_POST['item_code']);
120 update_item_code($selected_item, $kit_code, get_post('component'),
121 $props['description'], $props['category_id'], input_num('quantity'), 0);
122 display_notification(_("Component of selected kit has been updated."));
125 $Ajax->activate('_page_body');
128 //--------------------------------------------------------------------------------------------------
130 if (get_post('update_name')) {
131 update_kit_props(get_post('item_code'), get_post('description'), get_post('category'));
132 display_notification(_('Kit common properties has been updated'));
133 $Ajax->activate('_page_body');
136 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
137 update_component($_POST['item_code'], $selected_id);
139 if ($Mode == 'Delete')
141 // Before removing last component from selected kit check
142 // if selected kit is not included in any other kit.
144 $other_kits = get_where_used($_POST['item_code']);
145 $num_kits = db_num_rows($other_kits);
147 $msg = _("This item cannot be deleted because it is the last item in the kit used by following kits")
151 $kit = db_fetch($other_kits);
152 $msg .= "'".$kit[0]."'";
153 if ($num_kits) $msg .= ',';
157 delete_item_code($selected_id);
158 display_notification(_("The component item has been deleted from this bom"));
163 if ($Mode == 'RESET')
166 unset($_POST['quantity']);
167 unset($_POST['component']);
170 //--------------------------------------------------------------------------------------------------
172 start_form(false, true);
174 echo "<center>" . _("Select a sale kit:") . " ";
175 sales_kits_list('item_code', null, _('New kit'), true);
176 echo "</center><br>";
177 $props = get_kit_props($_POST['item_code']);
179 if (isset($_POST['_item_code_update'])) {
180 if (get_post('item_code') == '')
181 $_POST['description'] = '';
182 $Ajax->activate('_page_body');
185 $selected_kit = $_POST['item_code'];
186 //----------------------------------------------------------------------------------
187 if (get_post('item_code') == '') {
188 // New sales kit entry
189 start_table($table_style2);
190 text_row(_("Alias/kit code:"), 'kit_code', null, 20, 21);
192 { // Kit selected so display bom or edit component
193 $_POST['description'] = $props['description'];
194 $_POST['category'] = $props['category_id'];
195 start_table($table_style2);
196 text_row(_("Description:"), 'description', null, 50, 200);
197 stock_categories_list_row(_("Category:"), 'category', null);
198 submit_row('update_name', _("Update"), false, 'align=center colspan=2', _('Update kit/alias name'), true);
201 display_kit_items($selected_kit);
203 start_table($table_style2);
206 if ($Mode == 'Edit') {
207 $myrow = get_item_code($selected_id);
208 $_POST['component'] = $myrow["stock_id"];
209 $_POST['quantity'] = number_format2($myrow["quantity"], get_qty_dec($myrow["stock_id"]));
211 hidden("selected_id", $selected_id);
213 sales_local_items_list_row(_("Component:"),'component', null, false, true);
215 // if (get_post('description') == '')
216 // $_POST['description'] = get_kit_name($_POST['component']);
217 if (get_post('item_code') == '') { // new kit/alias
218 $_POST['description'] = $props['description'];
219 $_POST['category'] = $props['category_id'];
220 text_row(_("Description:"), 'description', null, 50, 200);
221 stock_categories_list_row(_("Category:"), 'category', null);
223 $res = get_item_edit_info(get_post('component'));
224 $dec = $res["decimals"] == '' ? 0 : $res["decimals"];
225 $units = $res["units"] == '' ? _('kits') : $res["units"];
226 if (list_updated('component'))
228 $_POST['quantity'] = number_format2(1, $dec);
229 $Ajax->activate('quantity');
230 $Ajax->activate('category');
232 qty_row(_("Quantity:"), 'quantity', null, '', $units, $dec);
235 submit_add_or_update_center($selected_id == -1, '', true);
237 //----------------------------------------------------------------------------------