Browse Source

Correctifs option "Commander en tant que visiteur" #310

[Backend] Utilisateurs > liste : ajout type de compte
refactoring
Guillaume Bourgeois 2 years ago
parent
commit
2e78fe3abf
4 changed files with 121 additions and 106 deletions
  1. +1
    -5
      backend/views/user/_form.php
  2. +111
    -100
      backend/views/user/index.php
  3. +8
    -1
      common/models/User.php
  4. +1
    -0
      common/models/UserSearch.php

+ 1
- 5
backend/views/user/_form.php View File

]); ?> ]); ?>


<?= $form->field($model, 'type') <?= $form->field($model, 'type')
->dropDownList([
User::TYPE_INDIVIDUAL => 'Particulier',
User::TYPE_LEGAL_PERSON => 'Personne morale',
User::TYPE_GUEST => 'Visiteur'
], [
->dropDownList(User::getTypeChoicesArray(), [
'v-model' => 'type' 'v-model' => 'type'
]) ; ?> ]) ; ?>
<?= $form->field($model, 'name_legal_person', ['options' => ['v-show' => "type == 'legal-person'"]])->textInput() ?> <?= $form->field($model, 'name_legal_person', ['options' => ['v-show' => "type == 'legal-person'"]])->textInput() ?>

+ 111
- 100
backend/views/user/index.php View File

<?= <?=


$this->render('_menu', [ $this->render('_menu', [
'idPointSaleActive' => $idPointSaleActive,
'sectionInactiveUsers' => $sectionInactiveUsers,
'sectionSubscribers' => $sectionSubscribers,
'pointsSaleArray' => $pointsSaleArray,
'section' => 'index'
'idPointSaleActive' => $idPointSaleActive,
'sectionInactiveUsers' => $sectionInactiveUsers,
'sectionSubscribers' => $sectionSubscribers,
'pointsSaleArray' => $pointsSaleArray,
'section' => 'index'
]); ]);


?> ?>


<?= GridView::widget([ <?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'username',
'label' => 'Nom',
'value' => function ($model) {
if (isset($model['name_legal_person']) && strlen($model['name_legal_person'])) {
return $model['name_legal_person'];
} else {
return $model['lastname'] . ' ' . $model['name'];
}
}
],
[
'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;
}
],
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Commandes',
'template' => '{orders}',
'headerOptions' => ['class' => 'actions'],
'buttons' => [
'orders' => function ($url, $model) {
$url = Yii::$app->urlManager->createUrl(['user/orders', 'id' => $model['id']]);
$countOrders = Order::searchCount([
'id_user' => $model['id']
], ['conditions' => 'date_delete IS NULL']);
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'username',
'label' => 'Nom',
'value' => function ($model) {
if (isset($model['name_legal_person']) && strlen($model['name_legal_person'])) {
return $model['name_legal_person'];
} else {
return $model['lastname'] . ' ' . $model['name'];
}
}
],
[
'attribute' => 'type',
'label' => 'Type',
'value' => function ($model) {
$typeArray = User::getTypeChoicesArray();
if(isset($typeArray[$model['type']])) {
return $typeArray[$model['type']];
}
return '';
}
],
[
'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;
}
],
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Commandes',
'template' => '{orders}',
'headerOptions' => ['class' => 'actions'],
'buttons' => [
'orders' => function ($url, $model) {
$url = Yii::$app->urlManager->createUrl(['user/orders', 'id' => $model['id']]);
$countOrders = Order::searchCount([
'id_user' => $model['id']
], ['conditions' => 'date_delete IS NULL']);


$html = '';
if ($countOrders) {
$html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> ' . $countOrders, $url, [
'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default '
]);;
} else {
$html .= 'Aucune commande';
}
$html = '';
if ($countOrders) {
$html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> ' . $countOrders, $url, [
'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default '
]);;
} else {
$html .= 'Aucune commande';
}


return $html;
},
],
],
[
'attribute' => 'credit',
'format' => 'raw',
'value' => function ($model) use ($producer) {
return $html;
},
],
],
[
'attribute' => 'credit',
'format' => 'raw',
'value' => function ($model) use ($producer) {


$userProducer = UserProducer::searchOne([
'id_user' => $model->id
]);
$credit = $userProducer ? $userProducer->credit : 0;
$classBtnCredit = $userProducer->credit_active ? 'btn-success' : 'btn-default';
$userProducer = UserProducer::searchOne([
'id_user' => $model->id
]);
$credit = $userProducer ? $userProducer->credit : 0;
$classBtnCredit = $userProducer->credit_active ? 'btn-success' : 'btn-default';


$html = '<div class="input-group">
$html = '<div class="input-group">
<input type="text" class="form-control input-credit" readonly="readonly" value="' . number_format($credit, 2) . ' €" placeholder=""> <input type="text" class="form-control input-credit" readonly="readonly" value="' . number_format($credit, 2) . ' €" placeholder="">
<span class="input-group-btn"> <span class="input-group-btn">
' . Html::a( ' . Html::a(
'<span class="glyphicon glyphicon-euro"></span>',
Yii::$app->urlManager->createUrl(['user/credit', 'id' => $model->id]),
[
'title' => 'Crédit',
'class' => 'btn ' . $classBtnCredit
]
) . '
'<span class="glyphicon glyphicon-euro"></span>',
Yii::$app->urlManager->createUrl(['user/credit', 'id' => $model->id]),
[
'title' => 'Crédit',
'class' => 'btn ' . $classBtnCredit
]
) . '
</span> </span>
</div>'; </div>';
return $html;
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'update' => function ($url, $model) {
$url = Yii::$app->urlManager->createUrl(['user/update', 'id' => $model->id]);
$user = User::find()->with('userProducer')->where(['id' => $model->id])->one();
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'Modifier'), '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 btn-confirm-delete'
]);
}
],
],
return $html;
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'update' => function ($url, $model) {
$url = Yii::$app->urlManager->createUrl(['user/update', 'id' => $model->id]);
$user = User::find()->with('userProducer')->where(['id' => $model->id])->one();
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'Modifier'), '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 btn-confirm-delete'
]);
}
],
], ],
],
]); ?> ]); ?>

+ 8
- 1
common/models/User.php View File

return false ; return false ;
} }



public static function getTypeChoicesArray()
{
return [
User::TYPE_INDIVIDUAL => 'Particulier',
User::TYPE_LEGAL_PERSON => 'Personne morale',
User::TYPE_GUEST => 'Visiteur'
];
}
} }

+ 1
- 0
common/models/UserSearch.php View File

. '`user`.id_producer, ' . '`user`.id_producer, '
. '`user`.date_last_connection, ' . '`user`.date_last_connection, '
. '`user`.name_legal_person, ' . '`user`.name_legal_person, '
. '`user`.type, '
. '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders'); . '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders');


$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([

Loading…
Cancel
Save