diff --git a/assets/controllers/form_controller.js b/assets/controllers/form_controller.js index 3e157b6..13b962d 100644 --- a/assets/controllers/form_controller.js +++ b/assets/controllers/form_controller.js @@ -12,6 +12,7 @@ export default class extends Controller { "ticketType", "foodType", "note", + "donation" ]; stripe; @@ -191,6 +192,7 @@ export default class extends Controller { lastname: this.lastnameTarget.value.trim(), email: this.emailTarget.value.trim(), phone: this.phoneTarget.value.trim(), + donation: Number(this.donationTarget.value) ?? null }; } diff --git a/src/Controller/Admin/CustomerCrudController.php b/src/Controller/Admin/CustomerCrudController.php index 0069cf6..8f4a91b 100644 --- a/src/Controller/Admin/CustomerCrudController.php +++ b/src/Controller/Admin/CustomerCrudController.php @@ -4,19 +4,16 @@ namespace App\Controller\Admin; use App\Entity\Customer; use App\Entity\Payment; -use App\Enum\TicketData; -use Doctrine\Common\Collections\Collection; +use App\Form\TicketType; use EasyCorp\Bundle\EasyAdminBundle\Config\Action; use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; -use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField; use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField; use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField; use EasyCorp\Bundle\EasyAdminBundle\Field\TelephoneField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; -use App\Form\TicketType; class CustomerCrudController extends AbstractCrudController { diff --git a/src/Controller/Admin/PaymentCrudController.php b/src/Controller/Admin/PaymentCrudController.php index ce3fcfe..6eac2b2 100644 --- a/src/Controller/Admin/PaymentCrudController.php +++ b/src/Controller/Admin/PaymentCrudController.php @@ -9,6 +9,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField; +use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField; class PaymentCrudController extends AbstractCrudController { @@ -23,6 +24,8 @@ class PaymentCrudController extends AbstractCrudController ->setCrudController(CustomerCrudController::class) ->formatValue(fn($value, $payment) => $payment->getCustomer()->getEmail()); yield BooleanField::new('completed', 'Bezahlt')->renderAsSwitch(false); + yield NumberField::new('donation', 'Spende') + ->formatValue(fn (?float $donation) => ($donation??'0').'€'); } public function configureActions(Actions $actions): Actions diff --git a/src/DataObjects/PersonalData.php b/src/DataObjects/PersonalData.php index f201c80..750203f 100644 --- a/src/DataObjects/PersonalData.php +++ b/src/DataObjects/PersonalData.php @@ -9,6 +9,7 @@ class PersonalData public string $lastname, public string $email, public string $phone, + public ?float $donation, ) { } } \ No newline at end of file diff --git a/src/Entity/Payment.php b/src/Entity/Payment.php index 80b6306..b1ea817 100644 --- a/src/Entity/Payment.php +++ b/src/Entity/Payment.php @@ -24,6 +24,9 @@ class Payment #[ORM\JoinColumn(nullable: false)] private ?Customer $customer = null; + #[ORM\Column(nullable: true)] + private ?float $donation = null; + public function getId(): ?int { return $this->id; @@ -71,4 +74,16 @@ class Payment return $total + TicketData::TICKET_DATA[$ticket->getType()]['price']; }, 0); } + + public function getDonation(): ?float + { + return $this->donation; + } + + public function setDonation(?float $donation): static + { + $this->donation = $donation; + + return $this; + } } diff --git a/src/Service/TicketService.php b/src/Service/TicketService.php index 3fe3a66..7e9dfc2 100644 --- a/src/Service/TicketService.php +++ b/src/Service/TicketService.php @@ -30,7 +30,7 @@ class TicketService public function handleTicketData(TicketFormData $data): Session { - $session = $this->createSession($this->getLineItems($data->tickets), $data->personal->email); + $session = $this->createSession($this->getLineItems($data->tickets, $data->personal->donation), $data->personal->email); $this->saveTicketData($data, $session->id); @@ -57,16 +57,30 @@ class TicketService $payment = (new Payment()) ->setSessionId($sessionId) ->setCompleted(false) - ->setCustomer($this->createEntityFromData($data)); + ->setCustomer($this->createEntityFromData($data)) + ->setDonation($data->personal->donation); $this->em->persist($payment); $this->em->flush(); } - private function getLineItems(array $tickets): array + private function getLineItems(array $tickets, float $donation = null): array { $lineItems = []; + if ($donation) { + $lineItems[] = [ + 'price_data' => [ + 'currency' => 'eur', + 'product_data' => [ + 'name' => 'Spende', + ], + 'unit_amount' => $donation * 100, + ], + 'quantity' => 1, + ]; + } + foreach ($tickets as $ticket) { $ticketData = TicketEnum::TICKET_DATA[$ticket->ticketType]; $lineItems[] = [ diff --git a/templates/email/contact.html.twig b/templates/email/contact.html.twig index e7bed3c..bbb5bc8 100644 --- a/templates/email/contact.html.twig +++ b/templates/email/contact.html.twig @@ -12,16 +12,7 @@ Contact Details - - - - - -
- Email
- {{ data.email }} -
- + {% if data.phone %}
@@ -30,7 +21,7 @@
- + {% endif %}
diff --git a/templates/home/index.html.twig b/templates/home/index.html.twig index 5cee8c9..e3fa47a 100644 --- a/templates/home/index.html.twig +++ b/templates/home/index.html.twig @@ -31,7 +31,7 @@

-
+

Datum & Uhrzeit

@@ -75,6 +75,39 @@
+
+

Ticket Preise

+
+
+ +
+ All-Inclusive Ticket + 50€ +
+
+
+ +
+ After-Show Ticket + 20€ +
+
+
+ +
+ Kind (6-12 Jahre) + 15€ +
+
+
+ +
+ Kind (0-6 Jahre) + 0€ +
+
+
+
diff --git a/templates/ticket/index.html.twig b/templates/ticket/index.html.twig index 2234232..f6ae65a 100644 --- a/templates/ticket/index.html.twig +++ b/templates/ticket/index.html.twig @@ -49,6 +49,10 @@
+
+ + +