restaturantApp

This commit is contained in:
sayaliparab
2024-06-03 14:40:08 +05:30
parent de33e95818
commit b9568d3dc2
3 changed files with 306 additions and 60 deletions

View File

@@ -46,48 +46,90 @@ class RestaurantAppController extends Controller
}
}
public function change_rest_user_status(Request $request)
{
// public function change_rest_user_status(Request $request)
// {
try {
DB::beginTransaction();
$status = IamPrincipal::find($request->rest_user_id);
$status->is_active = $request->status;
// try {
// DB::beginTransaction();
// $status = IamPrincipal::find($request->rest_user_id);
// $status->is_active = $request->status;
// Generate a random password
// // Generate a random password
// $randomPassword = \Str::random(8); // Adjust the length as per your requirements
// // Set the password
// $status->password = bcrypt($randomPassword); // Make sure to hash the password
// $status->save();
// if ($request->status == 1) {
// // Fetch user data based on user ID
// $user = IamPrincipal::find($request->rest_user_id);
// if ($user) {
// // Send email only if user exists
// $data = [
// 'first_name' => $user->first_name,
// 'last_name' => $user->last_name,
// 'email' => $user->email_address,
// 'password' => $randomPassword, // Pass the random password to the email template
// ];
// Mail::to($user->email_address)->send(new RestUserApproval($data));
// }
// }
// DB::commit();
// return jsonResponseWithSuccessMessage(__('success.update_data'));
// } catch (Exception $e) {
// Log::error("Update Status function Load Failed " . $e->getMessage());
// return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
// }
// }
public function change_rest_user_status(Request $request)
{
try {
DB::beginTransaction();
$status = IamPrincipal::find($request->rest_user_id);
$status->is_active = $request->status;
// Generate a random password if status is 1 (approved)
if ($request->status == 1) {
$randomPassword = \Str::random(8); // Adjust the length as per your requirements
// Set the password
$status->password = bcrypt($randomPassword); // Make sure to hash the password
$status->save();
if ($request->status == 1) {
// Fetch user data based on user ID
$user = IamPrincipal::find($request->rest_user_id);
if ($user) {
// Send email only if user exists
$data = [
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'email' => $user->email_address,
'password' => $randomPassword, // Pass the random password to the email template
];
Mail::to($user->email_address)->send(new RestUserApproval($data));
}
}
DB::commit();
return jsonResponseWithSuccessMessage(__('success.update_data'));
} catch (Exception $e) {
Log::error("Update Status function Load Failed " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
$status->save();
if ($request->status == 1) {
// Fetch user data based on user ID
$user = IamPrincipal::find($request->rest_user_id);
if ($user) {
// Send email only if user exists
$data = [
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'email' => $user->email_address,
'password' => $randomPassword, // Pass the random password to the email template
];
Mail::to($user->email_address)->send(new RestUserApproval($data));
}
}
DB::commit();
return jsonResponseWithSuccessMessage(__('success.update_data'));
} catch (Exception $e) {
Log::error("Update Status function Load Failed " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
}
}

View File

@@ -78,30 +78,181 @@ $(document).on("click", ".restaurant_unarchive", function (e) {
});
});
//old code for change status
$(".rest_users_table").on("change", ".active_rest_user", function () {
let base_url = url_path;
var status = $(this).prop("checked") == true ? 1 : 0;
var rest_user_id = $(this).data("id");
// $(".rest_users_table").on("change", ".active_rest_user", function () {
// let base_url = url_path;
// var status = $(this).prop("checked") == true ? 1 : 0;
// var rest_user_id = $(this).data("id");
$.ajax({
type: "GET",
dataType: "json",
url: base_url + '/change_rest_status',
data: {
status: status,
rest_user_id: rest_user_id,
},
success: function (data) {
if (status == 1) {
// $.ajax({
// type: "GET",
// dataType: "json",
// url: base_url + '/change_rest_status',
// data: {
// status: status,
// rest_user_id: rest_user_id,
// },
// success: function (data) {
// if (status == 1) {
// toastr.options = {
// "timeOut": 500
// }
// toastr.success("Status Activate successfully. !!");
// } else {
// toastr.error("Status Deactivate successfully. !!");
// }
// },
// });
// });
// $(document).ready(function () {
// // Handle approve button click
// $(".approve-btn").on("click", function () {
// let base_url = url_path;
// var rest_user_id = $(this).data("id");
// var status = 1;
// $.ajax({
// type: "GET",
// dataType: "json",
// url: base_url + '/change_rest_status',
// data: {
// status: status,
// rest_user_id: rest_user_id,
// },
// success: function (data) {
// toastr.options = {
// "timeOut": 500
// }
// toastr.success("User approved and status activated successfully. !!");
// // Update the switch to active
// $('#switch' + rest_user_id).prop('checked', true);
// },
// });
// });
// // Handle disapprove button click
// $(".disapprove-btn").on("click", function () {
// let base_url = url_path;
// var rest_user_id = $(this).data("id");
// var status = 0;
// $.ajax({
// type: "GET",
// dataType: "json",
// url: base_url + '/change_rest_status',
// data: {
// status: status,
// rest_user_id: rest_user_id,
// },
// success: function (data) {
// toastr.error("User disapproved and status deactivated successfully. !!");
// // Update the switch to inactive
// $('#switch' + rest_user_id).prop('checked', false);
// },
// });
// });
// $(".rest_users_table").on("change", ".active_rest_user", function () {
// // Revert the switch change
// var rest_user_id = $(this).data("id");
// var currentStatus = $(this).prop("checked");
// // Revert the switch state
// $(this).prop("checked", !currentStatus);
// toastr.options = {
// "timeOut": 6000
// }
// toastr.error("You can only change the status using Approve/Disapprove buttons.");
// });
// });
$(document).ready(function () {
// Handle approve button click
$(".approve-btn").on("click", function () {
let base_url = url_path;
var rest_user_id = $(this).data("id");
var switchElement = $('#switch' + rest_user_id);
// Check current status
if (switchElement.prop('checked')) {
toastr.options = {
"timeOut": 500
}
toastr.warning("User is already approved. !!");
return;
}
$.ajax({
type: "GET",
dataType: "json",
url: base_url + '/change_rest_status',
data: {
status: 1,
rest_user_id: rest_user_id,
},
success: function (data) {
toastr.options = {
"timeOut": 500
}
toastr.success("Status Activate successfully. !!");
} else {
toastr.error("Status Deactivate successfully. !!");
toastr.success("User approved and status activated successfully. !!");
// Update the switch to active
switchElement.prop('checked', true);
},
});
});
// Handle disapprove button click
$(".disapprove-btn").on("click", function () {
let base_url = url_path;
var rest_user_id = $(this).data("id");
var switchElement = $('#switch' + rest_user_id);
// Check current status
if (!switchElement.prop('checked')) {
toastr.options = {
"timeOut": 500
}
},
toastr.warning("User is already disapproved. !!");
return;
}
$.ajax({
type: "GET",
dataType: "json",
url: base_url + '/change_rest_status',
data: {
status: 0,
rest_user_id: rest_user_id,
},
success: function (data) {
toastr.error("User disapproved and status deactivated successfully. !!");
// Update the switch to inactive
switchElement.prop('checked', false);
},
});
});
// Handle switch change
$(".rest_users_table").on("change", ".active_rest_user", function () {
// Revert the switch change
var currentStatus = $(this).prop("checked");
// Revert the switch state
$(this).prop("checked", !currentStatus);
toastr.options = {
"timeOut": 500
}
toastr.error("You can only change the status using Approve/Disapprove buttons.");
});
});

View File

@@ -1,9 +1,39 @@
@extends('Admin.layouts.master')
@section('content')
<?php $currentPage = "manage-restaurant_app" ?>
@php
$currentPage = 'manage-restaurant_app';
@endphp
<style>
.btn {
padding: 10px 20px;
font-size: 16px;
border: none;
cursor: pointer;
}
.btn-success {
background-color: #28a745;
color: white;
}
.btn-danger {
background-color: #dc3545;
color: white;
}
.btn-success:hover {
background-color: #218838;
color: #fff;
}
.btn-danger:hover {
background-color: #c82333;
color: #fff;
}
</style>
<div class="layout-px-spacing">
<div class="middle-content container-xxl p-0">
<div class="row layout-top-spacing ">
@@ -30,10 +60,12 @@
<th class="text-start">Sr no</th>
<th class="text-start">Resturant Name</th>
<th class="text-start">Resturant ID</th>
<th class="text-start">Image</th>
<th class="text-start">Email Id </th>
<th class="text-start">Date Onboarded</th>
<th class="text-start">Location</th>
<!-- <th class="text-start">Passports</th> -->
<th class="no-content">Approve/Disapprove</th>
<th class="no-content">Action</th>
</tr>
</thead>
@@ -52,9 +84,14 @@
<td class="text-start">{{ $restaurant_user->first_name }}</td>
<td class="text-start">{{ $restaurant_user->id }}</td>
<td class="text-start">{{ $restaurant_user->email_address }}</td>
<td>{{ \Carbon\Carbon::parse($restaurant_user->date_of_birth)->format('d/m/y') }}
</td>
<td class="text-start">{{ $restaurant_user->phone_number }}</td>
<td>{{ \Carbon\Carbon::parse($restaurant_user->date_of_birth)->format('d/m/Y') }}</td>
<td>{{ $restaurant_user->state ? $restaurant_user->state->name : 'No state assigned' }}</td>
<!-- <td>
<button class="btn btn-success approve-btn" data-id="">Approve</button>
<button class="btn btn-danger disapprove-btn" data-id="">Disapprove</button>
</td>
<td>
<div class="switch-btn">
@@ -65,7 +102,23 @@
<label for="switch{{ $restaurant_user['id'] }}" data-on-label="Active"
data-off-label="Inactive"></label>
</div>
</td>
</td> -->
<td>
<button class="btn btn-success approve-btn" data-id="{{ $restaurant_user['id'] }}">Approve</button>
<button class="btn btn-danger disapprove-btn" data-id="{{ $restaurant_user['id'] }}">Disapprove</button>
</td>
<td>
<div class="switch-btn">
<input data-id="{{ $restaurant_user['id'] }}"
{{ $restaurant_user['is_active'] ? 'checked' : '' }}
class="active_rest_user" type="checkbox"
id="switch{{ $restaurant_user['id'] }}" switch="bool" />
<label for="switch{{ $restaurant_user['id'] }}" data-on-label="Active"
data-off-label="Inactive"></label>
</div>
</td>
{{-- <td class="text-start">
<a class="view-btn" href="#">View</a>
</td> --}}
@@ -85,7 +138,7 @@
</a>
</li>
<li>
<a class="cust_archive_btn" "
<a class="cust_archive_btn"
data-toggle="modal" data-target="#archive-modal">
<img src="{{ asset('public/assets/img/archive.svg') }}" />
<span>Archive</span>