|
|
@@ -158,14 +158,20 @@ class CronController extends BackendController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function actionProcessCommandes($key = '') { |
|
|
|
public function actionProcessCommandes($key = '', $force_date = '') { |
|
|
|
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { |
|
|
|
$heure = date('H'); |
|
|
|
|
|
|
|
if(strlen($force_date)) { |
|
|
|
$date = $force_date ; |
|
|
|
} |
|
|
|
else { |
|
|
|
$heure = date('H'); |
|
|
|
|
|
|
|
if ($heure == '00') { |
|
|
|
$date = date('Y-m-d'); |
|
|
|
} else { |
|
|
|
$date = date('Y-m-d', time() + 24 * 60 * 60); |
|
|
|
if ($heure == '00') { |
|
|
|
$date = date('Y-m-d'); |
|
|
|
} else { |
|
|
|
$date = date('Y-m-d', time() + 24 * 60 * 60); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$etablissements = Etablissement::find()->all(); |
|
|
@@ -177,7 +183,7 @@ class CronController extends BackendController { |
|
|
|
'id_etablissement' => $e['id'], |
|
|
|
]); |
|
|
|
|
|
|
|
if ($production && $heure == $e['heure_limite_commande']) { |
|
|
|
if ($production && ($heure == $e['heure_limite_commande'] || strlen($force_date))) { |
|
|
|
|
|
|
|
/* |
|
|
|
* Paiement des commandes (paiement automatique) |
|
|
@@ -209,49 +215,50 @@ class CronController extends BackendController { |
|
|
|
/* |
|
|
|
* Envoi des commandes par email au producteur |
|
|
|
*/ |
|
|
|
|
|
|
|
$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([ |
|
|
|
if(!strlen($force_date)) { |
|
|
|
$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'], |
|
|
|
'status' => User::STATUS_BOULANGER |
|
|
|
'key' => '64ac0bdab7e9f5e48c4d991ec5201d57' |
|
|
|
]); |
|
|
|
$mail->attach(Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $e['id'] . '.pdf')); |
|
|
|
} else { |
|
|
|
$sujet = '[La boîte à pain] Aucune commande'; |
|
|
|
} |
|
|
|
|
|
|
|
$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(); |
|
|
|
} |
|
|
|
|
|
|
|
$mail->setSubject($sujet) |
|
|
|
->send(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |