Browse Source

[Administration] Rapport paiements

feature/rotating_product
Guillaume Bourgeois 7 months ago
parent
commit
175a08e5c0
5 changed files with 92 additions and 0 deletions
  1. +55
    -0
      backend/controllers/ReportController.php
  2. +10
    -0
      domain/Order/Order/OrderRepository.php
  3. +9
    -0
      domain/Order/Order/OrderRepositoryQuery.php
  4. +13
    -0
      domain/Order/Order/OrderSolver.php
  5. +5
    -0
      domain/Payment/PaymentSolver.php

+ 55
- 0
backend/controllers/ReportController.php View File



namespace backend\controllers; namespace backend\controllers;


use common\helpers\CSV;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\MeanPayment;
use common\helpers\Price; use common\helpers\Price;
use Yii; use Yii;
use yii\filters\AccessControl; use yii\filters\AccessControl;
return $condition; return $condition;
} }


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

$datas = [
[
'Date',
'Client',
'Montant',
'Facture',
'Crédit',
'Espèce',
'Chèque',
'Virement',
'Carte bancaire',
'count paiements'
]
];

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

$strPayment = '';
foreach($order->payment as $payment) {
$strPayment .= $paymentModule->getSolver()->getStrMeanPayment($payment).', ';
}

$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
];

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

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

} }

+ 10
- 0
domain/Order/Order/OrderRepository.php View File

return $query->find(); return $query->find();
} }


public function findOrdersByPeriod(\DateTime $dateStart, \DateTime $dateEnd)
{
$query = $this->createDefaultQuery()
->filterByDistributionDateStartEnd($dateStart, $dateEnd)
->filterIsValid()
->orderBy('distribution.date ASC');

return $query->find();
}

public function findOrdersByUserAndInvoice(User $user, Invoice $invoice) public function findOrdersByUserAndInvoice(User $user, Invoice $invoice)
{ {
return $this return $this

+ 9
- 0
domain/Order/Order/OrderRepositoryQuery.php View File

return $this; return $this;
} }


public function filterByDistributionDateStartEnd(\DateTime $dateStart, \DateTime $dateEnd): self
{
$this
->andWhere('distribution.date >= \'' .$dateStart->format('Y-m-d').'\'')
->andWhere('distribution.date <= \'' .$dateEnd->format('Y-m-d').'\'');

return $this;
}

public function filterIsValid(): self public function filterIsValid(): self
{ {
$this->andWhere('date_delete IS NULL'); $this->andWhere('date_delete IS NULL');

+ 13
- 0
domain/Order/Order/OrderSolver.php View File



return ''; return '';
} }

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

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

return $amount;
}
} }

+ 5
- 0
domain/Payment/PaymentSolver.php View File

return $payment->mean_payment == MeanPayment::CREDIT; return $payment->mean_payment == MeanPayment::CREDIT;
} }


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

public function getStrMeanPayment(Payment $payment): string public function getStrMeanPayment(Payment $payment): string
{ {
return MeanPayment::getStrBy($payment->getMeanPayment()); return MeanPayment::getStrBy($payment->getMeanPayment());

Loading…
Cancel
Save