Browse Source

[Administration] Statistiques : rapport paiements

feature/rotating_product
Guillaume Bourgeois 7 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

$resArray[] = [ $resArray[] = [
'name' => '', 'name' => '',
'quantity' => '', 'quantity' => '',
'total' => '<strong>' . Price::format(round($totalGlobal, 2)) . '</strong>',
'total' => '<strong>' . Price::format(round($totalGlobal, 2)) . ' HT</strong>',
]; ];


return $resArray; return $resArray;
public function actionPayments(string $dateStart, string $dateEnd) public function actionPayments(string $dateStart, string $dateEnd)
{ {
$orderModule = $this->getOrderModule(); $orderModule = $this->getOrderModule();
$paymentModule = $this->getPaymentModule();
$ordersArray = $orderModule->getRepository() $ordersArray = $orderModule->getRepository()
->findOrdersByPeriod( ->findOrdersByPeriod(
new \DateTime($dateStart), new \DateTime($dateStart),
] ]
]; ];


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

foreach($ordersArray as $order) { foreach($ordersArray as $order) {
$orderModule->getBuilder()->initOrder($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[] = [ $datas[] = [
$order->distribution->date, $order->distribution->date,
$orderModule->getSolver()->getOrderUsername($order), $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); CSV::send('commandes.csv', $datas);
} }



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

{ {
return $this->getInvoiceAmountPaid($invoice) >= Price::numberTwoDecimals($this->getAmountWithTax($invoice, Order::INVOICE_AMOUNT_TOTAL)); return $this->getInvoiceAmountPaid($invoice) >= Price::numberTwoDecimals($this->getAmountWithTax($invoice, Order::INVOICE_AMOUNT_TOTAL));
} }

} }

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

return ''; return '';
} }


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


foreach($order->payment as $payment) { foreach($order->payment as $payment) {
if($this->paymentSolver->isMeanPayment($payment, $meanPayment)) { 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



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


public function getStrMeanPayment(Payment $payment): string public function getStrMeanPayment(Payment $payment): string

Loading…
Cancel
Save