Browse Source

Merge branch 'feature/options_credit' into dev

dev
Guillaume Bourgeois 5 years ago
parent
commit
0532733c2a
9 changed files with 131 additions and 47 deletions
  1. +10
    -0
      backend/views/producer/update.php
  2. +10
    -0
      common/models/PointSale.php
  3. +8
    -3
      common/models/Producer.php
  4. +17
    -0
      console/migrations/m190222_090304_ajout_champs_options_credit.php
  5. +23
    -14
      producer/controllers/OrderController.php
  6. +40
    -16
      producer/views/order/order.php
  7. +7
    -7
      producer/web/css/screen.css
  8. +12
    -5
      producer/web/js/vuejs/order-order.js
  9. +4
    -2
      producer/web/sass/order/_order.scss

+ 10
- 0
backend/views/producer/update.php View File

@@ -183,6 +183,16 @@ $this->addBreadcrumb($this->getTitle()) ;
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>

+ 10
- 0
common/models/PointSale.php View File

@@ -333,4 +333,14 @@ class PointSale extends ActiveRecordCommon
}
return $str ;
}
/**
* Retourne le mode de fonctionnement du crédit du point de vente.
*
* @return string
*/
public function getCreditFunctioning()
{
return $this->credit_functioning ? $this->credit_functioning : Producer::getConfig('credit_functioning') ;
}
}

+ 8
- 3
common/models/Producer.php View File

@@ -60,6 +60,9 @@ use yii\helpers\Html;
* @property string gcs
* @property boolean option_allow_user_gift
* @property string credit_functioning
* @property boolean use_credit_checked_default
* @property float credit_limit
*
*/
class Producer extends ActiveRecordCommon
{
@@ -99,9 +102,9 @@ class Producer extends ActiveRecordCommon
}
}],
[['description','mentions','gcs','order_infos','slug','secret_key_payplug'], 'string'],
[['negative_balance', 'credit', 'active','online_payment','user_manage_subscription', 'option_allow_user_gift'], 'boolean'],
[['negative_balance', 'credit', 'active','online_payment','user_manage_subscription', 'option_allow_user_gift','use_credit_checked_default'], 'boolean'],
[['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code','type','credit_functioning'], 'string', 'max' => 255],
[['free_price', 'credit_limit_reminder'], 'double'],
[['free_price', 'credit_limit_reminder','credit_limit'], 'double'],
['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'],
];
}
@@ -137,7 +140,9 @@ class Producer extends ActiveRecordCommon
'mentions' => 'Mentions légales',
'gcs' => 'Conditions générales de vente',
'option_allow_user_gift' => 'Autoriser les utilisateurs à effectuer un don à la plateforme lors de leur commande',
'credit_functioning' => 'Utilisation du Crédit par l\'utilisateur'
'credit_functioning' => 'Utilisation du Crédit par l\'utilisateur',
'credit_limit' => 'Crédit limite',
'use_credit_checked_default' => 'Cocher par défaut l\'option "Utiliser mon crédit" lors de la commande de l\'utilisateur'
];
}


+ 17
- 0
console/migrations/m190222_090304_ajout_champs_options_credit.php View File

@@ -0,0 +1,17 @@
<?php

use yii\db\Migration;
use yii\db\mysql\Schema;

class m190222_090304_ajout_champs_options_credit extends Migration {

public function up() {
$this->addColumn('producer', 'credit_limit', Schema::TYPE_FLOAT) ;
$this->addColumn('producer', 'use_credit_checked_default', Schema::TYPE_BOOLEAN.' DEFAULT 1') ;
}

public function down() {
$this->dropColumn('producer', 'credit_limit') ;
$this->dropColumn('producer', 'use_credit_checked_default') ;
}
}

+ 23
- 14
producer/controllers/OrderController.php View File

@@ -284,7 +284,6 @@ class OrderController extends ProducerBaseController
'id' => $order->id_point_sale
]) ;
$order->comment_point_sale = ($pointSale && strlen($pointSale->getComment())) ?
$pointSale->getComment() : '' ;
@@ -328,17 +327,24 @@ class OrderController extends ProducerBaseController

// credit
$credit = Producer::getConfig('credit');
$creditLimit = Producer::getConfig('credit_limit');
$creditFunctioning = $pointSale->getCreditFunctioning() ;
$creditUser = Yii::$app->user->identity->getCredit($distribution->id_producer);
$order = Order::searchOne([
'id' => $order->id
]) ;
$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)) {
$amountPaid = $order->getAmount(Order::AMOUNT_PAID);

// à payer
if ($order->getPaymentStatus() == Order::PAYMENT_UNPAID) {
$amountRemaining = $order->getAmount(Order::AMOUNT_REMAINING) ;
$credit = Yii::$app->user->identity->getCredit($distribution->id_producer);

if(!is_null($creditLimit) && $amountRemaining > $creditUser - $creditLimit) {
$amountRemaining = $creditUser - $creditLimit ;
}
if ($amountRemaining > 0) {
$order->saveCreditHistory(
CreditHistory::TYPE_PAYMENT,
@@ -362,17 +368,18 @@ class OrderController extends ProducerBaseController
}
}
}
else {
if (!count($productsArray)) {
$errors[] = "Vous n'avez choisi aucun produit" ;
}
if ($errorDate) {
$errors[] = "Vous ne pouvez pas commander pour cette date." ;
}
if ($errorPointSale) {
$errors[] = "Point de vente invalide." ;
}
if (!count($productsArray)) {
$errors[] = "Vous n'avez choisi aucun produit" ;
}
if ($errorDate) {
$errors[] = "Vous ne pouvez pas commander pour cette date." ;
}
if ($errorPointSale) {
$errors[] = "Point de vente invalide." ;
}
return $errors ;
}

@@ -455,6 +462,8 @@ class OrderController extends ProducerBaseController
'order_infos' => $producer->order_infos,
'credit' => $producer->credit,
'credit_functioning' => $producer->credit_functioning,
'use_credit_checked_default' => $producer->use_credit_checked_default,
'credit_limit' => is_numeric($producer->credit_limit) ? $producer->credit_limit : null
] ;
// Distributions

