activate('_page_body');
}
//--------------------------------------------------------------------------------------------------
if (get_post('update_name')) {
update_kit_props(get_post('item_code'), get_post('description'), get_post('category'));
display_notification(_('Kit common properties has been updated'));
$Ajax->activate('_page_body');
}
if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
update_component($_POST['item_code'], $selected_id);
if ($Mode == 'Delete')
{
// Before removing last component from selected kit check
// if selected kit is not included in any other kit.
//
$other_kits = get_where_used($_POST['item_code']);
$num_kits = db_num_rows($other_kits);
if ($num_kits) {
$msg = _("This item cannot be deleted because it is the last item in the kit used by following kits")
.':
';
while($num_kits--) {
$kit = db_fetch($other_kits);
$msg .= "'".$kit[0]."'";
if ($num_kits) $msg .= ',';
}
display_error($msg);
} else {
delete_item_code($selected_id);
display_notification(_("The component item has been deleted from this bom"));
$Mode = 'RESET';
}
}
if ($Mode == 'RESET')
{
$selected_id = -1;
unset($_POST['quantity']);
unset($_POST['component']);
}
//--------------------------------------------------------------------------------------------------
start_form(false, true);
echo "
" . _("Select a sale kit:") . " ";
sales_kits_list('item_code', null, _('New kit'), true);
echo "
";
$props = get_kit_props($_POST['item_code']);
if (isset($_POST['_item_code_update'])) {
if (get_post('item_code') == '')
$_POST['description'] = '';
$Ajax->activate('_page_body');
}
$selected_kit = $_POST['item_code'];
//----------------------------------------------------------------------------------
if (get_post('item_code') == '') {
// New sales kit entry
start_table($table_style2);
text_row(_("Alias/kit code:"), 'kit_code', null, 20, 21);
} else
{ // Kit selected so display bom or edit component
$_POST['description'] = $props['description'];
$_POST['category'] = $props['category_id'];
start_table($table_style2);
text_row(_("Description:"), 'description', null, 50, 200);
stock_categories_list_row(_("Category:"), 'category', null);
submit_row('update_name', _("Update"), false, 'align=center colspan=2', _('Update kit/alias name'), true);
end_row();
end_table(1);
display_kit_items($selected_kit);
echo '
';
start_table($table_style2);
}
if ($Mode == 'Edit') {
$myrow = get_item_code($selected_id);
$_POST['component'] = $myrow["stock_id"];
$_POST['quantity'] = number_format2($myrow["quantity"], get_qty_dec($myrow["stock_id"]));
}
hidden("selected_id", $selected_id);
sales_local_items_list_row(_("Component:"),'component', null, false, true);
// if (get_post('description') == '')
// $_POST['description'] = get_kit_name($_POST['component']);
if (get_post('item_code') == '') { // new kit/alias
$_POST['description'] = $props['description'];
$_POST['category'] = $props['category_id'];
text_row(_("Description:"), 'description', null, 50, 200);
stock_categories_list_row(_("Category:"), 'category', null);
}
$res = get_item_edit_info(get_post('component'));
$dec = $res["decimals"] == '' ? 0 : $res["decimals"];
$units = $res["units"] == '' ? _('kits') : $res["units"];
if (list_updated('component'))
{
$_POST['quantity'] = number_format2(1, $dec);
$Ajax->activate('quantity');
$Ajax->activate('category');
}
qty_row(_("Quantity:"), 'quantity', null, '', $units, $dec);
end_table(1);
submit_add_or_update_center($selected_id == -1, '', true);
end_form();
//----------------------------------------------------------------------------------
end_page();
?>