[ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER; } ] ], ], ]; } public function actionIndex() { /* * Volume de commande de l'année passée (par mois) */ $date_start = date('Y-m-d',time() - 60 * 60 * 24 * 365) ; $date_end = date('Y-m-d'); $data_pain = [] ; $data_vrac = [] ; // labels $data_labels = [] ; $start = new DateTime($date_start); $interval = new DateInterval('P1M'); $end = new DateTime($date_end); $period = new DatePeriod($start, $interval, $end); foreach($period as $date) { $mois = date('m/Y',$date->getTimestamp()) ; $data_labels[] = $mois ; $data_pain[$mois] = 0 ; $data_vrac[$mois] = 0 ; } // commandes $commandes = Commande::find() ->with('commandeProduits') ->joinWith('production') ->where('production.date > '.$date_start) ->all() ; foreach($commandes as $c) { $c->init(); $mois = date('m/Y',strtotime($c->production->date)) ; if(isset($data_pain[$mois])) { $data_pain[$mois] += $c->montant_pain ; $data_vrac[$mois] += $c->montant_vrac ; } } return $this->render('index', [ 'data_labels' => $data_labels, 'data_pain' => $data_pain, 'data_vrac' => $data_vrac, ]); } } ?>