From 5e41e3668eea1b9ec349678477ea986a4009b453 Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Thu, 11 Jun 2026 12:18:01 +0200 Subject: [PATCH 1/4] feat: :sparkles: Added hours to calendar date input --- resources/js/app.js | 12 ++++++------ resources/views/coupon/edit.blade.php | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/resources/js/app.js b/resources/js/app.js index 1549c0b..46ff3a0 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -33,7 +33,7 @@ const changeIcon = $('.marque') const dropDownMarque = $('.marque-select') // FancyBox Communes -// Confirmation +// Confirmation $.fancyConfirm = function( opts ) { opts = $.extend( true, { title : 'Are you sure?', @@ -42,7 +42,7 @@ $.fancyConfirm = function( opts ) { noButton : 'Cancel', callback : $.noop }, opts || {} ); - + $.fancybox.open({ type : 'html', src : @@ -68,7 +68,7 @@ $.fancyConfirm = function( opts ) { afterClose : function( instance, current, e ) { var button = e ? e.target || e.currentTarget : null; var value = button ? $(button).data('value') : 0; - + opts.callback( value ); } } @@ -84,7 +84,7 @@ $.fancyConfirm = function( opts ) { noButton : 'Cancel', callback : $.noop }, opts || {} ); - + $.fancybox.open({ type : 'html', src : @@ -92,7 +92,7 @@ $.fancyConfirm = function( opts ) { '

' + opts.title + '

' + '

' + opts.message + '

' + '

' + - '' + opts.noButton + '' + + '' + opts.noButton + '' + '' + '

' + '', @@ -226,7 +226,7 @@ $(document).ready(function(){ $('.addcalendar').on('click', function(event){ event.preventDefault(); - $('.calendar').append('
'); + $('.calendar').append('
'); }); $('.calendar').on('click', '.removecalendar', function(event){ diff --git a/resources/views/coupon/edit.blade.php b/resources/views/coupon/edit.blade.php index 47991dc..923f20f 100644 --- a/resources/views/coupon/edit.blade.php +++ b/resources/views/coupon/edit.blade.php @@ -101,8 +101,8 @@

{{ __('Calendrier de diffusion') }}

