From f8a389637bdb9acb85a96d33201c70702fc998db Mon Sep 17 00:00:00 2001 From: Thibault Richy Date: Thu, 21 Mar 2019 09:43:02 +0100 Subject: [PATCH] Fix datestart to check for each campaign --- app/Console/Kernel.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index c7e2b62..0fa9eef 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -109,14 +109,16 @@ class Kernel extends ConsoleKernel // ---- Sauvegarde des stats tous les jours a 23:45 $schedule->call(function () { - $last_stat = Statistique::orderBy('created_at', 'DESC')->first(); - if(isset($last_stat->created_at)){ - $dateStart = $last_stat->created_at; - } else { - $dateStart = Carbon::now()->setTime(0,0,0)->subMonth()->format('Y-m-d H:i:s'); - } $campagnes = Campagne::all(); foreach ($campagnes as $campagne) { + + $last_stat = Statistique::where(['stat_campId' => $campagne->camp_id])->orderBy('created_at', 'DESC')->first(); + if(isset($last_stat->created_at)){ + $dateStart = $last_stat->created_at; + } else { + $dateStart = Carbon::now()->setTime(0,0,0)->subMonth()->format('Y-m-d H:i:s'); + } + $coupons = $campagne->coupons()->get(); foreach ($coupons as $coupon) { if ($campagne->camp_type == 0 || $campagne->camp_type == 2) { //Calcul des BR consommé pour les murs