Add invitations tab: create free invitation with ticket generation and email

- New tab "Invitations" on event edit page
- Form: name, email, billet type, quantity
- Creates BilletBuyer with totalHT=0 (no payment), generates BilletOrders
  with isInvitation=true, sends email with PDF tickets
- List of sent invitations below the form

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-21 17:27:18 +01:00
parent 3ac47d9a57
commit 58d325f60c
2 changed files with 143 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ use App\Entity\Category;
use App\Entity\Event;
use App\Entity\Payout;
use App\Entity\User;
use App\Service\BilletOrderService;
use App\Service\EventIndexService;
use App\Service\MailerService;
use App\Service\OrderIndexService;
@@ -697,6 +698,69 @@ class AccountController extends AbstractController
return $this->json(['success' => true]);
}
#[Route('/mon-compte/evenement/{id}/invitation', name: 'app_account_event_create_invitation', methods: ['POST'])]
public function createInvitation(Event $event, Request $request, EntityManagerInterface $em, BilletOrderService $billetOrderService): Response
{
$this->denyAccessUnlessGranted('ROLE_ORGANIZER');
/** @var User $user */
$user = $this->getUser();
if ($event->getAccount()->getId() !== $user->getId()) {
throw $this->createAccessDeniedException();
}
$firstName = trim($request->request->getString('first_name'));
$lastName = trim($request->request->getString('last_name'));
$email = trim($request->request->getString('email'));
$billetId = $request->request->getInt('billet_id');
$quantity = $request->request->getInt('quantity', 1);
if ('' === $firstName || '' === $lastName || '' === $email || 0 === $billetId) {
$this->addFlash('error', 'Tous les champs sont requis.');
return $this->redirectToRoute('app_account_edit_event', ['id' => $event->getId(), 'tab' => 'invitations']);
}
$billet = $em->getRepository(Billet::class)->find($billetId);
if (!$billet || $billet->getCategory()->getEvent()->getId() !== $event->getId()) {
throw $this->createNotFoundException();
}
$count = $em->getRepository(BilletBuyer::class)->count([]) + 1;
$order = new BilletBuyer();
$order->setEvent($event);
$order->setFirstName($firstName);
$order->setLastName($lastName);
$order->setEmail($email);
$order->setOrderNumber(date('Y-m-d').'-'.$count);
$order->setTotalHT(0);
$item = new BilletBuyerItem();
$item->setBillet($billet);
$item->setBilletName($billet->getName());
$item->setQuantity($quantity);
$item->setUnitPriceHT(0);
$order->addItem($item);
$em->persist($order);
$em->flush();
$billetOrderService->generateOrderTickets($order);
$tickets = $em->getRepository(BilletOrder::class)->findBy(['billetBuyer' => $order]);
foreach ($tickets as $ticket) {
$ticket->setIsInvitation(true);
}
$em->flush();
$billetOrderService->generateAndSendTickets($order);
$this->addFlash('success', 'Invitation envoyee a '.$email.'.');
return $this->redirectToRoute('app_account_edit_event', ['id' => $event->getId(), 'tab' => 'invitations']);
}
#[Route('/mon-compte/evenement/{id}/commande/{orderId}/annuler', name: 'app_account_event_cancel_order', methods: ['POST'])]
public function cancelOrder(Event $event, int $orderId, EntityManagerInterface $em): Response
{