diff --git a/app/Http/Controllers/Admin/ManageLocationController.php b/app/Http/Controllers/Admin/ManageLocationController.php index 7ed01bf..9bcaf28 100644 --- a/app/Http/Controllers/Admin/ManageLocationController.php +++ b/app/Http/Controllers/Admin/ManageLocationController.php @@ -18,9 +18,11 @@ class ManageLocationController extends Controller Created at : 07 June 2024 Use : To get the page. */ + public function index() { $location = ManageState::with('timeInterval')->orderBy('id', 'asc')->get(); + // return $location; return view('Admin.pages.manage_states.manage_states', compact('location')); } /* @@ -122,29 +124,56 @@ class ManageLocationController extends Controller Use : To update location. */ - public function update(Request $request) - { - try { - DB::beginTransaction(); - // Check if the location name already exists, excluding the current location - if (ManageState::where('name', $request->location_name)->where('id', '!=', $request->id)->exists()) { - return response()->json(['success' => false, 'error' => 'Location name already exists', 'status' => 422]); - } - $location_data = ManageState::find($request->id); - $location_data->name = $request->location_name; - $location_data->save(); + public function update_location(Request $request) +{ + try { + DB::beginTransaction(); - DB::commit(); - - return response()->json(['success' => true, 'message' => __('success.update_data'), 'status' => 200]); - } catch (Exception $e) { - DB::rollBack(); - Log::error("Failed to update location: " . $e->getMessage()); - return response()->json(['success' => false, 'error' => __('auth.something_went_wrong'), 'status' => 500]); + // Find the location data + $location_data = ManageState::find($request->id); + if (!$location_data) { + return response()->json(['success' => false, 'error' => 'Location not found', 'status' => 404]); } - } + // Update the location data + $location_data->name = $request->location_name; + $location_data->save(); + + // Update or create the TimeInterval data + $timeInterval = TimeInterval::where('manage_state_xid', $request->input('id'))->first(); + + if ($timeInterval) { + // Update existing record + $timeInterval->update([ + 'manage_state_xid' => $request->input('id'), + + 'time_hours' => $request->input('time_hours'), + 'time_interval' => $request->input('time_interval'), + 'quantity' => $request->input('quantity'), + ]); + } else { + // Create new record + TimeInterval::create([ + 'manage_state_xid' => $request->input('id'), + 'time_hours' => $request->input('time_hours'), + 'time_interval' => $request->input('time_interval'), + 'quantity' => $request->input('quantity'), + ]); + } + + DB::commit(); + + return response()->json(['success' => true, 'message' => __('success.update_data'), 'status' => 200]); + } catch (Exception $e) { + DB::rollBack(); + Log::error("Failed to update location: " . $e->getMessage()); + return response()->json(['success' => false, 'error' => __('auth.something_went_wrong'), 'status' => 500]); + } +} + + + } diff --git a/public/assets/js/admin/manage_location/edit_location.js b/public/assets/js/admin/manage_location/edit_location.js index e088cc9..cb559e0 100644 --- a/public/assets/js/admin/manage_location/edit_location.js +++ b/public/assets/js/admin/manage_location/edit_location.js @@ -1,59 +1,217 @@ -$(document).on("click", ".edit_location_value", function (e) { - var edit_id = $(this).data('location-id'); - var edit_country = $(this).data('location-name'); - $('#location_id').val(edit_id); - $('#name').val(edit_country); +// $(document).on("click", ".edit_location_value", function (e) { +// var edit_id = $(this).data('location-id'); +// var edit_country = $(this).data('location-name'); +// console.log(edit_country); +// var edit_timeInterval = $(this).data('location-time_interval'); +// console.log(edit_timeInterval); + +// var edit_timeHours = $(this).data('location-timehours'); +// // console.log(edit_timeHours); +// var edit_Quantity = $(this).data('location-quantity'); + + +// $('#location_id').val(edit_id); +// $('#name').val(edit_country); +// $('#timeHours').val(edit_timeHours); + +// $('#timeInterval').val(edit_timeInterval); + +// $('#timeQuantity').val(edit_Quantity); + +// $('').val() + +// }); + + + + + +// $('#edit_location').validate({ +// rules: { +// location_name: { +// required: true, +// } +// }, +// messages: { +// location_name: { +// required: "Please enter the state.", +// } +// }, +// errorClass: 'error-message', +// submitHandler: function (form) { +// var formData = new FormData(form); +// $('#update_passport_btn').text('Please wait...'); +// $('#update_passport_btn').attr('disabled', true); +// let base_url = url_path; +// $.ajax({ +// url: base_url + '/update_location', +// type: 'POST', +// data: formData, +// processData: false, +// contentType: false, +// success: function(result) { +// if (result.status === 200) { +// toastr.success('Location Updated successfully'); +// setTimeout(function() { +// window.location.href = base_url + "/manage_location"; +// }, 2000); +// } +// else if (result.status === 422 && result.error === 'Location name already exists') { +// toastr.error('Location name already exists'); +// } +// else { +// toastr.error('Something Went Wrong'); +// setTimeout(function() { +// window.location.href = base_url + "/manage_location"; +// }, 2000); +// } +// $('#update_passport_btn').attr('disabled', false); +// $('#update_passport_btn').text('Submit'); +// }, +// error: function(xhr, status, error) { +// toastr.error('Something Went Wrong'); +// $('#update_passport_btn').attr('disabled', false); +// $('#update_passport_btn').text('Submit'); +// } +// }); +// } +// }); +// $('#edit_location').validate({ +// rules: { +// location_name: { +// required: true, +// }, +// time_hours: { +// required: true, +// digits: true // Ensure time_hours is a valid number +// }, +// quantity: { +// required: true, +// digits: true // Ensure quantity is a valid number +// }, +// time_interval: { +// required: true +// } +// }, +// messages: { +// location_name: { +// required: "Please enter the location name." +// }, +// time_hours: { +// required: "Please enter time hours.", +// digits: "Please enter a valid number for time hours." +// }, +// quantity: { +// required: "Please enter quantity.", +// digits: "Please enter a valid number for quantity." +// }, +// time_interval: { +// required: "Please select a time interval." +// } +// }, +// errorClass: 'error-message', +// submitHandler: function(form) { +// var formData = new FormData(form); +// formData.append('id', $('#location-id').val()); / +// $('#update_location').text('Please wait...'); +// $('#update_location').attr('disabled', true); +// let base_url = url_path; +// $.ajax({ +// url: base_url + '/update_location', +// type: 'POST', +// data: formData, +// processData: false, +// contentType: false, +// success: function(result) { +// if (result.success) { +// toastr.success('Location updated successfully'); +// setTimeout(function() { +// window.location.href = base_url + "/manage_location"; +// }, 2000); +// } else { +// toastr.error(result.error || 'Something went wrong'); +// setTimeout(function() { +// window.location.href = base_url + "/manage_location"; +// }, 2000); +// } +// $('#update_location').attr('disabled', false); +// $('#update_location').text('Save'); +// }, +// error: function(xhr, status, error) { +// toastr.error('Something went wrong'); +// $('#update_location').attr('disabled', false); +// $('#update_location').text('Save'); +// } +// }); +// } +// }); +// $('#edit_location').validate({ +// rules: { +// location_name: { +// required: true, +// }, +// time_hours: { +// required: true, +// digits: true // Ensure time_hours is a valid number +// }, +// quantity: { +// required: true, +// digits: true // Ensure quantity is a valid number +// }, +// time_interval: { +// required: true +// } +// }, +// messages: { +// location_name: { +// required: "Please enter the location name." +// }, +// time_hours: { +// required: "Please enter time hours.", +// digits: "Please enter a valid number for time hours." +// }, +// quantity: { +// required: "Please enter quantity.", +// digits: "Please enter a valid number for quantity." +// }, +// time_interval: { +// required: "Please select a time interval." +// } +// }, +// errorClass: 'error-message', +// submitHandler: function(form) { +// var formData = new FormData(form); +// formData.append('id', $('#location_id').val()); + +// $('#update_location').text('Please wait...'); +// $('#update_location').attr('disabled', true); +// let base_url = url_path; +// $.ajax({ +// url: base_url + '/update_location', +// type: 'POST', +// data: formData, +// processData: false, +// contentType: false, +// success: function(result) { +// if (result.success) { +// toastr.success('Location updated successfully'); +// setTimeout(function() { +// window.location.href = base_url + "/manage_location"; +// }, 2000); +// } else { +// toastr.error(result.error || 'Something went wrong'); +// } +// $('#update_location').attr('disabled', false); +// $('#update_location').text('Save'); +// }, +// error: function(xhr, status, error) { +// toastr.error('Something went wrong'); +// $('#update_location').attr('disabled', false); +// $('#update_location').text('Save'); +// } +// }); +// } +// }); -}); -$('#edit_location').validate({ - rules: { - location_name: { - required: true, - } - }, - messages: { - location_name: { - required: "Please enter the state.", - } - }, - errorClass: 'error-message', - submitHandler: function (form) { - var formData = new FormData(form); - $('#update_passport_btn').text('Please wait...'); - $('#update_passport_btn').attr('disabled', true); - let base_url = url_path; - $.ajax({ - url: base_url + '/update_location', - type: 'POST', - data: formData, - processData: false, - contentType: false, - success: function(result) { - if (result.status === 200) { - toastr.success('Location Updated successfully'); - setTimeout(function() { - window.location.href = base_url + "/manage_location"; - }, 2000); - } - else if (result.status === 422 && result.error === 'Location name already exists') { - toastr.error('Location name already exists'); - } - else { - toastr.error('Something Went Wrong'); - setTimeout(function() { - window.location.href = base_url + "/manage_location"; - }, 2000); - } - $('#update_passport_btn').attr('disabled', false); - $('#update_passport_btn').text('Submit'); - }, - error: function(xhr, status, error) { - toastr.error('Something Went Wrong'); - $('#update_passport_btn').attr('disabled', false); - $('#update_passport_btn').text('Submit'); - } - }); - } -}); diff --git a/resources/views/Admin/pages/manage_contact_us/manage_contact.blade.php b/resources/views/Admin/pages/manage_contact_us/manage_contact.blade.php index c7f6aa5..6a4c079 100644 --- a/resources/views/Admin/pages/manage_contact_us/manage_contact.blade.php +++ b/resources/views/Admin/pages/manage_contact_us/manage_contact.blade.php @@ -161,7 +161,7 @@ @endforeach - + @@ -229,7 +229,7 @@