Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Přidáni instruktoři do seznamu lidí u vzdělávaček #2330

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b4b57d7
Added querying of education instructors
marekdedic Sep 26, 2023
6829252
Created a superclass for participants and instructors
marekdedic Sep 26, 2023
9452eea
Using ParticipatingPerson in EditParticipantDialog
marekdedic Sep 26, 2023
f514a57
Editable participant list title
marekdedic Sep 26, 2023
e65ad34
Editable instructor payment amount
marekdedic Sep 26, 2023
40314b5
Not showing units for education instructors
marekdedic Sep 26, 2023
a05a981
Education participant tab rename
marekdedic Sep 26, 2023
473abe9
Fixed education payments being deleted
marekdedic Sep 28, 2023
a0c8d92
Added the ability to load HPD from instructors
marekdedic Sep 28, 2023
9c44da6
Renamed buttons for HPD import for education events
marekdedic Sep 28, 2023
7371635
removed an obsolete TODO
marekdedic Sep 28, 2023
e83b30d
Fixed coding standard
marekdedic Sep 28, 2023
0ac19f1
Pushed common properties from Participant and Instructor to Participa…
marekdedic Sep 28, 2023
57a9ede
Checking method existence before accessing it for participant days up…
marekdedic Sep 28, 2023
9115e42
Split participant export between participants and instructors
marekdedic Sep 29, 2023
e8d8f11
asserting object is Participant instead of checking method
marekdedic Oct 8, 2023
3c45a2d
Removed unused parameters from event and camp participan export
marekdedic Oct 8, 2023
d574bb7
Seznam lidí -> Seznam osob
marekdedic Oct 8, 2023
8d71539
Added missing parameter to ParticipantList factory call
marekdedic Oct 15, 2023
5b55574
Fixed IsAccepted for instructors
marekdedic Oct 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Assert\Assertion;
use Closure;
use Model\DTO\Participant\Participant;
use Model\DTO\Participant\ParticipatingPerson;
use Model\DTO\Participant\UpdateParticipant;

use function assert;
Expand All @@ -21,7 +22,7 @@ final class EditParticipantDialog extends Dialog
/** @var Closure[] */
public array $onUpdate = [];

/** @param array<int, Participant> $participants */
/** @param array<int, ParticipatingPerson> $participants */
public function __construct(private array $participants, private bool $isAllowedDaysUpdate, private bool $isAccountAllowed, private bool $isRepaymentAllowed, private bool $isOnlineLogin)
{
}
Expand All @@ -43,11 +44,12 @@ protected function createComponentForm(): BaseForm
Assertion::keyExists($this->participants, $this->participantId);

$participant = $this->participants[$this->participantId];
assert($participant instanceof Participant);
assert($participant instanceof ParticipatingPerson);

$form = new BaseForm();

if ($this->isAllowedDaysUpdate) {
assert($participant instanceof Participant);
$days = $form->addInteger('days', 'Počet dní')
->setRequired('Musíte vyplnit počet dní')
->addRule(BaseForm::MIN, 'Minimální počet dní je %d', 0)
Expand Down Expand Up @@ -87,7 +89,7 @@ protected function createComponentForm(): BaseForm
$changes[UpdateParticipant::FIELD_PAYMENT] = $values['payment'];
}

if ($this->isAllowedDaysUpdate && isset($values['days']) && $values['days'] !== $participant->getDays()) {
if ($this->isAllowedDaysUpdate && isset($values['days']) && $participant instanceof Participant && $values['days'] !== $participant->getDays()) {
$changes[UpdateParticipant::FIELD_DAYS] = $values['days'];
}

Expand All @@ -99,7 +101,7 @@ protected function createComponentForm(): BaseForm
$changes[UpdateParticipant::FIELD_IS_ACCOUNT] = $values['isAccount'];
}

$this->onUpdate($this->participantId, $changes, $participant->isAccepted());
$this->onUpdate($this->participantId, $changes, $participant instanceof Participant ? $participant->isAccepted() : null);
$this->hide();
};

Expand Down
33 changes: 21 additions & 12 deletions app/AccountancyModule/Components/Participants/ParticipantList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\AccountancyModule\Components\BaseControl;
use App\Forms\BaseForm;
use Model\DTO\Participant\Participant;
use Model\DTO\Participant\ParticipatingPerson;
use Model\DTO\Participant\UpdateParticipant;
use Model\Participant\ParticipantNotFound;
use Nette\Application\BadRequestException;
Expand Down Expand Up @@ -53,7 +54,7 @@ final class ParticipantList extends BaseControl
/** @persistent */
public string|null $sort = 'displayName';

