Переглянути джерело

[Administration] Rapport paiements

feature/rotating_product
Guillaume Bourgeois 7 місяці тому
джерело
коміт
175a08e5c0
5 змінених файлів з 92 додано та 0 видалено
  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 Переглянути файл

@@ -38,7 +38,9 @@

namespace backend\controllers;

use common\helpers\CSV;
use common\helpers\GlobalParam;
use common\helpers\MeanPayment;
use common\helpers\Price;
use Yii;
use yii\filters\AccessControl;
@@ -176,4 +178,57 @@ class ReportController extends BackendController
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 Переглянути файл

@@ -139,6 +139,16 @@ class OrderRepository extends AbstractRepository
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)
{
return $this

+ 9
- 0
domain/Order/Order/OrderRepositoryQuery.php Переглянути файл

@@ -46,6 +46,15 @@ class OrderRepositoryQuery extends AbstractRepositoryQuery
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
{
$this->andWhere('date_delete IS NULL');

+ 13
- 0
domain/Order/Order/OrderSolver.php Переглянути файл

@@ -528,4 +528,17 @@ class OrderSolver extends AbstractService implements SolverInterface

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 Переглянути файл

@@ -103,6 +103,11 @@ class PaymentSolver extends AbstractService implements SolverInterface
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
{
return MeanPayment::getStrBy($payment->getMeanPayment());

Завантаження…
Відмінити
Зберегти