Commit c0b30c38 by Damien Moulard

caissier can see the total amount of the transactions received since last fetch

parent c8a82722
...@@ -5,20 +5,25 @@ namespace App\Controller; ...@@ -5,20 +5,25 @@ namespace App\Controller;
use App\Entity\Groupe; use App\Entity\Groupe;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use App\Entity\Rubrique; use App\Entity\Rubrique;
use App\Entity\Flux;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\RouterInterface;
class PrestatairesController extends FrontController class PrestatairesController extends FrontController
{ {
protected $em; protected $em;
private $router; private $router;
private $session;
public function __construct(EntityManagerInterface $em, RouterInterface $router) public function __construct(EntityManagerInterface $em, RouterInterface $router, SessionInterface $session)
{ {
$this->em = $em; $this->em = $em;
$this->router = $router; $this->router = $router;
$this->session = $session;
} }
/** /**
...@@ -141,4 +146,50 @@ class PrestatairesController extends FrontController ...@@ -141,4 +146,50 @@ class PrestatairesController extends FrontController
'prestataires' => $this->em->getRepository(Prestataire::class)->findByRubrique($rubrique), 'prestataires' => $this->em->getRepository(Prestataire::class)->findByRubrique($rubrique),
]); ]);
} }
/**
* Get the total transactions amount towards the Prestataire since the last time it was fetched
*
* @Route("/prestataires/get_last_transactions", name="get_presta_last_transactions")
* @IsGranted({"ROLE_CAISSIER", "ROLE_PRESTATAIRE"})
*/
public function getLastTransactionsAmount()
{
if (!$this->session->has('_prestagere')) {
return null;
}
// Get last export datetime (presta creation if first export)
$presta = $this->em->getRepository(Prestataire::class)->findOneById($this->session->get('_prestagere')->getId());
$datetime_last_export = $presta->getLastTransactionsExportDatetime();
if (null == $datetime_last_export) {
$datetime_last_export = $presta->getCreatedAt();
}
// Get total amount
$flux = $this->em->getRepository(Flux::class)->getQueryByPrestataire(
$this->session->get('_prestagere'),
null,
null,
$datetime_last_export->format(("Y-m-d H:i:s"))
)->getResult();
$total_amount = 0;
foreach ($flux as $flux_item) {
$total_amount += $flux_item->getMontant();
}
// Set now as this presta last export date
$presta->setLastTransactionsExportDatetime(new \Datetime('now'));
$this->em->persist($presta);
$this->em->flush();
$str_datetime = $datetime_last_export->format('d/m/Y H\hi');
return $this->render('@kohinos/tav/last_transactions_amount.html.twig', [
'amount' => $total_amount,
'datetime_last_export' => $str_datetime
]);
}
} }
...@@ -301,6 +301,13 @@ class Prestataire extends AccountableObject implements AccountableInterface ...@@ -301,6 +301,13 @@ class Prestataire extends AccountableObject implements AccountableInterface
*/ */
private $comments; private $comments;
/**
* Caissiers can export all the transactions since the last export.
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastTransactionsExportDatetime;
public function __construct() public function __construct()
{ {
$this->users = new ArrayCollection(); $this->users = new ArrayCollection();
...@@ -1101,4 +1108,16 @@ class Prestataire extends AccountableObject implements AccountableInterface ...@@ -1101,4 +1108,16 @@ class Prestataire extends AccountableObject implements AccountableInterface
{ {
return 'mapcontentpresta'; return 'mapcontentpresta';
} }
public function getLastTransactionsExportDatetime(): ?\DateTimeInterface
{
return $this->lastTransactionsExportDatetime;
}
public function setLastTransactionsExportDatetime(?\DateTimeInterface $lastTransactionsExportDatetime): self
{
$this->lastTransactionsExportDatetime = $lastTransactionsExportDatetime;
return $this;
}
} }
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230111102816 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE prestataire ADD last_transactions_export_datetime DATETIME DEFAULT NULL, CHANGE iban iban LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:personal_data)\'');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE prestataire DROP last_transactions_export_datetime, CHANGE iban iban LONGTEXT CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_general_ci` COMMENT \'(DC2Type:personal_data)\'');
}
}
...@@ -29,10 +29,12 @@ class FluxRepository extends ServiceEntityRepository ...@@ -29,10 +29,12 @@ class FluxRepository extends ServiceEntityRepository
/** /**
* @param Prestataire $presta [description] * @param Prestataire $presta [description]
* @param string $parenttype Parent type of flux (cotisation, transfert, transaction, vente...) * @param string $parenttype Parent type of flux (cotisation, transfert, transaction, vente...)
* @param string $type Type of flux (cotisation, transfert, transaction, vente...)
* @param string $from Date from which to fetch the flux
* *
* @return Query Returns a query fo finding an array of Flux * @return Query Returns a query fo finding an array of Flux
*/ */
public function getQueryByPrestataire(Prestataire $presta, string $parenttype = null, string $type = null) public function getQueryByPrestataire(Prestataire $presta, string $parenttype = null, string $type = null, $from = null)
{ {
$sqlQuery = "SELECT f.id FROM {$this->tableName} f WHERE (f.prestataire_id = :id OR f.prestataire_dest_id = :id)"; $sqlQuery = "SELECT f.id FROM {$this->tableName} f WHERE (f.prestataire_id = :id OR f.prestataire_dest_id = :id)";
if (null != $parenttype) { if (null != $parenttype) {
...@@ -41,6 +43,9 @@ class FluxRepository extends ServiceEntityRepository ...@@ -41,6 +43,9 @@ class FluxRepository extends ServiceEntityRepository
if ($type != null) { if ($type != null) {
$sqlQuery .= " AND f.type = :type"; $sqlQuery .= " AND f.type = :type";
} }
if ($from != null) {
$sqlQuery .= " AND f.created_at >= :from";
}
$statement = $this->connection->prepare($sqlQuery); $statement = $this->connection->prepare($sqlQuery);
if (null != $parenttype) { if (null != $parenttype) {
$statement->bindValue(':type', $parenttype); $statement->bindValue(':type', $parenttype);
...@@ -48,6 +53,9 @@ class FluxRepository extends ServiceEntityRepository ...@@ -48,6 +53,9 @@ class FluxRepository extends ServiceEntityRepository
if ($type != null) { if ($type != null) {
$statement->bindValue(':type', $type); $statement->bindValue(':type', $type);
} }
if ($from != null) {
$statement->bindValue(':from', $from);
}
$statement->bindValue(':id', $presta->getId()); $statement->bindValue(':id', $presta->getId());
$statement->execute(); $statement->execute();
$results = $statement->fetchAll(); $results = $statement->fetchAll();
......
...@@ -104,6 +104,7 @@ class AppExtension extends AbstractExtension ...@@ -104,6 +104,7 @@ class AppExtension extends AbstractExtension
new \Twig_SimpleFunction('getPaymentReceiptUrlFromFlux', [$this, 'getPaymentReceiptUrlFromFlux']), new \Twig_SimpleFunction('getPaymentReceiptUrlFromFlux', [$this, 'getPaymentReceiptUrlFromFlux']),
new \Twig_SimpleFunction('getDonType', [$this, 'getDonType']), new \Twig_SimpleFunction('getDonType', [$this, 'getDonType']),
new \Twig_SimpleFunction('getLastTavCotisationForAdherent', [$this, 'getLastTavCotisationForAdherent']), new \Twig_SimpleFunction('getLastTavCotisationForAdherent', [$this, 'getLastTavCotisationForAdherent']),
new \Twig_SimpleFunction('getPrestaLastTransactionsExportDate', [$this, 'getPrestaLastTransactionsExportDate']),
new \Twig_SimpleFunction('parameter', function ($name) { new \Twig_SimpleFunction('parameter', function ($name) {
return $this->container->getParameter($name); return $this->container->getParameter($name);
}), }),
...@@ -525,4 +526,24 @@ class AppExtension extends AbstractExtension ...@@ -525,4 +526,24 @@ class AppExtension extends AbstractExtension
return str_replace('@', '&#64;', $email); return str_replace('@', '&#64;', $email);
} }
public function getPrestaLastTransactionsExportDate(?Adherent $adherent = null)
{
if (!$this->session->has('_prestagere')) {
return null;
}
$presta = $this->em->getRepository(Prestataire::class)->findOneById($this->session->get('_prestagere')->getId());
$datetime_last_export = $presta->getLastTransactionsExportDatetime();
$res = "";
if (null == $datetime_last_export) {
$res = $presta->getCreatedAt()->format('d/m/Y H\hi');
} else {
$res = $datetime_last_export->format('d/m/Y H\hi');
}
return $res;
}
} }
...@@ -3,5 +3,7 @@ ...@@ -3,5 +3,7 @@
{% include '@kohinos/block/solde.html.twig' with {'compte': getCurrentPrestataire().emlcAccount.balance, 'soldelabel': esoldelabel, 'currency' : 'e'~(KOH_MLC_SYMBOL|default(''))} %} {% include '@kohinos/block/solde.html.twig' with {'compte': getCurrentPrestataire().emlcAccount.balance, 'soldelabel': esoldelabel, 'currency' : 'e'~(KOH_MLC_SYMBOL|default(''))} %}
{% include '@kohinos/tav/block/encaisser_paiement.html.twig' %} {% include '@kohinos/tav/block/encaisser_paiement.html.twig' %}
{% endif %} {% include '@kohinos/tav/block/caissier_get_last_transactions.html.twig' with {'title': 'Transactions'} %}
{% include '@kohinos/block/transactions.html.twig' with {'title': 'Transactions'} %} {% else %}
\ No newline at end of file {% include '@kohinos/block/transactions.html.twig' with {'title': 'Transactions'} %}
{% endif %}
\ No newline at end of file
{% extends '@kohinos/block/block_collapse.html.twig' %}
{% block blocktitle %}
<i class="fa fa-list-alt mr-4"></i> {{'Transactions'|trans }}
{% endblock blocktitle %}
{% block blockcontent %}
{% set datetime_last_export = getPrestaLastTransactionsExportDate() %}
<p>Récupérer le montant total des transactions depuis le <b>{{ datetime_last_export }}</b></p>
<a class='btn btn-xs btn-primary mt-2' href='{{ path('get_presta_last_transactions') }}'>
{{ 'Exporter'|trans }}
</a>
{% endblock blockcontent %}
{% extends '@kohinos/common/layout.html.twig' %}
{% block content %}
<div class='container' style='max-width: 800px;'>
{% include '@kohinos/block/breadcrumb.html.twig' with {'label' : 'Total des transactions'} %}
<div class="text-center w-100">
<p style="font-size:1.1em">
Montant total des transactions depuis le {{ datetime_last_export }} : <b>{{ amount }} e-mlc</b>
</p>
</div>
</div>
{% endblock %}
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
{{ 'Nouvel encaissement'|trans }} {{ 'Nouvel encaissement'|trans }}
</a> </a>
</div> </div>
</div>
{% endblock %} {% endblock %}
{% block footer %}{% endblock footer %} {% block footer %}{% endblock footer %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment