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:
label: Ajouter
roles: ['ROLE_SUPER_ADMIN', 'ROLE_ADMIN_ADHERENT_GERER_ALL', 'ROLE_ADMIN_ADHERENT_GERER_CREATE']
- admin.adherent.gerer
# - admin.adherent.cotisations
- admin.adherent.cotisations
- admin.adherent.profilsdecotisation
sonata.admin.group.prestataire:
keep_open: false
......@@ -212,7 +212,7 @@ sonata_admin:
label: Ajouter
roles: ['ROLE_SUPER_ADMIN', 'ROLE_ADMIN_PRESTATAIRE_GERER_ALL', 'ROLE_ADMIN_PRESTATAIRE_GERER_CREATE']
- admin.prestataire.gerer
# - admin.prestataire.cotisations
- admin.prestataire.cotisations
- admin.groupepresta.gerer
- admin.etatpresta.gerer
- admin.rubrique.gerer
......
......@@ -111,17 +111,23 @@ services:
class: App\Utils\CotisationUtils
autowire: false
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:
class: App\Utils\AccountUtils
autowire: false
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:
class: App\Twig\AppExtension
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:
class: App\Twig\LogEntryExtension
......
......@@ -290,6 +290,10 @@ class AdherentAdmin extends AbstractAdmin
'label' => 'Date de mise à jour',
])
;
if ($this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$datagridMapper->remove('cotisationajour');
}
}
public function getCotisationFilter($queryBuilder, $alias, $field, $value)
......@@ -387,14 +391,31 @@ class AdherentAdmin extends AbstractAdmin
->addIdentifier('user.lastname', null, ['label' => 'Nom'])
->addIdentifier('user.firstname', null, ['label' => 'Prénom'])
->addIdentifier('user.email', null, ['label' => 'Email'])
->add(
'cotisation',
null,
[
'label' => 'Dernière cotisation',
'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_user_cotisation.html.twig',
]
)
;
if (!$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$listMapper
->add(
'cotisation',
null,
[
'label' => 'Cotisation à jour',
'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, [
'label' => 'Groupe',
'sortable' => true,
......
......@@ -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 !
if (!$presta->isMlc()) {
if (!$presta->isMlc() && !$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$menu->addChild('Ajouter une cotisation', [
'uri' => $this->getConfigurationPool()->getContainer()->get('router')->generate('cotisation_prestataire_create', ['expediteur' => $id], UrlGeneratorInterface::ABSOLUTE_URL),
]);
......@@ -519,6 +519,11 @@ class PrestataireAdmin extends AbstractAdmin
'advanced_filter' => false,
])
;
if ($this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$datagridMapper->remove('cotisationajour');
$datagridMapper->remove('gestionnaireajour');
}
}
public function getGestionnaireFilter($queryBuilder, $alias, $field, $value)
......@@ -692,8 +697,7 @@ class PrestataireAdmin extends AbstractAdmin
}
}
// listmappers for each environment (pro & tav_env)
if (!$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$listMapper
$listMapper
->addIdentifier('raisonAndIdmlc', 'html', [
'label' => 'Raison',
])
......@@ -747,43 +751,11 @@ class PrestataireAdmin extends AbstractAdmin
->add('_action', null, [
'actions' => $actions,
])
;
} else {
$listMapper
->addIdentifier('raisonAndIdmlc', 'html', [
'label' => 'Raison',
])
->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,
])
;
;
if ($this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$listMapper->remove('cotisation');
$listMapper->remove('users');
}
}
......
......@@ -264,4 +264,25 @@ class FluxRepository extends ServiceEntityRepository
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;
use App\Flux\AccountableInterface;
use App\Utils\CotisationUtils;
use App\Utils\OperationUtils;
use App\Utils\TAVCotisationUtils;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Model\UserInterface;
use Knp\Component\Pager\PaginatorInterface;
......@@ -46,9 +47,18 @@ class AppExtension extends AbstractExtension
public $session;
public $operationUtils;
public $cotisationUtils;
public function __construct(ContainerInterface $container, Security $security, EntityManagerInterface $em, PaginatorInterface $paginator, SessionInterface $session, OperationUtils $operationUtils, CotisationUtils $cotisationUtils)
{
public $tavCotisationUtils;
public function __construct(
ContainerInterface $container,
Security $security,
EntityManagerInterface $em,
PaginatorInterface $paginator,
SessionInterface $session,
OperationUtils $operationUtils,
CotisationUtils $cotisationUtils,
TAVCotisationUtils $tavCotisationUtils
) {
$this->em = $em;
$this->security = $security;
$this->container = $container;
......@@ -56,6 +66,7 @@ class AppExtension extends AbstractExtension
$this->session = $session;
$this->operationUtils = $operationUtils;
$this->cotisationUtils = $cotisationUtils;
$this->tavCotisationUtils = $tavCotisationUtils;
}
public function getFunctions()
......@@ -92,6 +103,7 @@ class AppExtension extends AbstractExtension
new \Twig_SimpleFunction('getCurrencyName', [$this, 'getCurrencyName']),
new \Twig_SimpleFunction('getPaymentReceiptUrlFromFlux', [$this, 'getPaymentReceiptUrlFromFlux']),
new \Twig_SimpleFunction('getDonType', [$this, 'getDonType']),
new \Twig_SimpleFunction('getLastTavCotisationForAdherent', [$this, 'getLastTavCotisationForAdherent']),
new \Twig_SimpleFunction('parameter', function ($name) {
return $this->container->getParameter($name);
}),
......@@ -287,6 +299,18 @@ class AppExtension extends AbstractExtension
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)
{
if (null == $username) {
......
......@@ -9,6 +9,7 @@ use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CotisationUtils
{
......@@ -16,13 +17,20 @@ class CotisationUtils
private $session;
private $security;
private $eventDispatcher;
public function __construct(CustomEntityManager $em, SessionInterface $session, Security $security, EventDispatcherInterface $eventDispatcher)
{
private $container;
public function __construct(
CustomEntityManager $em,
SessionInterface $session,
Security $security,
EventDispatcherInterface $eventDispatcher,
ContainerInterface $container
) {
$this->em = $em;
$this->session = $session;
$this->security = $security;
$this->eventDispatcher = $eventDispatcher;
$this->container = $container;
}
public function isUserCotisationExpired(UserInterface $user, int $nbDay = 30): bool
......@@ -97,6 +105,11 @@ class CotisationUtils
*/
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;
if (null !== $presta) {
$query = $this->em->getRepository(Flux::class)->getQueryByPrestataire($presta, 'cotisation');
......@@ -147,6 +160,11 @@ class CotisationUtils
*/
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;
if (null !== $adherent) {
$query = $this->em->getRepository(Flux::class)->getQueryByAdherent($adherent, 'cotisation');
......@@ -172,6 +190,11 @@ class CotisationUtils
*/
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;
if (null === $user && null != $this->security->getUser()) {
if ($this->security->isGranted('ROLE_ADHERENT') && null != $this->security->getUser()->getAdherent()) {
......
......@@ -2,6 +2,7 @@
namespace App\Utils;
use App\Entity\Adherent;
use App\Entity\Siege;
use App\Entity\Flux;
use App\Entity\TauxCotisationReversement;
......@@ -88,4 +89,25 @@ class TAVCotisationUtils
$this->em->persist($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>
{% 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