Pārlūkot izejas kodu

Intégration de l'option "credit_limit"

refactoring
Guillaume Bourgeois pirms 5 gadiem
vecāks
revīzija
67a2840e5a
6 mainītis faili ar 95 papildinājumiem un 42 dzēšanām
  1. +10
    -0
      common/models/PointSale.php
  2. +23
    -15
      producer/controllers/OrderController.php
  3. +40
    -16
      producer/views/order/order.php
  4. +7
    -7
      producer/web/css/screen.css
  5. +11
    -2
      producer/web/js/vuejs/order-order.js
  6. +4
    -2
      producer/web/sass/order/_order.scss

+ 10
- 0
common/models/PointSale.php Parādīt failu

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

+ 23
- 15
producer/controllers/OrderController.php Parādīt failu

@@ -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,7 +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
'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 Parādīt failu

@@ -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 Parādīt failu

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

+ 11
- 2
producer/web/js/vuejs/order-order.js Parādīt failu

@@ -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) {
@@ -111,6 +112,7 @@ var app = new Vue({
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 ;
@@ -319,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 Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt