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..9bedb97 100644 --- a/app/Models/Calendrier.php +++ b/app/Models/Calendrier.php @@ -39,4 +39,16 @@ 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()->betweenIncluded($this->calendrier_startdate, $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(); + }); + } +} diff --git a/resources/js/app.js b/resources/js/app.js index 1549c0b..36b6baa 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.message + '
' + '' + - '' + opts.noButton + '' + + '' + opts.noButton + '' + '' + '
' + '',