Ver código fonte

Intégration de la nouvelle option dans la prise de commande (app 'producer')

refactoring
Guillaume Bourgeois 5 anos atrás
pai
commit
2def921377
3 arquivos alterados com 32 adições e 16 exclusões
  1. +15
    -4
      producer/controllers/OrderController.php
  2. +7
    -7
      producer/views/order/order.php
  3. +10
    -5
      producer/web/js/vuejs/order-order.js

+ 15
- 4
producer/controllers/OrderController.php Ver arquivo

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

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

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

Carregando…
Cancelar
Salvar