Przeglądaj źródła

[Administration] Rapport paiements

feature/rotating_product
Guillaume Bourgeois 7 miesięcy temu
rodzic
commit
175a08e5c0
5 zmienionych plików z 92 dodań i 0 usunięć
  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 Wyświetl plik

@@ -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 Wyświetl plik

@@ -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 Wyświetl plik

@@ -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 Wyświetl plik

@@ -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 Wyświetl plik

@@ -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());

Ładowanie…
Anuluj
Zapisz