Browse Source

Section clients inactifs

Ajout d'une section listant les clients inactifs, cad supprimés par le producteur et qui ont déjà passé au moins une commande.
dev
keun 6 years ago
parent
commit
6b6ea1fc57
3 changed files with 28 additions and 11 deletions
  1. +8
    -4
      backend/controllers/UserController.php
  2. +9
    -4
      backend/views/user/index.php
  3. +11
    -3
      common/models/User.php

+ 8
- 4
backend/controllers/UserController.php View File

* Lists all User models. * Lists all User models.
* @return mixed * @return mixed
*/ */
public function actionIndex($id_point_vente = 0) {
public function actionIndex($id_point_vente = 0, $section_clients_inactifs = false) {
$params = Yii::$app->request->queryParams; $params = Yii::$app->request->queryParams;
if($id_point_vente) if($id_point_vente)
$params['id_point_vente'] = $id_point_vente ; $params['id_point_vente'] = $id_point_vente ;
if($section_clients_inactifs)
$params['inactifs'] = true ;
$query = User::findBy($params); $query = User::findBy($params);
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => $query 'query' => $query
]); ]);


$etablissement = Etablissement::find() $etablissement = Etablissement::find()
->where(['id' => Yii::$app->user->identity->id_etablissement])
->one();
->where(['id' => Yii::$app->user->identity->id_etablissement])
->one();
$points_vente = PointVente::find()->where(['id_etablissement' => $etablissement->id])->all() ; $points_vente = PointVente::find()->where(['id_etablissement' => $etablissement->id])->all() ;


'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'etablissement' => $etablissement, 'etablissement' => $etablissement,
'id_point_vente_active' => $id_point_vente, 'id_point_vente_active' => $id_point_vente,
'points_vente' => $points_vente
'points_vente' => $points_vente,
'section_clients_inactifs' => $section_clients_inactifs,
]); ]);
} }



+ 9
- 4
backend/views/user/index.php View File

</h1> </h1>
<ul id="tabs-points-vente" class="nav nav-tabs" role="tablist"> <ul id="tabs-points-vente" class="nav nav-tabs" role="tablist">
<li class="<?php if(!$id_point_vente_active): ?>active<?php endif; ?>">
<li class="<?php if(!$id_point_vente_active && !$section_clients_inactifs): ?>active<?php endif; ?>">
<a href="<?= Yii::$app->urlManager->createUrl(['user/index']); ?>">Tous</a> <a href="<?= Yii::$app->urlManager->createUrl(['user/index']); ?>">Tous</a>
</li> </li>
<?php foreach($points_vente as $pv): ?> <?php foreach($points_vente as $pv): ?>
<a href="<?= Yii::$app->urlManager->createUrl(['user/index','id_point_vente'=>$pv->id]); ?>"><?= Html::encode($pv->nom) ?></a> <a href="<?= Yii::$app->urlManager->createUrl(['user/index','id_point_vente'=>$pv->id]); ?>"><?= Html::encode($pv->nom) ?></a>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
<li class="<?php if($section_clients_inactifs): ?>active<?php endif; ?>">
<a href="<?= Yii::$app->urlManager->createUrl(['user/index','section_clients_inactifs' => 1]); ?>">Inactifs</a>
</li>
</ul> </ul>


<?= Html::a('<span class="glyphicon glyphicon-envelope"></span> Liste des emails', ['mail', 'id_point_vente' => $id_point_vente_active], ['class' => 'btn btn-default btn-liste-emails']) ?> <?= Html::a('<span class="glyphicon glyphicon-envelope"></span> Liste des emails', ['mail', 'id_point_vente' => $id_point_vente_active], ['class' => 'btn btn-default btn-liste-emails']) ?>
} }
}, },
'delete' => function($url, $model) { 'delete' => function($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', Yii::$app->urlManager->createUrl(['user/delete','id' => $model['user_id']]), [
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
if($model['actif']) {
return Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', Yii::$app->urlManager->createUrl(['user/delete','id' => $model['user_id']]), [
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
}
} }
], ],
], ],

+ 11
- 3
common/models/User.php View File

$query = (new \yii\db\Query()) $query = (new \yii\db\Query())
->select(['user.id AS user_id', 'user.prenom', 'user.nom', 'user.telephone', 'user.email', 'user.created_at', 'user.date_derniere_connexion', 'user_etablissement.*']) ->select(['user.id AS user_id', 'user.prenom', 'user.nom', 'user.telephone', 'user.email', 'user.created_at', 'user.date_derniere_connexion', 'user_etablissement.*'])
->from('user')
->innerJoin('user_etablissement','user.id = user_etablissement.id_user AND user_etablissement.actif = 1 AND user_etablissement.id_etablissement = :id_etablissement', [':id_etablissement' => $params['id_etablissement']])
;
->from('user');
$actif = (isset($params['inactifs']) && $params['inactifs']) ? 0 : 1 ;
$query->innerJoin('user_etablissement','user.id = user_etablissement.id_user AND user_etablissement.actif = '.$actif.' AND user_etablissement.id_etablissement = :id_etablissement', [':id_etablissement' => $params['id_etablissement']]) ;
if(isset($params['id_point_vente']) && $params['id_point_vente']) { if(isset($params['id_point_vente']) && $params['id_point_vente']) {
$point_vente = PointVente::findOne(['id' => $params['id_point_vente']]) ; $point_vente = PointVente::findOne(['id' => $params['id_point_vente']]) ;
} }
} }
if(isset($params['inactifs']) && $params['inactifs']) {
$query->innerJoin(
'commande',
'user.id = commande.id_user'
)
->groupBy('user.id');
}
if (isset($params['nom'])) if (isset($params['nom']))
$query->andFilterWhere(['like', 'nom', $params['nom']]); $query->andFilterWhere(['like', 'nom', $params['nom']]);

Loading…
Cancel
Save