X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=inventory%2Fmanage%2Flocations.php;h=6728e1e53fb9f72100da2cc69cbdab0efad6f7d1;hb=2bcdab793e406bb5a44d2c4e079ec7cc2a1aa857;hp=3fcddeae5ec451150f70abc3bea3fa1e30e5ac3c;hpb=8259c324f645a39cb847d5a4346b70e225e1b02c;p=fa-stable.git diff --git a/inventory/manage/locations.php b/inventory/manage/locations.php index 3fcddeae..6728e1e5 100644 --- a/inventory/manage/locations.php +++ b/inventory/manage/locations.php @@ -1,15 +1,31 @@ . +***********************************************************************/ +$page_security = 'SA_INVENTORYLOCATION'; +$path_to_root = "../.."; include($path_to_root . "/includes/session.inc"); -page(_("Inventory Locations")); include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/inventory/includes/inventory_db.inc"); +if (isset($_GET['FixedAsset'])) { + $help_context = "Fixed Assets Locations"; + $_POST['fixed_asset'] = 1; +} else + $help_context = "Inventory Locations"; + +page(_($help_context)); + simple_page_mode(true); if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') @@ -24,10 +40,10 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') //first off validate inputs sensible $_POST['loc_code'] = strtoupper($_POST['loc_code']); - if (strlen($_POST['loc_code']) > 5) + if ((strlen(db_escape($_POST['loc_code'])) > 7) || empty($_POST['loc_code'])) //check length after conversion { $input_error = 1; - display_error( _("The location code must be five characters or less long.")); + display_error( _("The location code must be five characters or less long (including converted special chars).")); set_focus('loc_code'); } elseif (strlen($_POST['location_name']) == 0) @@ -43,7 +59,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') { update_item_location($selected_id, $_POST['location_name'], $_POST['delivery_address'], - $_POST['phone'], $_POST['fax'], $_POST['email'], $_POST['contact']); + $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact'], check_value('fixed_asset')); display_notification(_('Selected location has been updated')); } else @@ -52,7 +68,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') /*selected_id is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Location form */ add_item_location($_POST['loc_code'], $_POST['location_name'], $_POST['delivery_address'], - $_POST['phone'], $_POST['fax'], $_POST['email'], $_POST['contact']); + $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact'], check_value('fixed_asset')); display_notification(_('New location has been added')); } @@ -62,33 +78,50 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') function can_delete($selected_id) { - $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_moves WHERE loc_code='$selected_id'"; - $result = db_query($sql, "could not query stock moves"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (key_in_foreign_table($selected_id, 'stock_moves', 'loc_code')) { display_error(_("Cannot delete this location because item movements have been created using this location.")); return false; } - $sql= "SELECT COUNT(*) FROM ".TB_PREF."workorders WHERE loc_code='$selected_id'"; - $result = db_query($sql, "could not query work orders"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (key_in_foreign_table($selected_id, 'workorders', 'loc_code')) { display_error(_("Cannot delete this location because it is used by some work orders records.")); return false; } - $sql= "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE default_location='$selected_id'"; - $result = db_query($sql, "could not query customer branches"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (key_in_foreign_table($selected_id, 'cust_branch', 'default_location')) { display_error(_("Cannot delete this location because it is used by some branch records as the default location to deliver from.")); return false; } + if (key_in_foreign_table($selected_id, 'bom', 'loc_code')) + { + display_error(_("Cannot delete this location because it is used by some related records in other tables.")); + return false; + } + + if (key_in_foreign_table($selected_id, 'grn_batch', 'loc_code')) + { + display_error(_("Cannot delete this location because it is used by some related records in other tables.")); + return false; + } + if (key_in_foreign_table($selected_id, 'purch_orders', 'into_stock_location')) + { + display_error(_("Cannot delete this location because it is used by some related records in other tables.")); + return false; + } + if (key_in_foreign_table($selected_id, 'sales_orders', 'from_stk_loc')) + { + display_error(_("Cannot delete this location because it is used by some related records in other tables.")); + return false; + } + if (key_in_foreign_table($selected_id, 'sales_pos', 'pos_location')) + { + display_error(_("Cannot delete this location because it is used by some related records in other tables.")); + return false; + } return true; } @@ -101,48 +134,53 @@ if ($Mode == 'Delete') { delete_item_location($selected_id); display_notification(_('Selected location has been deleted')); - $Mode = 'RESET'; } //end if Delete Location + $Mode = 'RESET'; } if ($Mode == 'RESET') { $selected_id = -1; + $sav = get_post('show_inactive'); + $sav2 = get_post('fixed_asset'); unset($_POST); + $_POST['show_inactive'] = $sav; + $_POST['fixed_asset'] = $sav2; } -$sql = "SELECT * FROM ".TB_PREF."locations"; -$result = db_query($sql, "could not query locations");; +$result = get_item_locations(check_value('show_inactive'), get_post('fixed_asset', 0)); start_form(); -start_table("$table_style width=30%"); -$th = array(_("Location Code"), _("Location Name"), "", ""); +start_table(TABLESTYLE); +$th = array(_("Location Code"), _("Location Name"), _("Address"), _("Phone"), _("Secondary Phone"), "", ""); +inactive_control_column($th); table_header($th); $k = 0; //row colour counter -while ($myrow = db_fetch_row($result)) +while ($myrow = db_fetch($result)) { alt_table_row_color($k); - label_cell($myrow[0]); - label_cell($myrow[1]); - edit_button_cell("Edit".$myrow[0], _("Edit")); - edit_button_cell("Delete".$myrow[0], _("Delete")); + label_cell($myrow["loc_code"]); + label_cell($myrow["location_name"]); + label_cell($myrow["delivery_address"]); + label_cell($myrow["phone"]); + label_cell($myrow["phone2"]); + inactive_control_cell($myrow["loc_code"], $myrow["inactive"], 'locations', 'loc_code'); + edit_button_cell("Edit".$myrow["loc_code"], _("Edit")); + delete_button_cell("Delete".$myrow["loc_code"], _("Delete")); end_row(); } //END WHILE LIST LOOP - -//end of ifs and buts! - +inactive_control_row($th); end_table(); -end_form(); echo '
'; -start_form(); - -start_table($table_style2); +start_table(TABLESTYLE2); +hidden("fixed_asset"); +$_POST['email'] = ""; if ($selected_id != -1) { //editing an existing Location @@ -155,6 +193,7 @@ if ($selected_id != -1) $_POST['delivery_address'] = $myrow["delivery_address"]; $_POST['contact'] = $myrow["contact"]; $_POST['phone'] = $myrow["phone"]; + $_POST['phone2'] = $myrow["phone2"]; $_POST['fax'] = $myrow["fax"]; $_POST['email'] = $myrow["email"]; } @@ -170,17 +209,17 @@ else text_row_ex(_("Location Name:"), 'location_name', 50, 50); text_row_ex(_("Contact for deliveries:"), 'contact', 30, 30); -textarea_row(_("Address:"), 'delivery_address', null, 35, 5); +textarea_row(_("Address:"), 'delivery_address', null, 34, 5); -text_row_ex(_("Telephone No:"), 'phone', 30, 30); -text_row_ex(_("Facsimile No:"), 'fax', 30, 30); -text_row_ex(_("Email:"), 'email', 30, 30); +text_row_ex(_("Telephone No:"), 'phone', 32, 30); +text_row_ex(_("Secondary Phone Number:"), 'phone2', 32, 30); +text_row_ex(_("Facsimile No:"), 'fax', 32, 30); +email_row_ex(_("E-mail:"), 'email', 50); end_table(1); -submit_add_or_update_center($selected_id == -1, '', true); +submit_add_or_update_center($selected_id == -1, '', 'both'); end_form(); end_page(); -?>