Commit 9497cdf1 by Damien Moulard

hide infos regarding standard cotisations & make all cotisations valid for all…

hide infos regarding standard cotisations & make all cotisations valid for all adherents and prestataires
parent 1667fb87
...@@ -200,7 +200,7 @@ sonata_admin: ...@@ -200,7 +200,7 @@ sonata_admin:
label: Ajouter label: Ajouter
roles: ['ROLE_SUPER_ADMIN', 'ROLE_ADMIN_ADHERENT_GERER_ALL', 'ROLE_ADMIN_ADHERENT_GERER_CREATE'] roles: ['ROLE_SUPER_ADMIN', 'ROLE_ADMIN_ADHERENT_GERER_ALL', 'ROLE_ADMIN_ADHERENT_GERER_CREATE']
- admin.adherent.gerer - admin.adherent.gerer
# - admin.adherent.cotisations - admin.adherent.cotisations
- admin.adherent.profilsdecotisation - admin.adherent.profilsdecotisation
sonata.admin.group.prestataire: sonata.admin.group.prestataire:
keep_open: false keep_open: false
...@@ -212,7 +212,7 @@ sonata_admin: ...@@ -212,7 +212,7 @@ sonata_admin:
label: Ajouter label: Ajouter
roles: ['ROLE_SUPER_ADMIN', 'ROLE_ADMIN_PRESTATAIRE_GERER_ALL', 'ROLE_ADMIN_PRESTATAIRE_GERER_CREATE'] roles: ['ROLE_SUPER_ADMIN', 'ROLE_ADMIN_PRESTATAIRE_GERER_ALL', 'ROLE_ADMIN_PRESTATAIRE_GERER_CREATE']
- admin.prestataire.gerer - admin.prestataire.gerer
# - admin.prestataire.cotisations - admin.prestataire.cotisations
- admin.groupepresta.gerer - admin.groupepresta.gerer
- admin.etatpresta.gerer - admin.etatpresta.gerer
- admin.rubrique.gerer - admin.rubrique.gerer
......
...@@ -111,17 +111,23 @@ services: ...@@ -111,17 +111,23 @@ services:
class: App\Utils\CotisationUtils class: App\Utils\CotisationUtils
autowire: false autowire: false
public: true public: true
arguments: ['@app.utils.custom_entity_manager', '@session', '@security.helper', '@event_dispatcher'] arguments: ['@app.utils.custom_entity_manager', '@session', '@security.helper', '@event_dispatcher', '@service_container']
app.utils.account: app.utils.account:
class: App\Utils\AccountUtils class: App\Utils\AccountUtils
autowire: false autowire: false
arguments: ['@doctrine.orm.entity_manager'] arguments: ['@doctrine.orm.entity_manager']
app.utils.tav_cotisations:
class: App\Utils\TAVCotisationUtils
autowire: false
public: true
arguments: ['@app.utils.custom_entity_manager', '@security.helper', '@app.utils.operations']
app.twig.main.extension: app.twig.main.extension:
class: App\Twig\AppExtension class: App\Twig\AppExtension
autowire: false autowire: false
arguments: ["@service_container", "@security.helper", "@doctrine.orm.entity_manager", "@knp_paginator", "@session", "@app.utils.operations", "@app.utils.cotisations"] arguments: ["@service_container", "@security.helper", "@doctrine.orm.entity_manager", "@knp_paginator", "@session", "@app.utils.operations", "@app.utils.cotisations", "@app.utils.tav_cotisations"]
app.twig.logentry.extension: app.twig.logentry.extension:
class: App\Twig\LogEntryExtension class: App\Twig\LogEntryExtension
......
...@@ -290,6 +290,10 @@ class AdherentAdmin extends AbstractAdmin ...@@ -290,6 +290,10 @@ class AdherentAdmin extends AbstractAdmin
'label' => 'Date de mise à jour', 'label' => 'Date de mise à jour',
]) ])
; ;
if ($this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$datagridMapper->remove('cotisationajour');
}
} }
public function getCotisationFilter($queryBuilder, $alias, $field, $value) public function getCotisationFilter($queryBuilder, $alias, $field, $value)
...@@ -387,14 +391,31 @@ class AdherentAdmin extends AbstractAdmin ...@@ -387,14 +391,31 @@ class AdherentAdmin extends AbstractAdmin
->addIdentifier('user.lastname', null, ['label' => 'Nom']) ->addIdentifier('user.lastname', null, ['label' => 'Nom'])
->addIdentifier('user.firstname', null, ['label' => 'Prénom']) ->addIdentifier('user.firstname', null, ['label' => 'Prénom'])
->addIdentifier('user.email', null, ['label' => 'Email']) ->addIdentifier('user.email', null, ['label' => 'Email'])
;
if (!$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$listMapper
->add( ->add(
'cotisation', 'cotisation',
null, null,
[ [
'label' => 'Dernière cotisation', 'label' => 'Cotisation à jour',
'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_user_cotisation.html.twig', 'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_user_cotisation.html.twig',
] ]
) );
} else {
$listMapper
->add(
'cotisation',
null,
[
'label' => 'Dernière cotisation',
'template' => '@kohinos/tav/list_user_tav_cotisation.html.twig',
]
);
}
$listMapper
->addIdentifier('groupe', null, [ ->addIdentifier('groupe', null, [
'label' => 'Groupe', 'label' => 'Groupe',
'sortable' => true, 'sortable' => true,
......
...@@ -144,7 +144,7 @@ class PrestataireAdmin extends AbstractAdmin ...@@ -144,7 +144,7 @@ class PrestataireAdmin extends AbstractAdmin
// ]); // ]);
} }
// Le prestataire "Monnaie Locale" représentant l'asso recevant les cotisations n'a pas de cotisations lui même ! // Le prestataire "Monnaie Locale" représentant l'asso recevant les cotisations n'a pas de cotisations lui même !
if (!$presta->isMlc()) { if (!$presta->isMlc() && !$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$menu->addChild('Ajouter une cotisation', [ $menu->addChild('Ajouter une cotisation', [
'uri' => $this->getConfigurationPool()->getContainer()->get('router')->generate('cotisation_prestataire_create', ['expediteur' => $id], UrlGeneratorInterface::ABSOLUTE_URL), 'uri' => $this->getConfigurationPool()->getContainer()->get('router')->generate('cotisation_prestataire_create', ['expediteur' => $id], UrlGeneratorInterface::ABSOLUTE_URL),
]); ]);
...@@ -519,6 +519,11 @@ class PrestataireAdmin extends AbstractAdmin ...@@ -519,6 +519,11 @@ class PrestataireAdmin extends AbstractAdmin
'advanced_filter' => false, 'advanced_filter' => false,
]) ])
; ;
if ($this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$datagridMapper->remove('cotisationajour');
$datagridMapper->remove('gestionnaireajour');
}
} }
public function getGestionnaireFilter($queryBuilder, $alias, $field, $value) public function getGestionnaireFilter($queryBuilder, $alias, $field, $value)
...@@ -692,7 +697,6 @@ class PrestataireAdmin extends AbstractAdmin ...@@ -692,7 +697,6 @@ class PrestataireAdmin extends AbstractAdmin
} }
} }
// listmappers for each environment (pro & tav_env) // listmappers for each environment (pro & tav_env)
if (!$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$listMapper $listMapper
->addIdentifier('raisonAndIdmlc', 'html', [ ->addIdentifier('raisonAndIdmlc', 'html', [
'label' => 'Raison', 'label' => 'Raison',
...@@ -748,42 +752,10 @@ class PrestataireAdmin extends AbstractAdmin ...@@ -748,42 +752,10 @@ class PrestataireAdmin extends AbstractAdmin
'actions' => $actions, 'actions' => $actions,
]) ])
; ;
} else {
$listMapper if ($this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
->addIdentifier('raisonAndIdmlc', 'html', [ $listMapper->remove('cotisation');
'label' => 'Raison', $listMapper->remove('users');
])
->add('groupe', null, [
'label' => 'Groupe',
'sortable' => true,
'sort_field_mapping' => ['fieldName' => 'name'],
'sort_parent_association_mappings' => [['fieldName' => 'groupe']],
])
->add('rubriques', null)
->add('etats', null, [
'label' => 'Tags',
])
->add('enabled', null, [
'label' => 'Activé',
'editable' => true,
])
->add('acceptemlc', null, [
'label' => 'Accepte e-mlc',
'editable' => true,
])
->add('createdAt', 'date', [
'pattern' => 'dd/MM/YYYY HH:mm',
'label' => 'Crée le',
])
->add('updatedAt', 'date', [
'pattern' => 'dd/MM/YYYY HH:mm',
'label' => 'Mis à jour le',
])
// You may also specify the actions you want to be displayed in the list
->add('_action', null, [
'actions' => $actions,
])
;
} }
} }
......
...@@ -264,4 +264,25 @@ class FluxRepository extends ServiceEntityRepository ...@@ -264,4 +264,25 @@ class FluxRepository extends ServiceEntityRepository
return $results; return $results;
} }
/**
* @param Adherent $adherent the user to look the cotisation for
*
* @return
*/
public function getLastTavCotisation($adherent)
{
$sqlQuery = "SELECT f.created_at
FROM {$this->tableName} f
WHERE f.type IN ('achat_monnaie_adherent', 'vente_emlc_adherent')
AND (f.adherent_id = :adh_id OR f.adherent_dest_id = :adh_id)
ORDER BY created_at DESC";
$statement = $this->connection->prepare($sqlQuery);
$statement->bindValue(':adh_id', $adherent->getId());
$statement->execute();
$results = $statement->fetchAll();
return $results;
}
} }
...@@ -27,6 +27,7 @@ use App\Enum\CurrencyEnum; ...@@ -27,6 +27,7 @@ use App\Enum\CurrencyEnum;
use App\Flux\AccountableInterface; use App\Flux\AccountableInterface;
use App\Utils\CotisationUtils; use App\Utils\CotisationUtils;
use App\Utils\OperationUtils; use App\Utils\OperationUtils;
use App\Utils\TAVCotisationUtils;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Model\UserInterface; use FOS\UserBundle\Model\UserInterface;
use Knp\Component\Pager\PaginatorInterface; use Knp\Component\Pager\PaginatorInterface;
...@@ -46,9 +47,18 @@ class AppExtension extends AbstractExtension ...@@ -46,9 +47,18 @@ class AppExtension extends AbstractExtension
public $session; public $session;
public $operationUtils; public $operationUtils;
public $cotisationUtils; public $cotisationUtils;
public $tavCotisationUtils;
public function __construct(ContainerInterface $container, Security $security, EntityManagerInterface $em, PaginatorInterface $paginator, SessionInterface $session, OperationUtils $operationUtils, CotisationUtils $cotisationUtils)
{ public function __construct(
ContainerInterface $container,
Security $security,
EntityManagerInterface $em,
PaginatorInterface $paginator,
SessionInterface $session,
OperationUtils $operationUtils,
CotisationUtils $cotisationUtils,
TAVCotisationUtils $tavCotisationUtils
) {
$this->em = $em; $this->em = $em;
$this->security = $security; $this->security = $security;
$this->container = $container; $this->container = $container;
...@@ -56,6 +66,7 @@ class AppExtension extends AbstractExtension ...@@ -56,6 +66,7 @@ class AppExtension extends AbstractExtension
$this->session = $session; $this->session = $session;
$this->operationUtils = $operationUtils; $this->operationUtils = $operationUtils;
$this->cotisationUtils = $cotisationUtils; $this->cotisationUtils = $cotisationUtils;
$this->tavCotisationUtils = $tavCotisationUtils;
} }
public function getFunctions() public function getFunctions()
...@@ -92,6 +103,7 @@ class AppExtension extends AbstractExtension ...@@ -92,6 +103,7 @@ class AppExtension extends AbstractExtension
new \Twig_SimpleFunction('getCurrencyName', [$this, 'getCurrencyName']), new \Twig_SimpleFunction('getCurrencyName', [$this, 'getCurrencyName']),
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('parameter', function ($name) { new \Twig_SimpleFunction('parameter', function ($name) {
return $this->container->getParameter($name); return $this->container->getParameter($name);
}), }),
...@@ -287,6 +299,18 @@ class AppExtension extends AbstractExtension ...@@ -287,6 +299,18 @@ class AppExtension extends AbstractExtension
return $this->cotisationUtils->isCotisationValidForAdherent($adherent); return $this->cotisationUtils->isCotisationValidForAdherent($adherent);
} }
/**
* [getLastTavCotisationForAdherent.
*
* @param Adherent|null $adherent
*
* @return bool|date
*/
public function getLastTavCotisationForAdherent(?Adherent $adherent = null)
{
return $this->tavCotisationUtils->getLastTavCotisationForAdherent($adherent);
}
public function isDevFixture(?string $username = null) public function isDevFixture(?string $username = null)
{ {
if (null == $username) { if (null == $username) {
......
...@@ -9,6 +9,7 @@ use FOS\UserBundle\Model\UserInterface; ...@@ -9,6 +9,7 @@ use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CotisationUtils class CotisationUtils
{ {
...@@ -16,13 +17,20 @@ class CotisationUtils ...@@ -16,13 +17,20 @@ class CotisationUtils
private $session; private $session;
private $security; private $security;
private $eventDispatcher; private $eventDispatcher;
private $container;
public function __construct(CustomEntityManager $em, SessionInterface $session, Security $security, EventDispatcherInterface $eventDispatcher)
{ public function __construct(
CustomEntityManager $em,
SessionInterface $session,
Security $security,
EventDispatcherInterface $eventDispatcher,
ContainerInterface $container
) {
$this->em = $em; $this->em = $em;
$this->session = $session; $this->session = $session;
$this->security = $security; $this->security = $security;
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
$this->container = $container;
} }
public function isUserCotisationExpired(UserInterface $user, int $nbDay = 30): bool public function isUserCotisationExpired(UserInterface $user, int $nbDay = 30): bool
...@@ -97,6 +105,11 @@ class CotisationUtils ...@@ -97,6 +105,11 @@ class CotisationUtils
*/ */
public function isCotisationValidForPresta(?Prestataire $presta) public function isCotisationValidForPresta(?Prestataire $presta)
{ {
// In TAV mode, cotisation is always valid. Return next year date.
if ($this->container->getParameter('tav_env')) {
return date('Y-m-d', strtotime('+1 year'));
}
$query = null; $query = null;
if (null !== $presta) { if (null !== $presta) {
$query = $this->em->getRepository(Flux::class)->getQueryByPrestataire($presta, 'cotisation'); $query = $this->em->getRepository(Flux::class)->getQueryByPrestataire($presta, 'cotisation');
...@@ -147,6 +160,11 @@ class CotisationUtils ...@@ -147,6 +160,11 @@ class CotisationUtils
*/ */
public function isCotisationValidForAdherent(?Adherent $adherent) public function isCotisationValidForAdherent(?Adherent $adherent)
{ {
// In TAV mode, cotisation is always valid. Return next year date.
if ($this->container->getParameter('tav_env')) {
return date('Y-m-d', strtotime('+1 year'));
}
$query = null; $query = null;
if (null !== $adherent) { if (null !== $adherent) {
$query = $this->em->getRepository(Flux::class)->getQueryByAdherent($adherent, 'cotisation'); $query = $this->em->getRepository(Flux::class)->getQueryByAdherent($adherent, 'cotisation');
...@@ -172,6 +190,11 @@ class CotisationUtils ...@@ -172,6 +190,11 @@ class CotisationUtils
*/ */
public function isCotisationValid(?UserInterface $user) public function isCotisationValid(?UserInterface $user)
{ {
// In TAV mode, cotisation is always valid. Return next year date.
if ($this->container->getParameter('tav_env')) {
return date('Y-m-d', strtotime('+1 year'));
}
$query = null; $query = null;
if (null === $user && null != $this->security->getUser()) { if (null === $user && null != $this->security->getUser()) {
if ($this->security->isGranted('ROLE_ADHERENT') && null != $this->security->getUser()->getAdherent()) { if ($this->security->isGranted('ROLE_ADHERENT') && null != $this->security->getUser()->getAdherent()) {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Utils; namespace App\Utils;
use App\Entity\Adherent;
use App\Entity\Siege; use App\Entity\Siege;
use App\Entity\Flux; use App\Entity\Flux;
use App\Entity\TauxCotisationReversement; use App\Entity\TauxCotisationReversement;
...@@ -88,4 +89,25 @@ class TAVCotisationUtils ...@@ -88,4 +89,25 @@ class TAVCotisationUtils
$this->em->persist($fluxCotis); $this->em->persist($fluxCotis);
$this->operationUtils->executeOperations($fluxCotis); $this->operationUtils->executeOperations($fluxCotis);
} }
/**
* Get the last cotisation of an adhérent
*
* @param Adherent $adherent
*
* @return bool|date
*/
public function getLastTavCotisationForAdherent(?Adherent $adherent)
{
$cotisations = [];
if (null !== $adherent) {
$cotisations = $this->em->getRepository(Flux::class)->getLastTavCotisation($adherent);
}
if (count($cotisations) > 0) {
return $cotisations[0]["created_at"];
}
return false;
}
} }
{% if false and not tav_env == isCotisationValid(app.user) %} {% if false == isCotisationValid(app.user) %}
<div class='text-danger mb-3'>{{ 'Si vous souhaitez utiliser les fonctionnalités de votre compte, vous devez avoir une cotisation valide !'|trans }}</div> <div class='text-danger mb-3'>{{ 'Si vous souhaitez utiliser les fonctionnalités de votre compte, vous devez avoir une cotisation valide !'|trans }}</div>
{% endif %} {% endif %}
......
{% extends admin.getTemplate('base_list_field') %}
{% block field %}
{%- spaceless %}
{% set cotisEnd = getLastTavCotisationForAdherent(object.user.adherent) %}
{% if false != cotisEnd %}
{% set text = cotisEnd|date('d/m/Y') %}
{% set class = 'label-success' %}
{% else %}
{% set text = 'aucune'|trans %}
{% set class = 'label-danger' %}
{% endif %}
<span class="label {{ class }}">{{ text }}</span>
{% endspaceless -%}
{% endblock %}
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