Commit fd30b467 by Yvon Kerdoncuff

Merge branch '4125-cotisation-hidden' into 'develop'

4125-cotisation-hidden

See merge request cooperatic/kohinos-tav!19
parents 928a32a7 45fe5e42
...@@ -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
......
...@@ -110,12 +110,14 @@ class AdherentAdmin extends AbstractAdmin ...@@ -110,12 +110,14 @@ class AdherentAdmin extends AbstractAdmin
'uri' => $this->getConfigurationPool()->getContainer()->get('router')->generate('admin_app_user_edit', ['id' => $user->getId()], UrlGeneratorInterface::ABSOLUTE_URL), 'uri' => $this->getConfigurationPool()->getContainer()->get('router')->generate('admin_app_user_edit', ['id' => $user->getId()], UrlGeneratorInterface::ABSOLUTE_URL),
]); ]);
} }
$menu->addChild('Ajouter une cotisation', [ if (!$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
'uri' => $this->getConfigurationPool()->getContainer()->get('router')->generate('cotisation_adherent_create', ['expediteur' => $id], UrlGeneratorInterface::ABSOLUTE_URL), $menu->addChild('Ajouter une cotisation', [
]); 'uri' => $this->getConfigurationPool()->getContainer()->get('router')->generate('cotisation_adherent_create', ['expediteur' => $id], UrlGeneratorInterface::ABSOLUTE_URL),
$menu->addChild('Voir les cotisations', [ ]);
'uri' => $this->getConfigurationPool()->getContainer()->get('router')->generate('cotisation_adherent_list', ['filter' => ['expediteur' => ['value' => $id]]], UrlGeneratorInterface::ABSOLUTE_URL), $menu->addChild('Voir les cotisations', [
]); 'uri' => $this->getConfigurationPool()->getContainer()->get('router')->generate('cotisation_adherent_list', ['filter' => ['expediteur' => ['value' => $id]]], UrlGeneratorInterface::ABSOLUTE_URL),
]);
}
} }
/** /**
...@@ -288,6 +290,10 @@ class AdherentAdmin extends AbstractAdmin ...@@ -288,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)
...@@ -385,14 +391,31 @@ class AdherentAdmin extends AbstractAdmin ...@@ -385,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'])
->add( ;
'cotisation',
null, if (!$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
[ $listMapper
'label' => 'Cotisation à jour', ->add(
'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_user_cotisation.html.twig', '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, [ ->addIdentifier('groupe', null, [
'label' => 'Groupe', 'label' => 'Groupe',
'sortable' => true, 'sortable' => true,
......
...@@ -21,6 +21,7 @@ use Symfony\Component\Form\Extension\Core\Type\HiddenType; ...@@ -21,6 +21,7 @@ use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType; use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\Regex; use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\HttpFoundation\RedirectResponse;
/** /**
* Administration des cotisations. * Administration des cotisations.
...@@ -189,6 +190,14 @@ class CotisationAdmin extends AbstractAdmin ...@@ -189,6 +190,14 @@ class CotisationAdmin extends AbstractAdmin
*/ */
protected function configureListFields(ListMapper $listMapper) protected function configureListFields(ListMapper $listMapper)
{ {
// In TAV env, block access to standard cotisations admin.
// TODO: find a better way (eg. block access with App\EventListener\MenuBuilderListener?)
if ($this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$url = $this->getConfigurationPool()->getContainer()->get( 'router' )->generate( 'sonata_admin_dashboard' );
$redirection = new RedirectResponse( $url );
$redirection->send();
}
unset($this->listModes['mosaic']); unset($this->listModes['mosaic']);
$listMapper $listMapper
->add('id', 'text', [ ->add('id', 'text', [
......
...@@ -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)
...@@ -691,60 +696,67 @@ class PrestataireAdmin extends AbstractAdmin ...@@ -691,60 +696,67 @@ class PrestataireAdmin extends AbstractAdmin
]; ];
} }
} }
// listmappers for each environment (pro & tav_env)
$listMapper $listMapper
->addIdentifier('raisonAndIdmlc', 'html', [ ->addIdentifier('raisonAndIdmlc', 'html', [
'label' => 'Raison', 'label' => 'Raison',
]) ])
->add('groupe', null, [ ->add('groupe', null, [
'label' => 'Groupe', 'label' => 'Groupe',
'sortable' => true, 'sortable' => true,
'sort_field_mapping' => ['fieldName' => 'name'], 'sort_field_mapping' => ['fieldName' => 'name'],
'sort_parent_association_mappings' => [['fieldName' => 'groupe']], 'sort_parent_association_mappings' => [['fieldName' => 'groupe']],
]) ])
// ->addIdentifier('users', null, array('label' => 'Gestionnaires')) // ->addIdentifier('users', null, array('label' => 'Gestionnaires'))
->add('rubriques', null) ->add('rubriques', null)
->add('etats', null, [ ->add('etats', null, [
'label' => 'Tags', 'label' => 'Tags',
// 'editable' => true, // 'editable' => true,
// 'class' => EtatPrestataire::class, // 'class' => EtatPrestataire::class,
// 'multiple' => true, // 'multiple' => true,
// // 'required' => false, // // 'required' => false,
// // 'by_reference' => false, // // 'by_reference' => false,
// 'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(EtatPrestataire::class)->findBy(array('enabled' => true)) // 'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(EtatPrestataire::class)->findBy(array('enabled' => true))
]) ])
->add( ->add(
'cotisation', 'cotisation',
null, null,
[ [
'label' => 'Cotisation à jour', 'label' => 'Cotisation à jour',
'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_presta_cotisation.html.twig', 'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_presta_cotisation.html.twig',
] ]
)
->add('users', null, [ )
'label' => 'Gestionnaires [Cotisation à jour]', ->add('users', null, [
'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_presta_gestionnaires.html.twig', 'label' => 'Gestionnaires [Cotisation à jour]',
]) 'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_presta_gestionnaires.html.twig',
->add('enabled', null, [ ])
'label' => 'Activé', ->add('enabled', null, [
'editable' => true, 'label' => 'Activé',
]) 'editable' => true,
->add('acceptemlc', null, [ ])
'label' => 'Accepte e-mlc', ->add('acceptemlc', null, [
'editable' => true, 'label' => 'Accepte e-mlc',
]) 'editable' => true,
->add('createdAt', 'date', [ ])
'pattern' => 'dd/MM/YYYY HH:mm', ->add('createdAt', 'date', [
'label' => 'Crée le', 'pattern' => 'dd/MM/YYYY HH:mm',
]) 'label' => 'Crée le',
->add('updatedAt', 'date', [ ])
'pattern' => 'dd/MM/YYYY HH:mm', ->add('updatedAt', 'date', [
'label' => 'Mis à jour le', '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, [ // You may also specify the actions you want to be displayed in the list
'actions' => $actions, ->add('_action', null, [
]) 'actions' => $actions,
])
; ;
if ($this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$listMapper->remove('cotisation');
$listMapper->remove('users');
}
} }
protected function configureRoutes(RouteCollection $collection) protected function configureRoutes(RouteCollection $collection)
......
...@@ -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, no standard cotisation required. Return next year date to make all accounts valid.
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, no standard cotisation required. Return next year date to make all accounts valid.
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, no standard cotisation required. Return next year date to make all accounts valid.
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;
}
} }
{% 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