<div class="clr"></div> | <div class="clr"></div> | ||||
</div> | </div> | ||||
<div class="alert alert-danger" v-if="missingSubscriptions && missingSubscriptions.length > 0"> | |||||
<div class="alert alert-info" v-if="missingSubscriptions && missingSubscriptions.length > 0"> | |||||
<span class="glyphicon glyphicon-info-sign"></span> | |||||
{{ missingSubscriptions.length }} abonnement<template v-if="missingSubscriptions.length > 1">s</template> manquant<template v-if="missingSubscriptions.length > 1">s</template> : | {{ missingSubscriptions.length }} abonnement<template v-if="missingSubscriptions.length > 1">s</template> manquant<template v-if="missingSubscriptions.length > 1">s</template> : | ||||
<ul> | |||||
<li v-for="subscription in missingSubscriptions">{{ subscription.username }}</li> | |||||
</ul> | |||||
<span v-for="(subscription, index) in missingSubscriptions"> | |||||
{{ subscription.username }}<template v-if="index != missingSubscriptions.length - 1">, </template><template v-else>.</template> | |||||
</span> | |||||
</div> | </div> | ||||
<div class="alert alert-danger" v-if="distribution && !distribution.active && orders && orders.length > 0"> | <div class="alert alert-danger" v-if="distribution && !distribution.active && orders && orders.length > 0"> |
return null; | return null; | ||||
} | } | ||||
public function getPaymentLabelShort(Order $order): string | |||||
{ | |||||
$isOrderPaid = $this->isOrderPaid($order); | |||||
$amountPaid = $this->orderSolver->getOrderAmountPaid($order); | |||||
$label = ' '; | |||||
if(!$amountPaid) { | |||||
if($isOrderPaid) { | |||||
$label = 'Facture payée'; | |||||
} | |||||
elseif($this->isCreditAutoPayment($order)) { | |||||
$label = 'Crédit non débité'; | |||||
} | |||||
else { | |||||
$label = 'Non réglé'; | |||||
} | |||||
} | |||||
else { | |||||
$mainPayment = $this->getMainPayment($order); | |||||
if($mainPayment) { | |||||
if($this->paymentSolver->isMeanPaymentCredit($mainPayment)) { | |||||
$label = 'Crédit débité'; | |||||
} | |||||
else { | |||||
$label = MeanPayment::getStrBy($mainPayment->mean_payment); | |||||
} | |||||
} | |||||
} | |||||
return '<span class="label label-'.($isOrderPaid ? 'success' : 'default').'">'.$label.'</span>'; | |||||
} | |||||
} | } |
foreach($order->payment as $payment) { | foreach($order->payment as $payment) { | ||||
if($this->paymentSolver->isMeanPaymentCredit($payment)) { | if($this->paymentSolver->isMeanPaymentCredit($payment)) { | ||||
$amount += $payment->amount; | |||||
$amount = $this->paymentSolver->sumAmountPaid($payment, $amount); | |||||
} | } | ||||
} | } | ||||
$amount = 0; | $amount = 0; | ||||
foreach($order->payment as $payment) { | foreach($order->payment as $payment) { | ||||
$amount += $payment->amount; | |||||
$amount = $this->paymentSolver->sumAmountPaid($payment, $amount); | |||||
} | } | ||||
return $amount; | return $amount; |
]); | ]); | ||||
} | } | ||||
public function sumAmountPaid(Payment $payment, float $amount = 0) | |||||
{ | |||||
if($this->isTypeDebit($payment)) { | |||||
$amount += $payment->amount; | |||||
} | |||||
else { | |||||
$amount -= $payment->amount; | |||||
} | |||||
return $amount; | |||||
} | |||||
public function getAmount(Payment $payment, bool $format = false): string | public function getAmount(Payment $payment, bool $format = false): string | ||||
{ | { | ||||
if ($format) { | if ($format) { |
} | } | ||||
} | } | ||||
public function refundSurplusOrder(Order $order, User $userAction): void | |||||
public function refundSurplusOrderCredit(Order $order, User $userAction): void | |||||
{ | { | ||||
$this->paymentBuilder->createPayment( | |||||
Payment::TYPE_REFUND, | |||||
$this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_SURPLUS), | |||||
$this->getProducerContext(), | |||||
$order->user, | |||||
$userAction, | |||||
MeanPayment::CREDIT, | |||||
$order | |||||
); | |||||
$amountPaidByCredit = $this->orderSolver->getOrderAmountPaidByCredit($order); | |||||
$amount = $this->orderSolver->getOrderAmountWithTax($order); | |||||
if($amountPaidByCredit > $amount) { | |||||
$this->paymentBuilder->createPayment( | |||||
Payment::TYPE_REFUND, | |||||
$amountPaidByCredit - $amount, | |||||
$this->getProducerContext(), | |||||
$order->user, | |||||
$userAction, | |||||
MeanPayment::CREDIT, | |||||
$order | |||||
); | |||||
} | |||||
} | } | ||||
public function payOrRefundOrder(string $type, Order $order, string $meanPayment, User $userAction, bool $checkCreditLimit = false): void | public function payOrRefundOrder(string $type, Order $order, string $meanPayment, User $userAction, bool $checkCreditLimit = false): void |
if (isset($order) && $order) { | if (isset($order) && $order) { | ||||
$paymentManager->payOrder($order, $user, true); | |||||
$paymentManager->payOrder($order, MeanPayment::CREDIT_CARD, $user, true); | |||||
// client : envoi d'un email de confirmation de paiement | // client : envoi d'un email de confirmation de paiement |
)) { | )) { | ||||
// à payer | // à payer | ||||
if ($orderManager->getPaymentStatus($order) == Order::PAYMENT_UNPAID) { | if ($orderManager->getPaymentStatus($order) == Order::PAYMENT_UNPAID) { | ||||
$paymentManager->payOrder($order, $this->getUserCurrent(), true); | |||||
$paymentManager->payOrderByCredit($order, $this->getUserCurrent(), true); | |||||
} // surplus à rembourser | } // surplus à rembourser | ||||
elseif ($orderManager->getPaymentStatus($order) == Order::PAYMENT_SURPLUS) { | elseif ($orderManager->getPaymentStatus($order) == Order::PAYMENT_SURPLUS) { | ||||
$paymentManager->refundSurplusOrder($order, $this->getUserCurrent()); | |||||
$paymentManager->refundSurplusOrderCredit($order, $this->getUserCurrent()); | |||||
} | } | ||||
} | } | ||||
if ($order) { | if ($order) { | ||||
$json['order'] = array_merge($order->getAttributes(), [ | $json['order'] = array_merge($order->getAttributes(), [ | ||||
'amount_total' => $orderManager->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL), | 'amount_total' => $orderManager->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL), | ||||
'amount_paid' => $orderManager->getOrderAmount($order, Order::AMOUNT_PAID), | |||||
'amount_paid' => $orderManager->getOrderAmountPaidByCredit($order), | |||||
]); | ]); | ||||
} | } | ||||
} | } |
} | } | ||||
if(updateOrder) { | if(updateOrder) { | ||||
if(response.data.products) { | |||||
app.products = response.data.products; | |||||
} | |||||
app.order = null ; | |||||
if(response.data.order) { | |||||
app.order = response.data.order ; | |||||
app.comment = app.order.comment ; | |||||
app.delivery = app.order.delivery_home ; | |||||
if(app.order.delivery_address && app.order.delivery_address.length > 0) { | |||||
app.deliveryAddress = app.order.delivery_address ; | |||||
} | |||||
app.pointSaleActive = app.getPointSale(response.data.order.id_point_sale) ; | |||||
} | |||||
else { | |||||
app.comment = null ; | |||||
app.delivery = false ; | |||||
app.deliveryAddress = null ; | |||||
if(app.user.address && app.user.address.length > 0) { | |||||
app.deliveryAddress = app.user.address ; | |||||
} | |||||
} | |||||
app.updateOrder(response); | |||||
} | } | ||||
if(type == 'first') { | if(type == 'first') { | ||||
if(app.getDate() && app.pointSaleActive) { | if(app.getDate() && app.pointSaleActive) { | ||||
app.step = 'products' ; | app.step = 'products' ; | ||||
if(response.data.products) { | if(response.data.products) { | ||||
app.products = response.data.products; | app.products = response.data.products; | ||||
} | } | ||||
app.updateOrder(response); | |||||
} | } | ||||
else if(app.producer.option_order_entry_point == 'point-sale') { | else if(app.producer.option_order_entry_point == 'point-sale') { | ||||
app.step = 'point-sale' ; | app.step = 'point-sale' ; | ||||
app.loadingInit = false ; | app.loadingInit = false ; | ||||
}); | }); | ||||
}, | }, | ||||
updateOrder: function(response) { | |||||
var app = this; | |||||
if(response.data.products) { | |||||
app.products = response.data.products; | |||||
} | |||||
app.order = null ; | |||||
if(response.data.order) { | |||||
app.order = response.data.order ; | |||||
app.comment = app.order.comment ; | |||||
app.delivery = app.order.delivery_home ; | |||||
if(app.order.delivery_address && app.order.delivery_address.length > 0) { | |||||
app.deliveryAddress = app.order.delivery_address ; | |||||
} | |||||
app.pointSaleActive = app.getPointSale(response.data.order.id_point_sale) ; | |||||
} | |||||
else { | |||||
app.comment = null ; | |||||
app.delivery = false ; | |||||
app.deliveryAddress = null ; | |||||
if(app.user.address && app.user.address.length > 0) { | |||||
app.deliveryAddress = app.user.address ; | |||||
} | |||||
} | |||||
}, | |||||
isMobile: function() { | isMobile: function() { | ||||
var width_window = parseInt($(window).width()); | var width_window = parseInt($(window).width()); | ||||
return width_window <= 768; | return width_window <= 768; |