|
- 0<?php
-
- use yii\helpers\Html;
- use yii\grid\GridView;
- use common\models\User ;
- use common\models\Commande ;
-
- /* @var $this yii\web\View */
- /* @var $dataProvider yii\data\ActiveDataProvider */
-
- $this->title = 'Clients';
- $this->params['breadcrumbs'][] = $this->title;
- ?>
-
-
- <div class="user-index">
- <h1>
- <?= Html::encode($this->title) ?>
- <?= Html::a('Ajouter', ['create'], ['class' => 'btn btn-primary']) ?>
- </h1>
-
- <ul id="tabs-points-vente" class="nav nav-tabs" role="tablist">
- <li class="<?php if(!$id_point_vente_active && !$section_clients_inactifs): ?>active<?php endif; ?>">
- <a href="<?= Yii::$app->urlManager->createUrl(['user/index']); ?>">Tous</a>
- </li>
- <?php foreach($points_vente as $pv): ?>
- <li class="<?php if($id_point_vente_active == $pv->id): ?>active<?php endif; ?>">
- <a href="<?= Yii::$app->urlManager->createUrl(['user/index','id_point_vente'=>$pv->id]); ?>"><?= Html::encode($pv->nom) ?></a>
- </li>
- <?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>
-
- <?= 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']) ?>
-
- <?= GridView::widget([
- 'dataProvider' => $dataProvider,
- 'filterModel' => true,
- 'columns' => [
- [
- 'attribute' => 'nom',
- 'filter' => Html::input(
- 'string',
- 'nom',
- isset(Yii::$app->request->queryParams['nom']) ? Html::encode(Yii::$app->request->queryParams['nom']) : '',
- [ 'class' => 'form-control']
- )
- ],
- [
- 'attribute' => 'prenom',
- 'filter' => Html::input(
- 'string',
- 'prenom',
- isset(Yii::$app->request->queryParams['prenom']) ? Html::encode(Yii::$app->request->queryParams['prenom']) : '',
- ['class' => 'form-control']
- )
- ],
- [
- 'attribute' => 'telephone',
- 'filter' => Html::input(
- 'string',
- 'telephone',
- isset(Yii::$app->request->queryParams['telephone']) ? Html::encode(Yii::$app->request->queryParams['telephone']) : '',
- ['class' => 'form-control']
- )
- ],
- [
- 'attribute' => 'email',
- 'filter' => Html::input(
- 'string',
- 'email',
- isset(Yii::$app->request->queryParams['email']) ? Html::encode(Yii::$app->request->queryParams['email']) : '',
- ['class' => 'form-control']
- )
- ],
- [
- 'attribute' => 'created_at',
- 'label' => 'Date d\'inscription',
- 'value' => function($model) {
- if(isset($model['created_at']))
- return date('m/d/Y à H:i', $model['created_at']);
- }
- ],
- [
- 'attribute' => 'date_derniere_connexion',
- 'label' => 'Dernière connexion',
- 'value' => function($model) {
- if(isset($model['date_derniere_connexion']))
- return date('d/m/Y à H:i', strtotime($model['date_derniere_connexion']));
- else
- return '' ;
- }
- ],
- [
- 'class' => 'yii\grid\ActionColumn',
- 'template' => '{commandes}',
- 'headerOptions' => ['class' => 'actions'],
- 'buttons' => [
- 'commandes' => function ($url, $model) {
- $url = Yii::$app->urlManager->createUrl(['user/commandes','id' => $model['user_id']]) ;
- $count_commandes = Commande::find()
- ->joinWith('production')
- ->where([
- 'id_user' => $model['user_id'],
- 'production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
- ->andWhere('date_delete IS NULL')
- ->count() ;
- $html = '' ;
- if($count_commandes)
- {
- $s = '' ;
- if($count_commandes > 1) $s = 's' ;
- $html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$count_commandes.' commande'.$s, $url, [
- 'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default '
- ]); ;
- }
- else {
- $html .= 'Aucune commande' ;
- }
-
- return $html ;
- },
- ],
- ],
- [
- 'attribute' => 'credit',
- 'format' => 'raw',
- 'value' => function($model) use($etablissement) {
- if(!isset($model['credit'])) $model['credit'] = 0 ;
- $user = User::findOne($model['user_id']) ;
- $html = '<div class="input-group">
- <input type="text" class="form-control input-credit" readonly="readonly" value="'.number_format($user->getCredit($etablissement->id),2).' €" placeholder="">
- <span class="input-group-btn">
- '.Html::a(
- '<span class="glyphicon glyphicon-euro"></span> Crédit',
- Yii::$app->urlManager->createUrl(['user/credit','id' => $model['user_id']]),
- [
- 'title' => 'Crédit',
- 'class' => 'btn btn-default'
- ]
- ).'
- </span>
- </div>' ;
- return $html ;
- }
- ],
- [
- 'class' => 'yii\grid\ActionColumn',
- 'template' => '{update} {delete}',
- 'headerOptions' => ['class' => 'actions'],
- 'buttons' => [
- 'update' => function ($url, $model) {
- $url = Yii::$app->urlManager->createUrl(['user/update','id' => $model['user_id']]) ;
- $user = User::find()->with('userEtablissement')->where(['id' => $model['user_id']])->one() ;
- if(count($user->userEtablissement) <= 1)
- {
- return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [
- 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
- ]);
- }
- else {
- return '<span data-toggle="tooltip" data-placement="top" title="Vous ne pouvez pas modifier les clients qui sont liés à plusieurs producteurs."><span class="glyphicon glyphicon-remove-sign"></span> Non modifiable</span>' ;
- }
- },
- 'delete' => function($url, $model) {
- if($model['actif']) {
- return Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', Yii::$app->urlManager->createUrl(array_merge(['user/delete','id' => $model['user_id']], Yii::$app->getRequest()->getQueryParams())), [
- 'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
- ]);
- }
- }
- ],
- ],
- ],
- ]); ?>
- </div>
|