-
Notifications
You must be signed in to change notification settings - Fork 70
Refonte - Événements > Inscriptions - Créer/Modifier/Supprimer #2136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stakovicz
wants to merge
2
commits into
afup:master
Choose a base branch
from
stakovicz:feat-admin-event-tickets-edit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| admin_event_ticket_list: | ||
| path: /tickets | ||
| defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\IndexAction } | ||
|
|
||
| admin_event_ticket_edit: | ||
| path: /tickets/{id} | ||
| requirements: | ||
| id: \d+ | ||
| defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\EditAction } | ||
|
|
||
| admin_event_ticket_add: | ||
| path: /tickets/add | ||
| defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\AddAction } | ||
|
|
||
| admin_event_ticket_delete: | ||
| path: /tickets/delete/{id} | ||
| requirements: | ||
| id: \d+ | ||
| defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\DeleteAction } |
97 changes: 97 additions & 0 deletions
97
sources/AppBundle/Controller/Admin/Event/Ticket/AddAction.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace AppBundle\Controller\Admin\Event\Ticket; | ||
|
|
||
| use Afup\Site\Forum\Facturation; | ||
| use AppBundle\AuditLog\Audit; | ||
| use AppBundle\Event\Form\TicketAdminWithInvoiceType; | ||
| use AppBundle\Event\Model\Event; | ||
| use AppBundle\Event\Model\Invoice; | ||
| use AppBundle\Event\Model\Repository\EventRepository; | ||
| use AppBundle\Event\Model\Repository\InvoiceRepository; | ||
| use AppBundle\Event\Model\Repository\TicketRepository; | ||
| use AppBundle\Event\Model\Ticket; | ||
| use AppBundle\Event\Model\TicketOffer; | ||
| use AppBundle\Event\Ticket\TicketOffers; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| final class AddAction extends AbstractController | ||
| { | ||
| public function __construct( | ||
| private readonly TicketOffers $ticketOffers, | ||
| private readonly TicketRepository $ticketRepository, | ||
| private readonly EventRepository $eventRepository, | ||
| private readonly InvoiceRepository $invoiceRepository, | ||
| private readonly Audit $audit, | ||
| private readonly Facturation $facturation, | ||
| ) {} | ||
|
|
||
| public function __invoke(Request $request): Response | ||
| { | ||
| $eventId = $request->query->getInt('eventId'); | ||
| $event = $this->eventRepository->get($eventId); | ||
| if (!$event instanceof Event) { | ||
| throw $this->createNotFoundException(sprintf('Event not found with id "%s"', $eventId)); | ||
| } | ||
|
|
||
| $offers = $this->ticketOffers->getAllOffersForEvent($event); | ||
|
|
||
| $ticket = new Ticket(); | ||
| $invoice = new Invoice(); | ||
| $invoice->setPaymentType(Ticket::PAYMENT_NONE); | ||
| $invoice->setPaymentDate(new \DateTime()); | ||
|
|
||
| $form = $this->createForm(TicketAdminWithInvoiceType::class, [ | ||
| 'ticket' => $ticket, | ||
| 'invoice' => $invoice, | ||
| ], [ | ||
| 'event' => $event, | ||
| 'offers' => $offers, | ||
| ]); | ||
|
|
||
| $form->handleRequest($request); | ||
| if ($form->isSubmitted() && $form->isValid()) { | ||
| ['ticket' => $ticket, 'invoice' => $invoice] = $form->getData(); | ||
|
|
||
| $ticketTypeId = $ticket->getTicketTypeId(); | ||
| $offer = array_find($offers, fn(TicketOffer $offer): bool => $offer->ticketTypeId === $ticketTypeId); | ||
| if (!$offer instanceof TicketOffer) { | ||
| throw $this->createNotFoundException(sprintf('Offer not found with ticketTypeId "%s"', $ticketTypeId)); | ||
| } | ||
|
|
||
| $reference = $this->facturation->creerReference($event->getId(), $ticket->getLabel()); | ||
| if ($offer->ticketEventType) { | ||
| $ticket->setTicketEventType($offer->ticketEventType); | ||
| } | ||
| $ticket->setForumId($event->getId()); | ||
| $ticket->setAmount($offer->price); | ||
| $ticket->setDate(new \DateTime()); | ||
| $ticket->setReference($reference); | ||
|
|
||
| $invoice->setReference($reference); | ||
| $invoice->setAmount($ticket->getAmount()); | ||
| $invoice->setForumId($ticket->getForumId()); | ||
| $invoice->setStatus($ticket->getInvoiceStatus()); | ||
| $invoice->setStatus($ticket->getStatus()); | ||
| $invoice->setInvoice(true); | ||
| $invoice->setInvoiceDate($invoice->getPaymentDate()); | ||
|
|
||
| $this->ticketRepository->save($ticket); | ||
| $this->invoiceRepository->save($invoice); | ||
|
|
||
| $this->audit->log(sprintf("Ajout de l'inscription de %s (%d)", $ticket->getLabel(), $ticket->getId())); | ||
| $this->addFlash('notice', "L'inscription a été ajoutée."); | ||
|
|
||
| return $this->redirectToRoute('admin_event_ticket_list'); | ||
| } | ||
|
|
||
| return $this->render('admin/event/ticket/add.html.twig', [ | ||
| 'event' => $event, | ||
| 'form' => $form->createView(), | ||
| ]); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
sources/AppBundle/Controller/Admin/Event/Ticket/DeleteAction.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace AppBundle\Controller\Admin\Event\Ticket; | ||
|
|
||
| use AppBundle\AuditLog\Audit; | ||
| use AppBundle\Event\Model\Repository\InvoiceRepository; | ||
| use AppBundle\Event\Model\Repository\TicketRepository; | ||
| use AppBundle\Event\Model\Ticket; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| final class DeleteAction extends AbstractController | ||
| { | ||
| public function __construct( | ||
| private readonly TicketRepository $ticketRepository, | ||
| private readonly InvoiceRepository $invoiceRepository, | ||
| private readonly Audit $audit, | ||
| ) {} | ||
|
|
||
| public function __invoke(int $id, Request $request): Response | ||
| { | ||
| $ticket = $this->ticketRepository->get($id); | ||
| if (!$ticket instanceof Ticket) { | ||
| throw $this->createNotFoundException(sprintf('Ticket not found with id "%s"', $id)); | ||
| } | ||
|
|
||
| $invoice = $this->invoiceRepository->getByReference($id); | ||
| if ($invoice) { | ||
| $this->invoiceRepository->delete($invoice); | ||
| } | ||
| $this->ticketRepository->delete($ticket); | ||
|
|
||
| $this->audit->log("Suppression de l'inscription " . $id); | ||
| $this->addFlash('notice', "L'inscription a été supprimée"); | ||
|
|
||
| return $this->redirectToRoute('admin_event_ticket_list'); | ||
| } | ||
| } |
78 changes: 78 additions & 0 deletions
78
sources/AppBundle/Controller/Admin/Event/Ticket/EditAction.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace AppBundle\Controller\Admin\Event\Ticket; | ||
|
|
||
| use AppBundle\AuditLog\Audit; | ||
| use AppBundle\Event\Form\TicketAdminWithInvoiceType; | ||
| use AppBundle\Event\Model\Event; | ||
| use AppBundle\Event\Model\Invoice; | ||
| use AppBundle\Event\Model\Repository\EventRepository; | ||
| use AppBundle\Event\Model\Repository\InvoiceRepository; | ||
| use AppBundle\Event\Model\Repository\TicketRepository; | ||
| use AppBundle\Event\Model\Ticket; | ||
| use AppBundle\Event\Ticket\TicketOffers; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| final class EditAction extends AbstractController | ||
| { | ||
| public function __construct( | ||
| private readonly TicketOffers $ticketOffers, | ||
| private readonly TicketRepository $ticketRepository, | ||
| private readonly EventRepository $eventRepository, | ||
| private readonly InvoiceRepository $invoiceRepository, | ||
| private readonly Audit $audit, | ||
| ) {} | ||
|
|
||
| public function __invoke(int $id, Request $request): Response | ||
| { | ||
| $ticket = $this->ticketRepository->get($id); | ||
| if (!$ticket instanceof Ticket) { | ||
| throw $this->createNotFoundException(sprintf('Ticket not found with id "%s"', $id)); | ||
| } | ||
| $event = $this->eventRepository->get($ticket->getForumId()); | ||
| if (!$event instanceof Event) { | ||
| throw $this->createNotFoundException(sprintf('Event not found with id "%s"', $ticket->getForumId())); | ||
| } | ||
| $invoice = $this->invoiceRepository->getByReference($ticket->getReference()); | ||
| if (!$invoice instanceof Invoice) { | ||
| throw $this->createNotFoundException(sprintf('Invoice not found with id "%s"', $ticket->getReference())); | ||
| } | ||
|
|
||
| $offers = $this->ticketOffers->getAllOffersForEvent($event); | ||
|
|
||
| $form = $this->createForm(TicketAdminWithInvoiceType::class, [ | ||
| 'ticket' => $ticket, | ||
| 'invoice' => $invoice, | ||
| ], [ | ||
| 'event' => $event, | ||
| 'offers' => $offers, | ||
| ]); | ||
|
|
||
| $form->handleRequest($request); | ||
| if ($form->isSubmitted() && $form->isValid()) { | ||
| ['ticket' => $ticket, 'invoice' => $invoice] = $form->getData(); | ||
|
|
||
| $invoice->setStatus($ticket->getInvoiceStatus()); | ||
| $invoice->setStatus($ticket->getStatus()); | ||
|
|
||
| $this->ticketRepository->save($ticket); | ||
| $this->invoiceRepository->save($invoice); | ||
|
|
||
| $this->audit->log(sprintf("Modification de l'inscription de %s (%d)", $ticket->getLabel(), $ticket->getId())); | ||
| $this->addFlash('notice', "L'inscription a été modifiée."); | ||
|
|
||
| return $this->redirectToRoute('admin_event_ticket_list'); | ||
| } | ||
|
|
||
| return $this->render('admin/event/ticket/edit.html.twig', [ | ||
| 'event' => $event, | ||
| 'ticket' => $ticket, | ||
| 'invoice' => $invoice, | ||
| 'form' => $form->createView(), | ||
| ]); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Y'a deux fois
$invoice->setStatusj'imagine que c'est pas normal ?