You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 satır
7.8KB

  1. <?php
  2. use yii\helpers\Html;
  3. use yii\grid\GridView;
  4. use common\models\User ;
  5. use common\models\Commande ;
  6. /* @var $this yii\web\View */
  7. /* @var $dataProvider yii\data\ActiveDataProvider */
  8. $this->title = 'Clients';
  9. $this->params['breadcrumbs'][] = $this->title;
  10. ?>
  11. <div class="user-index">
  12. <h1>
  13. <?= Html::encode($this->title) ?>
  14. <?= Html::a('Ajouter', ['create'], ['class' => 'btn btn-primary']) ?>
  15. </h1>
  16. <ul id="tabs-points-vente" class="nav nav-tabs" role="tablist">
  17. <li class="<?php if(!$id_point_vente_active): ?>active<?php endif; ?>">
  18. <a href="<?= Yii::$app->urlManager->createUrl(['user/index']); ?>">Tous</a>
  19. </li>
  20. <?php foreach($points_vente as $pv): ?>
  21. <li class="<?php if($id_point_vente_active == $pv->id): ?>active<?php endif; ?>">
  22. <a href="<?= Yii::$app->urlManager->createUrl(['user/index','id_point_vente'=>$pv->id]); ?>"><?= Html::encode($pv->nom) ?></a>
  23. </li>
  24. <?php endforeach; ?>
  25. </ul>
  26. <?= 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']) ?>
  27. <?= GridView::widget([
  28. 'dataProvider' => $dataProvider,
  29. 'filterModel' => true,
  30. 'columns' => [
  31. [
  32. 'attribute' => 'nom',
  33. 'filter' => Html::input(
  34. 'string',
  35. 'nom',
  36. isset(Yii::$app->request->queryParams['nom']) ? Html::encode(Yii::$app->request->queryParams['nom']) : '',
  37. [ 'class' => 'form-control']
  38. )
  39. ],
  40. [
  41. 'attribute' => 'prenom',
  42. 'filter' => Html::input(
  43. 'string',
  44. 'prenom',
  45. isset(Yii::$app->request->queryParams['prenom']) ? Html::encode(Yii::$app->request->queryParams['prenom']) : '',
  46. ['class' => 'form-control']
  47. )
  48. ],
  49. [
  50. 'attribute' => 'telephone',
  51. 'filter' => Html::input(
  52. 'string',
  53. 'telephone',
  54. isset(Yii::$app->request->queryParams['telephone']) ? Html::encode(Yii::$app->request->queryParams['telephone']) : '',
  55. ['class' => 'form-control']
  56. )
  57. ],
  58. [
  59. 'attribute' => 'email',
  60. 'filter' => Html::input(
  61. 'string',
  62. 'email',
  63. isset(Yii::$app->request->queryParams['email']) ? Html::encode(Yii::$app->request->queryParams['email']) : '',
  64. ['class' => 'form-control']
  65. )
  66. ],
  67. [
  68. 'attribute' => 'created_at',
  69. 'label' => 'Date d\'inscription',
  70. 'value' => function($model) {
  71. if(isset($model['created_at']))
  72. return date('m/d/Y à H:i', $model['created_at']);
  73. }
  74. ],
  75. [
  76. 'attribute' => 'date_derniere_connexion',
  77. 'label' => 'Dernière connexion',
  78. 'value' => function($model) {
  79. if(isset($model['date_derniere_connexion']))
  80. return date('d/m/Y à H:i', strtotime($model['date_derniere_connexion']));
  81. else
  82. return '' ;
  83. }
  84. ],
  85. [
  86. 'class' => 'yii\grid\ActionColumn',
  87. 'template' => '{commandes}',
  88. 'headerOptions' => ['class' => 'actions'],
  89. 'buttons' => [
  90. 'commandes' => function ($url, $model) {
  91. $url = Yii::$app->urlManager->createUrl(['user/commandes','id' => $model['user_id']]) ;
  92. $count_commandes = Commande::find()
  93. ->joinWith('production')
  94. ->where([
  95. 'id_user' => $model['user_id'],
  96. 'production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
  97. ->count() ;
  98. $html = '' ;
  99. if($count_commandes)
  100. {
  101. $s = '' ;
  102. if($count_commandes > 1) $s = 's' ;
  103. $html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$count_commandes.' commande'.$s, $url, [
  104. 'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default '
  105. ]); ;
  106. }
  107. else {
  108. $html .= 'Aucune commande' ;
  109. }
  110. return $html ;
  111. },
  112. ],
  113. ],
  114. [
  115. 'attribute' => 'credit',
  116. 'format' => 'raw',
  117. 'value' => function($model) use($etablissement) {
  118. if(!isset($model['credit'])) $model['credit'] = 0 ;
  119. $user = User::findOne($model['user_id']) ;
  120. $html = '<div class="input-group">
  121. <input type="text" class="form-control input-credit" readonly="readonly" value="'.number_format($user->getCredit($etablissement->id),2).' €" placeholder="">
  122. <span class="input-group-btn">
  123. '.Html::a(
  124. '<span class="glyphicon glyphicon-euro"></span> Crédit',
  125. Yii::$app->urlManager->createUrl(['user/credit','id' => $model['user_id']]),
  126. [
  127. 'title' => 'Crédit',
  128. 'class' => 'btn btn-default'
  129. ]
  130. ).'
  131. </span>
  132. </div>' ;
  133. return $html ;
  134. }
  135. ],
  136. [
  137. 'class' => 'yii\grid\ActionColumn',
  138. 'template' => '{update} {delete}',
  139. 'headerOptions' => ['class' => 'actions'],
  140. 'buttons' => [
  141. 'update' => function ($url, $model) {
  142. $url = Yii::$app->urlManager->createUrl(['user/update','id' => $model['user_id']]) ;
  143. $user = User::find()->with('userEtablissement')->where(['id' => $model['user_id']])->one() ;
  144. if(count($user->userEtablissement) <= 1)
  145. {
  146. return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [
  147. 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
  148. ]);
  149. }
  150. else {
  151. 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>' ;
  152. }
  153. },
  154. 'delete' => function($url, $model) {
  155. return Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', Yii::$app->urlManager->createUrl(['user/delete','id' => $model['user_id']]), [
  156. 'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
  157. ]);
  158. }
  159. ],
  160. ],
  161. ],
  162. ]); ?>
  163. </div>