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