Browse Source

Ajout de l'option 'credit_active' dans le modèle UserProducer

Intégration dans la liste des utilisateurs et dans la page de crédit des utilisateur.
refactoring
Guillaume Bourgeois 5 years ago
parent
commit
fa51566d67
8 changed files with 108 additions and 24 deletions
  1. +24
    -1
      backend/controllers/UserController.php
  2. +42
    -19
      backend/views/user/credit.php
  3. +9
    -3
      backend/views/user/index.php
  4. +5
    -0
      backend/web/css/screen.css
  5. +1
    -0
      backend/web/sass/screen.scss
  6. +10
    -0
      backend/web/sass/user/_credit.scss
  7. +2
    -1
      common/models/UserProducer.php
  8. +15
    -0
      console/migrations/m190225_093245_ajout_champs_gestion_credit_utilisateur.php

+ 24
- 1
backend/controllers/UserController.php View File

use common\models\Producer ; use common\models\Producer ;
use common\models\Distribution ; use common\models\Distribution ;
use backend\models\MailForm ; use backend\models\MailForm ;
use common\models\UserProducer ;


/** /**
* UserController implements the CRUD actions for User model. * UserController implements the CRUD actions for User model.


return $this->render('credit', [ return $this->render('credit', [
'user' => $user, 'user' => $user,
'userProducer' => $userProducer,
'creditForm' => $creditForm, 'creditForm' => $creditForm,
'history' => $history 'history' => $history
]); ]);
} }
else { 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.");
} }
} }


'user' => $user '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. * Finds the User model based on its primary key value.

+ 42
- 19
backend/views/user/credit.php View File

} }
?> ?>
<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> </div>
<?php ActiveForm::end(); ?>
</div> </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> <h2>Historique <span class="the-credit"><?= number_format($user->getCredit($producer->id), 2); ?> €</span></h2>
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>

+ 9
- 3
backend/views/user/index.php View File

'attribute' => 'credit', 'attribute' => 'credit',
'format' => 'raw', 'format' => 'raw',
'value' => function($model) use($producer) { '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"> $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"> <span class="input-group-btn">
'.Html::a( '.Html::a(
'<span class="glyphicon glyphicon-euro"></span>', '<span class="glyphicon glyphicon-euro"></span>',
Yii::$app->urlManager->createUrl(['user/credit','id' => $model->id]), Yii::$app->urlManager->createUrl(['user/credit','id' => $model->id]),
[ [
'title' => 'Crédit', 'title' => 'Crédit',
'class' => 'btn btn-default'
'class' => 'btn '.$classBtnCredit
] ]
).' ).'
</span> </span>

+ 5
- 0
backend/web/css/screen.css View File

margin-bottom: 20px; margin-bottom: 20px;
} }


/* line 5, ../sass/user/_credit.scss */
.user-credit .panel .panel-heading .btn {
float: right;
}

/* line 4, ../sass/producer/_update.scss */ /* line 4, ../sass/producer/_update.scss */
.producer-update #nav-params { .producer-update #nav-params {
margin-bottom: 30px; margin-bottom: 30px;

+ 1
- 0
backend/web/sass/screen.scss View File

@import "stats/_products.scss" ; @import "stats/_products.scss" ;
@import "distribution/_index.scss" ; @import "distribution/_index.scss" ;
@import "user/_emails.scss" ; @import "user/_emails.scss" ;
@import "user/_credit.scss" ;
@import "producer/_update.scss" ; @import "producer/_update.scss" ;
@import "point_sale/_index.scss" ; @import "point_sale/_index.scss" ;

+ 10
- 0
backend/web/sass/user/_credit.scss View File


.user-credit {
.panel {
.panel-heading {
.btn {
float: right ;
}
}
}
}

+ 2
- 1
common/models/UserProducer.php View File

return [ return [
[['id_user', 'id_producer'], 'required'], [['id_user', 'id_producer'], 'required'],
[['id_user', 'id_producer'], 'integer'], [['id_user', 'id_producer'], 'integer'],
[['active','bookmark'], 'boolean'],
[['active','bookmark','credit_active'], 'boolean'],
[['credit'], 'double'], [['credit'], 'double'],
]; ];
} }
'id_producer' => 'Producteur', 'id_producer' => 'Producteur',
'active' => 'Actif', 'active' => 'Actif',
'bookmark' => 'Favoris', 'bookmark' => 'Favoris',
'credit_active' => 'Crédit'
]; ];
} }

+ 15
- 0
console/migrations/m190225_093245_ajout_champs_gestion_credit_utilisateur.php View File

<?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') ;
}
}

Loading…
Cancel
Save