@foreach ($coupon->calendriers()->get() as $calendrier)
- - + +
@endforeach From 7d4381de19270dcf76dc721f98d7e3430ee2165e Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Thu, 11 Jun 2026 12:56:10 +0200 Subject: [PATCH 2/4] revert: 5e41e3668eea1b9ec349678477ea986a4009b453 --- resources/js/app.js | 2 +- resources/views/coupon/edit.blade.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/js/app.js b/resources/js/app.js index 46ff3a0..36b6baa 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -226,7 +226,7 @@ $(document).ready(function(){ $('.addcalendar').on('click', function(event){ event.preventDefault(); - $('.calendar').append('
'); + $('.calendar').append('
'); }); $('.calendar').on('click', '.removecalendar', function(event){ diff --git a/resources/views/coupon/edit.blade.php b/resources/views/coupon/edit.blade.php index 923f20f..47991dc 100644 --- a/resources/views/coupon/edit.blade.php +++ b/resources/views/coupon/edit.blade.php @@ -101,8 +101,8 @@

{{ __('Calendrier de diffusion') }}

@foreach ($coupon->calendriers()->get() as $calendrier)
- - + +
@endforeach From f15a2720930b4a66879dddb0c54d0948cc05cedc Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Thu, 11 Jun 2026 16:51:49 +0200 Subject: [PATCH 3/4] fix: use carbon and fix check for calendars dates --- .../Controllers/Api/v1/CustomerController.php | 4 +-- app/Http/Controllers/Api/v1/MurController.php | 2 +- app/Models/Calendrier.php | 13 +++++++ app/Traits/CouponTrait.php | 10 +++--- ...26_06_11_141125_alter_calendrier_table.php | 35 +++++++++++++++++++ 5 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 database/migrations/2026_06_11_141125_alter_calendrier_table.php diff --git a/app/Http/Controllers/Api/v1/CustomerController.php b/app/Http/Controllers/Api/v1/CustomerController.php index 458a417..e05f4bf 100644 --- a/app/Http/Controllers/Api/v1/CustomerController.php +++ b/app/Http/Controllers/Api/v1/CustomerController.php @@ -143,7 +143,7 @@ class CustomerController extends Controller if (!$calendars->isEmpty()) { $pub = false; foreach ($calendars as $calendar) { - if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) { + if ($calendar->isPublished()) { $pub = true; } } @@ -217,7 +217,7 @@ class CustomerController extends Controller if (!$calendars->isEmpty()) { $published = false; foreach ($calendars as $calendar) { - if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) { + if ($calendar->isPublished()) { $published = true; } } diff --git a/app/Http/Controllers/Api/v1/MurController.php b/app/Http/Controllers/Api/v1/MurController.php index b8ee182..1e115ab 100644 --- a/app/Http/Controllers/Api/v1/MurController.php +++ b/app/Http/Controllers/Api/v1/MurController.php @@ -39,7 +39,7 @@ class MurController extends Controller if (!$calendars->isEmpty()) { $pub = false; foreach ($calendars as $calendar) { - if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) { + if ($calendar->isPublished()) { $pub = true; } } diff --git a/app/Models/Calendrier.php b/app/Models/Calendrier.php index 12da07e..6cb1e84 100644 --- a/app/Models/Calendrier.php +++ b/app/Models/Calendrier.php @@ -39,4 +39,17 @@ class Calendrier extends Model { return $this->belongsTo('App\Models\Coupon', 'calendrier_couponId'); } + + // * METHODS + + /** + * Check if the current date is between the calendar publication dates. + * + * @return boolean + */ + public function isPublished(): bool + { + return now()->greaterThanOrEqualTo($this->calendrier_startdate) && + now()->lessThanOrEqualTo($this->calendrier_enddate->endOfDay()); + } } diff --git a/app/Traits/CouponTrait.php b/app/Traits/CouponTrait.php index 3848025..dee077c 100644 --- a/app/Traits/CouponTrait.php +++ b/app/Traits/CouponTrait.php @@ -45,7 +45,7 @@ trait CouponTrait if (isset($calendars) && !$calendars->isEmpty()) { $pub = false; foreach ($calendars as $calendar) { - if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) { + if ($calendar->isPublished()) { $pub = true; } } @@ -86,7 +86,7 @@ trait CouponTrait if (isset($calendars) && !$calendars->isEmpty()) { $pub = false; foreach ($calendars as $calendar) { - if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) { + if ($calendar->isPublished()) { $pub = true; } } @@ -128,7 +128,7 @@ trait CouponTrait if (isset($calendars) && !$calendars->isEmpty()) { $pub = false; foreach ($calendars as $calendar) { - if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) { + if ($calendar->isPublished()) { $pub = true; } } @@ -179,7 +179,7 @@ trait CouponTrait if (isset($calendars) && !$calendars->isEmpty()) { $pub = false; foreach ($calendars as $calendar) { - if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) { + if ($calendar->isPublished()) { $pub = true; } } @@ -211,7 +211,7 @@ trait CouponTrait if (isset($calendars) && !$calendars->isEmpty()) { $pub = false; foreach ($calendars as $calendar) { - if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) { + if ($calendar->isPublished()) { $pub = true; } } diff --git a/database/migrations/2026_06_11_141125_alter_calendrier_table.php b/database/migrations/2026_06_11_141125_alter_calendrier_table.php new file mode 100644 index 0000000..17aaada --- /dev/null +++ b/database/migrations/2026_06_11_141125_alter_calendrier_table.php @@ -0,0 +1,35 @@ +date('calendrier_startdate')->default(DB::raw("1970-01-01"))->change(); + $table->date('calendrier_enddate')->default(DB::raw("1970-01-01"))->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('calendrier', function (Blueprint $table) { + $table->timestamp('calendrier_startdate')->default(DB::raw("1970-01-01 00:00:01"))->change(); + $table->timestamp('calendrier_enddate')->default(DB::raw("1970-01-01 00:00:01"))->change(); + }); + } +} From f2423adbc0ac38599b5039e7f50ce8160b3ec30d Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Thu, 11 Jun 2026 17:13:15 +0200 Subject: [PATCH 4/4] refactor: :recycle: use betweenIncluded from Carbon instead of double condition --- app/Models/Calendrier.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Models/Calendrier.php b/app/Models/Calendrier.php index 6cb1e84..9bedb97 100644 --- a/app/Models/Calendrier.php +++ b/app/Models/Calendrier.php @@ -49,7 +49,6 @@ class Calendrier extends Model */ public function isPublished(): bool { - return now()->greaterThanOrEqualTo($this->calendrier_startdate) && - now()->lessThanOrEqualTo($this->calendrier_enddate->endOfDay()); + return now()->betweenIncluded($this->calendrier_startdate, $this->calendrier_enddate->endOfDay()); } }