Browse Source

[Administration] Statistiques : rapport paiements

feature/rotating_product
Guillaume Bourgeois 5 months ago
parent
commit
6b42f3565f
5 changed files with 190 additions and 74 deletions
  1. +83
    -69
      backend/controllers/ReportController.php
  2. +35
    -0
      backend/forms/ReportPaymentsForm.php
  3. +1
    -0
      backend/views/layouts/left.php
  4. +70
    -0
      backend/views/report/payments.php
  5. +1
    -5
      backend/web/js/backend.js

+ 83
- 69
backend/controllers/ReportController.php View File

@@ -44,6 +44,7 @@ use common\helpers\MeanPayment;
use common\helpers\Price;
use domain\Order\Order\OrderRepositoryQuery;
use domain\Order\OrderStatus\OrderStatus;
use backend\forms\ReportPaymentsForm;
use Yii;
use yii\filters\AccessControl;

@@ -198,85 +199,98 @@ class ReportController extends BackendController
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[] = [
$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
]);
}

}

+ 35
- 0
backend/forms/ReportPaymentsForm.php View File

@@ -0,0 +1,35 @@
<?php

namespace backend\forms;

use yii\base\Model;

/**
* UploadForm is the model behind the upload form.
*/
class ReportPaymentsForm extends Model
{
var $date_start;
var $date_end;

/**
* @return array the validation rules.
*/
public function rules()
{
return [
[['date_start', 'date_end'], 'required'],
[['date_start', 'date_end'], 'safe'],
];
}

public function attributeLabels()
{
return [
'date_start' => "Date de début",
'date_end' => "Date de fin"
];
}
}

?>

+ 1
- 0
backend/views/layouts/left.php View File

@@ -272,6 +272,7 @@ $isUserCurrentGrantedAsProducer = $userModule->getAuthorizationChecker()->isGran
['label' => 'Chiffre d\'affaire', 'icon' => 'line-chart', 'url' => ['/stats/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Rapports', 'icon' => 'pencil-square-o', 'url' => ['/report/index'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Produits', 'icon' => 'table', 'url' => ['/stats/products'], 'visible' => $isUserCurrentGrantedAsProducer],
['label' => 'Export paiements', 'icon' => 'euro', 'url' => ['/report/payments'], 'visible' => $isUserCurrentGrantedAsProducer],
],
],
['label' => 'Paramètres', 'icon' => 'cog', 'url' => ['/producer/update'], 'visible' => $isUserCurrentGrantedAsProducer],

+ 70
- 0
backend/views/report/payments.php View File

@@ -0,0 +1,70 @@
<?php

/**
Copyright Souke (2018)

contact@souke.fr

Ce logiciel est un programme informatique servant à aider les producteurs
à distribuer leur production en circuits courts.

Ce logiciel est régi par la licence CeCILL soumise au droit français et
respectant les principes de diffusion des logiciels libres. Vous pouvez
utiliser, modifier et/ou redistribuer ce programme sous les conditions
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
sur le site "http://www.cecill.info".

En contrepartie de l'accessibilité au code source et des droits de copie,
de modification et de redistribution accordés par cette licence, il n'est
offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
seule une responsabilité restreinte pèse sur l'auteur du programme, le
titulaire des droits patrimoniaux et les concédants successifs.

A cet égard l'attention de l'utilisateur est attirée sur les risques
associés au chargement, à l'utilisation, à la modification et/ou au
développement et à la reproduction du logiciel par l'utilisateur étant
donné sa spécificité de logiciel libre, qui peut le rendre complexe à
manipuler et qui le réserve donc à des développeurs et des professionnels
avertis possédant des connaissances informatiques approfondies. Les
utilisateurs sont donc invités à charger et tester l'adéquation du
logiciel à leurs besoins dans des conditions permettant d'assurer la
sécurité de leurs systèmes et ou de leurs données et, plus généralement,
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.

Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use yii\helpers\Html;
use yii\widgets\ActiveForm;

$this->setTitle('Paiements') ;
$this->addBreadcrumb('Paiements') ;

?>

<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<i class="fa fa-download"></i>
Export CSV des paiements
</h3>
</div>
<div class="panel-body">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($reportPaymentsForm, 'date_start')->textInput([
'class' => 'datepicker form-control'
]) ?>
<?= $form->field($reportPaymentsForm, 'date_end')->textInput([
'class' => 'datepicker form-control'
]) ?>
<?= Html::submitButton('Exporter', ['class' => 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>

</div>
</div>
</div>
</div>

+ 1
- 5
backend/web/js/backend.js View File

@@ -37,7 +37,6 @@
$(document).ready(function () {
opendistrib_datepicker();
opendistrib_popover();
opendistrib_commandeauto();
opendistrib_points_vente_acces();
opendistrib_tooltip();
opendistrib_ordre_produits();
@@ -491,10 +490,6 @@ function opendistrib_points_vente_acces_event() {
}
}

function opendistrib_commandeauto() {
$('#subscriptionform-date_begin, #subscriptionform-date_end').datepicker();
}

function opendistrib_sortable_list(element_selector, button_selector, route_ajax) {
var fixHelper = function (e, ui) {
ui.children().each(function () {
@@ -579,6 +574,7 @@ function opendistrib_features_index() {
}

function opendistrib_datepicker() {
$('#subscriptionform-date_begin, #subscriptionform-date_end').datepicker();
$('input.datepicker').datepicker({dateFormat: 'dd/mm/yy'});
}


Loading…
Cancel
Save