Project 'cooperatic/kohinos-tav' was moved to 'agplv3/kohinos-tav'. Please update any links and bookmarks that may still have the old path.
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:
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
......
......@@ -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),
]);
}
$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),
]);
if (!$this->getConfigurationPool()->getContainer()->getParameter('tav_env')) {
$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),
]);
}
}
/**
......@@ -288,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)
......@@ -385,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' => 'Cotisation à jour',
'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,
......
......@@ -21,6 +21,7 @@ use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Administration des cotisations.
......@@ -189,6 +190,14 @@ class CotisationAdmin extends AbstractAdmin
*/
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']);
$listMapper
->add('id', 'text', [
......
......@@ -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)
......@@ -691,60 +696,67 @@ class PrestataireAdmin extends AbstractAdmin
];
}
}
// listmappers for each environment (pro & tav_env)
$listMapper
->addIdentifier('raisonAndIdmlc', 'html', [
'label' => 'Raison',
])
->add('groupe', null, [
'label' => 'Groupe',
'sortable' => true,
'sort_field_mapping' => ['fieldName' => 'name'],
'sort_parent_association_mappings' => [['fieldName' => 'groupe']],
])
// ->addIdentifier('users', null, array('label' => 'Gestionnaires'))
->add('rubriques', null)
->add('etats', null, [
'label' => 'Tags',
// 'editable' => true,
// 'class' => EtatPrestataire::class,
// 'multiple' => true,
// // 'required' => false,
// // 'by_reference' => false,
// 'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(EtatPrestataire::class)->findBy(array('enabled' => true))
])
->add(
'cotisation',
null,
[
'label' => 'Cotisation à jour',
'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_presta_cotisation.html.twig',
]
)
->add('users', null, [
'label' => 'Gestionnaires [Cotisation à jour]',
'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_presta_gestionnaires.html.twig',
])
->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,
])
->addIdentifier('raisonAndIdmlc', 'html', [
'label' => 'Raison',
])
->add('groupe', null, [
'label' => 'Groupe',
'sortable' => true,
'sort_field_mapping' => ['fieldName' => 'name'],
'sort_parent_association_mappings' => [['fieldName' => 'groupe']],
])
// ->addIdentifier('users', null, array('label' => 'Gestionnaires'))
->add('rubriques', null)
->add('etats', null, [
'label' => 'Tags',
// 'editable' => true,
// 'class' => EtatPrestataire::class,
// 'multiple' => true,
// // 'required' => false,
// // 'by_reference' => false,
// 'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(EtatPrestataire::class)->findBy(array('enabled' => true))
])
->add(
'cotisation',
null,
[
'label' => 'Cotisation à jour',
'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_presta_cotisation.html.twig',
]
)
->add('users', null, [
'label' => 'Gestionnaires [Cotisation à jour]',
'template' => '@kohinos/bundles/SonataAdminBundle/CRUD/list_presta_gestionnaires.html.twig',
])
->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');
}
}
protected function configureRoutes(RouteCollection $collection)
......
......@@ -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, 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;
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, 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;
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, 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;
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;
}
}
{% 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