Files
cheerstothe_season_2.0/app/Http/Controllers/Admin/ManageRestrauntController.php

374 lines
13 KiB
PHP
Raw Normal View History

2024-05-23 15:20:21 +05:30
<?php
namespace App\Http\Controllers\Admin;
2024-06-17 13:22:20 +05:30
use App\Exports\RestaurantExport;
use App\Exports\RestaurantExportSelected;
2024-05-23 15:20:21 +05:30
use App\Http\Controllers\Controller;
2024-05-29 15:10:12 +05:30
use App\Models\ManageRestaurant;
use App\Models\OperatingHour;
2024-05-23 15:20:21 +05:30
use Illuminate\Http\Request;
2024-05-29 15:10:12 +05:30
use Exception;
2024-06-05 16:30:25 +05:30
use App\Helpers\onesignalhelper;
use App\Models\IamPrincipal;
2024-06-18 19:15:31 +05:30
use App\Models\ManageState;
2024-05-29 15:10:12 +05:30
use Illuminate\Support\Facades\Log;
2024-06-17 13:22:20 +05:30
use Maatwebsite\Excel\Facades\Excel;
2024-05-29 15:10:12 +05:30
use Illuminate\Support\Facades\DB;
2024-05-23 15:20:21 +05:30
class ManageRestrauntController extends Controller
{
2024-05-30 12:40:29 +05:30
/*
Created By : Sayli Raut
Created at : 29 May 2024
Use : To Get Restaurant Page.
*/
public function index(Request $request)
2024-05-29 17:11:02 +05:30
{
2024-05-30 12:40:29 +05:30
$activeQuery = $request->query('active');
if ($activeQuery == 1) {
$restaurant = ManageRestaurant::where('is_active', 1)->latest()->get();
} else if ($activeQuery == 0 && $activeQuery != null) {
$restaurant = ManageRestaurant::where('is_active', 0)->latest()->get();
} else {
$restaurant = ManageRestaurant::latest()->get();
}
2024-05-29 17:11:02 +05:30
return view('Admin.pages.manage_restaurants.manage_restaurants', compact('restaurant'));
2024-05-23 15:20:21 +05:30
}
2024-05-29 15:10:12 +05:30
2024-05-30 12:40:29 +05:30
/*
Created By : Sayli Raut
Created at : 29 May 2024
Use : To Add Restaurant Page.
*/
2024-05-29 15:10:12 +05:30
public function add()
{
2024-06-18 19:15:31 +05:30
$state = ManageState::where('is_active', 1)->get()->toArray();
return view('Admin.pages.manage_restaurants.add_restaurant', compact('state'));
2024-05-29 15:10:12 +05:30
}
2024-05-30 12:40:29 +05:30
/*
Created By : Sayli Raut
Created at : 29 May 2024
Use : To store resturant form.
*/
2024-05-29 17:11:02 +05:30
public function store_restaurant(Request $request)
2024-05-29 15:10:12 +05:30
{
try {
2024-05-29 17:11:02 +05:30
DB::beginTransaction();
// Handling image upload
if ($request->hasFile('image')) {
$image = $request->file('image');
$imagePath = saveSingleImageWithoutCrop($image, 'restaurant_images');
} else {
$imagePath = $request->image;
}
// Creating the restaurant
$restaurant = new ManageRestaurant();
$restaurant->name = $request->input('name');
$restaurant->image = $imagePath;
$restaurant->restaurant_id = $request->input('rest_id');
$restaurant->address = $request->input('address');
$restaurant->bio = $request->input('bio');
$restaurant->latitude = $request->input('latitude');
$restaurant->longtitude = $request->input('longitude');
$restaurant->exclusion = $request->input('exclusion');
2024-06-12 17:44:31 +05:30
$restaurant->phone_number = $request->input('phone_number');
2024-06-18 19:15:31 +05:30
$restaurant->state_xid = $request->input('state_xid');
2024-05-29 17:11:02 +05:30
$restaurant->try_on_1 = $request->input('try_on_1');
$restaurant->try_on_2 = $request->input('try_on_2');
$restaurant->try_on_3 = $request->input('try_on_3');
$restaurant->try_on_4 = $request->input('try_on_4');
$restaurant->save();
foreach ($request->input('operating_hours') as $day => $hours) {
OperatingHour::create([
'manage_restaurant_xid' => $restaurant->id,
'day_of_week' => $day,
'start_time' => $hours['start_time'],
'end_time' => $hours['end_time']
]);
}
2024-05-29 15:10:12 +05:30
2024-06-05 16:30:25 +05:30
$imagePath = ListingImageUrl('restaurant_images', $restaurant->image);
$allCustomerOneSignalIds = IamPrincipal::select('id', 'one_signal_player_id')->where('is_active', 1)->where('notification_status', 1)->where('principal_type_xid', 3)->get();
$title = "New " . $restaurant->name . " is added";
$message = "New Restaurant is Now Live.";
2024-06-06 14:44:22 +05:30
$content_type = 'New Restaurant Added';
2024-06-05 16:30:25 +05:30
$imageUrl = $imagePath;
foreach ($allCustomerOneSignalIds as $customerIdItem) {
if ($customerIdItem->one_signal_player_id) {
onesignalhelper::sendNotificationApi(
$customerIdItem->one_signal_player_id,
$title,
$message,
$content_type,
$imageUrl,
$id = null
);
}
onesignalhelper::StoreNotificationDetails($customerIdItem->id, $content_type, $title, $imagePath);
}
2024-05-29 17:11:02 +05:30
DB::commit();
return jsonResponseWithSuccessMessage(__('success.save_data'));
2024-05-29 15:10:12 +05:30
} catch (Exception $e) {
DB::rollBack();
2024-05-29 17:11:02 +05:30
Log::error("Restaurant Store Page Load Failed: " . $e->getMessage());
2024-05-29 15:10:12 +05:30
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
}
2024-05-30 12:40:29 +05:30
/*
Created By : Sayli Raut
Created at : 29 May 2024
Use : To edit Restaurant Page.
*/
2024-05-29 17:11:02 +05:30
public function edit_restaurant(Request $request, $id)
{
try {
2024-05-29 19:34:35 +05:30
$operating_hours = OperatingHour::where('manage_restaurant_xid', $id)->get()->keyBy('day_of_week');
2024-05-29 17:11:02 +05:30
$restaurantItem = ManageRestaurant::where('id', $id)->first();
2024-06-18 19:15:31 +05:30
$state = ManageState::where('is_active', 1)->get()->toArray();
2024-05-29 17:11:02 +05:30
$restaurantItem['image'] = ListingImageUrl('restaurant_images', $restaurantItem['image']);
return view(
'Admin.pages.manage_restaurants.edit_restaurant',
compact(
'restaurantItem',
2024-06-18 19:15:31 +05:30
'operating_hours',
'state'
2024-05-29 17:11:02 +05:30
)
);
} catch (Exception $e) {
Log::error("edit voucher Page Load Failed " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
2024-05-29 19:34:35 +05:30
}
2024-05-30 12:40:29 +05:30
/*
Created By : Sayli Raut
Created at : 29 May 2024
Use : To Update Resturant Form.
*/
2024-05-29 19:34:35 +05:30
public function update(Request $request)
{
try {
DB::beginTransaction();
2024-06-05 16:30:25 +05:30
2024-05-29 19:34:35 +05:30
$restaurant = ManageRestaurant::where('id', $request->id)->first();
2024-06-05 16:30:25 +05:30
2024-05-29 19:34:35 +05:30
if ($request->hasFile('image')) {
$image = $request->file('image');
$imagePath = saveSingleImageWithoutCrop($image, 'restaurant_images');
} else {
$imagePath = $restaurant->image;
}
2024-06-05 16:30:25 +05:30
2024-05-29 19:34:35 +05:30
$restaurant->name = $request->input('name');
$restaurant->description = $request->input('description');
$restaurant->image = $imagePath;
$restaurant->restaurant_id = $request->input('restaurant_id');
$restaurant->address = $request->input('location_name');
$restaurant->exclusion = $request->input('exclusion');
2024-06-12 19:37:07 +05:30
$restaurant->phone_number = $request->input('phone_number');
2024-06-18 19:15:31 +05:30
$restaurant->state_xid = $request->input('state_xid');
2024-05-29 19:34:35 +05:30
$restaurant->latitude = $request->input('latitude');
$restaurant->longtitude = $request->input('longitude');
$restaurant->bio = $request->input('bio');
$restaurant->try_on_1 = $request->input('try_on_1');
$restaurant->try_on_2 = $request->input('try_on_2');
$restaurant->try_on_3 = $request->input('try_on_3');
$restaurant->try_on_4 = $request->input('try_on_4');
$restaurant->save();
2024-06-05 16:30:25 +05:30
2024-05-29 19:34:35 +05:30
foreach ($request->input('operating_hours') as $day => $hours) {
2024-06-03 21:34:57 +05:30
$operatingHour = OperatingHour::where('manage_restaurant_xid', $restaurant->id)
2024-06-05 16:30:25 +05:30
->where('day_of_week', $day)
->first();
2024-06-03 21:34:57 +05:30
if ($operatingHour) {
// Update existing record
$operatingHour->update([
'start_time' => $hours['start_time'],
'end_time' => $hours['end_time']
]);
} else {
// Create new record
OperatingHour::create([
'manage_restaurant_xid' => $restaurant->id,
'day_of_week' => $day,
'start_time' => $hours['start_time'],
'end_time' => $hours['end_time']
]);
}
2024-05-29 19:34:35 +05:30
}
2024-06-05 16:30:25 +05:30
2024-05-29 19:34:35 +05:30
DB::commit();
2024-06-05 16:30:25 +05:30
2024-05-29 19:34:35 +05:30
return jsonResponseWithSuccessMessage(__('success.update_data'));
} catch (Exception $e) {
DB::rollBack();
Log::error("update Restaurant Services Page Load Failed " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
2024-05-29 17:11:02 +05:30
}
2024-06-05 16:30:25 +05:30
2024-05-29 17:11:02 +05:30
2024-05-29 23:05:31 +05:30
2024-05-30 12:40:29 +05:30
/*
Created By : Sayli Raut
Created at : 29 May 2024
Use : To view restaurant Page.
*/
2024-05-29 23:05:31 +05:30
public function viewRestaurant(Request $request, $id)
{
try {
$restaurantItem = ManageRestaurant::where('id', $id)->first();
$restaurantItem['image'] = ListingImageUrl('restaurant_images', $restaurantItem['image']);
$operating_hours = OperatingHour::where('manage_restaurant_xid', $id)->get()->keyBy('day_of_week');
2024-05-30 12:40:29 +05:30
return view('Admin.pages.manage_restaurants.view_restaurant', compact('restaurantItem', 'operating_hours'));
2024-05-29 23:05:31 +05:30
} catch (Exception $e) {
2024-06-14 15:07:45 +05:30
Log::error("view Voucher Load Failed" . $e->getMessage());
2024-05-29 23:05:31 +05:30
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
2024-05-30 12:40:29 +05:30
}
/*
Created By : Sayli Raut
Created at : 30 May 2024
Use : To Update status of restaurant.
*/
public function updateRestaurantStatus(Request $request)
{
try {
DB::beginTransaction();
$voucher_data = ManageRestaurant::where('id', $request->dataId)->first();
$voucher_data->is_active = $request->status ?? 0;
$voucher_data->save();
DB::commit();
2024-05-29 23:05:31 +05:30
2024-05-30 12:40:29 +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 23:05:31 +05:30
}
2024-05-30 12:40:29 +05:30
/*
Created By : Sayli Raut
Created at : 30 May 2024
Use : To Delete Restaurant.
*/
public function deleteRestaurant(Request $request, $id)
{
try {
2024-05-29 23:05:31 +05:30
2024-05-30 12:40:29 +05:30
DB::beginTransaction();
$update = ManageRestaurant::where('id', $id)->update(['is_active' => 0]);
$deleteRestaurant = ManageRestaurant::where('id', $id)->delete();
DB::commit();
return jsonResponseWithSuccessMessage(__('success.delete'));
} catch (Exception $e) {
Log::error("delete function Load Failed " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
}
2024-06-05 16:30:25 +05:30
/*
2024-05-30 15:28:17 +05:30
Created By : Sayli Raut
Created at : 30 May 2024
Use : To Get archieve restaurants.
*/
2024-06-05 16:30:25 +05:30
public function archive_restaurant()
{
2024-05-30 15:28:17 +05:30
2024-06-05 16:30:25 +05:30
try {
$restaurant = ManageRestaurant::onlyTrashed()->latest()->get();
return view('Admin.pages.manage_restaurants.archive_manage_restaurant', compact('restaurant'));
} catch (Exception $e) {
Log::error("Manage Voucher Page Not Load " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
2024-05-30 15:28:17 +05:30
}
2024-06-05 16:30:25 +05:30
/*
2024-05-30 15:28:17 +05:30
Created By : Sayli Raut
Created at : 30 May 2024
Use : To archieve restaurant.
*/
2024-06-05 16:30:25 +05:30
public function archive_delete_restaurant($id)
{
try {
DB::beginTransaction();
$restaurant = ManageRestaurant::find($id);
$restaurant->delete();
DB::commit();
2024-05-30 15:28:17 +05:30
2024-06-05 16:30:25 +05:30
return jsonResponseWithSuccessMessage(__('success.update_data'));
} 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')]);
}
2024-05-30 15:28:17 +05:30
}
2024-06-05 16:30:25 +05:30
/*
2024-05-30 15:28:17 +05:30
Created By : Sayli Raut
Created at : 30 May 2024
Use : To Deleted Data Restore.
*/
2024-06-05 16:30:25 +05:30
public function unarchive_restaurant($id)
{
2024-05-30 15:28:17 +05:30
2024-06-05 16:30:25 +05:30
try {
DB::beginTransaction();
ManageRestaurant::withTrashed()->where('id', $id)->restore();
2024-05-30 15:28:17 +05:30
2024-06-05 16:30:25 +05:30
DB::commit();
2024-05-30 15:28:17 +05:30
2024-06-05 16:30:25 +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')]);
}
2024-05-30 15:28:17 +05:30
}
2024-06-17 13:22:20 +05:30
/*
Created By : Sayli Raut
Created at : 17 June 2024
Use : To download Excel.
*/
public function exportSelectedRestaurant(Request $request)
{
try {
if ($request->has('all_id')) {
return Excel::download(new RestaurantExport, 'Restaurant_data.xlsx');
}
$ids = $request->selected_id;
// dd( $ids);
$fileName = 'selected_restaurant_data.xlsx';
return Excel::download(new RestaurantExportSelected($ids), $fileName);
} catch (\Exception $e) {
return response()->json(['error' => 'Export failed. Something went wrong.'], 500);
}
}
2024-05-30 15:28:17 +05:30
}