Procházet zdrojové kódy

Merge branch 'feature/fonctionnement_credit_base_sur_utilisateur' into dev

dev
Guillaume Bourgeois před 5 roky
rodič
revize
519da23e21
14 změnil soubory, kde provedl 166 přidání a 53 odebrání
  1. +24
    -1
      backend/controllers/UserController.php
  2. +4
    -3
      backend/views/point-sale/_form.php
  3. +14
    -10
      backend/views/producer/update.php
  4. +42
    -19
      backend/views/user/credit.php
  5. +9
    -3
      backend/views/user/index.php
  6. +5
    -0
      backend/web/css/screen.css
  7. +1
    -0
      backend/web/sass/screen.scss
  8. +10
    -0
      backend/web/sass/user/_credit.scss
  9. +8
    -0
      common/models/Producer.php
  10. +2
    -1
      common/models/UserProducer.php
  11. +15
    -0
      console/migrations/m190225_093245_ajout_champs_gestion_credit_utilisateur.php
  12. +15
    -4
      producer/controllers/OrderController.php
  13. +7
    -7
      producer/views/order/order.php
  14. +10
    -5
      producer/web/js/vuejs/order-order.js

+ 24
- 1
backend/controllers/UserController.php Zobrazit soubor

@@ -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.

+ 4
- 3
backend/views/point-sale/_form.php Zobrazit soubor

@@ -71,9 +71,10 @@ use common\models\Producer ;
<?= $form->field($model, 'credit_functioning')
->dropDownList([
'' => 'Paramètres globaux ('.Producer::$creditFunctioningArray[Producer::getConfig('credit_functioning')].')',
Producer::CREDIT_FUNCTIONING_OPTIONAL => 'Optionnelle',
Producer::CREDIT_FUNCTIONING_MANDATORY => 'Obligatoire',
], []) ; ?>
Producer::CREDIT_FUNCTIONING_OPTIONAL => Producer::$creditFunctioningArray[Producer::CREDIT_FUNCTIONING_OPTIONAL],
Producer::CREDIT_FUNCTIONING_MANDATORY => Producer::$creditFunctioningArray[Producer::CREDIT_FUNCTIONING_MANDATORY],
Producer::CREDIT_FUNCTIONING_USER => Producer::$creditFunctioningArray[Producer::CREDIT_FUNCTIONING_USER],
], [])->hint(Producer::HINT_CREDIT_FUNCTIONING) ; ?>

<div id="delivery-days">

+ 14
- 10
backend/views/producer/update.php Zobrazit soubor

@@ -173,26 +173,30 @@ $this->addBreadcrumb($this->getTitle()) ;
. 'Ils créditent leur compte en vous donnant la somme de leur choix et c\'est ensuite à vous de '.Html::a('mettre à jour', ['user/index']).' leur Crédit en ligne.<br />'
. 'Ceci fait, les clients paient leur commande directement via leur Crédit.') ; ?>

<?= $form->field($model, 'credit_functioning')
->dropDownList([
Producer::CREDIT_FUNCTIONING_OPTIONAL => Producer::$creditFunctioningArray[Producer::CREDIT_FUNCTIONING_OPTIONAL],
Producer::CREDIT_FUNCTIONING_MANDATORY => Producer::$creditFunctioningArray[Producer::CREDIT_FUNCTIONING_MANDATORY],
Producer::CREDIT_FUNCTIONING_USER => Producer::$creditFunctioningArray[Producer::CREDIT_FUNCTIONING_USER],
], [])->hint(Producer::HINT_CREDIT_FUNCTIONING) ; ?>
<?= $form->field($model, 'use_credit_checked_default')
->dropDownList([
0 => 'Non',
1 => 'Oui',
], [])->hint('Utilisation optionnelle du Crédit.') ; ?>
<?= $form->field($model, 'credit_limit_reminder',[
'template' => '{label}<div class="input-group">{input}<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span></div>{hint}',
])
->hint("Une relance est envoyé au client dès que ce seuil est dépassé.") ; ?>
<?= $form->field($model, 'credit_functioning')
->dropDownList([
Producer::CREDIT_FUNCTIONING_OPTIONAL => 'Optionnelle',
Producer::CREDIT_FUNCTIONING_MANDATORY => 'Obligatoire',
], []) ; ?>
<?= $form->field($model, 'credit_limit',[
'template' => '{label}<div class="input-group">{input}<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span></div>{hint}',
])->hint('Limite de crédit que l\'utilisateur ne pourra pas dépasser. Laisser vide pour permettre un crédit négatif et infini.'); ?>
<?= $form->field($model, 'use_credit_checked_default')
->dropDownList([
0 => 'Non',
1 => 'Oui',
], []) ; ?>
</div>
</div>

