Browse Source

[Administration] Statistiques : rapport paiements

feature/rotating_product
Guillaume Bourgeois 8 months ago
parent
commit
7f1a7ce331
4 changed files with 52 additions and 20 deletions
  1. +44
    -16
      backend/controllers/ReportController.php
  2. +0
    -1
      domain/Document/Invoice/InvoiceSolver.php
  3. +7
    -2
      domain/Order/Order/OrderSolver.php
  4. +1
    -1
      domain/Payment/PaymentSolver.php

+ 44
- 16
backend/controllers/ReportController.php View File

@@ -159,7 +159,7 @@ class ReportController extends BackendController
$resArray[] = [
'name' => '',
'quantity' => '',
'total' => '<strong>' . Price::format(round($totalGlobal, 2)) . '</strong>',
'total' => '<strong>' . Price::format(round($totalGlobal, 2)) . ' HT</strong>',
];

return $resArray;
@@ -181,7 +181,6 @@ class ReportController extends BackendController
public function actionPayments(string $dateStart, string $dateEnd)
{
$orderModule = $this->getOrderModule();
$paymentModule = $this->getPaymentModule();
$ordersArray = $orderModule->getRepository()
->findOrdersByPeriod(
new \DateTime($dateStart),
@@ -203,31 +202,60 @@ class ReportController extends BackendController
]
];

$sumAmountTotalSpentByCredit = 0;
$sumAmountTotalSpentByMoney = 0;
$sumAmountTotalSpentByCheque = 0;
$sumAmountTotalSpentByTransfer = 0;
$sumAmountTotalSpentByCreditCard = 0;

foreach($ordersArray as $order) {
$orderModule->getBuilder()->initOrder($order);

$strPayment = '';
foreach($order->payment as $payment) {
$strPayment .= $paymentModule->getSolver()->getStrMeanPayment($payment).', ';
$hasInvoice = false;
$referenceInvoice = 'Non';
if($order->invoice) {
$hasInvoice = true;
$referenceInvoice = $order->invoice->reference."";
}

$amountTotalSpentByCredit = $orderModule->getSolver()->getAmountTotalSpentByMeanPayment($order, MeanPayment::CREDIT);
$sumAmountTotalSpentByCredit += $amountTotalSpentByCredit;
$amountTotalSpentByMoney = $orderModule->getSolver()->getAmountTotalSpentByMeanPayment($order, MeanPayment::MONEY);
$sumAmountTotalSpentByMoney += $amountTotalSpentByMoney;
$amountTotalSpentByCheque = $orderModule->getSolver()->getAmountTotalSpentByMeanPayment($order, MeanPayment::CHEQUE);
$sumAmountTotalSpentByCheque += $amountTotalSpentByCheque;
$amountTotalSpentByTransfer = $orderModule->getSolver()->getAmountTotalSpentByMeanPayment($order, MeanPayment::TRANSFER);
$sumAmountTotalSpentByTransfer += $amountTotalSpentByTransfer;
$amountTotalSpentByCreditCard = $orderModule->getSolver()->getAmountTotalSpentByMeanPayment($order, MeanPayment::CREDIT_CARD);
$sumAmountTotalSpentByCreditCard += $amountTotalSpentByCreditCard;

$datas[] = [
$order->distribution->date,
$orderModule->getSolver()->getOrderUsername($order),
$orderModule->getSolver()->getOrderAmountWithTax($order),
$order->invoice ? $order->invoice->reference : 'Non',
$orderModule->getSolver()->getAmountTotalByMeanPayment($order, MeanPayment::CREDIT),
$orderModule->getSolver()->getAmountTotalByMeanPayment($order, MeanPayment::MONEY),
$orderModule->getSolver()->getAmountTotalByMeanPayment($order, MeanPayment::CHEQUE),
$orderModule->getSolver()->getAmountTotalByMeanPayment($order, MeanPayment::TRANSFER),
$orderModule->getSolver()->getAmountTotalByMeanPayment($order, MeanPayment::CREDIT_CARD),
count($order->payment) . ' : '.$strPayment
CSV::formatNumber($orderModule->getSolver()->getOrderAmountWithTax($order)),
$referenceInvoice,
$hasInvoice ? '' : CSV::formatNumber($amountTotalSpentByCredit),
$hasInvoice ? '' : CSV::formatNumber($amountTotalSpentByMoney),
$hasInvoice ? '' : CSV::formatNumber($amountTotalSpentByCheque),
$hasInvoice ? '' : CSV::formatNumber($amountTotalSpentByTransfer),
$hasInvoice ? '' : CSV::formatNumber($amountTotalSpentByCreditCard)
];

//print_r($order->payment);
//die();
}

$datas[] = [
'',
'',
'',
'Totaux paiements',
CSV::formatNumber($sumAmountTotalSpentByCredit),
CSV::formatNumber($sumAmountTotalSpentByMoney),
CSV::formatNumber($sumAmountTotalSpentByCheque),
CSV::formatNumber($sumAmountTotalSpentByTransfer),
CSV::formatNumber($sumAmountTotalSpentByCreditCard),
CSV::formatNumber($sumAmountTotalSpentByCredit + $sumAmountTotalSpentByMoney + $sumAmountTotalSpentByCheque +
$sumAmountTotalSpentByTransfer + $sumAmountTotalSpentByCreditCard)
];

CSV::send('commandes.csv', $datas);
}


+ 0
- 1
domain/Document/Invoice/InvoiceSolver.php View File

@@ -23,5 +23,4 @@ class InvoiceSolver extends DocumentSolver
{
return $this->getInvoiceAmountPaid($invoice) >= Price::numberTwoDecimals($this->getAmountWithTax($invoice, Order::INVOICE_AMOUNT_TOTAL));
}

}

+ 7
- 2
domain/Order/Order/OrderSolver.php View File

@@ -529,13 +529,18 @@ class OrderSolver extends AbstractService implements SolverInterface
return '';
}

public function getAmountTotalByMeanPayment(Order $order, string $meanPayment)
public function getAmountTotalSpentByMeanPayment(Order $order, string $meanPayment)
{
$amount = 0;

foreach($order->payment as $payment) {
if($this->paymentSolver->isMeanPayment($payment, $meanPayment)) {
$amount += $payment->getAmount();
if($this->paymentSolver->isTypeDebit($payment)) {
$amount += $payment->getAmount();
}
else {
$amount -= $payment->getAmount();
}
}
}


+ 1
- 1
domain/Payment/PaymentSolver.php View File

@@ -105,7 +105,7 @@ class PaymentSolver extends AbstractService implements SolverInterface

public function isMeanPayment(Payment $payment, string $meanPayment): bool
{
return $payment->mean_payment == $payment;
return $payment->mean_payment == $meanPayment;
}

public function getStrMeanPayment(Payment $payment): string

Loading…
Cancel
Save