X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=manufacturing%2Fmanage%2Fbom_edit.php;h=35230ddb5ab0a70ccb489d1e7be0adbb0d1ee8a2;hb=50d1a68af70dfcadbb3896798e8211881457e3fa;hp=181ad2076c3c5c30f488f69caf1024f9f6cfaee8;hpb=e3f700d1e11788f176bf02c7b9969780e66dc167;p=fa-stable.git diff --git a/manufacturing/manage/bom_edit.php b/manufacturing/manage/bom_edit.php index 181ad207..35230ddb 100644 --- a/manufacturing/manage/bom_edit.php +++ b/manufacturing/manage/bom_edit.php @@ -1,116 +1,47 @@ . +***********************************************************************/ +$page_security = 'SA_BOM'; +$path_to_root = "../.."; include_once($path_to_root . "/includes/session.inc"); -page(_("Bill Of Materials")); +page(_($help_context = "Bill Of Materials")); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/includes/data_checks.inc"); -include_once($path_to_root . "/includes/manufacturing.inc"); - check_db_has_bom_stock_items(_("There are no manufactured or kit items defined in the system.")); check_db_has_workcentres(_("There are no work centres defined in the system. BOMs require at least one work centre be defined.")); +simple_page_mode(true); +$selected_component = $selected_id; //-------------------------------------------------------------------------------------------------- -if (isset($_GET["NewItem"])) -{ - $_POST['stock_id'] = $_GET["NewItem"]; - if (isset($_GET['item']) && isset($_GET['qty'])) - add_material_cost($_GET["NewItem"], $_GET['item'], $_GET['qty'], false); - -} if (isset($_GET['stock_id'])) { $_POST['stock_id'] = $_GET['stock_id']; $selected_parent = $_GET['stock_id']; } -/* selected_parent could come from a post or a get */ -if (isset($_GET["selected_parent"])) -{ - $selected_parent = $_GET["selected_parent"]; -} -else if (isset($_POST["selected_parent"])) -{ - $selected_parent = $_POST["selected_parent"]; -} -/* selected_component could also come from a post or a get */ -if (isset($_GET["selected_component"])) -{ - $selected_component = $_GET["selected_component"]; -} -elseif (isset($_POST["selected_component"])) -{ - $selected_component = $_POST["selected_component"]; -} - -function add_material_cost($parent, $item, $n, $add=true) -{ - $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id='$parent'"; - $result = db_query($sql); - $myrow = db_fetch($result); - $material_cost = $myrow['material_cost']; - $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id='$item'"; - $result = db_query($sql); - $myrow = db_fetch($result); - $material_cost2 = $myrow['material_cost']; - if ($add) - $material_cost += ($material_cost2 * $n); - else - $material_cost -= ($material_cost2 * $n); - $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost - WHERE stock_id='$parent'"; - db_query($sql,"The cost details for the inventory item could not be updated"); -} - -//-------------------------------------------------------------------------------------------------- - -function check_for_recursive_bom($ultimate_parent, $component_to_check) -{ - - /* returns true ie 1 if the bom contains the parent part as a component - ie the bom is recursive otherwise false ie 0 */ - - $sql = "SELECT component FROM ".TB_PREF."bom WHERE parent='$component_to_check'"; - $result = db_query($sql,"could not check recursive bom"); - - if ($result != 0) - { - while ($myrow = db_fetch_row($result)) - { - if ($myrow[0] == $ultimate_parent) - { - return 1; - } - - if (check_for_recursive_bom($ultimate_parent, $myrow[0])) - { - return 1; - } - } //(while loop) - } //end if $result is true - - return 0; - -} //end of function check_for_recursive_bom - //-------------------------------------------------------------------------------------------------- function display_bom_items($selected_parent) { - global $table_style; - $result = get_bom($selected_parent); - - start_table("$table_style width=60%"); + div_start('bom'); + start_table(TABLESTYLE, "width='60%'"); $th = array(_("Code"), _("Description"), _("Location"), - _("Work Centre"), _("Quantity"), _("Units")); + _("Work Centre"), _("Quantity"), _("Units"),'',''); table_header($th); $k = 0; @@ -123,75 +54,54 @@ function display_bom_items($selected_parent) label_cell($myrow["description"]); label_cell($myrow["location_name"]); label_cell($myrow["WorkCentreDescription"]); - label_cell($myrow["quantity"]); + qty_cell($myrow["quantity"], false, get_qty_dec($myrow["component"])); label_cell($myrow["units"]); - edit_link_cell(SID . "NewItem=$selected_parent&selected_component=" . $myrow["id"]."&item=".$myrow['component']."&qty=".$myrow['quantity']); - delete_link_cell(SID . "delete=" . $myrow["id"]. "&stock_id=" . $_POST['stock_id']."&item=".$myrow['component']."&qty=".$myrow['quantity']); + edit_button_cell("Edit".$myrow['id'], _("Edit")); + delete_button_cell("Delete".$myrow['id'], _("Delete")); end_row(); } //END WHILE LIST LOOP end_table(); + div_end(); } //-------------------------------------------------------------------------------------------------- -function on_submit($selected_parent, $selected_component) +function on_submit($selected_parent, $selected_component=-1) { - if (!is_numeric($_POST['quantity'])) + if (!check_num('quantity', 0)) { - display_error(_("The quantity entered must be numeric.")); + display_error(_("The quantity entered must be numeric and greater than zero.")); + set_focus('quantity'); return; } - if ($_POST['quantity'] <= 0) + if ($selected_component != -1) { - display_error(_("The quantity entered must be greater than zero.")); - return; + update_bom($selected_parent, $selected_component, $_POST['workcentre_added'], $_POST['loc_code'], + input_num('quantity')); + display_notification(_('Selected component has been updated')); + $Mode = 'RESET'; } - - - if (isset($selected_parent) && isset($selected_component)) - { - - $sql = "UPDATE ".TB_PREF."bom SET workcentre_added='" . $_POST['workcentre_added'] . "', - loc_code='" . $_POST['loc_code'] . "', - quantity= " . $_POST['quantity'] . " - WHERE parent='" . $selected_parent . "' - AND id='" . $selected_component . "'"; - check_db_error("Could not update this bom component", $sql); - - add_material_cost($selected_parent, $_POST['item'], $_POST['quantity'], true); - - db_query($sql,"could not update bom"); - - } - elseif (!isset($selected_component) && isset($selected_parent)) + 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 */ + /*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'])) + 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 ".TB_PREF."bom - WHERE parent='$selected_parent' - AND component='" . $_POST['component'] . "' - AND workcentre_added='" . $_POST['workcentre_added'] . "' - AND loc_code='" . $_POST['loc_code'] . "'" ; - $result = db_query($sql,"check failed"); - - if (db_num_rows($result) == 0) + if (!is_component_already_on_bom($_POST['component'], $_POST['workcentre_added'], + $_POST['loc_code'], $selected_parent)) { - $sql = "INSERT INTO ".TB_PREF."bom (parent, component, workcentre_added, loc_code, quantity) - VALUES ('$selected_parent', '" . $_POST['component'] . "', '" . $_POST['workcentre_added'] . "', '" . $_POST['loc_code'] . "', " . $_POST['quantity'] . ")"; - - db_query($sql,"check failed"); - - add_material_cost($selected_parent, $_POST['component'], $_POST['quantity'], true); - //$msg = _("A new component part has been added to the bill of material for this item."); - + 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 { @@ -209,102 +119,95 @@ function on_submit($selected_parent, $selected_component) //-------------------------------------------------------------------------------------------------- -if (isset($_GET['delete'])) +if ($Mode == 'Delete') { - $sql = "DELETE FROM ".TB_PREF."bom WHERE id='".$_GET['delete']."'"; - db_query($sql,"Could not delete this bom components"); - - add_material_cost($_GET['stock_id'], $_GET['item'], $_GET['qty'], false); + delete_bom($selected_id); - display_note(_("The component item has been deleted from this bom.")); + display_notification(_("The component item has been deleted from this bom")); + $Mode = 'RESET'; +} +if ($Mode == 'RESET') +{ + $selected_id = -1; + unset($_POST['quantity']); } //-------------------------------------------------------------------------------------------------- -start_form(false, true); -//echo $msg; +start_form(); -echo "