1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace App\Controller;
use App\Entity\CotisationPrestataire;
use App\Entity\Prestataire;
use App\Enum\MoyenEnum;
use App\Utils\CustomEntityManager;
use DateTime;
use Sonata\AdminBundle\Controller\CRUDController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Security;
class PrestataireAdminController extends CRUDController
{
protected $em;
protected $security;
public function __construct(CustomEntityManager $em, Security $security)
{
$this->em = $em;
$this->security = $security;
}
/**
* @param $id
*/
public function addfreecotisationprestaAction($id): Response
{
$prestataire = $this->admin->getSubject();
if (!$prestataire) {
throw new NotFoundHttpException(sprintf('Impossible de trouver le prestataire avec l\'id: %s', $id));
}
$cotisation = new CotisationPrestataire();
$cotisation->setExpediteur($prestataire);
$now = new DateTime();
$cotisation->setRecu(true);
$cotisation->setReference('Cotisation gratuite');
// $cotisation->setOperateur(null);
$cotisation->setRole($this->getUser()->getGroups()[0]->__toString());
$mlcPrestataire = $this->em->getRepository(Prestataire::class)->findOneBy(['mlc' => true]);
$cotisation->setDestinataire($mlcPrestataire);
$cotisation->setMoyen(MoyenEnum::MOYEN_AUTRE);
$cotisation->setMontant(0);
$cotisation->getCotisationInfos()->setAnnee(date('Y'));
$cotisation->getCotisationInfos()->setDebut($now);
$cotisation->getCotisationInfos()->setFin(new DateTime('+ 1 year'));
$this->em->persist($cotisation);
$this->em->flush();
$this->addFlash('sonata_flash_success', sprintf('Cotisation gratuite ajouté au prestataire %s', $prestataire->__toString()));
return new RedirectResponse(
$this->admin->generateUrl('list', ['filter' => $this->admin->getFilterParameters()])
);
}
}