|
|
@@ -44,11 +44,11 @@ use yii\web\Controller; |
|
|
|
use common\models\LoginForm; |
|
|
|
use common\models\User; |
|
|
|
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 |
|
|
@@ -74,8 +74,7 @@ class SiteController extends BackendController |
|
|
|
'allow' => true, |
|
|
|
'roles' => ['@'], |
|
|
|
'matchCallback' => function ($rule, $action) { |
|
|
|
return Yii::$app->user->identity->status == USER::STATUS_ADMIN |
|
|
|
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; |
|
|
|
return User::hasAccessBackend() ; |
|
|
|
} |
|
|
|
], |
|
|
|
[ |
|
|
@@ -83,7 +82,7 @@ class SiteController extends BackendController |
|
|
|
'allow' => true, |
|
|
|
'roles' => ['@'], |
|
|
|
'matchCallback' => function ($rule, $action) { |
|
|
|
return Yii::$app->user->identity->status == USER::STATUS_ADMIN; |
|
|
|
return User::getStatus() == User::STATUS_ADMIN ; |
|
|
|
} |
|
|
|
], |
|
|
|
], |
|
|
@@ -119,48 +118,46 @@ class SiteController extends BackendController |
|
|
|
public function actionIndex() |
|
|
|
{ |
|
|
|
// 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([ |
|
|
|
'production.id_etablissement' => Yii::$app->user->identity->id_etablissement, |
|
|
|
'production.actif' => 1 |
|
|
|
'distribution.id_producer' => Producer::getId(), |
|
|
|
'distribution.active' => 1 |
|
|
|
]) |
|
|
|
->orderBy('date ASC') |
|
|
|
->limit(5) |
|
|
|
->all(); |
|
|
|
|
|
|
|
// dernières commandes |
|
|
|
$commandes = Commande::findBy([ |
|
|
|
$ordersArray = Order::searchAll([],[ |
|
|
|
'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 |
|
|
|
$nb_clients = User::findBy()->count(); |
|
|
|
$nbUsers = User::searchCount(); |
|
|
|
|
|
|
|
$clients = User::findBy() |
|
|
|
$usersArray = User::findBy() |
|
|
|
->orderBy('created_at DESC') |
|
|
|
->limit(5) |
|
|
|
->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(); |
|
|
|
|
|
|
|
// paramètres |
|
|
|
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement); |
|
|
|
$producer = Producer::get(); |
|
|
|
|
|
|
|
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, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
@@ -203,9 +200,9 @@ class SiteController extends BackendController |
|
|
|
* |
|
|
|
* @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(); |
|
|
|
$this->redirect(['site/index']); |
|
|
|
} |