/** @param Participant[] $currentParticipants */
/** @param ParticipatingPerson[] $currentParticipants */
public function __construct(
public int $aid,
private array $currentParticipants,
Expand All @@ -63,6 +64,9 @@ public function __construct(
protected bool $isAllowParticipantUpdate,
protected bool $isAllowParticipantDelete,
protected bool $isOnlineLogin,
protected bool $isAllowShowUnits,
protected string $title,
protected string $exportType,
) {
}

Expand All @@ -84,32 +88,35 @@ public function render(): void
$this->template->setFile(__DIR__ . '/templates/ParticipantList.latte');
$this->template->setParameters([
'aid' => $this->aid,
'title' => $this->title,
'participants' => $this->currentParticipants,
'sort' => $this->sort,
'sortOptions' => $sortOptions,
'isAllowShowUnits' => $this->isAllowShowUnits,
'showUnits' => $this->showUnits,
'isAllowDaysUpdate' => $this->isAllowDaysUpdate,
'isAllowRepayment' => $this->isAllowRepayment,
'isAllowIsAccount' => $this->isAllowIsAccount,
'isAllowParticipantUpdate' => $this->isAllowParticipantUpdate,
'isAllowParticipantDelete' => $this->isAllowParticipantDelete,
'isAllowAnyAction' => $this->isAllowParticipantUpdate || $this->isAllowParticipantDelete,
'exportType' => $this->exportType,
]);

$this->template->render();
}

/** @param Participant[] $participants */
/** @param ParticipatingPerson[] $participants */
protected function sortParticipants(array &$participants, string $sort): void
{
if (! isset(self::SORT_OPTIONS[$sort])) {
throw new BadRequestException(sprintf('Unknown sort option "%s"', $sort), 400);
}

if ($sort === 'displayName') {
$sortFunction = fn (Participant $a, Participant $b) => strcoll($a->{$sort}, $b->{$sort});
$sortFunction = fn (ParticipatingPerson $a, ParticipatingPerson $b) => strcoll($a->{$sort}, $b->{$sort});
} else {
$sortFunction = fn (Participant $a, Participant $b) => $a->{$sort} <=> $b->{$sort};
$sortFunction = fn (ParticipatingPerson $a, ParticipatingPerson $b) => $a->{$sort} <=> $b->{$sort};
}

usort($participants, $sortFunction);
Expand Down Expand Up @@ -144,7 +151,7 @@ public function handleRemove(int $participantId): void
$this->onRemove([$participantId]);
$this->currentParticipants = array_filter(
$this->currentParticipants,
function (Participant $p) use ($participantId) {
function (ParticipatingPerson $p) use ($participantId) {
return $p->getId() !== $participantId;
},
);
Expand All @@ -167,7 +174,7 @@ protected function createComponentEditDialog(): EditParticipantDialog
{
$dialog = new EditParticipantDialog($this->participantsById(), $this->isAllowDaysUpdate, $this->isAllowIsAccount, $this->isAllowRepayment, $this->isOnlineLogin);

$dialog->onUpdate[] = function (int $participantId, array $fields, bool $isAccepted): void {
$dialog->onUpdate[] = function (int $participantId, array $fields, bool|null $isAccepted): void {
$changes = [];

foreach ($fields as $field => $value) {
Expand Down Expand Up @@ -237,27 +244,29 @@ private function massEditSubmitted(SubmitButton $button): void
foreach ($button->getForm()->getValues()->participantIds as $participantId) {
$participant = $currentParticipants[$participantId] ?? throw new ParticipantNotFound('Cannot find participant from the given data');

$isAccepted = $participant instanceof Participant ? $participant->isAccepted() : null;

if ($values['days'] !== null) {
if ($this->isOnlineLogin && ! $participant->isAccepted()) {
if ($this->isOnlineLogin && ! $isAccepted) {
$participantUpdateError[] = $participant->displayName;
} else {
$changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_DAYS, $values['days'], $participant->isAccepted());
$changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_DAYS, $values['days'], $isAccepted);
}
}

if ($values['payment'] !== null) {
$changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_PAYMENT, $values['payment'], $participant->isAccepted());
$changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_PAYMENT, $values['payment'], $isAccepted);
}

if ($values['repayment'] !== null) {
$changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_REPAYMENT, $values['repayment'], $participant->isAccepted());
$changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_REPAYMENT, $values['repayment'], $isAccepted);
}

if (in_array($values['isAccount'], [self::NO_ACTION, null])) {
continue;
}

$changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_IS_ACCOUNT, $values['isAccount'], $participant->isAccepted());
$changes[] = new UpdateParticipant($this->aid, $participantId, UpdateParticipant::FIELD_IS_ACCOUNT, $values['isAccount'], $isAccepted);
}

