Skip to content

Commit

Permalink
added marking for deals as completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Aug 1, 2024
1 parent 96a155c commit 4db7ecd
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Application/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
22 changes: 22 additions & 0 deletions src/Deal/DealController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,6 +14,7 @@ class DealController extends AbstractController
{
public function __construct(
private readonly DealRepository $dealRepository,
private readonly ParticipantRepository $participantRepository,
) {
}

Expand Down Expand Up @@ -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,
],
);
}
}
20 changes: 20 additions & 0 deletions src/Deal/DealRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/Templates/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/Templates/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/Templates/sk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions src/Templates/translatable/admin/mendParticipant.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<form
method="POST"
action="{{ url_for('admin-set-deal-as-done', {'eventSlug': event.slug, 'participantId': participant.id, 'dealSlug': participantDeal.slug}) }}"
>
<input type="submit" class="btn btn-mini" value="{% trans %}mend-admin.setDealAsDone{% endtrans %}">
</form>
{% 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 }} ❌
<form
method="POST"
action="{{ url_for('admin-set-deal-as-done', {'eventSlug': event.slug, 'participantId': participant.id, 'dealSlug': eventDeal.slug}) }}"
>
<input type="submit" class="btn btn-mini" value="{% trans %}mend-admin.setDealAsDone{% endtrans %}">
</form>
{{ not loop.last ? ' | ' }}
{% endfor %}
{% endif %}
</div>
Expand Down

0 comments on commit 4db7ecd

Please sign in to comment.