Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.php 6.8KB

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