2024-05-29 17:11:02 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use Illuminate\Http\Request;
|
2024-05-30 19:41:43 +05:30
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use App\Models\IamPrincipal;
|
|
|
|
|
use App\Models\ManageRestaurant;
|
|
|
|
|
use App\Mail\RestUserApproval;
|
2024-06-03 20:26:36 +05:30
|
|
|
use App\Models\IamPrincipalRestaurantRole;
|
2024-05-30 19:41:43 +05:30
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
2024-05-29 17:11:02 +05:30
|
|
|
|
|
|
|
|
class RestaurantAppController extends Controller
|
|
|
|
|
{
|
2024-06-03 20:26:36 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
|
2024-06-05 20:10:10 +05:30
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 03 June 2024
|
|
|
|
|
* Use : To get restaturant user.
|
|
|
|
|
*/
|
2024-05-30 19:41:43 +05:30
|
|
|
public function index_restraunt_users(Request $request)
|
|
|
|
|
{
|
|
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
|
2024-05-30 19:41:43 +05:30
|
|
|
try {
|
|
|
|
|
$activeQuery = $request->query('active');
|
|
|
|
|
|
|
|
|
|
if ($activeQuery == 1) {
|
2024-06-05 12:25:42 +05:30
|
|
|
$restaurant_users = IamPrincipal::with('getresturant')
|
|
|
|
|
->where('principal_type_xid', 4)
|
|
|
|
|
->where('is_active', 1)
|
|
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
|
->get();
|
2024-05-30 19:41:43 +05:30
|
|
|
} else if ($activeQuery == 0 && $activeQuery != null) {
|
2024-06-05 12:25:42 +05:30
|
|
|
$restaurant_users = IamPrincipal::with('getresturant')
|
|
|
|
|
->where('principal_type_xid', 4)
|
|
|
|
|
->where('is_active', '0')
|
|
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
|
->get();
|
2024-05-30 19:41:43 +05:30
|
|
|
} else {
|
2024-06-05 12:25:42 +05:30
|
|
|
$restaurant_users = IamPrincipal::with('getresturant')
|
|
|
|
|
->where('principal_type_xid', 4)
|
|
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
|
->get();
|
2024-05-30 19:41:43 +05:30
|
|
|
}
|
2024-06-05 12:25:42 +05:30
|
|
|
|
2024-05-30 19:41:43 +05:30
|
|
|
foreach ($restaurant_users as $user) {
|
|
|
|
|
$restaurantIds = $user->getresturant->pluck('restaurant_xid')->toArray();
|
2024-06-03 20:26:36 +05:30
|
|
|
|
2024-06-05 12:25:42 +05:30
|
|
|
$user->restaurants = ManageRestaurant::whereIn('id', $restaurantIds)
|
2024-06-06 15:28:15 +05:30
|
|
|
->select('id','restaurant_id', 'name', 'image', 'address', 'latitude', 'longtitude')
|
2024-06-05 12:25:42 +05:30
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
// Optionally, if you want to format the images as in the previous example
|
|
|
|
|
foreach ($user->restaurants as &$restaurant) {
|
|
|
|
|
$restaurant->image = ListingImageUrl('restaurant_images', $restaurant->image);
|
|
|
|
|
}
|
2024-05-30 19:41:43 +05:30
|
|
|
}
|
2024-06-05 12:25:42 +05:30
|
|
|
|
|
|
|
|
// Return the response as JSON
|
|
|
|
|
// return response()->json($restaurant_users);
|
2024-06-03 21:43:16 +05:30
|
|
|
return view('Admin.pages.manage_users.restaurants_app.restaurants_users', compact('restaurant_users'));
|
2024-05-30 19:41:43 +05:30
|
|
|
} catch (Exception $e) {
|
|
|
|
|
Log::error("Manage Voucher Page Not Load " . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 12:25:42 +05:30
|
|
|
|
|
|
|
|
|
2024-06-03 14:40:08 +05:30
|
|
|
// public function change_rest_user_status(Request $request)
|
|
|
|
|
// {
|
2024-06-04 14:57:32 +05:30
|
|
|
|
2024-06-03 14:40:08 +05:30
|
|
|
// try {
|
|
|
|
|
// DB::beginTransaction();
|
|
|
|
|
// $status = IamPrincipal::find($request->rest_user_id);
|
|
|
|
|
// $status->is_active = $request->status;
|
2024-05-30 19:41:43 +05:30
|
|
|
|
2024-06-03 14:40:08 +05:30
|
|
|
// // 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);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-06-05 20:10:10 +05:30
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 03 June 2024
|
|
|
|
|
* Use : To change the status restaturant user.
|
|
|
|
|
*/
|
2024-06-03 14:40:08 +05:30
|
|
|
public function change_rest_user_status(Request $request)
|
2024-06-04 14:57:32 +05:30
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
$status->password = bcrypt($randomPassword); // Make sure to hash the password
|
|
|
|
|
}
|
2024-05-30 19:41:43 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
$status->save();
|
2024-05-30 19:41:43 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
if ($request->status == 1) {
|
|
|
|
|
// Fetch user data based on user ID
|
|
|
|
|
$user = IamPrincipal::find($request->rest_user_id);
|
2024-05-30 19:41:43 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
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
|
|
|
|
|
];
|
2024-05-30 19:41:43 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
Mail::to($user->email_address)->send(new RestUserApproval($data));
|
|
|
|
|
}
|
2024-05-30 19:41:43 +05:30
|
|
|
}
|
|
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
DB::commit();
|
2024-05-30 19:41:43 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
return jsonResponseWithSuccessMessage(__('success.update_data'));
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
Log::error("Update Status function Load Failed " . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
2024-05-29 17:11:02 +05:30
|
|
|
}
|
2024-05-30 19:41:43 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-05 20:10:10 +05:30
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 03 June 2024
|
|
|
|
|
* Use : To view restaturant user.
|
|
|
|
|
*/
|
2024-06-06 15:20:56 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
public function view_rest($id)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2024-06-06 15:20:56 +05:30
|
|
|
$restdata = IamPrincipalRestaurantRole::with('restaurant','customer')->where('principal_xid', $id)->first();
|
|
|
|
|
// return $restdata;
|
|
|
|
|
|
|
|
|
|
return view('Admin.pages.manage_users.restaurants_app.view_restaurant_users', compact('restdata'));
|
2024-06-04 14:57:32 +05:30
|
|
|
} catch (Exception $e) {
|
|
|
|
|
Log::error("Manage Voucher Page Not Load " . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
2024-06-03 20:26:36 +05:30
|
|
|
}
|
2024-06-06 15:20:56 +05:30
|
|
|
|
2024-06-03 20:26:36 +05:30
|
|
|
|
|
|
|
|
|
2024-06-05 20:10:10 +05:30
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 03 June 2024
|
|
|
|
|
* Use : To edit restaturant user.
|
|
|
|
|
*/
|
2024-06-04 14:57:32 +05:30
|
|
|
public function edit_Restaurant($id)
|
2024-06-03 20:26:36 +05:30
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$editRest = IamPrincipal::findOrFail($id);
|
|
|
|
|
return view('Admin.pages.manage_users.restaurants_app.edit_restaurant_users', compact('editRest'));
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
Log::error("Manage Voucher Page Not Load " . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
// public function updateRest(Request $request)
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
// DB::beginTransaction();
|
|
|
|
|
// $rest_data = IamPrincipal::where('id', $request->rest_id)->first();
|
|
|
|
|
// $rest_data->first_name = $request->input('name');
|
|
|
|
|
// $rest_data->last_name = $request->input('last_name');
|
|
|
|
|
|
|
|
|
|
// $rest_data->phone_number = $request->input('phone');
|
|
|
|
|
// $rest_data->email_address = $request->input('email_id');
|
|
|
|
|
// $rest_data->save();
|
|
|
|
|
// DB::commit();
|
|
|
|
|
|
|
|
|
|
// return jsonResponseWithSuccessMessage(__('success.update_data'));
|
|
|
|
|
// } catch (Exception $e) {
|
|
|
|
|
// DB::rollBack();
|
|
|
|
|
// Log::error("updateCustomerNewsArticle Services Page Load Failed " . $e->getMessage());
|
|
|
|
|
// return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public function updateRest(Request $request)
|
|
|
|
|
// {
|
|
|
|
|
// try {
|
|
|
|
|
// DB::beginTransaction();
|
|
|
|
|
|
|
|
|
|
// $rest_data = IamPrincipal::find($request->input('rest_id'));
|
|
|
|
|
// if (!$rest_data) {
|
|
|
|
|
// throw new Exception('Restaurant not found.');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// $rest_data->first_name = $request->input('restaurant_name');
|
|
|
|
|
// $rest_data->description = $request->input('restaurant_des');
|
|
|
|
|
// $rest_data->phone_number = $request->input('restaurant_phone');
|
|
|
|
|
// $rest_data->email_address = $request->input('restaurant_email');
|
|
|
|
|
// $rest_data->location = $request->input('restaurant_loc');
|
|
|
|
|
// $rest_data->bio = $request->input('restaurant_bio');
|
|
|
|
|
|
|
|
|
|
// if ($request->hasFile('restaurant_image')) {
|
|
|
|
|
// $imagePath = $request->file('restaurant_image')->store('images', 'public');
|
|
|
|
|
// $rest_data->image_path = $imagePath;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// $rest_data->save();
|
|
|
|
|
|
|
|
|
|
// DB::commit();
|
|
|
|
|
// return response()->json(['message' => __('success.update_data')], 200);
|
|
|
|
|
// } catch (Exception $e) {
|
|
|
|
|
// DB::rollBack();
|
|
|
|
|
// Log::error("Update Restaurant Failed: " . $e->getMessage());
|
|
|
|
|
// return response()->json(['message' => __('auth.something_went_wrong')], 500);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
2024-06-05 20:10:10 +05:30
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 04 June 2024
|
|
|
|
|
* Use : To update restaturant user.
|
|
|
|
|
*/
|
2024-06-03 20:26:36 +05:30
|
|
|
public function updateRest(Request $request)
|
|
|
|
|
{
|
2024-06-05 12:25:42 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
|
|
$rest_data = IamPrincipal::find($request->input('rest_id'));
|
2024-06-05 12:25:42 +05:30
|
|
|
// dd( $rest_data ) ;
|
2024-06-04 14:57:32 +05:30
|
|
|
if (!$rest_data) {
|
|
|
|
|
throw new Exception('Restaurant not found.');
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-06 15:20:56 +05:30
|
|
|
|
2024-06-05 12:25:42 +05:30
|
|
|
$rest_data->first_name = $request->input('first_name');
|
|
|
|
|
$rest_data->last_name = $request->input('last_name');
|
2024-06-04 14:57:32 +05:30
|
|
|
|
|
|
|
|
$rest_data->phone_number = $request->input('restaurant_phone');
|
2024-06-05 12:25:42 +05:30
|
|
|
$rest_data->date_of_birth = $request->input('user_birth');
|
2024-06-06 15:20:56 +05:30
|
|
|
|
2024-06-03 20:26:36 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
$rest_data->save();
|
|
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
return response()->json(['status_code' => 200, 'message' => __('success.update_data')], 200);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
Log::error("Update Restaurant Failed: " . $e->getMessage());
|
|
|
|
|
return response()->json(['status_code' => 500, 'message' => __('auth.something_went_wrong')], 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-03 20:26:36 +05:30
|
|
|
|
2024-06-05 20:10:10 +05:30
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 04 June 2024
|
|
|
|
|
* Use : To delete restaturant user.
|
|
|
|
|
*/
|
2024-06-05 12:25:42 +05:30
|
|
|
public function deleteRestaurantsUsers($id)
|
2024-06-04 14:57:32 +05:30
|
|
|
{
|
2024-06-05 12:25:42 +05:30
|
|
|
|
2024-06-03 20:26:36 +05:30
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
$restaurant = IamPrincipal::find($id);
|
|
|
|
|
$restaurant->delete();
|
|
|
|
|
|
2024-06-03 20:26:36 +05:30
|
|
|
DB::commit();
|
|
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
return response()->json(['success' => true, 'status' => 200]);
|
2024-06-03 20:26:36 +05:30
|
|
|
} catch (Exception $e) {
|
|
|
|
|
DB::rollBack();
|
2024-06-04 14:57:32 +05:30
|
|
|
Log::error("delete_passport function Load Failed " . $e->getMessage());
|
|
|
|
|
return response()->json(['success' => false, 'status' => 500, 'message' => __('auth.something_went_wrong')]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 20:10:10 +05:30
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 04 June 2024
|
|
|
|
|
* Use : To archieve restaturant user.
|
|
|
|
|
*/
|
2024-06-04 14:57:32 +05:30
|
|
|
public function archive_restaturant()
|
|
|
|
|
{
|
2024-06-05 12:25:42 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
try {
|
|
|
|
|
$rest_user = IamPrincipal::where('principal_type_xid', 4)->onlyTrashed()->latest()->get();
|
|
|
|
|
return view('Admin.pages.manage_users.restaurants_app.archive_manage_restaurant', compact('rest_user'));
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
Log::error("Manage Voucher Page Not Load " . $e->getMessage());
|
2024-06-03 20:26:36 +05:30
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-05 20:10:10 +05:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created By : sayali parab
|
|
|
|
|
* Created at : 04 June 2024
|
|
|
|
|
* Use : To unarchieve restaturant user.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
public function unarchive_rest($id)
|
|
|
|
|
{
|
2024-06-03 14:40:08 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
IamPrincipal::withTrashed()->where('id', $id)->restore();
|
2024-05-30 19:41:43 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
DB::commit();
|
2024-05-30 19:41:43 +05:30
|
|
|
|
2024-06-04 14:57:32 +05:30
|
|
|
return response()->json(['success' => true, 'status' => 200]);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
Log::error("delete_passport function Load Failed " . $e->getMessage());
|
|
|
|
|
return response()->json(['success' => false, 'status' => 500, 'message' => __('auth.something_went_wrong')]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|