Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/config/packages/backoffice_menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ parameters:
url: '/admin/event/tickets'
extra_routes:
- admin_event_ticket_list
- admin_event_ticket_add
- admin_event_ticket_edit
forum_pending_bankwires:
nom: 'Virements en attente'
niveau: 'ROLE_ADMIN'
Expand Down
5 changes: 2 additions & 3 deletions app/config/routing/admin_event.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,5 @@ admin_event_sessions_delete:
requirements:
id: \d+

admin_event_ticket_list:
path: /tickets
defaults: { _controller: AppBundle\Controller\Admin\Event\Ticket\IndexAction }
admin_event_ticket:
resource: "admin_event_ticket.yml"
19 changes: 19 additions & 0 deletions app/config/routing/admin_event_ticket.yml
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 sources/AppBundle/Controller/Admin/Event/Ticket/AddAction.php
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 sources/AppBundle/Controller/Admin/Event/Ticket/DeleteAction.php
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 sources/AppBundle/Controller/Admin/Event/Ticket/EditAction.php
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(),
]);
}
}
2 changes: 1 addition & 1 deletion sources/AppBundle/Controller/Admin/HomeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __invoke(): Response
}

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

$cards[] = $info;

Expand Down
Loading
Loading