+ 40
- 16
producer/views/order/order.php View File

@@ -232,25 +232,49 @@ $this->setTitle('Commander') ;
<label for="order-comment">Commentaire</label>
<textarea id="order-comment" v-model="comment" class="form-control"></textarea>
</div>
<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 class="info" v-if="useCredit">
<span v-if="order == null || order.amount_paid == 0">{{ priceTotal(true) }} seront débités</span>
<span v-else-if="order != null && order.amount_paid > 0 && order.amount_paid < priceTotal()">{{ formatPrice(priceTotal() - order.amount_paid) }} seront débités</span>
<span v-else-if="order != null && order.amount_paid > priceTotal()">{{ formatPrice(order.amount_paid - priceTotal()) }} seront remboursés</span>
<template v-if="!checkCreditLimit(order) && pointSaleActive.credit_functioning == 'mandatory'">
<div class="alert alert-danger">Vous devez recharger votre crédit ou supprimer des produits. Votre producteur n'autorise pas un crédit inférieur à <strong>{{ formatPrice(creditLimit) }}</strong>.</div>
<div class="block-actions">
<a class="btn btn-primary" href="<?= Yii::$app->urlManager->createUrl(['site/index']) ?>">Retour à l'accueil</a>
</div>
</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 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 />
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.
</span>
</template>
<template v-else-if="order != null && order.amount_paid > priceTotal()">
<span>{{ formatPrice(order.amount_paid - priceTotal()) }} seront remboursés</span>
</template>
</div>
</div>
<div v-else>
<span class="glyphicon glyphicon-chevron-right"></span> La commande sera à régler sur place.
</div>
</div>
<div v-else>
<span class="glyphicon glyphicon-chevron-right"></span> La commande sera à régler sur place.
<div class="block-actions">
<button class="btn btn-primary" disabled="disabled" v-if="disableConfirmButton">Je confirme ma commande</button>
<button class="btn btn-primary" v-else @click="confirmClick">Je confirme ma commande</button>
</div>
</div>
<div class="block-actions">
<button class="btn btn-primary" disabled="disabled" v-if="disableConfirmButton">Je confirme ma commande</button>
<button class="btn btn-primary" v-else @click="confirmClick">Je confirme ma commande</button>
</div>
</template>
</div>
</transition>
</div>

+ 7
- 7
producer/web/css/screen.css View File

@@ -1457,20 +1457,20 @@ termes.
.order-order #app-order-order table#products tr.total .price-total {
font-size: 23px;
}
/* line 239, ../sass/order/_order.scss */
.order-order #app-order-order #content-step-payment .credit {
margin-top: 20px;
}
/* line 242, ../sass/order/_order.scss */
/* line 240, ../sass/order/_order.scss */
.order-order #app-order-order #content-step-payment .credit .info {
margin-left: 20px;
color: gray;
}
/* line 249, ../sass/order/_order.scss */
/* line 246, ../sass/order/_order.scss */
.order-order #app-order-order #content-step-payment .comment {
margin-bottom: 20px;
}
/* line 251, ../sass/order/_order.scss */
.order-order #app-order-order #infos {
margin-top: 30px;
}
/* line 251, ../sass/order/_order.scss */
/* line 253, ../sass/order/_order.scss */
.order-order #app-order-order #infos .panel-body {
padding-top: 0px;
white-space: pre-line;

+ 12
- 5
producer/web/js/vuejs/order-order.js View File

@@ -17,6 +17,7 @@ var app = new Vue({
comment: '',
creditCheckbox: false,
credit: 0,
creditLimit: null,
useCredit: false,
errors: [],
disableConfirmButton: false,
@@ -91,10 +92,10 @@ var app = new Vue({
},
formatPrice: function(price) {
var isNumberRegExp = new RegExp(/^[-+]?[0-9]+(\.[0-9]+)*$/);
if(isNumberRegExp.test(price) && price > 0) {
if(isNumberRegExp.test(price)) {
return Number(price).toFixed(2).replace('.',',')+' €' ;
}
return '--' ;
return '0 €' ;
},
getPointSale: function(idPointSale) {
for(var key in this.pointsSale) {
@@ -110,7 +111,8 @@ var app = new Vue({
.then(function(response) {
app.producer = response.data.producer ;
app.credit = response.data.credit ;
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 ;
@@ -248,8 +250,6 @@ var app = new Vue({

validatePointSale: function(idPointSale) {
this.pointSaleActive = this.getPointSale(idPointSale) ;
this.useCredit = true ;
this.changeStep('products') ;
},
productQuantityClick: function(product, quantity) {
@@ -321,6 +321,13 @@ var app = new Vue({
if(!this.oneProductOrdered()) {
this.errors.push('Veuillez sélectionner au moins un produit.') ;
}
},
checkCreditLimit: function(order) {
var total = this.priceTotal() ;
if(order != null) {
total = this.priceTotal() - order.amount_paid ;
}
return this.creditLimit == null || (this.creditLimit != null && (this.credit - total >= this.creditLimit)) ;
}
}
});

+ 4
- 2
producer/web/sass/order/_order.scss View File

@@ -237,13 +237,15 @@
#content-step-payment {
.credit {
margin-top: 20px ;
.info {
margin-left: 20px ;
color: gray ;
}
}
.comment {
margin-bottom: 20px ;
}
}
#infos {

Loading…
Cancel
Save