diff --git a/app/Console/Commands/ReinstateRestaurant.php b/app/Console/Commands/ReinstateRestaurant.php index 7b0c926..58a9599 100644 --- a/app/Console/Commands/ReinstateRestaurant.php +++ b/app/Console/Commands/ReinstateRestaurant.php @@ -30,59 +30,56 @@ class ReinstateRestaurant extends Command * Execute the console command. */ - public function handle() - { - try { - $recordsToUpdate = RedeemRestaurant::where('is_redeem', 1)->get(); + public function handle() + { + try { + $recordsToUpdate = RedeemRestaurant::where('is_redeem', 1)->get(); - foreach ($recordsToUpdate as $record) { - //find restaurant - $managerestaurant = ManageRestaurant::where('id', $record->manage_restaurants_xid)->first(); + foreach ($recordsToUpdate as $record) { + //find restaurant + $managerestaurant = ManageRestaurant::where('id', $record->manage_restaurants_xid)->first(); - $customerData = IamPrincipal::where('id', $record->iam_principal_xid)->where('notification_status', 1)->where('principal_type_xid',3)->first(); //fetch customer + $customerData = IamPrincipal::where('id', $record->iam_principal_xid)->where('notification_status', 1)->where('principal_type_xid', 3)->first(); //fetch customer - if ($managerestaurant && $managerestaurant->is_active == 1) { - $redeemDate = Carbon::parse($record->redeem_date); + if ($managerestaurant && $managerestaurant->is_active == 1) { + $redeemDate = Carbon::parse($record->redeem_date); - $fourHourPlusTimeOfRecord = $redeemDate->copy()->addHours(4); + $fourHourPlusTimeOfRecord = $redeemDate->copy()->addHours($managerestaurant->time_hours); - $currentTime = Carbon::now(); + $currentTime = Carbon::now(); - if ($currentTime > $fourHourPlusTimeOfRecord) { - $record->update([ - 'is_redeem' => 0, - 'redeem_date' => null, - 'count' => $record->count + 1, - 'is_redeemption_undone' => 0, - 'redeemption_undone_date' => null, - ]); - $restImage = ListingImageUrl('restaurant_images', $managerestaurant->image); - $title = "Your " . $managerestaurant->name . " Reinstate successfully"; - $message = "Your " . $managerestaurant->name . " Reinstate successfully"; - $content_type = 'Restaurant Reinstate'; - $imageUrl = $restImage; + if ($currentTime > $fourHourPlusTimeOfRecord) { + $record->update([ + 'is_redeem' => 0, + 'redeem_date' => null, + 'count' => $record->count + 1, + 'is_redeemption_undone' => 0, + 'redeemption_undone_date' => null, + ]); + $restImage = ListingImageUrl('restaurant_images', $managerestaurant->image); + $title = "Your " . $managerestaurant->name . " Reinstate successfully"; + $message = "Your " . $managerestaurant->name . " Reinstate successfully"; + $content_type = 'Restaurant Reinstate'; + $imageUrl = $restImage; - onesignalhelper::sendNotificationApi( - $customerData->one_signal_player_id, - $title, - $message, - $content_type, - $imageUrl, - $id = null - ); - Log::info('Reinstate of record done at ' . now()); - - onesignalhelper::StoreNotificationDetails($customerData->id, $content_type, $title, $restImage); - } - } - } - - Log::info('Reinstate task ran successfully at ' . now()); - } catch (\Exception $e) { - Log::error('Reinstate function failed: ' . $e->getMessage()); - } - - } + onesignalhelper::sendNotificationApi( + $customerData->one_signal_player_id, + $title, + $message, + $content_type, + $imageUrl, + $id = null + ); + Log::info('Reinstate of record done at ' . now()); + onesignalhelper::StoreNotificationDetails($customerData->id, $content_type, $title, $restImage); + } + } + } + Log::info('Reinstate task ran successfully at ' . now()); + } catch (\Exception $e) { + Log::error('Reinstate function failed: ' . $e->getMessage()); + } + } } diff --git a/app/Http/Controllers/Admin/ManageRestrauntController.php b/app/Http/Controllers/Admin/ManageRestrauntController.php index ef3338a..9782f7e 100644 --- a/app/Http/Controllers/Admin/ManageRestrauntController.php +++ b/app/Http/Controllers/Admin/ManageRestrauntController.php @@ -84,6 +84,10 @@ class ManageRestrauntController extends Controller $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->time_hours = $request->input('timeHours'); + $restaurant->max_numb_day = $request->input('maxNumbDay'); + $restaurant->max_numb_week = $request->input('maxNumbWeek'); + $restaurant->max_numb_month = $request->input('maxNumbMonth'); $restaurant->save(); foreach ($request->input('operating_hours') as $day => $hours) { @@ -189,6 +193,10 @@ class ManageRestrauntController extends Controller $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->time_hours = $request->input('timeHours'); + $restaurant->max_numb_day = $request->input('maxNumbDay'); + $restaurant->max_numb_week = $request->input('maxNumbWeek'); + $restaurant->max_numb_month = $request->input('maxNumbMonth'); $restaurant->save(); foreach ($request->input('operating_hours') as $day => $hours) { diff --git a/app/Models/ManageRestaurant.php b/app/Models/ManageRestaurant.php index d796b29..66bc0f6 100644 --- a/app/Models/ManageRestaurant.php +++ b/app/Models/ManageRestaurant.php @@ -22,7 +22,7 @@ class ManageRestaurant extends Model protected $fillable = [ 'short_id', 'name', 'description', 'restaurant_id', 'address', 'image', 'bio', 'try_on_1', 'try_on_2', 'try_on_3', 'try_on_4', 'exclusion', 'latitude', 'longitude', - 'is_active', 'created_by', 'modified_by', 'phone_number' + 'is_active', 'created_by', 'modified_by', 'phone_number','time_hours','max_numb_day','max_numb_week','max_numb_month' ]; protected static function boot() diff --git a/database/migrations/2024_05_28_095429_create_manage_restaurants_table.php b/database/migrations/2024_05_28_095429_create_manage_restaurants_table.php index 7a6a0b8..58948c4 100644 --- a/database/migrations/2024_05_28_095429_create_manage_restaurants_table.php +++ b/database/migrations/2024_05_28_095429_create_manage_restaurants_table.php @@ -15,21 +15,25 @@ return new class extends Migration Schema::create('manage_restaurants', function (Blueprint $table) { $table->id(); $table->string('short_id')->unique(); - $table->string('name',255)->nullable(); + $table->string('name', 255)->nullable(); $table->longText('description')->nullable(); $table->string('phone_number', 15)->nullable(); $table->bigInteger('state_xid')->nullable(); $table->string('restaurant_id')->nullable(); - $table->string('address',255)->nullable(); + $table->string('address', 255)->nullable(); $table->string('image')->nullable(); $table->string('bio')->nullable(); $table->text('try_on_1')->nullable(); $table->text('try_on_2')->nullable(); $table->text('try_on_3')->nullable(); $table->text('try_on_4')->nullable(); - $table->string('exclusion',255)->nullable(); + $table->string('exclusion', 255)->nullable(); $table->string('latitude'); $table->string('longtitude'); + $table->integer('time_hours')->default(1)->comment('Time in hours between redeeming two cocktails'); + $table->integer('max_numb_day')->default(1)->comment('Maximum number of cocktails per day'); + $table->integer('max_numb_week')->default(1)->comment('Maximum number of cocktails per week'); + $table->integer('max_numb_month')->default(1)->comment('Maximum number of cocktails per month'); $table->boolean('is_active')->default(1)->comment('1=Active, 0=Expired'); $table->integer('created_by')->nullable(); $table->integer('modified_by')->nullable(); diff --git a/public/assets/js/admin/manage_restaurant/add_restaurant.js b/public/assets/js/admin/manage_restaurant/add_restaurant.js index ab5c7bd..c834ea4 100644 --- a/public/assets/js/admin/manage_restaurant/add_restaurant.js +++ b/public/assets/js/admin/manage_restaurant/add_restaurant.js @@ -50,6 +50,26 @@ $(document).on("click", "#update_restaurant_btn", function (e) { try_on_4: { required: true, }, + timeHours: { + required: true, + number: true, + min: 1 + }, + maxNumbDay: { + required: true, + number: true, + min: 1 + }, + maxNumbWeek: { + required: true, + number: true, + min: 1 + }, + maxNumbMonth: { + required: true, + number: true, + min: 1 + } }, messages: { name: { @@ -93,6 +113,26 @@ $(document).on("click", "#update_restaurant_btn", function (e) { try_on_4: { required: "Please enter this field", }, + timeHours: { + required: "Please enter the time in hours between redeeming two cocktails", + number: "Time must be a number", + min: "Time must be greater than 0" + }, + maxNumbDay: { + required: "Please enter the maximum number of cocktails per day", + number: "Value must be a number", + min: "Value must be greater than 0" + }, + maxNumbWeek: { + required: "Please enter the maximum number of cocktails per week", + number: "Value must be a number", + min: "Value must be greater than 0" + }, + maxNumbMonth: { + required: "Please enter the maximum number of cocktails per month", + number: "Value must be a number", + min: "Value must be greater than 0" + } }, errorClass: 'error-message', submitHandler: function (form) { @@ -144,3 +184,4 @@ $(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 96999cd..ae03f9c 100644 --- a/resources/views/Admin/pages/manage_restaurants/add_restaurant.blade.php +++ b/resources/views/Admin/pages/manage_restaurants/add_restaurant.blade.php @@ -132,6 +132,39 @@ @endforeach +