From 4db7ecd261ea864a0169b992ba16fb93e1e9957b Mon Sep 17 00:00:00 2001 From: Lung Date: Thu, 1 Aug 2024 10:46:59 +0200 Subject: [PATCH] added marking for deals as completed --- src/Application/Route.php | 3 +++ src/Deal/DealController.php | 22 +++++++++++++++++++ src/Deal/DealRepository.php | 20 +++++++++++++++++ src/Templates/cs.yaml | 1 + src/Templates/en.yaml | 1 + src/Templates/sk.yaml | 1 + .../translatable/admin/mendParticipant.twig | 20 +++++++++++++++-- 7 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/Application/Route.php b/src/Application/Route.php index 3334d96e..b0d10912 100755 --- a/src/Application/Route.php +++ b/src/Application/Route.php @@ -204,6 +204,9 @@ public function addRoutesInto(App $app): App $app->post('/unentry', EntryController::class . '::unentryFromAdmin') ->setName('admin-unentry-participant'); + $app->post('/setDealAsDone/{dealSlug}', DealController::class . '::setDealAsDone') + ->setName('admin-set-deal-as-done'); + $app->get('/showDetails', AdminController::class . '::showParticipantDetails') ->setName('admin-show-participant-details-changeable'); diff --git a/src/Deal/DealController.php b/src/Deal/DealController.php index 20c68e83..12e34d36 100644 --- a/src/Deal/DealController.php +++ b/src/Deal/DealController.php @@ -5,6 +5,7 @@ namespace kissj\Deal; use kissj\AbstractController; +use kissj\Participant\ParticipantRepository; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use kissj\Event\Event; @@ -13,6 +14,7 @@ class DealController extends AbstractController { public function __construct( private readonly DealRepository $dealRepository, + private readonly ParticipantRepository $participantRepository, ) { } @@ -41,4 +43,24 @@ public function catchDataFromGoogleForm( return $response->withStatus(201); } + + public function setDealAsDone( + Request $request, + Response $response, + Event $event, + int $participantId, + string $dealSlug, + ): Response { + $participant = $this->participantRepository->getParticipantById($participantId, $event); + $this->dealRepository->setDealAsDone($participant, $dealSlug); + + return $this->redirect( + $request, + $response, + 'admin-mend-participant', + [ + 'participantId' => (string)$participantId, + ], + ); + } } diff --git a/src/Deal/DealRepository.php b/src/Deal/DealRepository.php index 1268b9ce..38a6ec80 100644 --- a/src/Deal/DealRepository.php +++ b/src/Deal/DealRepository.php @@ -84,6 +84,26 @@ public function trySaveNewDealFromGoogleForm( return $deal; } + public function setDealAsDone( + Participant $participant, + string $dealSlug, + ): Deal { + $deal = $participant->findDeal($dealSlug); + if ($deal === null) { + $deal = new Deal(); + $deal->participant = $participant; + $deal->slug = $dealSlug; + $deal->data = 'by admin'; + $deal->urlAddress = ''; + } + + $deal->isDone = true; + $deal->doneAt = DateTimeUtils::getDateTime(); + $this->persist($deal); + + return $deal; + } + private function findDeal(string $slug, string $tieCode): ?Deal { $qb = $this->createFluent(); diff --git a/src/Templates/cs.yaml b/src/Templates/cs.yaml index a6a2d7ad..529e9382 100755 --- a/src/Templates/cs.yaml +++ b/src/Templates/cs.yaml @@ -442,6 +442,7 @@ mend-admin: uncancelParticipant: "Označit účastníka že opět přijede" entryParticipant: "Označit účastníka, že vstoupil na akci" unentryParticipant: "Označit účastníka, že na akci nevstoupil" + setDealAsDone: "Označit deal jako splněný" receipt: headline: "Potvrzení o přijetí platby" number: "Číslo dokladu" diff --git a/src/Templates/en.yaml b/src/Templates/en.yaml index 9219b8ab..e19c34d5 100755 --- a/src/Templates/en.yaml +++ b/src/Templates/en.yaml @@ -442,6 +442,7 @@ mend-admin: uncancelParticipant: "Mark participant as going, from state when he is not going" entryParticipant: "Mark participant as entered into event" unentryParticipant: "Mark participant as not entered into event" + setDealAsDone: "Set deal as completed" receipt: headline: "Confirmation of payment acceptance" number: "Receipt number" diff --git a/src/Templates/sk.yaml b/src/Templates/sk.yaml index 9a7081f9..09919a00 100755 --- a/src/Templates/sk.yaml +++ b/src/Templates/sk.yaml @@ -442,6 +442,7 @@ mend-admin: uncancelParticipant: "Označit účastníka že opět přijede" entryParticipant: "Označit účastníka, že vstoupil na akci" unentryParticipant: "Označit účastníka, že na akci nevstoupil" + setDealAsDone: "Označit deal jako splněný" receipt: headline: "Potvrzení o přijetí platby" number: "Číslo dokladu" diff --git a/src/Templates/translatable/admin/mendParticipant.twig b/src/Templates/translatable/admin/mendParticipant.twig index 71f740d3..eee51249 100755 --- a/src/Templates/translatable/admin/mendParticipant.twig +++ b/src/Templates/translatable/admin/mendParticipant.twig @@ -29,11 +29,27 @@ {% if participant.deals %} - {% for participantDeal in participant.deals %} - {{ participantDeal.slug }}{% if not participantDeal.isDone %} ❌{% else %} ✅{% endif %}{{ not loop.last ? ' | ' }} + {{ participantDeal.slug }}{% if not participantDeal.isDone %} + ❌ +
+ +
+ {% else %} ✅{% endif %}{{ not loop.last ? ' | ' }} {% endfor %} {% else %} + {# TODO fix for combination of participant deals with event deals #} {% for eventDeal in event.eventType.getEventDeals(participant) %} - {{ eventDeal.slug }} ❌{{ not loop.last ? ' | ' }} + {{ eventDeal.slug }} ❌ +
+ +
+ {{ not loop.last ? ' | ' }} {% endfor %} {% endif %}