diff --git a/app/Http/Controllers/Admin/ManageRestrauntController.php b/app/Http/Controllers/Admin/ManageRestrauntController.php index 10f4d39..3546f07 100644 --- a/app/Http/Controllers/Admin/ManageRestrauntController.php +++ b/app/Http/Controllers/Admin/ManageRestrauntController.php @@ -12,6 +12,7 @@ use Exception; use App\Helpers\onesignalhelper; use App\Models\IamPrincipal; use App\Models\ManageState; +use App\Models\RestaurantClosedHour; use App\Models\RestaurantTimeInterval; use Illuminate\Support\Facades\Log; use Maatwebsite\Excel\Facades\Excel; @@ -29,11 +30,11 @@ class ManageRestrauntController extends Controller $activeQuery = $request->query('active'); if ($activeQuery == 1) { - $restaurant = ManageRestaurant::where('is_active', 1)->latest()->get(); + $restaurant = ManageRestaurant::with('state')->where('is_active', 1)->latest()->get(); } else if ($activeQuery == 0 && $activeQuery != null) { - $restaurant = ManageRestaurant::where('is_active', 0)->latest()->get(); + $restaurant = ManageRestaurant::with('state')->where('is_active', 0)->latest()->get(); } else { - $restaurant = ManageRestaurant::latest()->get(); + $restaurant = ManageRestaurant::with('state')->latest()->get(); } return view('Admin.pages.manage_restaurants.manage_restaurants', compact('restaurant')); } @@ -87,6 +88,7 @@ class ManageRestrauntController extends Controller $restaurant->try_on_4 = $request->input('try_on_4'); $restaurant->save(); + // Storing operating hours foreach ($request->input('operating_hours') as $day => $hours) { OperatingHour::create([ 'manage_restaurant_xid' => $restaurant->id, @@ -96,6 +98,7 @@ class ManageRestrauntController extends Controller ]); } + // Storing restaurant time interval $restTimeInterval = new RestaurantTimeInterval(); $restTimeInterval->manage_restaurants_xid = $restaurant->id; $restTimeInterval->time_hours = $request->timeHours; @@ -103,8 +106,18 @@ class ManageRestrauntController extends Controller $restTimeInterval->quantity = $request->timeQuantity; $restTimeInterval->save(); - $imagePath = ListingImageUrl('restaurant_images', $restaurant->image); + // Storing closed restaurant date and time + if ($request->has('closed_date')) { + $ClosedTime = new RestaurantClosedHour(); + $ClosedTime->restaurant_id = $restaurant->id; + $ClosedTime->day = $request->closed_date; + $ClosedTime->start_time = $request->closed_start_time; + $ClosedTime->end_time = $request->closed_end_time; + $ClosedTime->save(); + } + // Sending notifications + $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."; @@ -125,7 +138,6 @@ class ManageRestrauntController extends Controller onesignalhelper::StoreNotificationDetails($customerIdItem->id, $content_type, $title, $imagePath); } - DB::commit(); return jsonResponseWithSuccessMessage(__('success.save_data')); } catch (Exception $e) { @@ -136,6 +148,7 @@ class ManageRestrauntController extends Controller } + /* Created By : Sayli Raut Created at : 29 May 2024 @@ -146,6 +159,7 @@ class ManageRestrauntController extends Controller try { $operating_hours = OperatingHour::where('manage_restaurant_xid', $id)->get()->keyBy('day_of_week'); $restaurantItem = ManageRestaurant::with('timeInterval')->where('id', $id)->first(); + $restaurantClosedTime = RestaurantClosedHour::with('restaurant')->where('restaurant_id', $id)->first(); $timeInterval = $restaurantItem->timeInterval->first(); $state = ManageState::where('is_active', 1)->get()->toArray(); @@ -157,7 +171,8 @@ class ManageRestrauntController extends Controller 'operating_hours', 'state', - 'timeInterval' + 'timeInterval', + 'restaurantClosedTime' ) ); } catch (Exception $e) { @@ -245,6 +260,26 @@ class ManageRestrauntController extends Controller ]); } + // Handle closed restaurant data + $closedTime = RestaurantClosedHour::where('restaurant_id', $restaurant->id)->first(); + + if ($closedTime) { + // Update existing record + $closedTime->update([ + 'day' => $request->input('closed_date'), + 'start_time' => $request->input('closed_start_time'), + 'end_time' => $request->input('closed_end_time'), + ]); + } else { + // Create new record + RestaurantClosedHour::create([ + 'restaurant_id' => $restaurant->id, + 'day' => $request->input('closed_date'), + 'start_time' => $request->input('closed_start_time'), + 'end_time' => $request->input('closed_end_time'), + ]); + } + DB::commit(); return jsonResponseWithSuccessMessage(__('success.update_data')); @@ -258,6 +293,7 @@ class ManageRestrauntController extends Controller + /* Created By : Sayli Raut Created at : 29 May 2024 diff --git a/app/Models/ManageRestaurant.php b/app/Models/ManageRestaurant.php index d1691a0..1802769 100644 --- a/app/Models/ManageRestaurant.php +++ b/app/Models/ManageRestaurant.php @@ -60,5 +60,10 @@ class ManageRestaurant extends Model return $this->hasMany(RestaurantTimeInterval::class, 'manage_restaurants_xid', 'id'); } + public function closedRestaurant() + { + return $this->hasMany(RestaurantClosedHour::class, 'restaurant_id', 'id'); + } + } diff --git a/app/Models/RestaurantClosedHour.php b/app/Models/RestaurantClosedHour.php new file mode 100644 index 0000000..161900b --- /dev/null +++ b/app/Models/RestaurantClosedHour.php @@ -0,0 +1,21 @@ +belongsTo(ManageRestaurant::class); + } +} diff --git a/database/migrations/2024_07_12_094733_create_restaurant_closed_hours_table.php b/database/migrations/2024_07_12_094733_create_restaurant_closed_hours_table.php new file mode 100644 index 0000000..b5a5b35 --- /dev/null +++ b/database/migrations/2024_07_12_094733_create_restaurant_closed_hours_table.php @@ -0,0 +1,33 @@ +id(); + $table->unsignedBigInteger('restaurant_id'); + $table->string('day'); + $table->time('start_time')->nullable(); + $table->time('end_time')->nullable(); + $table->timestamps(); + + $table->foreign('restaurant_id')->references('id')->on('manage_restaurants')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('restaurant_closed_hours'); + } +}; diff --git a/public/assets/js/admin/manage_restaurant/add_restaurant.js b/public/assets/js/admin/manage_restaurant/add_restaurant.js index ce4f7d0..48ec218 100644 --- a/public/assets/js/admin/manage_restaurant/add_restaurant.js +++ b/public/assets/js/admin/manage_restaurant/add_restaurant.js @@ -64,6 +64,16 @@ $(document).on("click", "#update_restaurant_btn", function (e) { required: true, number: true, min: 1 + }, + closed_start_time: { + required: function (element) { + return $('input[name="closed_date"]').val() !== ''; + } + }, + closed_end_time: { + required: function (element) { + return $('input[name="closed_date"]').val() !== ''; + } } }, messages: { @@ -122,11 +132,17 @@ $(document).on("click", "#update_restaurant_btn", function (e) { required: "Please enter the maximum number of cocktails", number: "Maximum number of cocktails must be a number", min: "Maximum number of cocktails must be greater than 0" + }, + closed_start_time: { + required: "Please select the start time for closing hours" + }, + closed_end_time: { + required: "Please select the end time for closing hours" } }, errorClass: 'error-message', submitHandler: function (form) { - e.preventDefault(); // Prevent default form submission + e.preventDefault(); var form = $('#update_restaurant_form')[0]; var formData = new FormData(form); @@ -163,7 +179,6 @@ $(document).on("click", "#update_restaurant_btn", function (e) { }, error: function (xhr, status, error) { toastr.error('Something Went Wrong'); - // Handle error }, complete: function () { $('#update_restaurant_btn').attr('disabled', false); @@ -173,5 +188,3 @@ $(document).on("click", "#update_restaurant_btn", function (e) { } }); }); - - diff --git a/resources/views/Admin/pages/manage_restaurants/add_restaurant.blade.php b/resources/views/Admin/pages/manage_restaurants/add_restaurant.blade.php index bfb03c6..68e8b7b 100644 --- a/resources/views/Admin/pages/manage_restaurants/add_restaurant.blade.php +++ b/resources/views/Admin/pages/manage_restaurants/add_restaurant.blade.php @@ -24,37 +24,33 @@