Parcourir la source

Gestion du crédit

refactoring
Guillaume Bourgeois il y a 5 ans
Parent
révision
bf7cf030bb
3 fichiers modifiés avec 29 ajouts et 16 suppressions
  1. +7
    -3
      producer/controllers/OrderController.php
  2. +12
    -8
      producer/views/order/order.php
  3. +10
    -5
      producer/web/js/vuejs/order-order.js

+ 7
- 3
producer/controllers/OrderController.php Voir le fichier

@@ -477,7 +477,7 @@ class OrderController extends ProducerBaseController
}

// credit
$credit = isset($posts['use_credit']) && $posts['use_credit'];
$credit = Producer::getConfig('credit');
$order = Order::searchOne([
'id' => $order->id
]) ;
@@ -610,7 +610,8 @@ class OrderController extends ProducerBaseController
'id' => $this->getProducer()->id
]) ;
$json['producer'] = [
'order_infos' => $producer->order_infos
'order_infos' => $producer->order_infos,
'credit' => $producer->credit
] ;
// Distributions
@@ -672,7 +673,10 @@ class OrderController extends ProducerBaseController
]);
if($orderUser) {
$json['order'] = $orderUser->getAttributes() ;
$json['order'] = array_merge($orderUser->getAttributes(), [
'amount_total' => $orderUser->getAmount(Order::AMOUNT_TOTAL),
'amount_paid' => $orderUser->getAmount(Order::AMOUNT_PAID),
]) ;
}
// distribution

+ 12
- 8
producer/views/order/order.php Voir le fichier

@@ -63,7 +63,7 @@ $this->setTitle('Commander') ;
<li><span class="glyphicon glyphicon-time"></span> {{ dateFormat }}</li>
<li><span class="glyphicon glyphicon-map-marker"></span> {{ pointSaleActive.name }} <span class="locality" v-if="pointSaleActive.locality.length > 0">à {{ pointSaleActive.locality }}</span></li>
<li><span class="glyphicon glyphicon-th-list"></span> {{ countProductOrdered() }} produits</li>
<li><span class="glyphicon glyphicon-chevron-right"></span> {{ priceTotal() }}</li>
<li><span class="glyphicon glyphicon-chevron-right"></span> {{ priceTotal(true) }}</li>
</ul>
</div>
<div class="clr"></div>
@@ -218,7 +218,7 @@ $this->setTitle('Commander') ;
</tr>
<tr class="total">
<td colspan="3"></td>
<td class="price-total">{{ priceTotal() }}</td>
<td class="price-total">{{ priceTotal(true) }}</td>
</tr>
</tbody>
</table>
@@ -238,12 +238,16 @@ $this->setTitle('Commander') ;
<textarea id="order-comment" v-model="comment" class="form-control"></textarea>
</div>
<div class="credit">
<input type="checkbox" id="checkbox-credit" v-model="creditCheckbox" />
<label for="checkbox-credit">Utiliser mon Crédit : {{ formatPrice(credit) }}</label>
<div class="info">
<span v-if="creditCheckbox == true">
{{ priceTotal() }} seront débités
</span>
<div v-if="producer.credit == 1 && pointSaleActive.credit == 1">
<span class="glyphicon glyphicon-chevron-right"></span> La commande va être réglée via votre Crédit ({{ formatPrice(credit) }}).
<div class="info">
<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>
</div>
</div>
<div v-else>
<span class="glyphicon glyphicon-chevron-right"></span> La commande sera à régler sur place.
</div>
</div>
<div class="block-actions">

+ 10
- 5
producer/web/js/vuejs/order-order.js Voir le fichier

@@ -153,7 +153,9 @@ var app = new Vue({
this.products = response.data.products ;
}
this.order = null ;
if(response.data.order) {
this.order = response.data.order ;
this.pointSaleActive = this.getPointSale(response.data.order.id_point_sale) ;
}
else {
@@ -243,15 +245,19 @@ var app = new Vue({
}
return count ;
},
priceTotal: function() {
priceTotal: function(format) {
var price = 0 ;
for(var key in this.products) {
if(this.products[key].quantity_form > 0) {
price += this.products[key].quantity_form * this.products[key].price ;
}
}
return this.formatPrice(price) ;
if(format) {
return this.formatPrice(price) ;
}
else {
return price ;
}
},
confirmClick: function() {
var productsArray = {} ;
@@ -269,8 +275,7 @@ var app = new Vue({
comment: this.comment
},
code_point_sale: this.pointsSaleCodes[this.pointSaleActive.id],
products: productsArray,
use_credit: this.creditCheckbox
products: productsArray
}).then(response => {
if(response.data.status == 'success') {
this.orderSuccess = true ;

Chargement…
Annuler
Enregistrer