Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

130 Zeilen
3.8KB

  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use yii\data\ActiveDataProvider;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. use yii\filters\AccessControl;
  10. use kartik\mpdf\Pdf;
  11. use common\models\Etablissement;
  12. use common\models\Commande ;
  13. use common\models\Production ;
  14. /**
  15. * UserController implements the CRUD actions for User model.
  16. */
  17. class CronController extends BackendController
  18. {
  19. public function behaviors()
  20. {
  21. return [
  22. 'verbs' => [
  23. 'class' => VerbFilter::className(),
  24. 'actions' => [
  25. 'delete' => ['post'],
  26. ],
  27. ],
  28. 'access' => [
  29. 'class' => AccessControl::className(),
  30. 'rules' => [
  31. [
  32. 'allow' => true,
  33. 'roles' => ['?'],
  34. ]
  35. ],
  36. ],
  37. ];
  38. }
  39. public function actionSendCommandes($key = '')
  40. {
  41. if($key == '64ac0bdab7e9f5e48c4d991ec5201d57')
  42. {
  43. $heure = date('H') ;
  44. if($heure == '00')
  45. {
  46. $date = date('Y-m-d') ;
  47. }
  48. else {
  49. $date = date('Y-m-d', time()+24*60*60) ;
  50. }
  51. $etablissements = Etablissement::find()->all() ;
  52. foreach($etablissements as $e)
  53. {
  54. $production = Production::findOne([
  55. 'date' => $date,
  56. 'actif' => 1,
  57. 'id_etablissement' => $e['id'],
  58. ]) ;
  59. if($production && $heure == $e['heure_limite_commande'])
  60. {
  61. $commandes = Commande::find()
  62. ->with('commandeProduits', 'user')
  63. ->joinWith('production')
  64. ->where(['production.date' => $date])
  65. ->andWhere(['production.id_etablissement' => $e['id']])
  66. ->orderBy('date ASC')
  67. ->all();
  68. $user = User::findOne([
  69. 'id_etablissement' => $e['id'],
  70. 'status' => User::STATUS_BOULANGER
  71. ]) ;
  72. $mail = Yii::$app->mailer->compose(
  73. [
  74. 'html' => 'cronRecapCommandes-html',
  75. 'text' => 'cronRecapCommandes-text',
  76. ],
  77. [
  78. 'date' => $date,
  79. 'commandes' => $commandes
  80. ]
  81. )
  82. ->setTo($user->email)
  83. ->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']) ;
  84. if(count($commandes))
  85. {
  86. $sujet = '[La boîte à pain] Commandes du '.date('d/m',strtotime($date)) ;
  87. // génération du pdf de commande
  88. Yii::$app->runAction('commande/report-cron', [
  89. 'date' => $date,
  90. 'save' => true,
  91. 'id_etablissement' => $e['id'] ,
  92. 'key' => '64ac0bdab7e9f5e48c4d991ec5201d57'
  93. ]);
  94. $mail->attach(Yii::getAlias('@app/web/pdf/Commandes-'.$date.'-'.$e['id'].'.pdf')) ;
  95. }
  96. else {
  97. $sujet = '[La boîte à pain] Aucune commande' ;
  98. }
  99. $mail->setSubject($sujet)
  100. ->send();
  101. }
  102. }
  103. }
  104. }
  105. }