{ | { | ||||
$posts = Yii::$app->request->post(); | $posts = Yii::$app->request->post(); | ||||
$productsArray = []; | $productsArray = []; | ||||
$totalQuantity = 0; | $totalQuantity = 0; | ||||
$producer = $this->getProducer() ; | |||||
foreach ($posts['products'] as $key => $quantity) { | foreach ($posts['products'] as $key => $quantity) { | ||||
$product = Product::find()->where(['id' => (int) $key])->one(); | $product = Product::find()->where(['id' => (int) $key])->one(); | ||||
} | } | ||||
} | } | ||||
$producer = $this->getProducer() ; | |||||
// date | // date | ||||
$errorDate = false; | $errorDate = false; | ||||
if ($order->validate() && count($productsArray) && !$errorDate && !$errorPointSale) { | if ($order->validate() && count($productsArray) && !$errorDate && !$errorPointSale) { | ||||
$userProducer = UserProducer::searchOne([ | |||||
'id_producer' => $order->distribution->id_producer, | |||||
'id_user' => User::getCurrentId() | |||||
]) ; | |||||
// gestion point de vente | // gestion point de vente | ||||
$pointSale = PointSale::searchOne([ | $pointSale = PointSale::searchOne([ | ||||
'id' => $order->id_point_sale | 'id' => $order->id_point_sale | ||||
$amountPaid = $order->getAmount(Order::AMOUNT_PAID); | $amountPaid = $order->getAmount(Order::AMOUNT_PAID); | ||||
$amountRemaining = $order->getAmount(Order::AMOUNT_REMAINING) ; | $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 | // à payer | ||||
if ($order->getPaymentStatus() == Order::PAYMENT_UNPAID) { | if ($order->getPaymentStatus() == Order::PAYMENT_UNPAID) { | ||||
'id_user' => User::getCurrentId() | 'id_user' => User::getCurrentId() | ||||
]) ; | ]) ; | ||||
$json['credit'] = $userProducer->credit ; | |||||
$json['user'] = [ | |||||
'credit' => $userProducer->credit, | |||||
'credit_active' => $userProducer->credit_active, | |||||
] ; | |||||
if($dateObject && $dateObject->format($format) === $date) { | if($dateObject && $dateObject->format($format) === $date) { | ||||
</template> | </template> | ||||
<template v-else> | <template v-else> | ||||
<div class="credit"> | <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"> | <div class="info" v-if="useCredit"> | ||||
<template v-if="order == null || order.amount_paid == 0"> | <template v-if="order == null || order.amount_paid == 0"> | ||||
<span v-if="checkCreditLimit(order)">{{ priceTotal(true) }} seront débités</span> | <span v-if="checkCreditLimit(order)">{{ priceTotal(true) }} seront débités</span> | ||||
<span v-else> | <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. | Restera {{ formatPrice(priceTotal() - credit) }} à régler. | ||||
</span> | </span> | ||||
</template> | </template> | ||||
<template v-else-if="order != null && order.amount_paid > 0 && order.amount_paid < priceTotal()"> | <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-if="checkCreditLimit(order)">{{ formatPrice(priceTotal() - order.amount_paid) }} seront débités</span> | ||||
<span v-else> | <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> | </span> | ||||
</template> | </template> | ||||
<template v-else-if="order != null && order.amount_paid > priceTotal()"> | <template v-else-if="order != null && order.amount_paid > priceTotal()"> |
loadingInit: true, | loadingInit: true, | ||||
step: 'date', | step: 'date', | ||||
producer: null, | producer: null, | ||||
user: null, | |||||
date: null, | date: null, | ||||
dateFormat: null, | dateFormat: null, | ||||
distributions: [], | distributions: [], | ||||
products: [], | products: [], | ||||
comment: '', | comment: '', | ||||
creditCheckbox: false, | creditCheckbox: false, | ||||
credit: 0, | |||||
creditLimit: null, | |||||
useCredit: false, | useCredit: false, | ||||
errors: [], | errors: [], | ||||
disableConfirmButton: false, | disableConfirmButton: false, | ||||
axios.get("ajax-infos",{params: {date : this.getDate()}}) | axios.get("ajax-infos",{params: {date : this.getDate()}}) | ||||
.then(function(response) { | .then(function(response) { | ||||
app.producer = response.data.producer ; | 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.useCredit = response.data.producer.use_credit_checked_default ; | ||||
app.creditLimit = response.data.producer.credit_limit ; | |||||
app.calendar.attrs = [] ; | app.calendar.attrs = [] ; | ||||
app.calendar.availableDates = [] ; | app.calendar.availableDates = [] ; | ||||
var distributions = response.data.distributions ; | var distributions = response.data.distributions ; | ||||
validatePointSale: function(idPointSale) { | validatePointSale: function(idPointSale) { | ||||
this.pointSaleActive = this.getPointSale(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') ; | this.changeStep('products') ; | ||||
}, | }, | ||||
productQuantityClick: function(product, quantity) { | productQuantityClick: function(product, quantity) { | ||||
if(order != null) { | if(order != null) { | ||||
total = this.priceTotal() - order.amount_paid ; | 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)) ; | |||||
} | } | ||||
} | } | ||||
}); | }); |