Skip to content

Commit b202d7d

Browse files
authored
Refonte - Événements > Inscriptions - Créer/Modifier/Supprimer (#2136)
1 parent 57cae11 commit b202d7d

File tree

23 files changed

+708
-39
lines changed

23 files changed

+708
-39
lines changed

app/config/packages/backoffice_menu.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ parameters:
139139
url: '/admin/event/tickets'
140140
extra_routes:
141141
- admin_event_ticket_list
142+
- admin_event_ticket_add
143+
- admin_event_ticket_edit
142144
forum_pending_bankwires:
143145
nom: 'Virements en attente'
144146
niveau: 'ROLE_ADMIN'

app/config/routing/admin_event.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,5 @@ admin_event_sessions_delete:
137137
requirements:
138138
id: \d+
139139

140-
admin_event_ticket_list:
141-
path: /tickets
142-
defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\IndexAction }
140+
admin_event_ticket:
141+
resource: "admin_event_ticket.yml"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
admin_event_ticket_list:
2+
path: /tickets
3+
defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\IndexAction }
4+
5+
admin_event_ticket_edit:
6+
path: /tickets/{id}
7+
requirements:
8+
id: \d+
9+
defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\EditAction }
10+
11+
admin_event_ticket_add:
12+
path: /tickets/add
13+
defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\AddAction }
14+
15+
admin_event_ticket_delete:
16+
path: /tickets/delete/{id}
17+
requirements:
18+
id: \d+
19+
defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\DeleteAction }
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AppBundle\Controller\Admin\Event\Ticket;
6+
7+
use Afup\Site\Forum\Facturation;
8+
use AppBundle\AuditLog\Audit;
9+
use AppBundle\Event\Form\TicketAdminWithInvoiceType;
10+
use AppBundle\Event\Model\Event;
11+
use AppBundle\Event\Model\Invoice;
12+
use AppBundle\Event\Model\Repository\EventRepository;
13+
use AppBundle\Event\Model\Repository\InvoiceRepository;
14+
use AppBundle\Event\Model\Repository\TicketRepository;
15+
use AppBundle\Event\Model\Ticket;
16+
use AppBundle\Event\Model\TicketOffer;
17+
use AppBundle\Event\Ticket\TicketOffers;
18+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
19+
use Symfony\Component\HttpFoundation\Request;
20+
use Symfony\Component\HttpFoundation\Response;
21+
22+
final class AddAction extends AbstractController
23+
{
24+
public function __construct(
25+
private readonly TicketOffers $ticketOffers,
26+
private readonly TicketRepository $ticketRepository,
27+
private readonly EventRepository $eventRepository,
28+
private readonly InvoiceRepository $invoiceRepository,
29+
private readonly Audit $audit,
30+
private readonly Facturation $facturation,
31+
) {}
32+
33+
public function __invoke(Request $request): Response
34+
{
35+
$eventId = $request->query->getInt('eventId');
36+
$event = $this->eventRepository->get($eventId);
37+
if (!$event instanceof Event) {
38+
throw $this->createNotFoundException(sprintf('Event not found with id "%s"', $eventId));
39+
}
40+
41+
$offers = $this->ticketOffers->getAllOffersForEvent($event);
42+
43+
$ticket = new Ticket();
44+
$invoice = new Invoice();
45+
$invoice->setPaymentType(Ticket::PAYMENT_NONE);
46+
$invoice->setPaymentDate(new \DateTime());
47+
48+
$form = $this->createForm(TicketAdminWithInvoiceType::class, [
49+
'ticket' => $ticket,
50+
'invoice' => $invoice,
51+
], [
52+
'event' => $event,
53+
'offers' => $offers,
54+
]);
55+
56+
$form->handleRequest($request);
57+
if ($form->isSubmitted() && $form->isValid()) {
58+
['ticket' => $ticket, 'invoice' => $invoice] = $form->getData();
59+
60+
$ticketTypeId = $ticket->getTicketTypeId();
61+
$offer = array_find($offers, fn(TicketOffer $offer): bool => $offer->ticketTypeId === $ticketTypeId);
62+
if (!$offer instanceof TicketOffer) {
63+
throw $this->createNotFoundException(sprintf('Offer not found with ticketTypeId "%s"', $ticketTypeId));
64+
}
65+
66+
$reference = $this->facturation->creerReference($event->getId(), $ticket->getLabel());
67+
if ($offer->ticketEventType) {
68+
$ticket->setTicketEventType($offer->ticketEventType);
69+
}
70+
$ticket->setForumId($event->getId());
71+
$ticket->setAmount($offer->price);
72+
$ticket->setDate(new \DateTime());
73+
$ticket->setReference($reference);
74+
75+
$invoice->setReference($reference);
76+
$invoice->setAmount($ticket->getAmount());
77+
$invoice->setForumId($ticket->getForumId());
78+
$invoice->setStatus($ticket->getInvoiceStatus());
79+
$invoice->setStatus($ticket->getStatus());
80+
$invoice->setInvoice(true);
81+
$invoice->setInvoiceDate($invoice->getPaymentDate());
82+
83+
$this->ticketRepository->save($ticket);
84+
$this->invoiceRepository->save($invoice);
85+
86+
$this->audit->log(sprintf("Ajout de l'inscription de %s (%d)", $ticket->getLabel(), $ticket->getId()));
87+
$this->addFlash('notice', "L'inscription a été ajoutée.");
88+
89+
return $this->redirectToRoute('admin_event_ticket_list');
90+
}
91+
92+
return $this->render('admin/event/ticket/add.html.twig', [
93+
'event' => $event,
94+
'form' => $form->createView(),
95+
]);
96+
}
97+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AppBundle\Controller\Admin\Event\Ticket;
6+
7+
use AppBundle\AuditLog\Audit;
8+
use AppBundle\Event\Model\Repository\InvoiceRepository;
9+
use AppBundle\Event\Model\Repository\TicketRepository;
10+
use AppBundle\Event\Model\Ticket;
11+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
12+
use Symfony\Component\HttpFoundation\Request;
13+
use Symfony\Component\HttpFoundation\Response;
14+
15+
final class DeleteAction extends AbstractController
16+
{
17+
public function __construct(
18+
private readonly TicketRepository $ticketRepository,
19+
private readonly InvoiceRepository $invoiceRepository,
20+
private readonly Audit $audit,
21+
) {}
22+
23+
public function __invoke(int $id, Request $request): Response
24+
{
25+
$ticket = $this->ticketRepository->get($id);
26+
if (!$ticket instanceof Ticket) {
27+
throw $this->createNotFoundException(sprintf('Ticket not found with id "%s"', $id));
28+
}
29+
30+
$invoice = $this->invoiceRepository->getByReference($id);
31+
if ($invoice) {
32+
$this->invoiceRepository->delete($invoice);
33+
}
34+
$this->ticketRepository->delete($ticket);
35+
36+
$this->audit->log("Suppression de l'inscription " . $id);
37+
$this->addFlash('notice', "L'inscription a été supprimée");
38+
39+
return $this->redirectToRoute('admin_event_ticket_list');
40+
}
41+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AppBundle\Controller\Admin\Event\Ticket;
6+
7+
use AppBundle\AuditLog\Audit;
8+
use AppBundle\Event\Form\TicketAdminWithInvoiceType;
9+
use AppBundle\Event\Model\Event;
10+
use AppBundle\Event\Model\Invoice;
11+
use AppBundle\Event\Model\Repository\EventRepository;
12+
use AppBundle\Event\Model\Repository\InvoiceRepository;
13+
use AppBundle\Event\Model\Repository\TicketRepository;
14+
use AppBundle\Event\Model\Ticket;
15+
use AppBundle\Event\Ticket\TicketOffers;
16+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
17+
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpFoundation\Response;
19+
20+
final class EditAction extends AbstractController
21+
{
22+
public function __construct(
23+
private readonly TicketOffers $ticketOffers,
24+
private readonly TicketRepository $ticketRepository,
25+
private readonly EventRepository $eventRepository,
26+
private readonly InvoiceRepository $invoiceRepository,
27+
private readonly Audit $audit,
28+
) {}
29+
30+
public function __invoke(int $id, Request $request): Response
31+
{
32+
$ticket = $this->ticketRepository->get($id);
33+
if (!$ticket instanceof Ticket) {
34+
throw $this->createNotFoundException(sprintf('Ticket not found with id "%s"', $id));
35+
}
36+
$event = $this->eventRepository->get($ticket->getForumId());
37+
if (!$event instanceof Event) {
38+
throw $this->createNotFoundException(sprintf('Event not found with id "%s"', $ticket->getForumId()));
39+
}
40+
$invoice = $this->invoiceRepository->getByReference($ticket->getReference());
41+
if (!$invoice instanceof Invoice) {
42+
throw $this->createNotFoundException(sprintf('Invoice not found with id "%s"', $ticket->getReference()));
43+
}
44+
45+
$offers = $this->ticketOffers->getAllOffersForEvent($event);
46+
47+
$form = $this->createForm(TicketAdminWithInvoiceType::class, [
48+
'ticket' => $ticket,
49+
'invoice' => $invoice,
50+
], [
51+
'event' => $event,
52+
'offers' => $offers,
53+
]);
54+
55+
$form->handleRequest($request);
56+
if ($form->isSubmitted() && $form->isValid()) {
57+
['ticket' => $ticket, 'invoice' => $invoice] = $form->getData();
58+
59+
$invoice->setStatus($ticket->getStatus());
60+
61+
$this->ticketRepository->save($ticket);
62+
$this->invoiceRepository->save($invoice);
63+
64+
$this->audit->log(sprintf("Modification de l'inscription de %s (%d)", $ticket->getLabel(), $ticket->getId()));
65+
$this->addFlash('notice', "L'inscription a été modifiée.");
66+
67+
return $this->redirectToRoute('admin_event_ticket_list');
68+
}
69+
70+
return $this->render('admin/event/ticket/edit.html.twig', [
71+
'event' => $event,
72+
'ticket' => $ticket,
73+
'invoice' => $invoice,
74+
'form' => $form->createView(),
75+
]);
76+
}
77+
}

sources/AppBundle/Controller/Admin/HomeAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __invoke(): Response
7373
}
7474

7575
$info['statistics']['montant total'] = number_format($montantTotal, 0, ',', "\u{a0}") . "\u{a0}";
76-
$info['url'] = '/pages/administration/index.php?page=forum_inscriptions&id_forum=' . $event->getId();
76+
$info['url'] = $this->generateUrl('admin_event_ticket_list', ['id' => $event->getId()]);
7777

7878
$cards[] = $info;
7979

0 commit comments

Comments
 (0)