+ 42
- 19
backend/views/user/credit.php Zobrazit soubor

@@ -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>

+ 9
- 3
backend/views/user/index.php Zobrazit soubor

@@ -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>

+ 5
- 0
backend/web/css/screen.css Zobrazit soubor

@@ -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;

+ 1
- 0
backend/web/sass/screen.scss Zobrazit soubor

@@ -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" ;

+ 10
- 0
backend/web/sass/user/_credit.scss Zobrazit soubor

@@ -0,0 +1,10 @@

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

+ 8
- 0
common/models/Producer.php Zobrazit soubor

@@ -68,10 +68,18 @@ class Producer extends ActiveRecordCommon
{
const CREDIT_FUNCTIONING_MANDATORY = 'mandatory' ;
const CREDIT_FUNCTIONING_OPTIONAL = 'optional' ;
const CREDIT_FUNCTIONING_USER = 'user' ;
const HINT_CREDIT_FUNCTIONING = '<ul>'
. '<li>Optionnelle : l\'utilisateur choisit s\'il utilise son Crédit ou non. Les commandes peuvent être payées ou impayées.</li>'
. '<li>Obligatoire : toutes les commandes de l\'utilisateur son comptabilisées au niveau du Crédit. Toutes les commandes sont payées.</li>'
. '<li>Basée sur l\'utilisateur : Crédit obligatoire si l\'utilisateur a le crédit activé au niveau de son compte, système de Crédit non affiché sinon.</li>'
. '</ul>' ;
public static $creditFunctioningArray = [
self::CREDIT_FUNCTIONING_MANDATORY => 'Obligatoire',
self::CREDIT_FUNCTIONING_OPTIONAL => 'Optionnelle',
self::CREDIT_FUNCTIONING_USER => 'Basée sur l\'utilisateur',
];
var $secret_key_payplug ;

+ 2
- 1
common/models/UserProducer.php Zobrazit soubor

@@ -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'
];
}

+ 15
- 0
console/migrations/m190225_093245_ajout_champs_gestion_credit_utilisateur.php Zobrazit soubor

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

+ 15
- 4
producer/controllers/OrderController.php Zobrazit soubor

@@ -217,8 +217,8 @@ class OrderController extends ProducerBaseController
{
$posts = Yii::$app->request->post();
$productsArray = [];

$totalQuantity = 0;
$producer = $this->getProducer() ;

foreach ($posts['products'] as $key => $quantity) {
$product = Product::find()->where(['id' => (int) $key])->one();
@@ -228,7 +228,6 @@ class OrderController extends ProducerBaseController
}
}
$producer = $this->getProducer() ;

