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.

index.php 8.3KB

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