} | } | ||||
return $str ; | 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') ; | |||||
} | |||||
} | } |
'id' => $order->id_point_sale | 'id' => $order->id_point_sale | ||||
]) ; | ]) ; | ||||
$order->comment_point_sale = ($pointSale && strlen($pointSale->getComment())) ? | $order->comment_point_sale = ($pointSale && strlen($pointSale->getComment())) ? | ||||
$pointSale->getComment() : '' ; | $pointSale->getComment() : '' ; | ||||
// credit | // credit | ||||
$credit = Producer::getConfig('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([ | $order = Order::searchOne([ | ||||
'id' => $order->id | '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)) { | if($credit && $pointSale->credit && ($posts['use_credit'] || $pointSale->credit_functioning == Producer::CREDIT_FUNCTIONING_MANDATORY)) { | ||||
$amountPaid = $order->getAmount(Order::AMOUNT_PAID); | |||||
// à payer | // à payer | ||||
if ($order->getPaymentStatus() == Order::PAYMENT_UNPAID) { | 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) { | if ($amountRemaining > 0) { | ||||
$order->saveCreditHistory( | $order->saveCreditHistory( | ||||
CreditHistory::TYPE_PAYMENT, | CreditHistory::TYPE_PAYMENT, | ||||
} | } | ||||
} | } | ||||
} | } | ||||
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 ; | return $errors ; | ||||
} | } | ||||
'order_infos' => $producer->order_infos, | 'order_infos' => $producer->order_infos, | ||||
'credit' => $producer->credit, | 'credit' => $producer->credit, | ||||
'credit_functioning' => $producer->credit_functioning, | '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 | // Distributions |
<label for="order-comment">Commentaire</label> | <label for="order-comment">Commentaire</label> | ||||
<textarea id="order-comment" v-model="comment" class="form-control"></textarea> | <textarea id="order-comment" v-model="comment" class="form-control"></textarea> | ||||
</div> | </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> | </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> | |||||
<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> | </div> | ||||
</transition> | </transition> | ||||
</div> | </div> |
.order-order #app-order-order table#products tr.total .price-total { | .order-order #app-order-order table#products tr.total .price-total { | ||||
font-size: 23px; | 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 { | .order-order #app-order-order #content-step-payment .credit .info { | ||||
margin-left: 20px; | margin-left: 20px; | ||||
color: gray; | 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 { | .order-order #app-order-order #infos { | ||||
margin-top: 30px; | margin-top: 30px; | ||||
} | } | ||||
/* line 251, ../sass/order/_order.scss */ | |||||
/* line 253, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #infos .panel-body { | .order-order #app-order-order #infos .panel-body { | ||||
padding-top: 0px; | padding-top: 0px; | ||||
white-space: pre-line; | white-space: pre-line; |
comment: '', | comment: '', | ||||
creditCheckbox: false, | creditCheckbox: false, | ||||
credit: 0, | credit: 0, | ||||
creditLimit: null, | |||||
useCredit: false, | useCredit: false, | ||||
errors: [], | errors: [], | ||||
disableConfirmButton: false, | disableConfirmButton: false, | ||||
}, | }, | ||||
formatPrice: function(price) { | formatPrice: function(price) { | ||||
var isNumberRegExp = new RegExp(/^[-+]?[0-9]+(\.[0-9]+)*$/); | 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 Number(price).toFixed(2).replace('.',',')+' €' ; | ||||
} | } | ||||
return '--' ; | |||||
return '0 €' ; | |||||
}, | }, | ||||
getPointSale: function(idPointSale) { | getPointSale: function(idPointSale) { | ||||
for(var key in this.pointsSale) { | for(var key in this.pointsSale) { | ||||
app.producer = response.data.producer ; | app.producer = response.data.producer ; | ||||
app.credit = response.data.credit ; | app.credit = response.data.credit ; | ||||
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 ; | ||||
if(!this.oneProductOrdered()) { | if(!this.oneProductOrdered()) { | ||||
this.errors.push('Veuillez sélectionner au moins un produit.') ; | 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)) ; | |||||
} | } | ||||
} | } | ||||
}); | }); |
#content-step-payment { | #content-step-payment { | ||||
.credit { | .credit { | ||||
margin-top: 20px ; | |||||
.info { | .info { | ||||
margin-left: 20px ; | margin-left: 20px ; | ||||
color: gray ; | color: gray ; | ||||
} | } | ||||
} | } | ||||
.comment { | |||||
margin-bottom: 20px ; | |||||
} | |||||
} | } | ||||
#infos { | #infos { |