// date
$errorDate = false;
@@ -279,6 +278,11 @@ class OrderController extends ProducerBaseController
if ($order->validate() && count($productsArray) && !$errorDate && !$errorPointSale) {

$userProducer = UserProducer::searchOne([
'id_producer' => $order->distribution->id_producer,
'id_user' => User::getCurrentId()
]) ;
// gestion point de vente
$pointSale = PointSale::searchOne([
'id' => $order->id_point_sale
@@ -336,7 +340,11 @@ class OrderController extends ProducerBaseController
$amountPaid = $order->getAmount(Order::AMOUNT_PAID);
$amountRemaining = $order->getAmount(Order::AMOUNT_REMAINING) ;
if($credit && $pointSale->credit && ($posts['use_credit'] || $pointSale->credit_functioning == Producer::CREDIT_FUNCTIONING_MANDATORY)) {
if($credit && $pointSale->credit &&
( $posts['use_credit'] ||
$pointSale->credit_functioning == Producer::CREDIT_FUNCTIONING_MANDATORY ||
($pointSale->credit_functioning == Producer::CREDIT_FUNCTIONING_USER && $userProducer->credit_active)
)) {

// à payer
if ($order->getPaymentStatus() == Order::PAYMENT_UNPAID) {
@@ -505,7 +513,10 @@ class OrderController extends ProducerBaseController
'id_user' => User::getCurrentId()
]) ;
$json['credit'] = $userProducer->credit ;
$json['user'] = [
'credit' => $userProducer->credit,
'credit_active' => $userProducer->credit_active,
] ;
if($dateObject && $dateObject->format($format) === $date) {

+ 7
- 7
producer/views/order/order.php Zobrazit soubor

@@ -242,23 +242,23 @@ $this->setTitle('Commander') ;
</template>
<template v-else>
<div class="credit">
<div v-if="producer.credit == 1 && pointSaleActive.credit == 1">
<input type="checkbox" id="use-credit" v-model="useCredit" disabled="disabled" v-if="pointSaleActive.credit_functioning == 'mandatory'" />
<input type="checkbox" id="use-credit" v-model="useCredit" v-else /> <label for="use-credit">Utiliser mon Crédit ({{ formatPrice(credit) }})</label>
<div v-if="producer.credit == 1 && pointSaleActive.credit == 1 && (pointSaleActive.credit_functioning != 'user' || (pointSaleActive.credit_functioning == 'user' && user.credit_active))">
<input type="checkbox" id="use-credit" v-model="useCredit" disabled="disabled" v-if="pointSaleActive.credit_functioning == 'mandatory' || (pointSaleActive.credit_functioning == 'user' && user.credit_active)" />
<input type="checkbox" id="use-credit" v-model="useCredit" v-else /> <label for="use-credit">Utiliser mon Crédit ({{ formatPrice(user.credit) }})</label>
<div class="info" v-if="useCredit">
<template v-if="order == null || order.amount_paid == 0">
<span v-if="checkCreditLimit(order)">{{ priceTotal(true) }} seront débités</span>
<span v-else>
{{ formatPrice(credit) }} seront débités. (Limite de crédit à {{ formatPrice(creditLimit) }})<br />
{{ formatPrice(user.credit) }} seront débités. (Limite de crédit à {{ formatPrice(producer.credit_limit) }})<br />
Restera {{ formatPrice(priceTotal() - credit) }} à régler.
</span>
</template>
<template v-else-if="order != null && order.amount_paid > 0 && order.amount_paid < priceTotal()">
<span v-if="checkCreditLimit(order)">{{ formatPrice(priceTotal() - order.amount_paid) }} seront débités</span>
<span v-else>
{{ formatPrice(credit) }} seront débités. (Limite de crédit à {{ formatPrice(creditLimit) }})<br />
Restera {{ formatPrice(priceTotal() - order.amount_paid - credit) }} à régler.
{{ formatPrice(user.credit) }} seront débités. (Limite de crédit à {{ formatPrice(producer.credit_limit) }})<br />
Restera {{ formatPrice(priceTotal() - order.amount_paid - user.credit) }} à régler.
</span>
</template>
<template v-else-if="order != null && order.amount_paid > priceTotal()">

+ 10
- 5
producer/web/js/vuejs/order-order.js Zobrazit soubor

@@ -6,6 +6,7 @@ var app = new Vue({
loadingInit: true,
step: 'date',
producer: null,
user: null,
date: null,
dateFormat: null,
distributions: [],
@@ -16,8 +17,6 @@ var app = new Vue({
products: [],
comment: '',
creditCheckbox: false,
credit: 0,
creditLimit: null,
useCredit: false,
errors: [],
disableConfirmButton: false,
@@ -110,9 +109,8 @@ var app = new Vue({
axios.get("ajax-infos",{params: {date : this.getDate()}})
.then(function(response) {
app.producer = response.data.producer ;
app.credit = response.data.credit ;
app.user = response.data.user ;
app.useCredit = response.data.producer.use_credit_checked_default ;
app.creditLimit = response.data.producer.credit_limit ;
app.calendar.attrs = [] ;
app.calendar.availableDates = [] ;
var distributions = response.data.distributions ;
@@ -250,6 +248,13 @@ var app = new Vue({

validatePointSale: function(idPointSale) {
this.pointSaleActive = this.getPointSale(idPointSale) ;
if(this.pointSaleActive.credit_functioning == 'mandatory' || (this.pointSaleActive.credit_functioning == 'user' && this.user.credit_active)) {
this.useCredit = true ;
}
else {
this.useCredit = false ;
}
this.changeStep('products') ;
},
productQuantityClick: function(product, quantity) {
@@ -327,7 +332,7 @@ var app = new Vue({
if(order != null) {
total = this.priceTotal() - order.amount_paid ;
}
return this.creditLimit == null || (this.creditLimit != null && (this.credit - total >= this.creditLimit)) ;
return this.producer.credit_limit == null || (this.producer.credit_limit != null && (this.user.credit - total >= this.producer.credit_limit)) ;
}
}
});

Načítá se…
Zrušit
Uložit