Commit 94c2f465 by Julien Jorry

Fix bug cotisations BO + front

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