|
|
|
|
|
|
|
|
use common\helpers\Price; |
|
|
use common\helpers\Price; |
|
|
use domain\Order\Order\OrderRepositoryQuery; |
|
|
use domain\Order\Order\OrderRepositoryQuery; |
|
|
use domain\Order\OrderStatus\OrderStatus; |
|
|
use domain\Order\OrderStatus\OrderStatus; |
|
|
|
|
|
use backend\forms\ReportPaymentsForm; |
|
|
use Yii; |
|
|
use Yii; |
|
|
use yii\filters\AccessControl; |
|
|
use yii\filters\AccessControl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $condition; |
|
|
return $condition; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionPayments(string $dateStart, string $dateEnd) |
|
|
|
|
|
|
|
|
public function actionPayments() |
|
|
{ |
|
|
{ |
|
|
$orderModule = $this->getOrderModule(); |
|
|
|
|
|
$ordersArray = $orderModule->getRepository() |
|
|
|
|
|
->findOrdersByPeriod( |
|
|
|
|
|
new \DateTime($dateStart), |
|
|
|
|
|
new \DateTime($dateEnd) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$datas = [ |
|
|
|
|
|
[ |
|
|
|
|
|
'Date', |
|
|
|
|
|
'Client', |
|
|
|
|
|
'Montant', |
|
|
|
|
|
'Facture', |
|
|
|
|
|
'Crédit', |
|
|
|
|
|
'Espèce', |
|
|
|
|
|
'Chèque', |
|
|
|
|
|
'Virement', |
|
|
|
|
|
'Carte bancaire', |
|
|
|
|
|
'Total' |
|
|
|
|
|
] |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
$dateStart = $dateEnd = null; |
|
|
|
|
|
$reportPaymentsForm = new ReportPaymentsForm(); |
|
|
|
|
|
if($reportPaymentsForm->load(Yii::$app->request->post()) && $reportPaymentsForm->validate()) { |
|
|
|
|
|
$dateStart = date('Y-m-d', strtotime(str_replace('/', '-', $reportPaymentsForm->date_start))); |
|
|
|
|
|
$dateEnd = date('Y-m-d', strtotime(str_replace('/', '-', $reportPaymentsForm->date_end))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if($dateStart && $dateEnd) { |
|
|
|
|
|
$orderModule = $this->getOrderModule(); |
|
|
|
|
|
$ordersArray = $orderModule->getRepository() |
|
|
|
|
|
->findOrdersByPeriod( |
|
|
|
|
|
new \DateTime($dateStart), |
|
|
|
|
|
new \DateTime($dateEnd) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
$sumAmountTotalSpentByCredit = 0; |
|
|
|
|
|
$sumAmountTotalSpentByMoney = 0; |
|
|
|
|
|
$sumAmountTotalSpentByCheque = 0; |
|
|
|
|
|
$sumAmountTotalSpentByTransfer = 0; |
|
|
|
|
|
$sumAmountTotalSpentByCreditCard = 0; |
|
|
|
|
|
|
|
|
$datas = [ |
|
|
|
|
|
[ |
|
|
|
|
|
'Date', |
|
|
|
|
|
'Client', |
|
|
|
|
|
'Montant', |
|
|
|
|
|
'Facture', |
|
|
|
|
|
'Crédit', |
|
|
|
|
|
'Espèce', |
|
|
|
|
|
'Chèque', |
|
|
|
|
|
'Virement', |
|
|
|
|
|
'Carte bancaire', |
|
|
|
|
|
'Total' |
|
|
|
|
|
] |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
foreach($ordersArray as $order) { |
|
|
|
|
|
$orderModule->getBuilder()->initOrder($order); |
|
|
|
|
|
|
|
|
$sumAmountTotalSpentByCredit = 0; |
|
|
|
|
|
$sumAmountTotalSpentByMoney = 0; |
|
|
|
|
|
$sumAmountTotalSpentByCheque = 0; |
|
|
|
|
|
$sumAmountTotalSpentByTransfer = 0; |
|
|
|
|
|
$sumAmountTotalSpentByCreditCard = 0; |
|
|
|
|
|
|
|
|
$hasInvoice = false; |
|
|
|
|
|
$referenceInvoice = 'Non'; |
|
|
|
|
|
if($order->invoice) { |
|
|
|
|
|
$hasInvoice = true; |
|
|
|
|
|
$referenceInvoice = $order->invoice->reference.""; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
foreach($ordersArray as $order) { |
|
|
|
|
|
$orderModule->getBuilder()->initOrder($order); |
|
|
|
|
|
|
|
|
|
|
|
$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; |
|
|
|
|
|
|
|
|
$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[] = [ |
|
|
|
|
|
$order->distribution->date, |
|
|
|
|
|
$orderModule->getSolver()->getOrderUsername($order), |
|
|
|
|
|
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) |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$datas[] = [ |
|
|
$datas[] = [ |
|
|
$order->distribution->date, |
|
|
|
|
|
$orderModule->getSolver()->getOrderUsername($order), |
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
'', |
|
|
|
|
|
'', |
|
|
|
|
|
'', |
|
|
|
|
|
'Totaux paiements', |
|
|
|
|
|
CSV::formatNumber($sumAmountTotalSpentByCredit), |
|
|
|
|
|
CSV::formatNumber($sumAmountTotalSpentByMoney), |
|
|
|
|
|
CSV::formatNumber($sumAmountTotalSpentByCheque), |
|
|
|
|
|
CSV::formatNumber($sumAmountTotalSpentByTransfer), |
|
|
|
|
|
CSV::formatNumber($sumAmountTotalSpentByCreditCard), |
|
|
|
|
|
CSV::formatNumber($sumAmountTotalSpentByCredit + $sumAmountTotalSpentByMoney + $sumAmountTotalSpentByCheque + |
|
|
|
|
|
$sumAmountTotalSpentByTransfer + $sumAmountTotalSpentByCreditCard) |
|
|
]; |
|
|
]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$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); |
|
|
|
|
|
|
|
|
return $this->render('payments', [ |
|
|
|
|
|
'reportPaymentsForm' => $reportPaymentsForm |
|
|
|
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |