Commit 94c2f465 by Julien Jorry

Fix bug cotisations BO + front

parent 23cd4354
...@@ -129,7 +129,7 @@ services: ...@@ -129,7 +129,7 @@ services:
admin.adherent.cotisations: admin.adherent.cotisations:
class: App\Admin\CotisationAdherentAdmin class: App\Admin\CotisationAdherentAdmin
arguments: [~, App\Entity\Cotisation, ~] arguments: [~, App\Entity\CotisationAdherent, ~]
tags: tags:
- name: sonata.admin - name: sonata.admin
manager_type: orm manager_type: orm
...@@ -167,7 +167,7 @@ services: ...@@ -167,7 +167,7 @@ services:
admin.prestataire.cotisations: admin.prestataire.cotisations:
class: App\Admin\CotisationPrestataireAdmin class: App\Admin\CotisationPrestataireAdmin
arguments: [~, App\Entity\Cotisation, ~] arguments: [~, App\Entity\CotisationPrestataire, ~]
tags: tags:
- name: sonata.admin - name: sonata.admin
manager_type: orm manager_type: orm
......
...@@ -117,6 +117,8 @@ class AdherentAdmin extends AbstractAdmin ...@@ -117,6 +117,8 @@ class AdherentAdmin extends AbstractAdmin
} }
if (count($adherent->getUser()->getCotisations()) <= 0) { if (count($adherent->getUser()->getCotisations()) <= 0) {
$cotisation = new Cotisation(); $cotisation = new Cotisation();
$cotisation->setOperateur($adherent->getUser());
$cotisation->setExpediteur($adherent);
$cotisation->setDebut($now); $cotisation->setDebut($now);
$cotisation->setFin(new \DateTime('+ 1 year')); $cotisation->setFin(new \DateTime('+ 1 year'));
$adherent->getUser()->addCotisation($cotisation); $adherent->getUser()->addCotisation($cotisation);
......
...@@ -2,11 +2,15 @@ ...@@ -2,11 +2,15 @@
namespace App\Admin; namespace App\Admin;
use App\Entity\Adherent;
use App\Entity\User;
use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection; use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Show\ShowMapper; use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
class CotisationAdherentAdmin extends CotisationAdmin class CotisationAdherentAdmin extends CotisationAdmin
{ {
...@@ -26,7 +30,8 @@ class CotisationAdherentAdmin extends CotisationAdmin ...@@ -26,7 +30,8 @@ class CotisationAdherentAdmin extends CotisationAdmin
$user = $this->security->getUser(); $user = $this->security->getUser();
$query = parent::createQuery($context); $query = parent::createQuery($context);
$query->leftJoin($query->getRootAliases()[0] . '.operateur', 'u') $query->leftJoin($query->getRootAliases()[0] . '.operateur', 'u')
->andWhere('u.adherent IS NOT NULL') ->andWhere($query->getRootAliases()[0] .".type='cotisation_adherent'")
// ->andWhere('u.adherent IS NOT NULL')
; ;
if ($user->isGranted('ROLE_GESTION_GROUPE') || $user->isGranted('ROLE_CONTACT')) { if ($user->isGranted('ROLE_GESTION_GROUPE') || $user->isGranted('ROLE_CONTACT')) {
if (empty($user->getGroupesgere())) { if (empty($user->getGroupesgere())) {
...@@ -70,11 +75,23 @@ class CotisationAdherentAdmin extends CotisationAdmin ...@@ -70,11 +75,23 @@ class CotisationAdherentAdmin extends CotisationAdmin
{ {
$formMapper $formMapper
->with('Cotisation', ['class' => 'col-md-8']) ->with('Cotisation', ['class' => 'col-md-8'])
->add('operateur', null, array( ->add('reference', HiddenType::class, array(
'label' => 'Adhérent', 'data' => 'cotisation_adherent'
'disabled' => true ))
), array( ->add('type', HiddenType::class, array(
'admin_code' => 'admin.adherent.gerer' 'data' => 'cotisation_adherent'
))
->add('expediteur', EntityType::class, array(
'label' => 'Expéditeur',
'class' => Adherent::class,
'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Adherent::class)->findBy(array('enabled' => true)),
'placeholder' => 'Choisir un adhérent',
'required' => true,
))
->add('operateur', HiddenType::class, array(
'data' => $this->security->getUser()->getId(),
'entity_class' => User::class,
'em' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager()
)) ))
->end() ->end()
; ;
...@@ -96,8 +113,13 @@ class CotisationAdherentAdmin extends CotisationAdmin ...@@ -96,8 +113,13 @@ class CotisationAdherentAdmin extends CotisationAdmin
{ {
unset($this->listModes['mosaic']); unset($this->listModes['mosaic']);
$listMapper $listMapper
->addIdentifier('operateur.username', null, array('label' => 'Login')) ->addIdentifier('expediteur', null, array(
->addIdentifier('operateur.email', null, array('label' => 'Email')); 'label' => 'Adherent'
))
->addIdentifier('expediteur.user.email', null, array(
'label' => 'Email'
))
;
parent::configureListFields($listMapper); parent::configureListFields($listMapper);
} }
} }
...@@ -4,6 +4,7 @@ namespace App\Admin; ...@@ -4,6 +4,7 @@ namespace App\Admin;
use App\Entity\Adherent; use App\Entity\Adherent;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use App\Entity\Siege;
use App\Enum\MoyenEnum; use App\Enum\MoyenEnum;
use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper;
...@@ -11,9 +12,12 @@ use Sonata\AdminBundle\Datagrid\ListMapper; ...@@ -11,9 +12,12 @@ use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection; use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Show\ShowMapper; use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\Form\Extension\Core\Type\DateType;
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\Security\Core\Security;
class CotisationAdmin extends AbstractAdmin class CotisationAdmin extends AbstractAdmin
...@@ -21,6 +25,7 @@ class CotisationAdmin extends AbstractAdmin ...@@ -21,6 +25,7 @@ class CotisationAdmin extends AbstractAdmin
protected $baseRouteName = 'cotisation'; protected $baseRouteName = 'cotisation';
protected $baseRoutePattern = 'cotisation'; protected $baseRoutePattern = 'cotisation';
protected $security; protected $security;
protected $container;
protected $translator; protected $translator;
protected $datagridValues = [ protected $datagridValues = [
...@@ -28,9 +33,10 @@ class CotisationAdmin extends AbstractAdmin ...@@ -28,9 +33,10 @@ class CotisationAdmin extends AbstractAdmin
'_sort_by' => 'createdAt', '_sort_by' => 'createdAt',
]; ];
public function setSecurity(Security $security) public function setSecurity(Security $security, ContainerInterface $container)
{ {
$this->security = $security; $this->security = $security;
$this->container = $container;
} }
/** /**
...@@ -56,8 +62,20 @@ class CotisationAdmin extends AbstractAdmin ...@@ -56,8 +62,20 @@ class CotisationAdmin extends AbstractAdmin
$now = new \DateTime(); $now = new \DateTime();
$formMapper $formMapper
->with('Cotisation', ['class' => 'col-md-8']) ->with('Cotisation', ['class' => 'col-md-8'])
->add('parenttype', HiddenType::class, array(
'data' => 'cotisation'
))
->add('destinataire', HiddenType::class, array(
'data' => 1,
'data_class' => null,
'entity_class' => Siege::class,
'em' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager()
))
->add('cotisationInfos.annee', null, array('label' => 'Année', 'data' => $now->format('Y'))) ->add('cotisationInfos.annee', null, array('label' => 'Année', 'data' => $now->format('Y')))
->add('montant', null, array('label' => 'Montant')) ->add('montant', MoneyType::class, array(
'label' => 'Montant',
'data' => $this->container->getParameter('cotisation_montant')
))
->add('moyen', ChoiceType::class, array( ->add('moyen', ChoiceType::class, array(
'required' => true, 'required' => true,
'choices' => MoyenEnum::getAvailableTypes(), 'choices' => MoyenEnum::getAvailableTypes(),
...@@ -93,7 +111,7 @@ class CotisationAdmin extends AbstractAdmin ...@@ -93,7 +111,7 @@ class CotisationAdmin extends AbstractAdmin
protected function configureRoutes(RouteCollection $collection) protected function configureRoutes(RouteCollection $collection)
{ {
$collection->remove('delete'); $collection->remove('delete');
if ($this->security->getUser() != null && !$this->security->getUser()->isGranted('ROLE_TRESORIER')) { if ($this->security->getUser() != null && !($this->security->getUser()->isGranted('ROLE_TRESORIER') || $this->security->getUser()->isGranted('ROLE_SUPER_ADMIN'))) {
$collection->clearExcept('list'); $collection->clearExcept('list');
} }
} }
...@@ -105,14 +123,22 @@ class CotisationAdmin extends AbstractAdmin ...@@ -105,14 +123,22 @@ class CotisationAdmin extends AbstractAdmin
{ {
unset($this->listModes['mosaic']); unset($this->listModes['mosaic']);
$listMapper $listMapper
->addIdentifier('cotisationInfos.annee', null, array(
'label' => 'Année'
))
->addIdentifier('montant', null, array(
'label' => 'Montant'
))
->addIdentifier('moyen', null, array(
'label' => 'Moyen'
))
->addIdentifier('createdAt', null, array(
'label' => 'Crée le'
))
->addIdentifier('operateur', null, array( ->addIdentifier('operateur', null, array(
'label' => 'Opérateur', 'label' => 'Opérateur',
'disabled' => true 'disabled' => true
)) ))
->addIdentifier('cotisationInfos.annee')
->addIdentifier('montant')
->addIdentifier('moyen')
->addIdentifier('createdAt')
; ;
} }
} }
...@@ -2,17 +2,27 @@ ...@@ -2,17 +2,27 @@
namespace App\Admin; namespace App\Admin;
use App\Entity\Prestataire;
use App\Entity\User;
use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection; use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Show\ShowMapper; use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
class CotisationPrestataireAdmin extends CotisationAdmin class CotisationPrestataireAdmin extends CotisationAdmin
{ {
protected $baseRouteName = 'cotisation_prestataire'; protected $baseRouteName = 'cotisation_prestataire';
protected $baseRoutePattern = 'cotisation_prestataire'; protected $baseRoutePattern = 'cotisation_prestataire';
public function configure()
{
parent::configure();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -21,7 +31,8 @@ class CotisationPrestataireAdmin extends CotisationAdmin ...@@ -21,7 +31,8 @@ class CotisationPrestataireAdmin extends CotisationAdmin
$user = $this->security->getUser(); $user = $this->security->getUser();
$query = parent::createQuery($context); $query = parent::createQuery($context);
$query->leftJoin($query->getRootAliases()[0] . '.operateur', 'u') $query->leftJoin($query->getRootAliases()[0] . '.operateur', 'u')
->andWhere('u.prestataire IS NOT NULL') ->andWhere($query->getRootAliases()[0] .".type='cotisation_prestataire'")
// ->andWhere('u.prestataire IS NOT NULL')
; ;
if ($user->isGranted('ROLE_GESTION_GROUPE') || $user->isGranted('ROLE_CONTACT')) { if ($user->isGranted('ROLE_GESTION_GROUPE') || $user->isGranted('ROLE_CONTACT')) {
if (empty($user->getGroupesgere())) { if (empty($user->getGroupesgere())) {
...@@ -58,6 +69,7 @@ class CotisationPrestataireAdmin extends CotisationAdmin ...@@ -58,6 +69,7 @@ class CotisationPrestataireAdmin extends CotisationAdmin
parent::configureDatagridFilters($datagridMapper); parent::configureDatagridFilters($datagridMapper);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -65,11 +77,23 @@ class CotisationPrestataireAdmin extends CotisationAdmin ...@@ -65,11 +77,23 @@ class CotisationPrestataireAdmin extends CotisationAdmin
{ {
$formMapper $formMapper
->with('Cotisation', ['class' => 'col-md-8']) ->with('Cotisation', ['class' => 'col-md-8'])
->add('operateur', null, array( ->add('reference', HiddenType::class, array(
'label' => 'Prestataire', 'data' => 'cotisation_prestataire'
'disabled' => true ))
), array( ->add('type', HiddenType::class, array(
'admin_code' => 'admin.prestataire.gerer' 'data' => 'cotisation_prestataire'
))
->add('expediteur', EntityType::class, array(
'label' => 'Expéditeur',
'class' => Prestataire::class,
'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Prestataire::class)->findBy(array('enabled' => true)),
'placeholder' => 'Choisir un prestataire',
'required' => true,
))
->add('operateur', HiddenType::class, array(
'data' => $this->security->getUser()->getId(),
'entity_class' => User::class,
'em' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager()
)) ))
->end() ->end()
; ;
...@@ -91,8 +115,8 @@ class CotisationPrestataireAdmin extends CotisationAdmin ...@@ -91,8 +115,8 @@ class CotisationPrestataireAdmin extends CotisationAdmin
{ {
unset($this->listModes['mosaic']); unset($this->listModes['mosaic']);
$listMapper $listMapper
->addIdentifier('operateur.username', null, array('label' => 'Login')) ->addIdentifier('expediteur', null, array('label' => 'Prestataire'))
->addIdentifier('operateur.email', null, array('label' => 'Email')); ->addIdentifier('expediteur.user.email', null, array('label' => 'Email'));
parent::configureListFields($listMapper); parent::configureListFields($listMapper);
} }
} }
...@@ -122,7 +122,7 @@ abstract class Flux ...@@ -122,7 +122,7 @@ abstract class Flux
/** /**
* @return User operateur * @return User operateur
*/ */
public function getOperateur(): User public function getOperateur(): ?User
{ {
return $this->operateur; return $this->operateur;
} }
......
...@@ -7,7 +7,6 @@ use App\Entity\Groupe; ...@@ -7,7 +7,6 @@ use App\Entity\Groupe;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use App\Entity\User; use App\Entity\User;
use App\Enum\MoyenEnum; use App\Enum\MoyenEnum;
use App\Form\Type\CotisationFormType;
use App\Form\Type\GeolocFormType; use App\Form\Type\GeolocFormType;
use App\Form\Type\RegistrationFormType; use App\Form\Type\RegistrationFormType;
use Doctrine\DBAL\Types\FloatType; use Doctrine\DBAL\Types\FloatType;
......
...@@ -7,8 +7,6 @@ use App\Entity\Groupe; ...@@ -7,8 +7,6 @@ use App\Entity\Groupe;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use App\Entity\User; use App\Entity\User;
use App\Enum\MoyenEnum; use App\Enum\MoyenEnum;
use App\Form\Type\AddCotisationFormType;
use App\Form\Type\CotisationFormType;
use App\Form\Type\GeolocFormType; use App\Form\Type\GeolocFormType;
use App\Form\Type\RegistrationFormType; use App\Form\Type\RegistrationFormType;
use Doctrine\DBAL\Types\FloatType; use Doctrine\DBAL\Types\FloatType;
......
...@@ -5,8 +5,10 @@ namespace App\Form\Type; ...@@ -5,8 +5,10 @@ namespace App\Form\Type;
use App\Entity\Cotisation; use App\Entity\Cotisation;
use App\Enum\MoyenEnum; use App\Enum\MoyenEnum;
use App\Form\Type\CotisationInfosFormType; use App\Form\Type\CotisationInfosFormType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
...@@ -17,6 +19,13 @@ class CotisationFormType extends FluxFormType ...@@ -17,6 +19,13 @@ class CotisationFormType extends FluxFormType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder $builder
->add('type', HiddenType::class, array(
'data' => 'cotisation',
'data_class' => null
))
->add('montant', MoneyType::class, array(
'label' => 'Montant',
))
->add('moyen', ChoiceType::class, array( ->add('moyen', ChoiceType::class, array(
'required' => true, 'required' => true,
'choices' => MoyenEnum::getAvailableTypes(), 'choices' => MoyenEnum::getAvailableTypes(),
...@@ -24,16 +33,12 @@ class CotisationFormType extends FluxFormType ...@@ -24,16 +33,12 @@ class CotisationFormType extends FluxFormType
return MoyenEnum::getTypeName($choice); return MoyenEnum::getTypeName($choice);
}, },
)) ))
->add('montant', HiddenType::class, array( ->add('recu', CheckboxType::class, array(
'data' => $this->getParameter('cotisation_montant'), 'label' => 'Reçu'
))
->add('cotisationInfos', CotisationInfosFormType::class, array(
'label' => 'Infos'
)) ))
->add('type', HiddenType::class, array(
'data' => 'cotisation',
'data_class' => null
));
// ->add('cotisationInfos', CotisationInfosFormType::class, array(
// 'label' => 'Infos'
// ))
; ;
} }
...@@ -49,10 +54,10 @@ class CotisationFormType extends FluxFormType ...@@ -49,10 +54,10 @@ class CotisationFormType extends FluxFormType
} }
public function getParent() // public function getParent()
{ // {
return FluxFormType::class; // return FluxFormType::class;
} // }
public function getBlockPrefix() public function getBlockPrefix()
{ {
......
...@@ -4,7 +4,6 @@ namespace App\Form\Type; ...@@ -4,7 +4,6 @@ namespace App\Form\Type;
use App\Entity\CotisationInfos; use App\Entity\CotisationInfos;
use App\Entity\User; use App\Entity\User;
use App\Form\Type\CotisationFormType;
use Doctrine\DBAL\Types\FloatType; use Doctrine\DBAL\Types\FloatType;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
......
...@@ -7,7 +7,6 @@ use App\Entity\Groupe; ...@@ -7,7 +7,6 @@ use App\Entity\Groupe;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use App\Entity\User; use App\Entity\User;
use App\Enum\MoyenEnum; use App\Enum\MoyenEnum;
use App\Form\Type\CotisationFormType;
use App\Form\Type\GeolocFormType; use App\Form\Type\GeolocFormType;
use App\Form\Type\RegistrationFormType; use App\Form\Type\RegistrationFormType;
use Doctrine\DBAL\Types\FloatType; use Doctrine\DBAL\Types\FloatType;
......
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