Commit 899e2e8d by Yvon

create btn independant from cotisation registering so that comptoir can register…

create btn independant from cotisation registering so that comptoir can register donations from adherent separately
parent f59dd2c0
...@@ -6,6 +6,7 @@ use App\Entity\Adherent; ...@@ -6,6 +6,7 @@ use App\Entity\Adherent;
use App\Entity\ChangeAdherentComptoir; use App\Entity\ChangeAdherentComptoir;
use App\Entity\ChangePrestataireComptoir; use App\Entity\ChangePrestataireComptoir;
use App\Entity\Comptoir; use App\Entity\Comptoir;
use App\Entity\DonAdherent;
use App\Entity\RetraitComptoirAdherent; use App\Entity\RetraitComptoirAdherent;
use App\Entity\RetraitComptoirPrestataire; use App\Entity\RetraitComptoirPrestataire;
use App\Entity\VenteComptoirAdherent; use App\Entity\VenteComptoirAdherent;
...@@ -14,6 +15,7 @@ use App\Entity\VenteEmlcComptoirAdherent; ...@@ -14,6 +15,7 @@ use App\Entity\VenteEmlcComptoirAdherent;
use App\Entity\VenteEmlcComptoirPrestataire; use App\Entity\VenteEmlcComptoirPrestataire;
use App\Form\Type\ChangeAdherentComptoirFormType; use App\Form\Type\ChangeAdherentComptoirFormType;
use App\Form\Type\ChangePrestataireComptoirFormType; use App\Form\Type\ChangePrestataireComptoirFormType;
use App\Form\Type\ComptoirEncaisserDonAdherentFormType;
use App\Form\Type\ComptoirInfosFormType; use App\Form\Type\ComptoirInfosFormType;
use App\Form\Type\RetraitComptoirAdherentFormType; use App\Form\Type\RetraitComptoirAdherentFormType;
use App\Form\Type\RetraitComptoirPrestataireFormType; use App\Form\Type\RetraitComptoirPrestataireFormType;
...@@ -243,4 +245,37 @@ class UserComptoirController extends FluxController ...@@ -243,4 +245,37 @@ class UserComptoirController extends FluxController
return $this->redirectToRoute('index'); return $this->redirectToRoute('index');
} }
/**
* @Route("/user/comptoir/encaisser/don/adherent/", name="comptoirEncaisserDonAdherent")
* @IsGranted("ROLE_COMPTOIR")
*/
public function comptoirEncaisserDonAdherentAction(Request $request)
{
$entity = new DonAdherent();
$entity->setOperateur($this->getUser());
$form = $this->createForm(ComptoirEncaisserDonAdherentFormType::class, $entity);
$form->handleRequest($request);
if ($form->isSubmitted()) {
if($form->isValid()) {
$flux = $form->getData();
$this->em->persist($flux);
$this->operationUtils->executeOperations($flux);
$this->em->flush();
$this->addFlash(
'success',
$this->translator->trans('Opération réussie !')
);
} else {
$this->addFlash(
'error',
$this->translator->trans('Erreur : le don n\'a pas été enregistré.')
);
}
}
return $this->redirectToRoute('index');
}
} }
...@@ -9,6 +9,7 @@ use App\Entity\AchatMonnaiePrestataire; ...@@ -9,6 +9,7 @@ use App\Entity\AchatMonnaiePrestataire;
use App\Entity\ChangeAdherentComptoir; use App\Entity\ChangeAdherentComptoir;
use App\Entity\ChangePrestataireComptoir; use App\Entity\ChangePrestataireComptoir;
use App\Entity\Comptoir; use App\Entity\Comptoir;
use App\Entity\DonAdherent;
use App\Entity\Groupe; use App\Entity\Groupe;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use App\Entity\Reconversion; use App\Entity\Reconversion;
...@@ -31,6 +32,7 @@ use App\Form\Type\AchatMonnaiePrestataireFormType; ...@@ -31,6 +32,7 @@ use App\Form\Type\AchatMonnaiePrestataireFormType;
use App\Form\Type\AdherentInfosFormType; use App\Form\Type\AdherentInfosFormType;
use App\Form\Type\ChangeAdherentComptoirFormType; use App\Form\Type\ChangeAdherentComptoirFormType;
use App\Form\Type\ChangePrestataireComptoirFormType; use App\Form\Type\ChangePrestataireComptoirFormType;
use App\Form\Type\ComptoirEncaisserDonAdherentFormType;
use App\Form\Type\ComptoirInfosFormType; use App\Form\Type\ComptoirInfosFormType;
use App\Form\Type\GroupeInfosFormType; use App\Form\Type\GroupeInfosFormType;
use App\Form\Type\GroupePrestataireInscriptionFormType; use App\Form\Type\GroupePrestataireInscriptionFormType;
...@@ -471,4 +473,17 @@ class FormFactory ...@@ -471,4 +473,17 @@ class FormFactory
return $form->createView(); return $form->createView();
} }
public function getComptoirEncaisserDonAdherentForm(User $user)
{
if (empty($user) || empty($this->session->get('_comptoirgere'))) {
throw new \Exception('[FORM 27] Opération impossible !');
}
$entity = new DonAdherent();
$entity->setOperateur($user);
$form = $this->ff->create(ComptoirEncaisserDonAdherentFormType::class, $entity, ['action' => $this->router->generate('comptoirEncaisserDonAdherent')]);
return $form->createView();
}
} }
<?php
namespace App\Form\Type;
use App\Entity\Adherent;
use App\Entity\DonAdherent;
use App\Entity\Prestataire;
use App\Enum\MoyenEnum;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
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\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
class ComptoirEncaisserDonAdherentFormType extends FluxFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (empty($this->security) || empty($this->security->getUser())) {
throw new \Exception('[FORM COMPTOIR ENCAISSEMENT DON ADHERENT] Opération impossible !');
}
$builder
->add('moyen', ChoiceType::class, [
'required' => true,
'choices' => MoyenEnum::getAvailableTypesComptoir(),
'choice_label' => function ($choice) {
return MoyenEnum::getTypeName($choice);
},
'expanded' => true,
'multiple' => false,
'label' => 'Sélectionnez un moyen de paiement :',
])
->add('destinataire', HiddenType::class, [
'data' => $this->em->getRepository(Prestataire::class)->findOneBy(['mlc' => true]),
'data_class' => null,
'entity_class' => Prestataire::class,
'em' => $this->em,
])
->add('montant', MoneyType::class, [
'data' => 0,
'label' => $this->container->getParameter('tav_env') ? "Don à la caisse alimentaire :" : "Don à l'association :",
'required' => false,
'constraints' => [
new GreaterThanOrEqual(['value' => 0]),
],
'attr' => ['autocomplete' => 'off']
])
->add('expediteur', EntityType::class, [
'class' => Adherent::class,
'choices' => $this->em->getRepository(Adherent::class)->findOrderByName(),
'placeholder' => $this->container->getParameter('tav_env') ? 'Habitant' : 'Adherent',
'required' => true,
'label' => $this->container->getParameter('tav_env') ? 'Habitant :' : 'Adherent :'
])
->add('reference', HiddenType::class, [
'data' => 'Don Adhérent'
])
->remove('save')
->add('save', SubmitType::class, [
'label' => 'Valider',
'attr' => [
// 'class' => 'btn-primary btn fluxSubmit', with fluxSubmit class, required attributes does not prevent incorrect form to be submit
'class' => 'btn-primary',
],
])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'class' => DonAdherent::class,
]);
}
public function getParent()
{
return FluxFormType::class;
}
public function getBlockPrefix()
{
return 'formComptoirEncaisserDonAdherent';
}
}
...@@ -54,7 +54,8 @@ class FormExtension extends AbstractExtension ...@@ -54,7 +54,8 @@ class FormExtension extends AbstractExtension
new \Twig_SimpleFunction('getTicketFixDestroyForm', [$this, 'getTicketFixDestroyForm']), new \Twig_SimpleFunction('getTicketFixDestroyForm', [$this, 'getTicketFixDestroyForm']),
new \Twig_SimpleFunction('getSetPaymentCodeForm', [$this, 'getSetPaymentCodeForm']), new \Twig_SimpleFunction('getSetPaymentCodeForm', [$this, 'getSetPaymentCodeForm']),
new \Twig_SimpleFunction('getComptoirEncaisserCotisationForm', [$this, 'getComptoirEncaisserCotisationForm']), new \Twig_SimpleFunction('getComptoirEncaisserCotisationForm', [$this, 'getComptoirEncaisserCotisationForm']),
new \Twig_SimpleFunction('getPayerCotisationTAVForm', [$this, 'getPayerCotisationTAVForm']) new \Twig_SimpleFunction('getPayerCotisationTAVForm', [$this, 'getPayerCotisationTAVForm']),
new \Twig_SimpleFunction('getComptoirEncaisserDonAdherentForm', [$this, 'getComptoirEncaisserDonAdherentForm'])
]; ];
} }
...@@ -217,4 +218,9 @@ class FormExtension extends AbstractExtension ...@@ -217,4 +218,9 @@ class FormExtension extends AbstractExtension
{ {
return $this->container->get('app.formfactory')->getPayerCotisationTAVForm($user); return $this->container->get('app.formfactory')->getPayerCotisationTAVForm($user);
} }
public function getComptoirEncaisserDonAdherentForm(User $user)
{
return $this->container->get('app.formfactory')->getComptoirEncaisserDonAdherentForm($user);
}
} }
...@@ -16,5 +16,6 @@ ...@@ -16,5 +16,6 @@
{% include '@kohinos/comptoir/block/vente_emlc_prestataire.html.twig' %} {% include '@kohinos/comptoir/block/vente_emlc_prestataire.html.twig' %}
{% else %} {% else %}
{% include '@kohinos/tav/block/comptoir_encaisser_cotisation.html.twig' %} {% include '@kohinos/tav/block/comptoir_encaisser_cotisation.html.twig' %}
{% include '@kohinos/tav/block/comptoir_encaisser_don.html.twig' %}
{% endif %} {% endif %}
{% endif %} {% endif %}
\ No newline at end of file
{% extends '@kohinos/block/onetransaction.html.twig' %}
{% block blocktitle %}
<i class="fa fa-exchange fa-exchange-alt mr-4"></i> {{ 'Encaisser un don d\'un habitant'|trans }}
{% endblock blocktitle %}
{% block blockcontent %}
{% if app.session.has('_comptoirgere') %}
{% set form = getComptoirEncaisserDonAdherentForm(app.user) %}
{{ form_start(form) }}
{{ form_row(form.expediteur) }}
{{ form_row(form.montant) }}
{{ form_row(form.moyen) }}
{{ form_row(form.save) }}
{{ parent() }}
{{ form_end(form) }}
{% else %}
<span><em> {{ 'Aucun Comptoir assigné ! Veuillez contacter un administrateur !'|trans }} </em></span>
{% endif %}
{% endblock blockcontent %}
\ No newline at end of file
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