Participant mangement
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
namespace App\Domains\Event\Actions\ManualCertificateOfConductionCheck;
|
||||
|
||||
use App\Enumerations\EfzStatus;
|
||||
use App\Mail\ParticipantCocMails\ParticipantCocCompleteMail;
|
||||
use App\Mail\ParticipantCocMails\ParticipantCocInvalidMail;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class ManualCertificateOfConductionCheckCommand {
|
||||
function __construct(public ManualCertificateOfConductionCheckRequest $request)
|
||||
@@ -16,6 +19,11 @@ class ManualCertificateOfConductionCheckCommand {
|
||||
$this->request->participant->efz_status = EfzStatus::EFZ_STATUS_CHECKED_VALID;
|
||||
$this->request->participant->save();
|
||||
$response->success = true;
|
||||
|
||||
Mail::to($this->request->participant->email_1)->send(new ParticipantCocCompleteMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
namespace App\Domains\Event\Actions\ParticipantPayment;
|
||||
|
||||
use App\Mail\ParticipantPaymentMails\ParticipantPaymentMissingPaymentMail;
|
||||
use App\Mail\ParticipantPaymentMails\ParticipantPaymentOverpaidMail;
|
||||
use App\Mail\ParticipantPaymentMails\ParticipantPaymentPaidMail;
|
||||
use App\Providers\MissingPaymentProvider;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class ParticipantPaymentCommand {
|
||||
public function __construct(public ParticipantPaymentRequest $request) {
|
||||
}
|
||||
@@ -12,6 +18,50 @@ class ParticipantPaymentCommand {
|
||||
$this->request->participant->amount_paid = $this->request->amountPaid;
|
||||
$this->request->participant->save();
|
||||
|
||||
$response->amountPaid = $this->request->participant->amount_paid;
|
||||
$response->amountExpected = $this->request->participant->amount;
|
||||
|
||||
$amountToPay = MissingPaymentProvider::calculateMissingPayment(
|
||||
amountPaid: $this->request->participant->amount_paid,
|
||||
amountToPay: $this->request->participant->amount,
|
||||
);
|
||||
|
||||
switch (true) {
|
||||
case $amountToPay->getAmount() > 0:
|
||||
Mail::to($this->request->participant->email_1)->send(new ParticipantPaymentMissingPaymentMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
|
||||
if ($this->request->participant->email_2 !== null) {
|
||||
Mail::to($this->request->participant->email_2)->send(new ParticipantPaymentMissingPaymentMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
}
|
||||
break;
|
||||
case $amountToPay->getAmount() < 0:
|
||||
Mail::to($this->request->participant->email_1)->send(new ParticipantPaymentOverpaidMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
|
||||
if ($this->request->participant->email_2 !== null) {
|
||||
Mail::to($this->request->participant->email_2)->send(new ParticipantPaymentOverpaidMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Mail::to($this->request->participant->email_1)->send(new ParticipantPaymentPaidMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
|
||||
if ($this->request->participant->email_2 !== null) {
|
||||
Mail::to($this->request->participant->email_2)->send(new ParticipantPaymentPaidMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$response->participant = $this->request->participant;
|
||||
$response->success = true;
|
||||
|
||||
return $response;
|
||||
|
||||
@@ -2,6 +2,19 @@
|
||||
|
||||
namespace App\Domains\Event\Actions\ParticipantPayment;
|
||||
|
||||
use App\Models\EventParticipant;
|
||||
use App\ValueObjects\Amount;
|
||||
|
||||
class ParticipantPaymentResponse {
|
||||
public bool $success = false;
|
||||
public bool $success;
|
||||
public ?Amount $amountPaid;
|
||||
public ?Amount $amountExpected;
|
||||
public ?EventParticipant $participant;
|
||||
|
||||
public function __construct() {
|
||||
$this->amountPaid = null;
|
||||
$this->amountExpected = null;
|
||||
$this->success = false;
|
||||
$this->participant = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Event\Actions\SetParticipationState;
|
||||
|
||||
use App\Mail\ParticipantParticipationMails\EventSignUpSuccessfullMail;
|
||||
use App\Mail\ParticipantParticipationMails\ParticipantSignOffMail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SetParticipationStateCommand {
|
||||
function __construct(private SetParticipationStateSignoffRequest|SetParticipationStateReSignonRequest $request) {}
|
||||
|
||||
public function execute() : SetParticipationStateResponse {
|
||||
$response = new SetParticipationStateResponse();
|
||||
|
||||
|
||||
switch (true) {
|
||||
case $this->request instanceof SetParticipationStateSignoffRequest:
|
||||
$this->request->participant->unregistered_at = $this->request->date;
|
||||
$this->request->participant->save();
|
||||
$response->success = true;
|
||||
Mail::to($this->request->participant->email_1)->send(new ParticipantSignOffMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
|
||||
if ($this->request->participant->email_2 !== null) {
|
||||
Mail::to($this->request->participant->email_2)->send(new ParticipantSignOffMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
}
|
||||
|
||||
break;
|
||||
case $this->request instanceof SetParticipationStateReSignonRequest:
|
||||
$this->request->participant->unregistered_at = null;
|
||||
$this->request->participant->save();
|
||||
|
||||
Mail::to($this->request->participant->email_1)->send(new EventSignUpSuccessfullMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
|
||||
if ($this->request->participant->email_2 !== null) {
|
||||
Mail::to($this->request->participant->email_2)->send(new EventSignUpSuccessfullMail(
|
||||
participant: $this->request->participant,
|
||||
));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Event\Actions\SetParticipationState;
|
||||
|
||||
use App\Models\EventParticipant;
|
||||
|
||||
class SetParticipationStateReSignonRequest {
|
||||
function __construct(public EventParticipant $participant) {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Event\Actions\SetParticipationState;
|
||||
|
||||
class SetParticipationStateResponse {
|
||||
function __construct(public bool $success = false) {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Event\Actions\SetParticipationState;
|
||||
|
||||
use App\Models\EventParticipant;
|
||||
|
||||
class SetParticipationStateSignoffRequest {
|
||||
function __construct(public EventParticipant $participant, public \DateTime $date) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Event\Actions\UpdateParticipant;
|
||||
|
||||
use App\Enumerations\EfzStatus;
|
||||
use App\Mail\ParticipantCocMails\ParticipantCocCompleteMail;
|
||||
use App\Mail\ParticipantCocMails\ParticipantCocInvalidMail;
|
||||
use App\Mail\ParticipantPaymentMails\ParticipantPaymentMissingPaymentMail;
|
||||
use App\Mail\ParticipantPaymentMails\ParticipantPaymentOverpaidMail;
|
||||
use App\Mail\ParticipantPaymentMails\ParticipantPaymentPaidMail;
|
||||
use App\Models\EventParticipant;
|
||||
use App\Providers\MissingPaymentProvider;
|
||||
use App\ValueObjects\Amount;
|
||||
use DateTime;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class UpdateParticipantCommand {
|
||||
private UpdateParticipantResponse $response;
|
||||
function __construct(public UpdateParticipantRequest $request) {
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$this->response = new UpdateParticipantResponse();
|
||||
|
||||
$p = clone($this->request->participant);
|
||||
|
||||
$p->firstname = $this->request->firstname;
|
||||
$p->lastname = $this->request->lastname;
|
||||
$p->nickname = $this->request->nickname;
|
||||
$p->address_1 = $this->request->address_1;
|
||||
$p->address_2 = $this->request->address_2;
|
||||
$p->postcode = $this->request->postcode;
|
||||
$p->city = $this->request->city;
|
||||
$p->local_group = $this->request->localgroup;
|
||||
$p->birthday = DateTime::createFromFormat('Y-m-d', $this->request->birthday);
|
||||
$p->email_1 = $this->request->email_1;
|
||||
$p->phone_1 = $this->request->phone_1;
|
||||
$p->contact_person = $this->request->contact_person;
|
||||
$p->email_2 = $this->request->email_2;
|
||||
$p->phone_2 = $this->request->phone_2;
|
||||
$p->arrival_date = DateTime::createFromFormat('Y-m-d', $this->request->arrival);
|
||||
$p->departure_date = DateTime::createFromFormat('Y-m-d', $this->request->departure);
|
||||
$p->participation_type = $this->request->participationType;
|
||||
$p->eating_habit = $this->request->eatingHabit;
|
||||
$p->allergies = $this->request->allergies;
|
||||
$p->intolerances = $this->request->intolerances;
|
||||
$p->medications = $this->request->medications;
|
||||
$p->first_aid_permission = $this->request->extendedFirstAid;
|
||||
$p->swimming_permission = $this->request->swimmingPermission;
|
||||
$p->tetanus_vaccination = $this->request->tetanusVaccination !== null
|
||||
? DateTime::createFromFormat('Y-m-d', $this->request->tetanusVaccination)
|
||||
: null;
|
||||
$p->notes = $this->request->notes;
|
||||
$p->amount_paid = Amount::fromString($this->request->amountPaid);
|
||||
$p->amount = Amount::fromString($this->request->amountExpected);
|
||||
$p->efz_status = $this->request->cocStatus;
|
||||
|
||||
if (
|
||||
MissingPaymentProvider::calculateMissingPayment(amountPaid: $p->amount_paid, amountToPay: $p->amount)->getAmount()
|
||||
!==
|
||||
MissingPaymentProvider::calculateMissingPayment(amountPaid: $this->request->participant->amount_paid, amountToPay: $this->request->participant->amount)->getAmount()
|
||||
) {
|
||||
$this->handleAmountChanges($p);
|
||||
}
|
||||
|
||||
if (
|
||||
$p->efz_status !== $this->request->participant->efz_status
|
||||
) {
|
||||
$this->handleCocStatusChange($p);
|
||||
}
|
||||
|
||||
|
||||
$p->save();
|
||||
$this->response->success = true;
|
||||
$this->response->participant = $p;
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
private function handleAmountChanges(EventParticipant $participant) {
|
||||
$this->response->amountPaid = $participant->amount_paid;
|
||||
$this->response->amountExpected = $participant->amount;
|
||||
|
||||
$amountToPay = MissingPaymentProvider::calculateMissingPayment(
|
||||
amountPaid: $participant->amount_paid,
|
||||
amountToPay: $participant->amount,
|
||||
);
|
||||
|
||||
switch (true) {
|
||||
case $amountToPay->getAmount() > 0:
|
||||
Mail::to($participant->email_1)->send(new ParticipantPaymentMissingPaymentMail(
|
||||
participant: $participant,
|
||||
));
|
||||
|
||||
if ($participant->email_2 !== null) {
|
||||
Mail::to($participant->email_2)->send(new ParticipantPaymentMissingPaymentMail(
|
||||
participant: $participant,
|
||||
));
|
||||
}
|
||||
break;
|
||||
case $amountToPay->getAmount() < 0:
|
||||
Mail::to($participant->email_1)->send(new ParticipantPaymentOverpaidMail(
|
||||
participant: $participant,
|
||||
));
|
||||
|
||||
if ($participant->email_2 !== null) {
|
||||
Mail::to($participant->email_2)->send(new ParticipantPaymentOverpaidMail(
|
||||
participant: $participant,
|
||||
));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Mail::to($participant->email_1)->send(new ParticipantPaymentPaidMail(
|
||||
participant: $participant,
|
||||
));
|
||||
|
||||
if ($participant->email_2 !== null) {
|
||||
Mail::to($participant->email_2)->send(new ParticipantPaymentPaidMail(
|
||||
participant: $participant,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function handleCocStatusChange(EventParticipant $participant) {
|
||||
$this->response->cocStatus = $participant->efzStatus()->first();
|
||||
|
||||
switch ($participant->efzStatus()->first()->slug) {
|
||||
case EfzStatus::EFZ_STATUS_CHECKED_VALID:
|
||||
case EfzStatus::EFZ_STATUS_NOT_REQUIRED:
|
||||
Mail::to($participant->email_1)->send(new ParticipantCocCompleteMail(
|
||||
participant: $participant,
|
||||
));
|
||||
break;
|
||||
|
||||
case EfzStatus::EFZ_STATUS_CHECKED_INVALID:
|
||||
Mail::to($participant->email_1)->send(new ParticipantCocInvalidMail(
|
||||
participant: $participant,
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Event\Actions\UpdateParticipant;
|
||||
|
||||
use App\Models\EventParticipant;
|
||||
|
||||
class UpdateParticipantRequest {
|
||||
function __construct(
|
||||
public EventParticipant $participant,
|
||||
public string $firstname,
|
||||
public string $lastname,
|
||||
public ?string $nickname,
|
||||
public string $address_1,
|
||||
public ?string $address_2,
|
||||
public string $postcode,
|
||||
public string $city,
|
||||
public string $localgroup,
|
||||
public string $birthday,
|
||||
public string $email_1,
|
||||
public string $phone_1,
|
||||
public string $contact_person,
|
||||
public ?string $email_2,
|
||||
public ?string $phone_2,
|
||||
public string $arrival,
|
||||
public string $departure,
|
||||
public string $participationType,
|
||||
public string $eatingHabit,
|
||||
public ?string $allergies,
|
||||
public ?string $intolerances,
|
||||
public ?string $medications,
|
||||
public string $extendedFirstAid,
|
||||
public string $swimmingPermission,
|
||||
public ?string $tetanusVaccination,
|
||||
public ?string $notes,
|
||||
public string $amountPaid,
|
||||
public string $amountExpected,
|
||||
public string $cocStatus,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Event\Actions\UpdateParticipant;
|
||||
|
||||
use App\Enumerations\EfzStatus;
|
||||
use App\Models\EventParticipant;
|
||||
use App\ValueObjects\Amount;
|
||||
|
||||
class UpdateParticipantResponse {
|
||||
public bool $success;
|
||||
public ?EfzStatus $cocStatus;
|
||||
public ?Amount $amountPaid;
|
||||
public ?Amount $amountExpected;
|
||||
public ?EventParticipant $participant;
|
||||
|
||||
public function __construct() {
|
||||
$this->success = false;
|
||||
$this->cocStatus =null;
|
||||
$this->amountPaid = null;
|
||||
$this->amountExpected = null;
|
||||
$this->participant = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user