*/ | */ | ||||
public function actionIndex( | public function actionIndex( | ||||
$idPointSale = 0, $sectionInactiveUsers = false) | $idPointSale = 0, $sectionInactiveUsers = false) | ||||
{ | |||||
$params = Yii::$app->request->queryParams; | |||||
if($idPointSale) { | |||||
$params['id_point_sale'] = $idPointSale ; | |||||
} | |||||
if($sectionInactiveUsers) { | |||||
$params['inactive'] = true ; | |||||
} | |||||
$query = User::findBy($params); | |||||
$dataProvider = new ActiveDataProvider([ | |||||
'query' => $query, | |||||
'sort' => ['attributes' => ['lastname','name']], | |||||
]); | |||||
{ | |||||
$searchModel = new UserSearch ; | |||||
$dataProvider = $searchModel->search([ | |||||
'UserSearch' => array_merge( | |||||
[ | |||||
'id_point_sale' => $idPointSale, | |||||
'inactive' => (int) $sectionInactiveUsers | |||||
], | |||||
isset(Yii::$app->request->queryParams['UserSearch']) ? | |||||
Yii::$app->request->queryParams['UserSearch'] : | |||||
[] | |||||
) | |||||
]) ; | |||||
$producer = Producer::searchOne([ | $producer = Producer::searchOne([ | ||||
'id' => Producer::getId() | 'id' => Producer::getId() | ||||
$pointsSaleArray = PointSale::searchAll() ; | $pointsSaleArray = PointSale::searchAll() ; | ||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | |||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'producer' => $producer, | 'producer' => $producer, | ||||
'idPointSaleActive' => $idPointSale, | 'idPointSaleActive' => $idPointSale, | ||||
])->all() ; | ])->all() ; | ||||
$usersArray = []; | $usersArray = []; | ||||
foreach ($usersArray as $user) { | |||||
foreach ($users as $user) { | |||||
if (isset($user['email']) && strlen($user['email'])) | if (isset($user['email']) && strlen($user['email'])) | ||||
$usersArray[] = $user['email']; | $usersArray[] = $user['email']; | ||||
} | } | ||||
$pointSale = null ; | $pointSale = null ; | ||||
if($idPointSale) { | if($idPointSale) { | ||||
$pointSale = PointSale::findOne(['id' => $idPointSale, 'id_producer' => Producer::getId()]) ; | |||||
$pointSale = PointSale::findOne(['id' => $idPointSale]) ; | |||||
} | } | ||||
return $this->render('emails', [ | return $this->render('emails', [ |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
$this->setTitle('Ajouter un client') ; | $this->setTitle('Ajouter un client') ; | ||||
$this->addBreadcrumb(['label' => 'Clients', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => 'Utilisateurs', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb('Ajouter') ; | $this->addBreadcrumb('Ajouter') ; | ||||
?> | ?> |
use common\models\Producer; | use common\models\Producer; | ||||
$this->setTitle('Créditer <small>'.Html::encode($user->lastname.' '.$user->name).'</small>', 'Créditer '.Html::encode($user->lastname.' '.$user->name)) ; | $this->setTitle('Créditer <small>'.Html::encode($user->lastname.' '.$user->name).'</small>', 'Créditer '.Html::encode($user->lastname.' '.$user->name)) ; | ||||
$this->addBreadcrumb(['label' => 'Clients', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => 'Utilisateurs', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => Html::encode($user->lastname.' '.$user->name)]) ; | $this->addBreadcrumb(['label' => Html::encode($user->lastname.' '.$user->name)]) ; | ||||
$this->addBreadcrumb('Créditer') ; | $this->addBreadcrumb('Créditer') ; | ||||
if(!$producer->credit) | if(!$producer->credit) | ||||
{ | { | ||||
echo '<div class="alert alert-warning">Attention, la fonctionnalité <strong>Crédit</strong> est désactivée dans vos <a href="'.Yii::$app->urlManager->createurl(['producer/update']).'">paramètres</a>.' | echo '<div class="alert alert-warning">Attention, la fonctionnalité <strong>Crédit</strong> est désactivée dans vos <a href="'.Yii::$app->urlManager->createurl(['producer/update']).'">paramètres</a>.' | ||||
. ' Pensez à l\'activer si vous souhaitez qu\'elle soit visible de vos clients.</div>' ; | |||||
. ' Pensez à l\'activer si vous souhaitez qu\'elle soit visible de vos utilisateurs.</div>' ; | |||||
} | } | ||||
?> | ?> | ||||
<li class="<?php if(!isset($pointSale)): ?>active<?php endif; ?>"> | <li class="<?php if(!isset($pointSale)): ?>active<?php endif; ?>"> | ||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/mail']); ?>">Tous</a> | <a href="<?= Yii::$app->urlManager->createUrl(['user/mail']); ?>">Tous</a> | ||||
</li> | </li> | ||||
<?php foreach($pointsSaleArray as $pointSale): ?> | |||||
<li class="<?php if(isset($pointSale) && $pointSale->id == $pointSale->id): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/mail','idPointSale'=>$pointSale->id]); ?>"><?= Html::encode($pointSale->name) ?></a> | |||||
<?php foreach($pointsSaleArray as $thePointSale): ?> | |||||
<li class="<?php if(isset($pointSale) && $pointSale->id == $thePointSale->id): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/mail','idPointSale'=>$thePointSale->id]); ?>"><?= Html::encode($thePointSale->name) ?></a> | |||||
</li> | </li> | ||||
<?php endforeach; ?> | <?php endforeach; ?> | ||||
</ul> | </ul> |
<?= GridView::widget([ | <?= GridView::widget([ | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'filterModel' => true, | |||||
'filterModel' => $searchModel, | |||||
'columns' => [ | 'columns' => [ | ||||
[ | [ | ||||
'attribute' => 'lastname', | |||||
'filter' => Html::input( | |||||
'string', | |||||
'lastname', | |||||
isset(Yii::$app->request->queryParams['lastname']) ? Html::encode(Yii::$app->request->queryParams['lastname']) : '', | |||||
[ 'class' => 'form-control'] | |||||
) | |||||
], | |||||
[ | |||||
'attribute' => 'name', | |||||
'filter' => Html::input( | |||||
'string', | |||||
'name', | |||||
isset(Yii::$app->request->queryParams['name']) ? Html::encode(Yii::$app->request->queryParams['name']) : '', | |||||
['class' => 'form-control'] | |||||
) | |||||
], | |||||
[ | |||||
'attribute' => 'phone', | |||||
'filter' => Html::input( | |||||
'string', | |||||
'phone', | |||||
isset(Yii::$app->request->queryParams['phone']) ? Html::encode(Yii::$app->request->queryParams['phone']) : '', | |||||
['class' => 'form-control'] | |||||
) | |||||
'attribute' => 'username', | |||||
'label' => 'Nom', | |||||
'value' => function($model) { | |||||
return $model['lastname'].' '.$model['name'] ; | |||||
} | |||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'email', | |||||
'filter' => Html::input( | |||||
'string', | |||||
'email', | |||||
isset(Yii::$app->request->queryParams['email']) ? Html::encode(Yii::$app->request->queryParams['email']) : '', | |||||
['class' => 'form-control'] | |||||
) | |||||
'attribute' => 'contacts', | |||||
'header' => 'Contacts', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
$html = '' ; | |||||
if(strlen($model['phone'])) { | |||||
$html .= $model['phone'] ; | |||||
} | |||||
if(strlen($model['phone']) && strlen($model['email'])) { | |||||
$html .= '<br />' ; | |||||
} | |||||
if(strlen($model['email'])) { | |||||
$html .= $model['email'] ; | |||||
} | |||||
return $html ; | |||||
} | |||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'created_at', | 'attribute' => 'created_at', | ||||
return date('m/d/Y à H:i', $model['created_at']); | return date('m/d/Y à H:i', $model['created_at']); | ||||
} | } | ||||
], | ], | ||||
[ | |||||
'attribute' => 'date_last_connection', | |||||
'label' => 'Dernière connexion', | |||||
'value' => function($model) { | |||||
if(isset($model['date_last_connection'])) | |||||
return date('d/m/Y à H:i', strtotime($model['date_last_connection'])); | |||||
else | |||||
return '' ; | |||||
} | |||||
], | |||||
[ | [ | ||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'header' => 'Commandes', | |||||
'template' => '{orders}', | 'template' => '{orders}', | ||||
'headerOptions' => ['class' => 'actions'], | 'headerOptions' => ['class' => 'actions'], | ||||
'buttons' => [ | 'buttons' => [ | ||||
'orders' => function ($url, $model) { | 'orders' => function ($url, $model) { | ||||
$url = Yii::$app->urlManager->createUrl(['user/orders','id' => $model['user_id']]) ; | |||||
$url = Yii::$app->urlManager->createUrl(['user/orders','id' => $model['id']]) ; | |||||
$countOrders = Order::searchCount([ | $countOrders = Order::searchCount([ | ||||
'id_user' => $model['user_id'] | |||||
'id_user' => $model['id'] | |||||
], ['conditions' => 'date_delete IS NULL']) ; | ], ['conditions' => 'date_delete IS NULL']) ; | ||||
$html = '' ; | $html = '' ; | ||||
if($countOrders) { | if($countOrders) { | ||||
$s = '' ; | |||||
if($countOrders > 1) $s = 's' ; | |||||
$html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$countOrders.' commande'.$s, $url, [ | |||||
$html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$countOrders, $url, [ | |||||
'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default ' | 'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default ' | ||||
]); ; | ]); ; | ||||
} | } | ||||
'attribute' => 'credit', | 'attribute' => 'credit', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function($model) use($producer) { | 'value' => function($model) use($producer) { | ||||
if(!isset($model['credit'])) $model['credit'] = 0 ; | |||||
$user = User::findOne($model['user_id']) ; | |||||
$user = User::findOne($model->id) ; | |||||
$html = '<div class="input-group"> | $html = '<div class="input-group"> | ||||
<input type="text" class="form-control input-credit" readonly="readonly" value="'.number_format($user->getCredit($producer->id),2).' €" placeholder=""> | <input type="text" class="form-control input-credit" readonly="readonly" value="'.number_format($user->getCredit($producer->id),2).' €" placeholder=""> | ||||
<span class="input-group-btn"> | <span class="input-group-btn"> | ||||
'.Html::a( | '.Html::a( | ||||
'<span class="glyphicon glyphicon-euro"></span> Crédit', | |||||
Yii::$app->urlManager->createUrl(['user/credit','id' => $model['user_id']]), | |||||
'<span class="glyphicon glyphicon-euro"></span>', | |||||
Yii::$app->urlManager->createUrl(['user/credit','id' => $model->id]), | |||||
[ | [ | ||||
'title' => 'Crédit', | 'title' => 'Crédit', | ||||
'class' => 'btn btn-default' | 'class' => 'btn btn-default' | ||||
[ | [ | ||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{update} {delete}', | 'template' => '{update} {delete}', | ||||
'headerOptions' => ['class' => 'actions'], | |||||
'headerOptions' => ['class' => 'column-actions'], | |||||
'contentOptions' => ['class' => 'column-actions'], | |||||
'buttons' => [ | 'buttons' => [ | ||||
'update' => function ($url, $model) { | 'update' => function ($url, $model) { | ||||
$url = Yii::$app->urlManager->createUrl(['user/update','id' => $model['user_id']]) ; | |||||
$user = User::find()->with('userProducer')->where(['id' => $model['user_id']])->one() ; | |||||
$url = Yii::$app->urlManager->createUrl(['user/update','id' => $model->id]) ; | |||||
$user = User::find()->with('userProducer')->where(['id' => $model->id])->one() ; | |||||
if(count($user->userProducer) <= 1) | if(count($user->userProducer) <= 1) | ||||
{ | { | ||||
return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [ | |||||
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ | |||||
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | ||||
]); | ]); | ||||
} | } | ||||
else { | 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>' ; | |||||
return '<span data-toggle="tooltip" data-placement="top" title="Vous ne pouvez pas modifier les utilisateurs qui sont liés à plusieurs producteurs."><span class="glyphicon glyphicon-remove-sign"></span> Non modifiable</span>' ; | |||||
} | } | ||||
}, | }, | ||||
'delete' => function($url, $model) { | |||||
if($model['active']) { | |||||
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' | |||||
]); | |||||
} | |||||
'delete' => function($url, $model) { | |||||
return Html::a('<span class="glyphicon glyphicon-trash"></span>', Yii::$app->urlManager->createUrl(array_merge(['user/delete','id' => $model->id], Yii::$app->getRequest()->getQueryParams())), [ | |||||
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default' | |||||
]); | |||||
} | } | ||||
], | ], | ||||
], | ], |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
$this->setTitle('Modifier un client') ; | $this->setTitle('Modifier un client') ; | ||||
$this->addBreadcrumb(['label' => 'Clients', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => 'Utilisateurs', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => Html::encode($model->lastname.' '.$model->name)]) ; | $this->addBreadcrumb(['label' => Html::encode($model->lastname.' '.$model->name)]) ; | ||||
$this->addBreadcrumb('Modifier') ; | $this->addBreadcrumb('Modifier') ; | ||||
.user-index .btn-liste-emails { | .user-index .btn-liste-emails { | ||||
float: right; | float: right; | ||||
position: relative; | position: relative; | ||||
top: -8px; | |||||
top: 6px; | |||||
} | } | ||||
/* line 1213, ../sass/screen.scss */ | /* line 1213, ../sass/screen.scss */ | ||||
} | } | ||||
/* line 127, ../sass/_adminlte.scss */ | /* line 127, ../sass/_adminlte.scss */ | ||||
body.skin-black .content-wrapper .table th.column-actions, body.skin-black .content-wrapper .table td.column-actions { | body.skin-black .content-wrapper .table th.column-actions, body.skin-black .content-wrapper .table td.column-actions { | ||||
width: 130px; | |||||
width: 150px; | |||||
text-align: right; | text-align: right; | ||||
} | } | ||||
/* line 131, ../sass/_adminlte.scss */ | /* line 131, ../sass/_adminlte.scss */ |
font-size: 13px ; | font-size: 13px ; | ||||
} | } | ||||
th.column-actions, td.column-actions { | th.column-actions, td.column-actions { | ||||
width: 130px ; | |||||
width: 150px ; | |||||
text-align: right ; | text-align: right ; | ||||
} | } | ||||
td.text-small, th.text-small { | td.text-small, th.text-small { |
.btn-liste-emails { | .btn-liste-emails { | ||||
float: right ; | float: right ; | ||||
position: relative ; | position: relative ; | ||||
top: -8px ; | |||||
top: 6px ; | |||||
} | } | ||||
} | } | ||||
<?php | |||||
/** | |||||
Copyright La boîte à pain (2018) | |||||
contact@laboiteapain.net | |||||
Ce logiciel est un programme informatique servant à aider les producteurs | |||||
à distribuer leur production en circuits courts. | |||||
Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||||
respectant les principes de diffusion des logiciels libres. Vous pouvez | |||||
utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||||
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||||
sur le site "http://www.cecill.info". | |||||
En contrepartie de l'accessibilité au code source et des droits de copie, | |||||
de modification et de redistribution accordés par cette licence, il n'est | |||||
offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||||
seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||||
titulaire des droits patrimoniaux et les concédants successifs. | |||||
A cet égard l'attention de l'utilisateur est attirée sur les risques | |||||
associés au chargement, à l'utilisation, à la modification et/ou au | |||||
développement et à la reproduction du logiciel par l'utilisateur étant | |||||
donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||||
manipuler et qui le réserve donc à des développeurs et des professionnels | |||||
avertis possédant des connaissances informatiques approfondies. Les | |||||
utilisateurs sont donc invités à charger et tester l'adéquation du | |||||
logiciel à leurs besoins dans des conditions permettant d'assurer la | |||||
sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||||
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||||
Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||||
pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||||
termes. | |||||
*/ | |||||
namespace common\models ; | |||||
use common\models\User ; | |||||
class UserSearch extends User | |||||
{ | |||||
var $id_point_sale ; | |||||
var $inactive ; | |||||
var $username ; | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday', 'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday', 'mail_distribution_sunday'], 'boolean'], | |||||
[['lastname', 'name', 'phone', 'address'], 'string'], | |||||
[['id_point_sale', 'inactive'],'integer'], | |||||
[['date_last_connection', 'id_point_sale', 'username'], 'safe'], | |||||
]; | |||||
} | |||||
public function search($params) | |||||
{ | |||||
$optionsSearch = self::defaultOptionsSearch() ; | |||||
$query = User::find(); | |||||
$dataProvider = new ActiveDataProvider([ | |||||
'query' => $query, | |||||
'sort' => ['attributes' => ['username','credit','orders']], | |||||
'pagination' => [ | |||||
'pageSize' => 20, | |||||
], | |||||
]); | |||||
$dataProvider->sort->attributes['username'] = [ | |||||
'asc' => ['user.lastname' => SORT_ASC, 'user.name' => SORT_ASC], | |||||
'desc' => ['user.lastname' => SORT_DESC, 'user.name' => SORT_DESC], | |||||
]; | |||||
$dataProvider->sort->attributes['credit'] = [ | |||||
'asc' => ['user_producer.credit' => SORT_ASC], | |||||
'desc' => ['user_producer.credit' => SORT_DESC], | |||||
]; | |||||
$this->load($params); | |||||
if (!$this->validate()) { | |||||
return $dataProvider; | |||||
} | |||||
$active = (isset($this->inactive) && $this->inactive) ? 0 : 1 ; | |||||
$query->innerJoin('user_producer','user.id = user_producer.id_user AND user_producer.active = '.$active.' AND user_producer.id_producer = :id_producer', [':id_producer' => Producer::getId()]) ; | |||||
if(isset($this->id_point_sale) && $this->id_point_sale) { | |||||
$pointSale = PointSale::findOne(['id' => $this->id_point_sale]) ; | |||||
if($pointSale->restricted_access) { | |||||
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ; | |||||
} | |||||
else { | |||||
$query->innerJoin( | |||||
'order', | |||||
'user.id = order.id_user AND order.id_point_sale = :id_point_sale', | |||||
[':id_point_sale' => $this->id_point_sale] | |||||
)->groupBy('user.id') ; | |||||
} | |||||
} | |||||
if(isset($this->inactive) && $this->inactive) { | |||||
$query->innerJoin( | |||||
'order', | |||||
'user.id = order.id_user' | |||||
) | |||||
->groupBy('user.id'); | |||||
} | |||||
$query->andFilterWhere([ | |||||
'or', | |||||
['like', 'user.lastname', $this->username], | |||||
['like', 'user.name', $this->username] | |||||
]); | |||||
return $dataProvider; | |||||
} | |||||
} |