This commit is contained in:
Hritikkk9
2024-07-02 19:20:33 +05:30
6 changed files with 452 additions and 131 deletions

View File

@@ -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]);
}
}
}

View File

@@ -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');
}
});
}
});

View File

@@ -69,13 +69,19 @@ $currentPage = 'manage-faq';
{{ $faqs['answers'] }}
@endif
</td>
<td class="text-start">
@if($faqs['faq_category_id'] == 1)
Customer
@else
Restaurant
@endif
@if($faqs['faq_category_id'] == 1)
Customer
@elseif($faqs['faq_category_id'] == 2)
Restaurant
@elseif($faqs['faq_category_id'] == 3)
Subscription
@else
Unknown Category
@endif
</td>
<td class="text-start">
@if (isset($faqs['created_at']))
{{ \Carbon\Carbon::parse($faqs['created_at'])->format('m/d/Y') }}
@@ -138,6 +144,8 @@ $currentPage = 'manage-faq';
<option value="">Select</option>
<option value="1">Customer</option>
<option value="2">Restaurant</option>
<option value="3">Subscription</option>
</select>
</div>
<button type="submit" id="submit_faq" class="download-btn-custom mt-4 mx-auto w-25">

View File

@@ -161,7 +161,7 @@
</a>
</tr>
@endforeach
</table>
</table>
</div>
</td>
@@ -229,7 +229,7 @@
<div class="col-xxl-12">
<p><span id="reply-message"></span></p>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -64,13 +64,28 @@
</div> -->
</li>
<li>
<a href="#" data-toggle="modal"
data-target="#edit-location-modal" class="edit_location_value"
data-location-id="{{ $locations->id }}"
data-location-name="{{ $locations->name }}">
<img src="{{ asset('public/assets/img/edit.svg') }}" />
<span>Edit</span>
</a>
<a href="#"
data-toggle="modal"
data-target="#edit-location-modal"
class="edit_location_value"
data-location-id="{{ $locations->id }}"
data-location-name="{{ $locations->name }}"
data-location-timehours="{{ $locations->timeInterval->isNotEmpty() ? $locations->timeInterval->first()->time_hours : '' }}"
data-location-timeinterval="{{ $locations->timeInterval->isNotEmpty() ? $locations->timeInterval->first()->time_interval : '' }}"
data-location-quantity="{{ $locations->timeInterval->isNotEmpty() ? $locations->timeInterval->first()->quantity : '' }}">
<img src="{{ asset('public/assets/img/edit.svg') }}" />
<span>Edit</span>
</a>
</li>
<li>
@@ -140,50 +155,60 @@
</div>
</div>
</div>
<div class="modal fade" id="edit-location-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="modal-header p-0">
<h5 class="modal-title">Edit state</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="row">
<form id="edit_location">
<div class="col-md-12 mb-3">
@csrf
<input class="form-control" name="id" type="hidden" value=""
id="location_id">
<label for="">Name</label>
<input class="form-control" name="location_name" type="text" value=""
id="name">
<label for="timeHours" class="label">Time in hours between redeeming two
cocktails</label>
<input type="number" class="form-control" id="timeHours" name="timeHours" required>
<label for="timeQuantity" class="label">Maximum number of cocktails</label>
<div class="input-group">
<select class="form-control" id="timeInterval" name="timeInterval" required>
<option value="day">Day</option>
<option value="week">Week</option>
<option value="month">Month</option>
</select>
<input type="number" class="form-control" id="timeQuantity" name="timeQuantity"
required>
</div>
</div>
<button type="submit" id="update_location" class="download-btn-custom mt-4 mx-auto w-25">
<span>Save</span>
</button>
</form>
</div>
</div>
</div>
<div class="modal fade" id="edit-location-modal" tabindex="-1" role="dialog" aria-labelledby="editLocationModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="edit_location" enctype="multipart/form-data">
@csrf
<input class="form-control" name="id" type="hidden" id="location_id" value="">
<input class="form-control" name="manage_state_xid" type="hidden" id="manage_state_xid" value="">
<div class="modal-header">
<h5 class="modal-title" id="editLocationModalLabel">Edit Location</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="location-name">Location Name</label>
<input type="text" class="form-control" id="location-name" name="location_name">
</div>
<div class="form-group">
<label for="time-hours">Time Hours</label>
<input type="number" class="form-control" id="time-hours" name="time_hours">
</div>
<div class="form-group">
<label for="time-interval">Time Interval</label>
<select class="form-control" id="time-interval" name="time_interval">
<option value="day">Day</option>
<option value="week">Week</option>
<option value="month">Month</option>
</select>
</div>
<div class="form-group">
<label for="quantity">Quantity</label>
<input type="number" class="form-control" id="quantity" name="quantity">
</div>
</div>
<div class="modal-footer">
<button type="submit" id="update_location" class="download-btn-custom mt-4 mx-auto w-25">
<span>Save</span>
</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="delete-location-modal" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
@@ -216,4 +241,105 @@
.insertBefore("#zero-config_filter label");
});
</script>
<script>
$(document).ready(function() {
$(document).on("click", ".edit_location_value", function (e) {
e.preventDefault(); // Prevent default action
var locationId = $(this).data('location-id');
var locationName = $(this).data('location-name');
var timeHours = $(this).data('location-timehours');
var timeInterval = $(this).data('location-timeinterval');
var quantity = $(this).data('location-quantity');
console.log('Location ID:', locationId);
console.log('Location Name:', locationName);
console.log('Time Hours:', timeHours);
console.log('Time Interval:', timeInterval);
console.log('Quantity:', quantity);
$('#location_id').val(locationId);
$('#location-name').val(locationName);
$('#time-hours').val(timeHours);
$('#time-interval').val(timeInterval);
$('#quantity').val(quantity);
$('#edit-location-modal').modal('show');
});
});
</script>
<script>
$(document).ready(function() {
// Assuming you have a mechanism to set manage_state_xid in the modal
$('#edit-location-modal').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var locationId = button.data('location-id'); // Extract info from data-* attributes
var manageStateXid = button.data('manage-state-xid');
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content.
var modal = $(this);
modal.find('#location_id').val(locationId);
modal.find('#manage_state_xid').val(manageStateXid);
});
$('#edit_location').validate({
rules: {
location_name: { required: true },
time_hours: { required: true, digits: true },
quantity: { required: true, digits: true },
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);
let base_url = url_path;
$('#update_location').text('Please wait...');
$('#update_location').attr('disabled', true);
$.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');
}
});
}
});
});
</script>
@endsection

View File

@@ -199,7 +199,7 @@ Route::group(['middleware' => ['checkStatus']], function () {
Route::post('/insert_location', [ManageLocationController::class, 'store'])->name('store_location');
Route::get('/change_location_status', [ManageLocationController::class, 'change_location_status']);
Route::delete('/delete_location/{id}', [ManageLocationController::class, 'delete_location']);
Route::post('/update_location', [ManageLocationController::class, 'update']);
Route::post('/update_location', [ManageLocationController::class, 'update_location']);
//*******************************************************Rules and regulation********************************************************
Route::get('/manage_rules', [ManageRulesController::class, 'index'])->name('manage_rules');