Browse Source

Adaptations refactoring/traduction backend/controllers/SiteController

refactoring
Guillaume Bourgeois 6 years ago
parent
commit
3b4410efb3
1 changed files with 28 additions and 31 deletions
  1. +28
    -31
      backend/controllers/SiteController.php

+ 28
- 31
backend/controllers/SiteController.php View File

use common\models\LoginForm; use common\models\LoginForm;
use common\models\User; use common\models\User;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use common\models\Produit;
use common\models\PointVente;
use common\models\Etablissement;
use common\models\Production;
use common\models\Commande;
use common\models\Product;
use common\models\PointSale;
use common\models\Producer;
use common\models\Distribution;
use common\models\Order;


/** /**
* Site controller * Site controller
'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
'matchCallback' => function ($rule, $action) { 'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->status == USER::STATUS_ADMIN
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
return User::hasAccessBackend() ;
} }
], ],
[ [
'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
'matchCallback' => function ($rule, $action) { 'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->status == USER::STATUS_ADMIN;
return User::getStatus() == User::STATUS_ADMIN ;
} }
], ],
], ],
public function actionIndex() public function actionIndex()
{ {
// commandes // commandes
$productions = Production::find()
->with('commande')
->where(['>=', 'production.date', date('Y-m-d')])
$distributions = Distribution::find()
->with('order')
->where(['>=', 'distribution.date', date('Y-m-d')])
->andWhere([ ->andWhere([
'production.id_etablissement' => Yii::$app->user->identity->id_etablissement,
'production.actif' => 1
'distribution.id_producer' => Producer::getId(),
'distribution.active' => 1
]) ])
->orderBy('date ASC') ->orderBy('date ASC')
->limit(5) ->limit(5)
->all(); ->all();


// dernières commandes // dernières commandes
$commandes = Commande::findBy([
$ordersArray = Order::searchAll([],[
'orderby' => 'date DESC', 'orderby' => 'date DESC',
'condition' => 'production.date > \'' . date('Y-m-d 00:00:00') . '\' AND (type = \'' . Commande::TYPE_USER . '\' OR type = \'' . Commande::TYPE_ADMIN . '\' OR (type = \'' . Commande::TYPE_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))'
'conditions' => 'distribution.date > :date AND (origin = \'' . Order::ORIGIN_USER . '\' OR type = \'' . Order::ORIGIN_ADMIN . '\' OR (type = \'' . Order::ORIGIN_AUTO . '\' AND (date_update IS NOT NULL OR date_delete IS NOT NULL)))',
'params' => [':date' => date('Y-m-d 00:00:00')],
]); ]);


foreach ($commandes as $c)
$c->init();

// clients // clients
$nb_clients = User::findBy()->count();
$nbUsers = User::searchCount();


$clients = User::findBy()
$usersArray = User::findBy()
->orderBy('created_at DESC') ->orderBy('created_at DESC')
->limit(5) ->limit(5)
->all(); ->all();


$clients_credit_pain_negatif = User::findBy(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
->andWhere('user_etablissement.credit < 0')
$usersNegativeCredit = User::findBy(['id_producer' => Producer::getId()])
->andWhere('user_producer.credit < 0')
->all(); ->all();


// paramètres // paramètres
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement);
$producer = Producer::get();


return $this->render('index', [ return $this->render('index', [
'productions' => $productions,
'commandes' => $commandes,
'clients' => $clients,
'nb_clients' => $nb_clients,
'clients_credit_pain_negatif' => $clients_credit_pain_negatif,
'etablissement' => $etablissement,
'distributionsArray' => $distributions,
'ordersArray' => $ordersArray,
'usersArray' => $usersArray,
'nbUsers' => $nbUsers,
'usersNegativeCredit' => $usersNegativeCredit,
'producer' => $producer,
]); ]);
} }


* *
* @param integer $id * @param integer $id
*/ */
public function actionChangeEtablissement($id)
public function actionChangeProducer($id)
{ {
Yii::$app->user->identity->id_etablissement = $id;
Yii::$app->user->identity->id_producer = $id;
Yii::$app->user->identity->save(); Yii::$app->user->identity->save();
$this->redirect(['site/index']); $this->redirect(['site/index']);
} }

Loading…
Cancel
Save