Bläddra i källkod

Adaptations refactoring/traduction backend/controllers/CronController

dev
Guillaume Bourgeois 6 år sedan
förälder
incheckning
0ccd7f4c36
5 ändrade filer med 89 tillägg och 99 borttagningar
  1. +87
    -97
      backend/controllers/CronController.php
  2. +0
    -0
      common/mail/cronOrdersSummary-html.php
  3. +0
    -0
      common/mail/cronOrdersSummary-text.php
  4. +1
    -1
      common/models/Producer.php
  5. +1
    -1
      common/models/User.php

+ 87
- 97
backend/controllers/CronController.php Visa fil

@@ -46,17 +46,17 @@ use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use kartik\mpdf\Pdf;
use common\models\Etablissement;
use common\models\Commande;
use common\models\CommandeAuto;
use common\models\Production;
use common\models\Producer;
use common\models\Order;
use common\models\Subscription;
use common\models\Distribution;
use common\models\CreditHistory ;

/**
* UserController implements the CRUD actions for User model.
*/
class CronController extends BackendController
{

public function behaviors()
{
return [
@@ -84,11 +84,11 @@ class CronController extends BackendController
*
* @param string $key
*/
public function actionInitBddDemo($key = '')
public function actionInitDatabaseDemo($key = '')
{
if ($key == '45432df6e842ac71aa0b5bb6b9f25d44' && YII_ENV == 'demo') {

$arr_noms = [
$arrayLastnames = [
'Martin', 'Bernard', 'Thomas', 'Petit', 'Robert', 'Richard', 'Durand', 'Dubois',
'Moreau', 'Laurent', 'Simon', 'Michel', 'Lefebvre', 'Leroy', 'Roux', 'David',
'Bertrand', 'Morel', 'Fournier', 'Girard', 'Bonnet', 'Dupont', 'Lambert', 'Fontaine',
@@ -110,7 +110,7 @@ class CronController extends BackendController
'Poulain', 'Girondin', 'Gillet', 'Guichard'
];

$arr_prenoms = [
$arrayNames = [
'Adel', 'Antonin', 'Armand', 'Arnaud', 'Aymeric', 'Baptiste', 'Barnabé', 'Bernard', 'Brice', 'Baudouin',
'Camille', 'Cassandre', 'Célestin', 'Christian', 'Clément', 'Cyril', 'Claude', 'Damien', 'Daniel', 'David',
'Delphin', 'Denis', 'Didier', 'Dimitri', 'Dorothée', 'Désiré', 'Edgard', 'Etienne', 'Eugène', 'Eudes', 'Eric',
@@ -129,31 +129,30 @@ class CronController extends BackendController
'Rose', 'Roseline', 'Renée', 'Sabine', 'Sophie', 'Suzanne', 'Sylvie', 'Thérèse',
];

$arr_noms_checked = [];
$arr_prenoms_checked = [];
$arrayNamesChecked = [];
$arrayLastnameschecked = [];

$users = User::find()
->joinWith('userEtablissement')
->where('user_etablissement.id_etablissement = 1')
->all();
$users = User::searchAll([
'user_etablissement.id_etablissement' => 1
]) ;

foreach ($users as $u) {
if ($u->email != 'boulanger@laboiteapain.net') {
do {
$i_nom = rand(0, count($arr_noms) - 1);
$i_prenom = rand(0, count($arr_prenoms) - 1);
} while (isset($arr_noms_checked[$i_nom]) || isset($arr_prenoms_checked[$i_prenom]));
$indexLastname = rand(0, count($arrayLastnames) - 1);
$indexName = rand(0, count($arrayNames) - 1);
} while (isset($arrayLastnameschecked[$i_nom]) || isset($arrayNamesChecked[$i_prenom]));

$arr_noms_checked[$i_nom] = true;
$arr_prenoms_checked[$i_prenom] = true;
$arrayLastnameschecked[$i_nom] = true;
$arrayNamesChecked[$i_prenom] = true;

$nom = $arr_noms[$i_nom];
$prenom = $arr_prenoms[$i_prenom];
$lastname = $arrayLastnameschecked[$indexLastname];
$name = $arrayNamesChecked[$indexName];

$u->nom = $nom;
$u->prenom = $prenom;
$u->name = $name;
$u->lastname = $lastname;

$email = strtolower($prenom) . '.' . strtolower($nom) . '@yopmail.com';
$email = strtolower($name) . '.' . strtolower($lastname) . '@yopmail.com';
$email = htmlentities($email, ENT_NOQUOTES, 'utf-8');
$email = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $email);
$email = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $email); // pour les ligatures e.g. 'œ'
@@ -175,29 +174,27 @@ class CronController extends BackendController
$u->save();
}

$commandes = Commande::find()
$arrayOrders = Order::find()
->where('username IS NOT NULL')
->all();

foreach ($commandes as $c) {
$nom = $arr_noms[rand(0, count($arr_noms) - 1)];
$prenom = $arr_prenoms[rand(0, count($arr_prenoms) - 1)];
foreach ($arrayOrders as $order) {
$lastname = $arrayLastnames[rand(0, count($arrayLastnames) - 1)];
$name = $arrayNames[rand(0, count($arrayNames) - 1)];

$c->username = $prenom . ' ' . $nom;
$c->username = $name . ' ' . $lastname;

$c->save();
}

$commandes_auto = CommandeAuto::find()
->where('username IS NOT NULL')
->all();

foreach ($commandes_auto as $c) {
$nom = $arr_noms[rand(0, count($arr_noms) - 1)];
$prenom = $arr_prenoms[rand(0, count($arr_prenoms) - 1)];

$c->username = $prenom . ' ' . $nom;
$arraySubscription = Subscription::find()
->where('username IS NOT NULL')
->all();

foreach ($arraySubscription as $subscription) {
$lastname = $arrayLastnames[rand(0, count($arrayLastnames) - 1)];
$name = $arrayNames[rand(0, count($arrayNames) - 1)];
$c->username = $name . ' ' . $lastname;
$c->save();
}
}
@@ -210,55 +207,51 @@ class CronController extends BackendController
* @param string $key
* @param string $force_date
*/
public function actionProcessCommandes($key = '', $force_date = '')
public function actionProcessOrders($key = '', $forceDate = '')
{
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') {
if(strlen($force_date)) {
$date = $force_date ;
if(strlen($forceDate)) {
$date = $forceDate ;
}
else {
$heure = date('H');
$hour = date('H');

if ($heure == '00') {
if ($hour == '00') {
$date = date('Y-m-d');
} else {
$date = date('Y-m-d', time() + 24 * 60 * 60);
}
}

$etablissements = Etablissement::find()->all();
$arrayProducers = Producer::searchAll() ;

foreach ($etablissements as $e) {
$production = Production::findOne([
'date' => $date,
'actif' => 1,
'id_etablissement' => $e['id'],
]);
foreach ($arrayProducers as $producer) {
$distribution = Distribution::findOne([
'date' => $date,
'active' => 1,
'id_producer' => $producer['id'],
]);

if ($production && ($heure == $e['heure_limite_commande'] || strlen($force_date))) {
if ($distribution && ($hour == $producer['order_deadline'] || strlen($forceDate))) {
/*
* Paiement des commandes (paiement automatique)
*/
$commandes = Commande::find()
->with('commandeProduits', 'user')
->joinWith('production')
->where(['production.date' => $date])
->orderBy('date ASC')
->all();

foreach($commandes as $c) {
if($c->paiement_automatique && Etablissement::getConfig('credit_pain', $c->production->id_etablissement)) {
$c->init() ;

if ($c->getMontantRestant() > 0) {
$c->creditHistorique(
CreditHistorique::TYPE_PAIEMENT,
$c->getMontantRestant(),
$c->production->id_etablissement,
$c->id_user,
$arrayOrders = Order::searchAll([
'distribution.date' => $date
]) ;

foreach($arrayOrders as $order) {
if($order->payment_auto && Producer::getConfig('credit', $order->distribution->id_producer)) {
if ($order->getAmount(Order::AMOUNT_REMAINING) > 0) {
$order->creditHistory(
CreditHistory::TYPE_PAYMENT,
$order->getAmount(Order::AMOUNT_REMAINING),
$order->distribution->id_producer,
$order->id_user,
User::ID_USER_SYSTEM
);
}
@@ -268,43 +261,40 @@ class CronController extends BackendController
/*
* Envoi des commandes par email au producteur
*/
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
]);
if(!strlen($forceDate)) {
$arrayOrders = Order::searchAll([
'distribution.date' => $date,
'distribution.id_producer' => $producer['id']
]) ;
$user = User::searchOne([
'id_producer' => $producer['id'],
'status' => User::STATUS_PRODUCER
]);

$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));
[
'html' => 'cronOrdersSummary-html',
'text' => 'cronOrdersSummary-text',
], [
'date' => $date,
'orders' => $arrayOrders
]
)
->setTo($user->email)
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain']);
if (count($arrayOrders)) {
$subject = '[La boîte à pain] Commandes du ' . date('d/m', strtotime($date));

// génération du pdf de commande
Yii::$app->runAction('commande/report-cron', [
Yii::$app->runAction('order/report-cron', [
'date' => $date,
'save' => true,
'id_etablissement' => $e['id'],
'id_producer' => $producer['id'],
'key' => '64ac0bdab7e9f5e48c4d991ec5201d57'
]);
$mail->attach(Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $e['id'] . '.pdf'));
$mail->attach(Yii::getAlias('@app/web/pdf/Orders-' . $date . '-' . $producer['id'] . '.pdf'));
} else {
$sujet = '[La boîte à pain] Aucune commande';
}

common/mail/cronRecapCommandes-html.php → common/mail/cronOrdersSummary-html.php Visa fil


common/mail/cronRecapCommandes-text.php → common/mail/cronOrdersSummary-text.php Visa fil


+ 1
- 1
common/models/Producer.php Visa fil

@@ -149,7 +149,7 @@ class Producer extends \yii\db\ActiveRecord
'with' => [],
'join_with' => [],
'orderby' => 'name ASC',
'attribute_id_producer' => 'producer.id'
'attribute_id_producer' => ''
] ;
}


+ 1
- 1
common/models/User.php Visa fil

@@ -140,7 +140,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
public static function defaultOptionsSearch() {
return [
'with' => [],
'join_with' => [],
'join_with' => ['userEtablissement'],
'orderby' => 'user.name ASC, user.lastname ASC',
'attribute_id_producer' => ''
] ;

Laddar…
Avbryt
Spara