[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['post'], ], ], 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['?'], ] ], ], ]; } public function actionSendCommandes($key = '') { if($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { $heure = date('H') ; if($heure == '00') { $date = date('Y-m-d') ; } else { $date = date('Y-m-d', time()+24*60*60) ; } $etablissements = Etablissement::find()->all() ; foreach($etablissements as $e) { $production = Production::findOne([ 'date' => $date, 'actif' => 1, 'id_etablissement' => $e['id'], ]) ; if($production && $heure == $e['heure_limite_commande']) { $commandes = Commande::find() ->with('commandeProduits', 'user') ->joinWith('production') ->where(['production.date' => $date]) ->andWhere(['production.id_etablissement' => $e['id']]) ->orderBy('date ASC') ->all(); $user = User::findOne([ 'id_etablissement' => $e['id'], 'status' => User::STATUS_BOULANGER ]) ; $mail = Yii::$app->mailer->compose( [ 'html' => 'cronRecapCommandes-html', 'text' => 'cronRecapCommandes-text', ], [ 'date' => $date, 'commandes' => $commandes ] ) ->setTo($user->email) ->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']) ; if(count($commandes)) { $sujet = '[La boîte à pain] Commandes du '.date('d/m',strtotime($date)) ; // génération du pdf de commande Yii::$app->runAction('commande/report-cron', [ 'date' => $date, 'save' => true, 'id_etablissement' => $e['id'] , 'key' => '64ac0bdab7e9f5e48c4d991ec5201d57' ]); $mail->attach(Yii::getAlias('@app/web/pdf/Commandes-'.$date.'-'.$e['id'].'.pdf')) ; } else { $sujet = '[La boîte à pain] Aucune commande' ; } $mail->setSubject($sujet) ->send(); } } } } }