Explorar el Código

[Administration] Documents > Factures : gestion des paiements #1219

feature/souke
Guillaume Bourgeois hace 1 año
padre
commit
ae529c21ed
Se han modificado 8 ficheros con 97 adiciones y 44 borrados
  1. +5
    -4
      backend/views/distribution/index.php
  2. +32
    -0
      common/logic/Order/Order/Repository/OrderRepository.php
  3. +2
    -2
      common/logic/Order/Order/Service/OrderSolver.php
  4. +12
    -0
      common/logic/Payment/Service/PaymentSolver.php
  5. +15
    -10
      common/logic/Payment/Service/PaymentUtils.php
  6. +1
    -1
      producer/controllers/CreditController.php
  7. +3
    -3
      producer/controllers/OrderController.php
  8. +27
    -24
      producer/web/js/vuejs/order-order.js

+ 5
- 4
backend/views/distribution/index.php Ver fichero

@@ -295,11 +295,12 @@ $this->setPageTitle('Distributions') ;
<div class="clr"></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> :
<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 class="alert alert-danger" v-if="distribution && !distribution.active && orders && orders.length > 0">

+ 32
- 0
common/logic/Order/Order/Repository/OrderRepository.php Ver fichero

@@ -515,4 +515,36 @@ class OrderRepository extends AbstractRepository

return null;
}

public function getPaymentLabelShort(Order $order): string
{
$isOrderPaid = $this->isOrderPaid($order);
$amountPaid = $this->orderSolver->getOrderAmountPaid($order);
$label = '&nbsp;';

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>';
}
}

+ 2
- 2
common/logic/Order/Order/Service/OrderSolver.php Ver fichero

@@ -336,7 +336,7 @@ class OrderSolver extends AbstractService implements SolverInterface

foreach($order->payment as $payment) {
if($this->paymentSolver->isMeanPaymentCredit($payment)) {
$amount += $payment->amount;
$amount = $this->paymentSolver->sumAmountPaid($payment, $amount);
}
}

@@ -348,7 +348,7 @@ class OrderSolver extends AbstractService implements SolverInterface
$amount = 0;

foreach($order->payment as $payment) {
$amount += $payment->amount;
$amount = $this->paymentSolver->sumAmountPaid($payment, $amount);
}

return $amount;

+ 12
- 0
common/logic/Payment/Service/PaymentSolver.php Ver fichero

@@ -27,6 +27,18 @@ class PaymentSolver extends AbstractService implements SolverInterface
]);
}

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
{
if ($format) {

+ 15
- 10
common/logic/Payment/Service/PaymentUtils.php Ver fichero

@@ -145,17 +145,22 @@ class PaymentUtils extends AbstractService implements UtilsInterface
}
}

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

+ 1
- 1
producer/controllers/CreditController.php Ver fichero

@@ -239,7 +239,7 @@ class CreditController extends ProducerBaseController

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

+ 3
- 3
producer/controllers/OrderController.php Ver fichero

@@ -455,10 +455,10 @@ class OrderController extends ProducerBaseController
)) {
// à payer
if ($orderManager->getPaymentStatus($order) == Order::PAYMENT_UNPAID) {
$paymentManager->payOrder($order, $this->getUserCurrent(), true);
$paymentManager->payOrderByCredit($order, $this->getUserCurrent(), true);
} // surplus à rembourser
elseif ($orderManager->getPaymentStatus($order) == Order::PAYMENT_SURPLUS) {
$paymentManager->refundSurplusOrder($order, $this->getUserCurrent());
$paymentManager->refundSurplusOrderCredit($order, $this->getUserCurrent());
}
}

@@ -626,7 +626,7 @@ class OrderController extends ProducerBaseController
if ($order) {
$json['order'] = array_merge($order->getAttributes(), [
'amount_total' => $orderManager->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL),
'amount_paid' => $orderManager->getOrderAmount($order, Order::AMOUNT_PAID),
'amount_paid' => $orderManager->getOrderAmountPaidByCredit($order),
]);
}
}

+ 27
- 24
producer/web/js/vuejs/order-order.js Ver fichero

@@ -228,38 +228,17 @@ var app = new Vue({
}

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(app.getDate() && app.pointSaleActive) {
app.step = 'products' ;

if(response.data.products) {
app.products = response.data.products;
}

app.updateOrder(response);
}
else if(app.producer.option_order_entry_point == 'point-sale') {
app.step = 'point-sale' ;
@@ -281,7 +260,31 @@ var app = new Vue({
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() {
var width_window = parseInt($(window).width());
return width_window <= 768;

Cargando…
Cancelar
Guardar