Intégration dans la liste des utilisateurs et dans la page de crédit des utilisateur.refactoring
@@ -42,6 +42,7 @@ use common\models\User ; | |||
use common\models\Producer ; | |||
use common\models\Distribution ; | |||
use backend\models\MailForm ; | |||
use common\models\UserProducer ; | |||
/** | |||
* UserController implements the CRUD actions for User model. | |||
@@ -300,12 +301,13 @@ class UserController extends BackendController | |||
return $this->render('credit', [ | |||
'user' => $user, | |||
'userProducer' => $userProducer, | |||
'creditForm' => $creditForm, | |||
'history' => $history | |||
]); | |||
} | |||
else { | |||
throw new UserException("Vous ne pouvez pas créditer un utilisateur qui n'est pas associé à votre boulangerie."); | |||
throw new UserException("Vous ne pouvez pas créditer un utilisateur qui n'est pas associé à votre établissement."); | |||
} | |||
} | |||
@@ -328,6 +330,27 @@ class UserController extends BackendController | |||
'user' => $user | |||
]); | |||
} | |||
/** | |||
* Modifie l'option "credit_active" d'un utilisateur pour le producteur courant. | |||
* Redirige vers la page de crédit de l'utilisateur. | |||
* | |||
* @param integer $idUser | |||
* @param boolean $state | |||
*/ | |||
public function actionStateCredit($idUser, $state) | |||
{ | |||
$userProducer = UserProducer::searchOne([ | |||
'id_user' => $idUser | |||
]) ; | |||
if($userProducer) { | |||
$userProducer->credit_active = $state ; | |||
$userProducer->save() ; | |||
} | |||
return $this->redirect(['user/credit','id' => $idUser]) ; | |||
} | |||
/** | |||
* Finds the User model based on its primary key value. |
@@ -62,29 +62,52 @@ $this->addBreadcrumb('Créditer') ; | |||
} | |||
?> | |||
<div class="col-md-12"> | |||
<?php $form = ActiveForm::begin(); ?> | |||
<?= $form->field($creditForm, 'type')->dropDownList([ | |||
CreditHistory::TYPE_CREDIT => 'Crédit', | |||
CreditHistory::TYPE_DEBIT => 'Débit', | |||
]) ?> | |||
<?= $form->field($creditForm, 'amount')->textInput() ?> | |||
<?= $form->field($creditForm, 'mean_payment')->dropDownList([ | |||
CreditHistory::MEAN_PAYMENT_MONEY => CreditHistory::getStrMeanPaymentBy(CreditHistory::MEAN_PAYMENT_MONEY), | |||
CreditHistory::MEAN_PAYMENT_CREDIT_CARD => CreditHistory::getStrMeanPaymentBy(CreditHistory::MEAN_PAYMENT_CREDIT_CARD), | |||
CreditHistory::MEAN_PAYMENT_CHEQUE => CreditHistory::getStrMeanPaymentBy(CreditHistory::MEAN_PAYMENT_CHEQUE), | |||
CreditHistory::MEAN_PAYMENT_OTHER => CreditHistory::getStrMeanPaymentBy(CreditHistory::MEAN_PAYMENT_OTHER), | |||
]) ?> | |||
<?= $form->field($creditForm, 'comment')->textarea() ?> | |||
<?= $form->field($creditForm, 'send_mail')->checkbox() ?> | |||
<div class="col-md-4"> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title"> | |||
Crédit obligatoire | |||
<?= Html::a($userProducer->credit_active ? 'Désactiver' : 'Activer', ['user/state-credit', 'idUser' => $user->id,'state' => !$userProducer->credit_active], ['class' => 'btn btn-default btn-xs']); ?> | |||
</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<?php if($userProducer->credit_active): ?> | |||
<div class="alert alert-success">Activé</div> | |||
<?php else: ?> | |||
<div class="alert alert-danger">Désactivé</div> | |||
<?php endif; ?> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<?= Html::submitButton( 'Créditer', ['class' => 'btn btn-primary']) ?> | |||
<div class="panel panel-default"> | |||
<div class="panel-heading"> | |||
<h3 class="panel-title">Crédit / débit</h3> | |||
</div> | |||
<div class="panel-body"> | |||
<?php $form = ActiveForm::begin(); ?> | |||
<?= $form->field($creditForm, 'type')->dropDownList([ | |||
CreditHistory::TYPE_CREDIT => 'Crédit', | |||
CreditHistory::TYPE_DEBIT => 'Débit', | |||
]) ?> | |||
<?= $form->field($creditForm, 'amount')->textInput() ?> | |||
<?= $form->field($creditForm, 'mean_payment')->dropDownList([ | |||
CreditHistory::MEAN_PAYMENT_MONEY => CreditHistory::getStrMeanPaymentBy(CreditHistory::MEAN_PAYMENT_MONEY), | |||
CreditHistory::MEAN_PAYMENT_CREDIT_CARD => CreditHistory::getStrMeanPaymentBy(CreditHistory::MEAN_PAYMENT_CREDIT_CARD), | |||
CreditHistory::MEAN_PAYMENT_CHEQUE => CreditHistory::getStrMeanPaymentBy(CreditHistory::MEAN_PAYMENT_CHEQUE), | |||
CreditHistory::MEAN_PAYMENT_OTHER => CreditHistory::getStrMeanPaymentBy(CreditHistory::MEAN_PAYMENT_OTHER), | |||
]) ?> | |||
<?= $form->field($creditForm, 'comment')->textarea() ?> | |||
<?= $form->field($creditForm, 'send_mail')->checkbox() ?> | |||
<div class="form-group"> | |||
<?= Html::submitButton( 'Créditer', ['class' => 'btn btn-primary']) ?> | |||
</div> | |||
<?php ActiveForm::end(); ?> | |||
</div> | |||
</div> | |||
<?php ActiveForm::end(); ?> | |||
</div> | |||
<div class="col-md-12"> | |||
<div class="col-md-8"> | |||
<h2>Historique <span class="the-credit"><?= number_format($user->getCredit($producer->id), 2); ?> €</span></h2> | |||
<table class="table table-bordered"> | |||
<thead> |
@@ -117,16 +117,22 @@ $this->render('_menu',[ | |||
'attribute' => 'credit', | |||
'format' => 'raw', | |||
'value' => function($model) use($producer) { | |||
$user = User::findOne($model->id) ; | |||
$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"> | |||
<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($credit,2).' €" placeholder=""> | |||
<span class="input-group-btn"> | |||
'.Html::a( | |||
'<span class="glyphicon glyphicon-euro"></span>', | |||
Yii::$app->urlManager->createUrl(['user/credit','id' => $model->id]), | |||
[ | |||
'title' => 'Crédit', | |||
'class' => 'btn btn-default' | |||
'class' => 'btn '.$classBtnCredit | |||
] | |||
).' | |||
</span> |
@@ -1962,6 +1962,11 @@ termes. | |||
margin-bottom: 20px; | |||
} | |||
/* line 5, ../sass/user/_credit.scss */ | |||
.user-credit .panel .panel-heading .btn { | |||
float: right; | |||
} | |||
/* line 4, ../sass/producer/_update.scss */ | |||
.producer-update #nav-params { | |||
margin-bottom: 30px; |
@@ -1333,5 +1333,6 @@ a.btn, button.btn { | |||
@import "stats/_products.scss" ; | |||
@import "distribution/_index.scss" ; | |||
@import "user/_emails.scss" ; | |||
@import "user/_credit.scss" ; | |||
@import "producer/_update.scss" ; | |||
@import "point_sale/_index.scss" ; |
@@ -0,0 +1,10 @@ | |||
.user-credit { | |||
.panel { | |||
.panel-heading { | |||
.btn { | |||
float: right ; | |||
} | |||
} | |||
} | |||
} |
@@ -68,7 +68,7 @@ class UserProducer extends ActiveRecordCommon | |||
return [ | |||
[['id_user', 'id_producer'], 'required'], | |||
[['id_user', 'id_producer'], 'integer'], | |||
[['active','bookmark'], 'boolean'], | |||
[['active','bookmark','credit_active'], 'boolean'], | |||
[['credit'], 'double'], | |||
]; | |||
} | |||
@@ -83,6 +83,7 @@ class UserProducer extends ActiveRecordCommon | |||
'id_producer' => 'Producteur', | |||
'active' => 'Actif', | |||
'bookmark' => 'Favoris', | |||
'credit_active' => 'Crédit' | |||
]; | |||
} | |||
@@ -0,0 +1,15 @@ | |||
<?php | |||
use yii\db\Migration; | |||
use yii\db\mysql\Schema; | |||
class m190225_093245_ajout_champs_gestion_credit_utilisateur extends Migration { | |||
public function up() { | |||
$this->addColumn('user_producer', 'credit_active', Schema::TYPE_BOOLEAN.' DEFAULT 0') ; | |||
} | |||
public function down() { | |||
$this->dropColumn('user_producer', 'credit_active') ; | |||
} | |||
} |