- <?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']) ?>
- <?= Html::a('<span class="glyphicon glyphicon-envelope"></span> Liste des emails', ['mail'], ['class' => 'btn btn-default']) ?>
- </h1>
-
- <?= 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])
- ->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}',
- '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>' ;
- }
- },
- ],
- ],
- ],
- ]); ?>
- </div>
|