if (! empty($participantUpdateError)) {
Expand Down Expand Up @@ -287,7 +296,7 @@ private function massRemoveSubmitted(SubmitButton $button): void
$this->reload('Účastníci byli odebráni');
}

/** @return array<int, Participant> Participant's indexed by their ID */
/** @return array<int, ParticipatingPerson> Participant's indexed by their ID */
private function participantsById(): array
{
$participants = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $showUnits bool - zobrazovat číslo jednotky

{var $tabIndex = 1}
<div n:ifset="$participants">
<h2 class="mb-3">Seznam účastníků</h2>
<h2 class="mb-3">{$title}</h2>
<div class="d-flex mb-2">
<div class="dropdown d-inline-block mr-auto">
<button n:class="btn, btn-light, dropdown-toggle, empty($participants) ? 'disabled'"
Expand All @@ -71,10 +71,10 @@ $showUnits bool - zobrazovat číslo jednotky
<i class="fas fa-arrow-down"></i> Exportovat&hellip;
</button>
<div class="dropdown-menu" aria-labelledby="exportParticipantsButton">
<a class="dropdown-item" href="{plink export $aid}">
<a class="dropdown-item" href="{plink export $aid, $exportType}">
<span class="mr-1"><i class="far fa-file-pdf"></i></span> PDF
</a>
<a class="dropdown-item" href="{plink exportExcel $aid}">
<a class="dropdown-item" href="{plink exportExcel $aid, $exportType}">
<span class="mr-1"><i class="far fa-file-excel"></i></span>
Excel
</a>
Expand All @@ -89,7 +89,7 @@ $showUnits bool - zobrazovat číslo jednotky
<a n:href="sort $id" class="dropdown-item ajax">{$label}</a>
</div>
</span>
<a n:href="showUnits !$showUnits" class='btn btn-light ajax'>
<a n:if="$isAllowShowUnits" n:href="showUnits !$showUnits" class='btn btn-light ajax'>
<i n:class="fas, $showUnits ? 'fa-eye' : 'fa-eye-slash'"></i>
{$showUnits ? 'Skrýt' : 'Zobrazit'} jednotku
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Model\Cashbook\ReadModel\Queries\CategoryListQuery;
use Model\Cashbook\ReadModel\Queries\ChitListQuery;
use Model\Cashbook\ReadModel\Queries\EducationCashbookIdQuery;
use Model\Cashbook\ReadModel\Queries\EducationInstructorIncomeQuery;
use Model\Cashbook\ReadModel\Queries\EducationParticipantCategoryIdQuery;
use Model\Cashbook\ReadModel\Queries\EducationParticipantIncomeQuery;
use Model\Cashbook\ReadModel\Queries\FinalCashBalanceQuery;
Expand Down Expand Up @@ -81,6 +82,9 @@ protected function createComponentCashbook(): CashbookControl
protected function createComponentFormImportHpd(): BaseForm
{
$form = new BaseForm();
$form->addRadioList('from', 'Od:', ['participant' => 'Od účastníků', 'instructor' => 'Od instruktorů'])
->addRule($form::FILLED, 'Musíte vyplnit kategorii.')
->setDefaultValue('participant');
$form->addRadioList('isAccount', 'Placeno:', ['N' => 'Hotově', 'Y' => 'Přes účet'])
->addRule($form::FILLED, 'Musíte vyplnit způsob platby.')
->setDefaultValue('N');
Expand All @@ -102,14 +106,16 @@ private function formImportHpdSubmitted(BaseForm $form): void
$this->editableOnly();
$values = $form->getValues();

$amount = $this->queryBus->handle(new EducationParticipantIncomeQuery(new SkautisEducationId($this->aid)));
$amount = $values->from === 'instructor'
? $this->queryBus->handle(new EducationInstructorIncomeQuery(new SkautisEducationId($this->aid)))
: $this->queryBus->handle(new EducationParticipantIncomeQuery(new SkautisEducationId($this->aid)));

if ($amount === 0.0) {
$this->flashMessage('Nemáte žádné příjmy od účastníků, které by bylo možné importovat.', 'warning');
$this->redirect('default', ['aid' => $this->aid]);
}

$purpose = 'úč. příspěvky ' . ($values->isAccount === 'Y' ? '- účet' : '- hotovost');
$purpose = 'úč. příspěvky - ' . ($values->from === 'instructor' ? 'instruktoři' : 'účastníci') . ' - ' . ($values->isAccount === 'Y' ? 'účet' : 'hotovost');
$body = new ChitBody(null, $this->event->getStartDate(), null);

$categoryId = $this->queryBus->handle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
use App\AccountancyModule\ExcelResponse;
use App\AccountancyModule\Factories\Participants\IParticipantListFactory;
use Model\Auth\Resources\Education;
use Model\Cashbook\ReadModel\Queries\EducationInstructorListQuery;
use Model\Cashbook\ReadModel\Queries\EducationParticipantListQuery;
use Model\DTO\Instructor\Instructor;
use Model\DTO\Participant\Participant;
use Model\DTO\Participant\ParticipatingPerson;
use Model\DTO\Participant\UpdateParticipant;
use Model\ExcelService;
use Model\ExportService;
Expand Down Expand Up @@ -76,7 +79,7 @@ public function renderDefault(int $aid): void
$this->redrawControl('contentSnip');
}

public function actionExportExcel(int $aid): void
public function actionExportExcel(int $aid, string $exportType): void
{
if ($this->event->getStartDate() === null) {
$this->flashMessage('Bez vyplněného počátku akce nelze exportovat seznam účastníků, protože nelze dopočítat věk v době akce.', 'danger');
Expand All @@ -94,6 +97,37 @@ public function actionExportExcel(int $aid): void
}
}

protected function createComponentInstructorList(): ParticipantList
{
$control = $this->participantListFactory->create(
$this->aid,
$this->eventInstructors(),
false,
true,
true,
true,
false,
false,
false,
'Seznam instruktorů',
ParticipatingPerson::INSTRUCTOR,
);

$control->onUpdate[] = function (array $updates): void {
foreach ($updates as $u) {
assert($u instanceof UpdateParticipant);
if (! in_array($u->getField(), UpdateParticipant::getEducationFields())) {
$this->flashMessage(sprintf('Nelze upravit pole: %s', $u->getField()), 'warning');
$this->redirect('this');
}

$this->participants->update(EventType::EDUCATION(), $u);
}
};

return $control;
}

protected function createComponentParticipantList(): ParticipantList
{
$control = $this->participantListFactory->create(
Expand Down Expand Up @@ -122,10 +156,10 @@ protected function createComponentParticipantList(): ParticipantList
return $control;
}

public function actionExport(int $aid): void
public function actionExport(int $aid, string $exportType): void
{
try {
$template = $this->exportService->getParticipants($aid, EventType::EDUCATION);
$template = $this->exportService->getParticipants($aid, EventType::EDUCATION, $exportType);
$this->pdf->render($template, 'seznam-ucastniku.pdf', false);
} catch (PermissionException $ex) {
$this->flashMessage('Nemáte oprávnění k záznamu osoby! (' . $ex->getMessage() . ')', 'danger');
Expand All @@ -135,6 +169,12 @@ public function actionExport(int $aid): void
$this->terminate();
}

/** @return Instructor[] */
private function eventInstructors(): array
{
return $this->queryBus->handle(new EducationInstructorListQuery($this->event->getId()));
}

/** @return Participant[] */
private function eventParticipants(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="mb-2 card" n:if="$isEditable">
<div class="card-body">
<a n:if="$isEditable" href="#importHpd" role="button" data-toggle="modal" class="btn btn-primary">
<i class="far fa-user"></i>&nbsp;Načíst příjmy od účastníků
<i class="far fa-user"></i>&nbsp;Načíst účastnické poplatky
</a>
</div>
</div>
Expand All @@ -27,7 +27,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Import příjmů od účastníků</h3>
<h3 class="modal-title">Import účastnických poplatků</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"> &times; </span></button>
</div>
<div class="modal-body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
{block #content}
{include ../header.latte}

<div class="row">
<div class="col-lg-12">
{control instructorList}
</div>
</div>

<div class="row">
<div class="col-lg-12">
{control participantList}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<li n:class="nav-item, $presenterName === 'Participant' ? active">
<a class="nav-link" n:href="Participant: $event->getId()->toInt()"><i
class="fas fa-users"></i>
Seznam účastníků</a>
Seznam osob</a>
</li>
<li n:class="nav-item, $presenterName === 'Cashbook' ? active">
<a class="nav-link" n:href="Cashbook: $event->getId()->toInt()"><i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace App\AccountancyModule\Factories\Participants;

use App\AccountancyModule\Components\Participants\ParticipantList;
use Model\DTO\Participant\Participant;
use Model\DTO\Participant\ParticipatingPerson;

interface IParticipantListFactory
{
/** @param Participant[] $currentParticipants */
/** @param ParticipatingPerson[] $currentParticipants */
public function create(
int $aid,
array $currentParticipants,
Expand All @@ -19,5 +19,8 @@ public function create(
bool $isAllowParticipantUpdate,
bool $isAllowParticipantDelete,
bool $isOnlineLogin,
bool $isAllowShowUnits = true,
string $title = 'Seznam účastníků',
string $exportType = ParticipatingPerson::PARTICIPANT,
): ParticipantList;
}
Loading
Loading