function on_submit($selected_parent, $selected_component = -1) { if (!check_num('quantity', 0)) { display_error(_("The quantity entered must be numeric and greater than zero.")); set_focus('quantity'); return; } if ($selected_component != -1) { update_bom($selected_parent, $selected_component, $_POST['workcentre_added'], $_POST['loc_code'], input_num('quantity')); display_notification(_('Selected component has been updated')); $Mode = 'RESET'; } else { /*Selected component is null cos no item selected on first time round so must be adding a record must be Submitting new entries in the new component form */ //need to check not recursive bom component of itself! if (!check_for_recursive_bom($selected_parent, $_POST['component'])) { /*Now check to see that the component is not already on the bom */ if (!is_component_already_on_bom($_POST['component'], $_POST['workcentre_added'], $_POST['loc_code'], $selected_parent)) { add_bom($selected_parent, $_POST['component'], $_POST['workcentre_added'], $_POST['loc_code'], input_num('quantity')); display_notification(_("A new component part has been added to the bill of material for this item.")); $Mode = 'RESET'; } else { /*The component must already be on the bom */ display_error(_("The selected component is already on this bom. You can modify it's quantity but it cannot appear more than once on the same bom.")); } } else { display_error(_("The selected component is a parent of the current item. Recursive BOMs are not allowed.")); } } }
function on_submit($selected_parent, $selected_component = null) { if (!check_num('quantity', 0)) { display_error(tr("The quantity entered must be numeric and greater than zero.")); set_focus('quantity'); return; } if (isset($selected_parent) && isset($selected_component)) { $sql = "UPDATE bom SET workcentre_added='" . $_POST['workcentre_added'] . "',\n\t\t\tloc_code='" . $_POST['loc_code'] . "',\n\t\t\tquantity= " . input_num('quantity') . "\n\t\t\tWHERE parent='" . $selected_parent . "'\n\t\t\tAND id='" . $selected_component . "'"; check_db_error("Could not update this bom component", $sql); db_query($sql, "could not update bom"); } elseif (!isset($selected_component) && isset($selected_parent)) { /*Selected component is null cos no item selected on first time round so must be adding a record must be Submitting new entries in the new component form */ //need to check not recursive bom component of itself! if (!check_for_recursive_bom($selected_parent, $_POST['component'])) { /*Now check to see that the component is not already on the bom */ $sql = "SELECT component FROM bom\n\t\t\t\tWHERE parent='{$selected_parent}'\n\t\t\t\tAND component='" . $_POST['component'] . "'\n\t\t\t\tAND workcentre_added='" . $_POST['workcentre_added'] . "'\n\t\t\t\tAND loc_code='" . $_POST['loc_code'] . "'"; $result = db_query($sql, "check failed"); if (db_num_rows($result) == 0) { $sql = "INSERT INTO bom (parent, component, workcentre_added, loc_code, quantity)\n\t\t\t\t\tVALUES ('{$selected_parent}', '" . $_POST['component'] . "', '" . $_POST['workcentre_added'] . "', '" . $_POST['loc_code'] . "', " . input_num('quantity') . ")"; db_query($sql, "check failed"); //$msg = tr("A new component part has been added to the bill of material for this item."); } else { /*The component must already be on the bom */ display_error(tr("The selected component is already on this bom. You can modify it's quantity but it cannot appear more than once on the same bom.")); } } else { display_error(tr("The selected component is a parent of the current item. Recursive BOMs are not allowed.")); } } }