UserComptoirController.php 5.65 KB
Newer Older
Julien Jorry committed
1 2 3 4 5 6 7 8 9 10
<?php

namespace App\Controller;

use App\Entity\Adherent;
use App\Entity\Cotisation;
use App\Entity\Geoloc;
use App\Entity\Groupe;
use App\Entity\TransactionAdherentPrestataire;
use App\Entity\TransfertComptoirAdherent;
11
use App\Entity\TransfertComptoirPrestataire;
Julien Jorry committed
12 13
use App\Entity\TransfertPrestataireComptoir;
use App\Entity\Usergroup;
14 15
use App\Entity\VenteComptoirAdherent;
use App\Entity\VenteComptoirPrestataire;
Julien Jorry committed
16 17 18 19 20
use App\Form\Type\AdherentInfosFormType;
use App\Form\Type\AdhererFormType;
use App\Form\Type\GroupeInfosFormType;
use App\Form\Type\TransactionAdherentPrestataireFormType;
use App\Form\Type\TransfertComptoirAdherentFormType;
21
use App\Form\Type\TransfertComptoirPrestataireFormType;
Julien Jorry committed
22
use App\Form\Type\TransfertPrestataireComptoirFormType;
23 24
use App\Form\Type\VenteComptoirAdherentFormType;
use App\Form\Type\VenteComptoirPrestataireFormType;
Julien Jorry committed
25 26 27 28 29 30
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
31
use Symfony\Component\Translation\TranslatorInterface;
Julien Jorry committed
32

33
class UserComptoirController extends FluxController
Julien Jorry committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
{
    /**
     * @Route("/user/comptoir/infos", name="comptoir_infos")
     * @IsGranted("ROLE_COMPTOIR")
     */
    public function groupeInfosAction(Request $request)
    {
        $form = $this->createForm(ComptoirInfosFormType::class, $this->getUser()->getComptoirsgere());
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();
            $this->em->persist($data);
            $this->em->flush();
            $this->addFlash(
                'success',
50
                $this->translator->trans('Comptoir bien modifié !')
Julien Jorry committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
            );
            $referer = $request->headers->get('referer');
            if ($referer && !$request->isXmlHttpRequest()) {
                return $this->redirect($referer);
            } elseif (!$request->isXmlHttpRequest()) {
                return new Response('', Response::HTTP_BAD_REQUEST);
            }
        }

        return $this->redirectToRoute('index');
    }

    /**
     * @Route("/user/comptoir/transfert/adherent/", name="transfertComptoirAdherent")
     * @IsGranted("ROLE_COMPTOIR")
     */
    public function transfertComptoirAdherentAction(Request $request)
    {
        $entity = new TransfertComptoirAdherent();
        $entity->setOperateur($this->getUser());
        $form = $this->createForm(TransfertComptoirAdherentFormType::class, $entity);
72 73 74 75 76 77 78 79
        return $this->manageFluxForm(
            $request,
            $form,
            $this->getUser()->getComptoirsgere()->getCompte(),
            $this->translator->trans('Transfert à un adhérent bien effectuée !'),
            $this->translator->trans('Transfert à un adhérent')
        );
    }
Julien Jorry committed
80

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    /**
     * @Route("/user/comptoir/transfert/prestataire/", name="transfertComptoirPrestataire")
     * @IsGranted("ROLE_COMPTOIR")
     */
    public function transfertComptoirPrestataireAction(Request $request)
    {
        $entity = new TransfertComptoirPrestataire();
        $entity->setOperateur($this->getUser());
        $form = $this->createForm(TransfertComptoirPrestataireFormType::class, $entity);
        return $this->manageFluxForm(
            $request,
            $form,
            $this->getUser()->getComptoirsgere()->getCompte(),
            $this->translator->trans('Transfert à un prestataire bien effectuée !'),
            $this->translator->trans('Transfert à un prestataire')
        );
Julien Jorry committed
97 98
    }

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    /**
     * @Route("/user/comptoir/vente/adherent/", name="venteComptoirAdherent")
     * @IsGranted("ROLE_COMPTOIR")
     */
    public function venteComptoirAdherentAction(Request $request)
    {
        $entity = new VenteComptoirAdherent();
        $entity->setOperateur($this->getUser());
        $form = $this->createForm(VenteComptoirAdherentFormType::class, $entity);
        return $this->manageFluxForm(
            $request,
            $form,
            $this->getUser()->getComptoirsgere()->getCompte(),
            $this->translator->trans('Vente à un adhérent bien effectuée !'),
            $this->translator->trans('Vente à un adhérent')
        );
    }

    /**
     * @Route("/user/comptoir/vente/prestataire/", name="venteComptoirPrestataire")
     * @IsGranted("ROLE_COMPTOIR")
     */
    public function venteComptoirPrestataireAction(Request $request)
    {
        $entity = new VenteComptoirPrestataire();
        $entity->setOperateur($this->getUser());
        $form = $this->createForm(VenteComptoirPrestataireFormType::class, $entity);
        return $this->manageFluxForm(
            $request,
            $form,
            $this->getUser()->getComptoirsgere()->getCompte(),
            $this->translator->trans('Vente à un prestataire bien effectuée !'),
            $this->translator->trans('Vente à un prestataire')
        );
    }

Julien Jorry committed
135 136 137 138 139 140 141 142 143
    /**
     * @Route("/user/comptoir/reconversion/", name="transfertPrestataireComptoir")
     * @IsGranted("ROLE_COMPTOIR")
     */
    public function transfertPrestataireComptoirAction(Request $request)
    {
        $entity = new TransfertPrestataireComptoir();
        $entity->setOperateur($this->getUser());
        $form = $this->createForm(TransfertPrestataireComptoirFormType::class, $entity);
144 145 146 147 148 149 150
        return $this->manageFluxForm(
            $request,
            $form,
            $this->getUser()->getComptoirsgere()->getCompte(),
            $this->translator->trans('Reconversion bien effectuée !'),
            $this->translator->trans("Reconversion d'un prestataire")
        );
Julien Jorry committed
151 152
    }
}