From 68554e701061f19ca0091937314671f837ff7aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Wed, 25 Oct 2023 23:31:54 +0200 Subject: [PATCH 1/6] Added year to table of education cashbooks --- migrations/2023/Version20231025231859.php | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 migrations/2023/Version20231025231859.php diff --git a/migrations/2023/Version20231025231859.php b/migrations/2023/Version20231025231859.php new file mode 100644 index 000000000..fae608c43 --- /dev/null +++ b/migrations/2023/Version20231025231859.php @@ -0,0 +1,28 @@ +addSql('ALTER TABLE `ac_education_cashbooks` ADD COLUMN `year` INT NOT NULL AFTER `id`;'); + $this->addSql('ALTER TABLE `ac_education_cashbooks` DROP PRIMARY KEY, ADD PRIMARY KEY(`id`, `year`);'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE `ac_education_cashbooks` DROP PRIMARY KEY, ADD PRIMARY KEY(`id`);'); + $this->addSql('ALTER TABLE `ac_education_cashbooks` DROP COLUMN `year`;'); + } +} From cab03bd9c2c45a62cf683e5f9b8bedd05b6facd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Wed, 25 Oct 2023 23:56:31 +0200 Subject: [PATCH 2/6] Loading education cashbooks by event ID + year --- .../EducationModule/EducationListDataSource.php | 2 +- .../EducationModule/presenters/BudgetPresenter.php | 10 +++++----- .../presenters/CashbookPresenter.php | 2 +- .../presenters/EducationPresenter.php | 10 +++++----- app/model/Cashbook/Education.php | 14 +++++++++++++- .../ReadModel/Queries/EducationCashbookIdQuery.php | 7 ++++++- .../InconsistentEducationCategoryTotalsQuery.php | 7 ++++++- .../EducationCashbookIdQueryHandler.php | 2 +- ...nsistentEducationCategoryTotalsQueryHandler.php | 2 +- .../Cashbook/Repositories/IEducationRepository.php | 2 +- app/model/Export/ExportService.php | 4 ++-- .../Repositories/Cashbook/EducationRepository.php | 4 ++-- 12 files changed, 44 insertions(+), 22 deletions(-) diff --git a/app/AccountancyModule/EducationModule/EducationListDataSource.php b/app/AccountancyModule/EducationModule/EducationListDataSource.php index 926028d71..693c02e2a 100644 --- a/app/AccountancyModule/EducationModule/EducationListDataSource.php +++ b/app/AccountancyModule/EducationModule/EducationListDataSource.php @@ -54,7 +54,7 @@ function (Education $education): EducationListItem { private function chitNumberPrefix(Education $camp): string|null { - $cashbookId = $this->queryBus->handle(new EducationCashbookIdQuery($camp->getId())); + $cashbookId = $this->queryBus->handle(new EducationCashbookIdQuery($camp->getId(), $camp->endDate->year)); assert($cashbookId instanceof CashbookId); diff --git a/app/AccountancyModule/EducationModule/presenters/BudgetPresenter.php b/app/AccountancyModule/EducationModule/presenters/BudgetPresenter.php index acd78eb8e..391885b90 100644 --- a/app/AccountancyModule/EducationModule/presenters/BudgetPresenter.php +++ b/app/AccountancyModule/EducationModule/presenters/BudgetPresenter.php @@ -44,12 +44,12 @@ public function renderDefault(int $aid): void $educationId = new SkautisEducationId($aid); - $inconsistentTotals = $this->queryBus->handle(new InconsistentEducationCategoryTotalsQuery($educationId)); + $inconsistentTotals = $this->queryBus->handle(new InconsistentEducationCategoryTotalsQuery($educationId, $this->event->endDate->year)); $this->template->setParameters([ 'isConsistent' => count($inconsistentTotals) === 0, 'toRepair' => $inconsistentTotals, 'budgetEntries' => $this->queryBus->handle(new EducationBudgetQuery($educationId, $this->event->grantId)), - 'categoriesSummary' => $this->queryBus->handle(new CategoriesSummaryQuery($this->getCashbookId($aid))), + 'categoriesSummary' => $this->queryBus->handle(new CategoriesSummaryQuery($this->getCashbookId($aid, $this->event->endDate->year))), 'isUpdateStatementAllowed' => $this->authorizator->isAllowed(Grant::UPDATE_REAL_BUDGET_SPENDING, $this->event->grantId->toInt()), ]); if (! $this->isAjax()) { @@ -66,7 +66,7 @@ public function handleConvert(int $aid): void { $this->editableOnly(); - $this->commandBus->handle(new UpdateEducationCategoryTotals($this->getCashbookId($aid))); + $this->commandBus->handle(new UpdateEducationCategoryTotals($this->getCashbookId($aid, $this->event->endDate->year))); $this->flashMessage('Kategorie byly přepočítány.'); if ($this->isAjax()) { @@ -76,8 +76,8 @@ public function handleConvert(int $aid): void } } - private function getCashbookId(int $educationId): CashbookId + private function getCashbookId(int $educationId, int $year): CashbookId { - return $this->queryBus->handle(new EducationCashbookIdQuery(new SkautisEducationId($educationId))); + return $this->queryBus->handle(new EducationCashbookIdQuery(new SkautisEducationId($educationId), $year)); } } diff --git a/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php b/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php index fe4366810..f4a0f7f10 100644 --- a/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php +++ b/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php @@ -128,7 +128,7 @@ private function formImportHpdSubmitted(BaseForm $form): void private function getCashbookId(): CashbookId { - return $this->queryBus->handle(new EducationCashbookIdQuery(new SkautisEducationId($this->aid))); + return $this->queryBus->handle(new EducationCashbookIdQuery(new SkautisEducationId($this->aid), $this->event->endDate->year)); } private function isCashbookEmpty(): bool diff --git a/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php b/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php index cdd0e5f57..878433011 100644 --- a/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php +++ b/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php @@ -50,13 +50,13 @@ public function renderDefault(int|null $aid): void $this->redirect('Default:'); } - $cashbook = $this->queryBus->handle(new CashbookQuery($this->getCashbookId($aid))); + $cashbook = $this->queryBus->handle(new CashbookQuery($this->getCashbookId($aid, $this->event->endDate->year))); assert($cashbook instanceof Cashbook); $finalRealBalance = null; if ($this->authorizator->isAllowed(Education::ACCESS_BUDGET, $aid)) { try { - $finalRealBalance = $this->queryBus->handle(new FinalRealBalanceQuery($this->getCashbookId($aid))); + $finalRealBalance = $this->queryBus->handle(new FinalRealBalanceQuery($this->getCashbookId($aid, $this->event->endDate->year))); } catch (MissingCategory) { } } @@ -134,15 +134,15 @@ public function renderReport(int $aid): void $this->redirect('default', ['aid' => $aid]); } - $template = $this->exportService->getEducationReport(new SkautisEducationId($aid)); + $template = $this->exportService->getEducationReport(new SkautisEducationId($aid), $this->event->endDate->year); $this->pdf->render($template, 'report.pdf'); $this->terminate(); } - private function getCashbookId(int $skautisEducationId): CashbookId + private function getCashbookId(int $skautisEducationId, int $year): CashbookId { - return $this->queryBus->handle(new EducationCashbookIdQuery(new SkautisEducationId($skautisEducationId))); + return $this->queryBus->handle(new EducationCashbookIdQuery(new SkautisEducationId($skautisEducationId), $year)); } /** diff --git a/app/model/Cashbook/Education.php b/app/model/Cashbook/Education.php index 94fad4464..67b2c45e1 100644 --- a/app/model/Cashbook/Education.php +++ b/app/model/Cashbook/Education.php @@ -21,12 +21,19 @@ class Education extends Aggregate */ private SkautisEducationId $id; + /** + * @ORM\Id() + * @ORM\Column(type="int") + */ + private int $year; + /** @ORM\Column(type="cashbook_id") */ private CashbookId $cashbookId; - public function __construct(SkautisEducationId $id, CashbookId $cashbookId) + public function __construct(SkautisEducationId $id, int $year, CashbookId $cashbookId) { $this->id = $id; + $this->year = $year; $this->cashbookId = $cashbookId; } @@ -35,6 +42,11 @@ public function getSkautisId(): SkautisEducationId return $this->id; } + public function getYear(): int + { + return $this->year; + } + public function getCashbookId(): CashbookId { return $this->cashbookId; diff --git a/app/model/Cashbook/ReadModel/Queries/EducationCashbookIdQuery.php b/app/model/Cashbook/ReadModel/Queries/EducationCashbookIdQuery.php index 8d4015ca0..aa42aeb2c 100644 --- a/app/model/Cashbook/ReadModel/Queries/EducationCashbookIdQuery.php +++ b/app/model/Cashbook/ReadModel/Queries/EducationCashbookIdQuery.php @@ -11,7 +11,7 @@ final class EducationCashbookIdQuery { private SkautisEducationId $educationId; - public function __construct(SkautisEducationId $eventId) + public function __construct(SkautisEducationId $eventId, private int $year) { $this->educationId = $eventId; } @@ -20,4 +20,9 @@ public function getEducationId(): SkautisEducationId { return $this->educationId; } + + public function getYear(): int + { + return $this->year; + } } diff --git a/app/model/Cashbook/ReadModel/Queries/InconsistentEducationCategoryTotalsQuery.php b/app/model/Cashbook/ReadModel/Queries/InconsistentEducationCategoryTotalsQuery.php index 9e96cc4d7..fc96e6bca 100644 --- a/app/model/Cashbook/ReadModel/Queries/InconsistentEducationCategoryTotalsQuery.php +++ b/app/model/Cashbook/ReadModel/Queries/InconsistentEducationCategoryTotalsQuery.php @@ -14,7 +14,7 @@ */ final class InconsistentEducationCategoryTotalsQuery { - public function __construct(private SkautisEducationId $educationId) + public function __construct(private SkautisEducationId $educationId, private int $year) { } @@ -22,4 +22,9 @@ public function getEducationId(): SkautisEducationId { return $this->educationId; } + + public function getYear(): int + { + return $this->year; + } } diff --git a/app/model/Cashbook/ReadModel/QueryHandlers/EducationCashbookIdQueryHandler.php b/app/model/Cashbook/ReadModel/QueryHandlers/EducationCashbookIdQueryHandler.php index 6ff3401a4..642d531f5 100644 --- a/app/model/Cashbook/ReadModel/QueryHandlers/EducationCashbookIdQueryHandler.php +++ b/app/model/Cashbook/ReadModel/QueryHandlers/EducationCashbookIdQueryHandler.php @@ -16,6 +16,6 @@ public function __construct(private IEducationRepository $eventRepository) public function __invoke(EducationCashbookIdQuery $query): CashbookId { - return $this->eventRepository->findBySkautisId($query->getEducationId())->getCashbookId(); + return $this->eventRepository->findBySkautisIdAndYear($query->getEducationId(), $query->getYear())->getCashbookId(); } } diff --git a/app/model/Cashbook/ReadModel/QueryHandlers/InconsistentEducationCategoryTotalsQueryHandler.php b/app/model/Cashbook/ReadModel/QueryHandlers/InconsistentEducationCategoryTotalsQueryHandler.php index 56c39d5f4..abae2e56c 100644 --- a/app/model/Cashbook/ReadModel/QueryHandlers/InconsistentEducationCategoryTotalsQueryHandler.php +++ b/app/model/Cashbook/ReadModel/QueryHandlers/InconsistentEducationCategoryTotalsQueryHandler.php @@ -23,7 +23,7 @@ public function __construct(private IEducationCategoryRepository $educationCateg /** @return float[] */ public function __invoke(InconsistentEducationCategoryTotalsQuery $query): array { - $cashbookId = $this->queryBus->handle(new EducationCashbookIdQuery($query->getEducationId())); + $cashbookId = $this->queryBus->handle(new EducationCashbookIdQuery($query->getEducationId(), $query->getYear())); $categories = $this->queryBus->handle(new CategoriesSummaryQuery($cashbookId)); $skautisTotals = []; diff --git a/app/model/Cashbook/Repositories/IEducationRepository.php b/app/model/Cashbook/Repositories/IEducationRepository.php index 5da9df069..3f8ce8dc6 100644 --- a/app/model/Cashbook/Repositories/IEducationRepository.php +++ b/app/model/Cashbook/Repositories/IEducationRepository.php @@ -12,7 +12,7 @@ interface IEducationRepository { /** @throws CashbookNotFound */ - public function findBySkautisId(SkautisEducationId $id): Education; + public function findBySkautisIdAndYear(SkautisEducationId $id, int $year): Education; /** @throws CashbookNotFound */ public function findByCashbookId(CashbookId $cashbookId): Education; diff --git a/app/model/Export/ExportService.php b/app/model/Export/ExportService.php index 608e775f5..768c69790 100644 --- a/app/model/Export/ExportService.php +++ b/app/model/Export/ExportService.php @@ -270,9 +270,9 @@ public function getCampReport(int $skautisCampId, bool $areTotalsConsistentWithS ]); } - public function getEducationReport(SkautisEducationId $educationId): string + public function getEducationReport(SkautisEducationId $educationId, int $year): string { - $cashbookId = $this->queryBus->handle(new EducationCashbookIdQuery($educationId)); + $cashbookId = $this->queryBus->handle(new EducationCashbookIdQuery($educationId, $year)); $categories = $this->queryBus->handle(new CategoriesSummaryQuery($cashbookId)); $total = [ diff --git a/app/model/Infrastructure/Repositories/Cashbook/EducationRepository.php b/app/model/Infrastructure/Repositories/Cashbook/EducationRepository.php index f4ade5ee5..e9d817c0a 100644 --- a/app/model/Infrastructure/Repositories/Cashbook/EducationRepository.php +++ b/app/model/Infrastructure/Repositories/Cashbook/EducationRepository.php @@ -24,7 +24,7 @@ public function __construct(EntityManager $entityManager, EventBus $eventBus, pr parent::__construct($entityManager, $eventBus); } - public function findBySkautisId(SkautisEducationId $id): Education + public function findBySkautisIdAndYear(SkautisEducationId $id, int $year): Education { $builder = $this->getEntityManager()->createQueryBuilder(); @@ -36,7 +36,7 @@ public function findBySkautisId(SkautisEducationId $id): Education ->getQuery() ->getSingleResult(); } catch (NoResultException) { - $cashbook = new Education($id, CashbookId::generate()); + $cashbook = new Education($id, $year, CashbookId::generate()); $this->save($cashbook); $this->commandBus->handle(new CreateCashbook($cashbook->getCashbookId(), CashbookType::get(CashbookType::EDUCATION))); From 01e58faef2b74ea45cf8102e0735dc6823cfb196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Thu, 26 Oct 2023 00:08:46 +0200 Subject: [PATCH 3/6] Querying SkautIS education categories with year --- .../presenters/CashbookPresenter.php | 2 +- .../EducationParticipantCategoryIdQuery.php | 7 +++- .../Queries/SkautisEducationYearQuery.php | 21 ++++++++++ ...ationParticipantCategoryIdQueryHandler.php | 2 +- ...entEducationCategoryTotalsQueryHandler.php | 2 +- .../SkautisEducationYearQueryHandler.php | 38 +++++++++++++++++++ .../Repositories/CategoryRepository.php | 4 +- .../IEducationCategoryRepository.php | 2 +- .../Cashbook/EducationCategoryUpdater.php | 7 ++-- .../EducationCategoryRepository.php | 3 +- 10 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 app/model/Cashbook/ReadModel/Queries/SkautisEducationYearQuery.php create mode 100644 app/model/Cashbook/ReadModel/QueryHandlers/SkautisEducationYearQueryHandler.php diff --git a/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php b/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php index f4a0f7f10..2da374073 100644 --- a/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php +++ b/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php @@ -114,7 +114,7 @@ private function formImportHpdSubmitted(BaseForm $form): void $body = new ChitBody(null, $this->event->getStartDate(), null); $categoryId = $this->queryBus->handle( - new EducationParticipantCategoryIdQuery(new SkautisEducationId($this->aid)), + new EducationParticipantCategoryIdQuery(new SkautisEducationId($this->aid), $this->event->endDate->year), ); $categoriesDto = $this->queryBus->handle(new CategoryListQuery($this->getCashbookId())); diff --git a/app/model/Cashbook/ReadModel/Queries/EducationParticipantCategoryIdQuery.php b/app/model/Cashbook/ReadModel/Queries/EducationParticipantCategoryIdQuery.php index fc1c97a7e..1784bab71 100644 --- a/app/model/Cashbook/ReadModel/Queries/EducationParticipantCategoryIdQuery.php +++ b/app/model/Cashbook/ReadModel/Queries/EducationParticipantCategoryIdQuery.php @@ -10,7 +10,7 @@ /** @see EducationParticipantCategoryIdQueryHandler */ final class EducationParticipantCategoryIdQuery { - public function __construct(private SkautisEducationId $educationId) + public function __construct(private SkautisEducationId $educationId, private int $year) { } @@ -18,4 +18,9 @@ public function getEducationId(): SkautisEducationId { return $this->educationId; } + + public function getYear(): int + { + return $this->year; + } } diff --git a/app/model/Cashbook/ReadModel/Queries/SkautisEducationYearQuery.php b/app/model/Cashbook/ReadModel/Queries/SkautisEducationYearQuery.php new file mode 100644 index 000000000..173496de8 --- /dev/null +++ b/app/model/Cashbook/ReadModel/Queries/SkautisEducationYearQuery.php @@ -0,0 +1,21 @@ +cashbookId; + } +} diff --git a/app/model/Cashbook/ReadModel/QueryHandlers/EducationParticipantCategoryIdQueryHandler.php b/app/model/Cashbook/ReadModel/QueryHandlers/EducationParticipantCategoryIdQueryHandler.php index 359c228a6..fd60e5d2a 100644 --- a/app/model/Cashbook/ReadModel/QueryHandlers/EducationParticipantCategoryIdQueryHandler.php +++ b/app/model/Cashbook/ReadModel/QueryHandlers/EducationParticipantCategoryIdQueryHandler.php @@ -16,7 +16,7 @@ public function __construct(private IEducationCategoryRepository $categories) public function __invoke(EducationParticipantCategoryIdQuery $query): int { - foreach ($this->categories->findForEducation($query->getEducationId()->toInt()) as $category) { + foreach ($this->categories->findForEducation($query->getEducationId()->toInt(), $query->getYear()) as $category) { if ($category->getName() === 'Účastnické poplatky') { return $category->getId(); } diff --git a/app/model/Cashbook/ReadModel/QueryHandlers/InconsistentEducationCategoryTotalsQueryHandler.php b/app/model/Cashbook/ReadModel/QueryHandlers/InconsistentEducationCategoryTotalsQueryHandler.php index abae2e56c..3a0337f06 100644 --- a/app/model/Cashbook/ReadModel/QueryHandlers/InconsistentEducationCategoryTotalsQueryHandler.php +++ b/app/model/Cashbook/ReadModel/QueryHandlers/InconsistentEducationCategoryTotalsQueryHandler.php @@ -28,7 +28,7 @@ public function __invoke(InconsistentEducationCategoryTotalsQuery $query): array $skautisTotals = []; - foreach ($this->educationCategories->findForEducation($query->getEducationId()->toInt()) as $educationCategory) { + foreach ($this->educationCategories->findForEducation($query->getEducationId()->toInt(), $query->getYear()) as $educationCategory) { $id = $educationCategory->getId(); $total = $educationCategory->getTotal(); $category = $categories[$id]; diff --git a/app/model/Cashbook/ReadModel/QueryHandlers/SkautisEducationYearQueryHandler.php b/app/model/Cashbook/ReadModel/QueryHandlers/SkautisEducationYearQueryHandler.php new file mode 100644 index 000000000..1033dd968 --- /dev/null +++ b/app/model/Cashbook/ReadModel/QueryHandlers/SkautisEducationYearQueryHandler.php @@ -0,0 +1,38 @@ +cashbooks->find($query->getCashbookId()); + $objectType = $cashbook->getType()->getSkautisObjectType(); + + if (! $objectType->equalsValue(ObjectType::EDUCATION)) { + throw new ShouldNotHappen(); + } + + return $this->educationRepository->findByCashbookId($query->getCashbookId())->getYear(); + } +} diff --git a/app/model/Cashbook/Repositories/CategoryRepository.php b/app/model/Cashbook/Repositories/CategoryRepository.php index 0027d5aaa..6cf59c71d 100644 --- a/app/model/Cashbook/Repositories/CategoryRepository.php +++ b/app/model/Cashbook/Repositories/CategoryRepository.php @@ -8,6 +8,7 @@ use Model\Cashbook\Cashbook\CashbookType; use Model\Cashbook\CategoryNotFound; use Model\Cashbook\ICategory; +use Model\Cashbook\ReadModel\Queries\SkautisEducationYearQuery; use Model\Cashbook\ReadModel\Queries\SkautisIdQuery; use Model\Common\Services\QueryBus; @@ -39,7 +40,8 @@ public function findForCashbook(CashbookId $cashbookId, CashbookType $type): arr if ($skautisType->equalsValue(CashbookType::EDUCATION)) { $educationId = $this->queryBus->handle(new SkautisIdQuery($cashbookId)); - $educationCategories = $this->educationCategories->findForEducation($educationId); + $educationYear = $this->queryBus->handle(new SkautisEducationYearQuery($cashbookId)); + $educationCategories = $this->educationCategories->findForEducation($educationId, $educationYear); return array_merge($categories, $educationCategories); } diff --git a/app/model/Cashbook/Repositories/IEducationCategoryRepository.php b/app/model/Cashbook/Repositories/IEducationCategoryRepository.php index 83c84aa74..97f4f619e 100644 --- a/app/model/Cashbook/Repositories/IEducationCategoryRepository.php +++ b/app/model/Cashbook/Repositories/IEducationCategoryRepository.php @@ -9,5 +9,5 @@ interface IEducationCategoryRepository { /** @return EducationCategory[] */ - public function findForEducation(int $educationId): array; + public function findForEducation(int $educationId, int $year): array; } diff --git a/app/model/Skautis/Cashbook/EducationCategoryUpdater.php b/app/model/Skautis/Cashbook/EducationCategoryUpdater.php index 986e5698f..7a243dd70 100644 --- a/app/model/Skautis/Cashbook/EducationCategoryUpdater.php +++ b/app/model/Skautis/Cashbook/EducationCategoryUpdater.php @@ -36,7 +36,8 @@ public function __construct( public function updateCategories(CashbookId $cashbookId, array $cashbookTotals): void { $educationSkautisId = $this->educationRepository->findByCashbookId($cashbookId)->getSkautisId(); - $skautisTotals = $this->getSkautisTotals($educationSkautisId); + $educationYear = $this->educationRepository->findByCashbookId($cashbookId)->getYear(); + $skautisTotals = $this->getSkautisTotals($educationSkautisId, $educationYear); // Update categories that are not in cashbook, has total > 0 in Skautis $categoriesOnlyInSkautis = array_diff(array_keys($skautisTotals), array_keys($cashbookTotals)); @@ -74,9 +75,9 @@ public function updateCategories(CashbookId $cashbookId, array $cashbookTotals): } /** @return float[] */ - private function getSkautisTotals(SkautisEducationId $educationSkautisId): array + private function getSkautisTotals(SkautisEducationId $educationSkautisId, int $year): array { - $categories = $this->educationCategories->findForEducation($educationSkautisId->toInt()); + $categories = $this->educationCategories->findForEducation($educationSkautisId->toInt(), $year); $totals = []; foreach ($categories as $category) { diff --git a/app/model/Skautis/Cashbook/Repositories/EducationCategoryRepository.php b/app/model/Skautis/Cashbook/Repositories/EducationCategoryRepository.php index fc4033dad..c17733369 100644 --- a/app/model/Skautis/Cashbook/Repositories/EducationCategoryRepository.php +++ b/app/model/Skautis/Cashbook/Repositories/EducationCategoryRepository.php @@ -22,11 +22,12 @@ public function __construct(private WebServiceInterface $grantsWebService) /** @return EducationCategory[] */ // phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - public function findForEducation(int $educationId): array + public function findForEducation(int $educationId, int $year): array { $skautisCategories = $this->grantsWebService->StatementAll([ 'ID_EventEducation' => $educationId, 'IsBudget' => false, + 'Year' => $year, ]); if (is_object($skautisCategories)) { From 68c00a1015cadaf6003c2351177c3191ecc2f6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Thu, 26 Oct 2023 10:25:10 +0200 Subject: [PATCH 4/6] Fixed Doctrine ORM integer type --- app/model/Cashbook/Education.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/model/Cashbook/Education.php b/app/model/Cashbook/Education.php index 67b2c45e1..39f85dcee 100644 --- a/app/model/Cashbook/Education.php +++ b/app/model/Cashbook/Education.php @@ -23,7 +23,7 @@ class Education extends Aggregate /** * @ORM\Id() - * @ORM\Column(type="int") + * @ORM\Column(type="integer") */ private int $year; From c370fc3fcc8c9fd5dc5b85e7503475a3aeea0780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Thu, 26 Oct 2023 14:34:19 +0200 Subject: [PATCH 5/6] Using event startDate instead of endDate for education cashbooks --- .../EducationModule/EducationListDataSource.php | 2 +- .../EducationModule/presenters/BudgetPresenter.php | 6 +++--- .../EducationModule/presenters/CashbookPresenter.php | 4 ++-- .../EducationModule/presenters/EducationPresenter.php | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/AccountancyModule/EducationModule/EducationListDataSource.php b/app/AccountancyModule/EducationModule/EducationListDataSource.php index 693c02e2a..fa6a79bef 100644 --- a/app/AccountancyModule/EducationModule/EducationListDataSource.php +++ b/app/AccountancyModule/EducationModule/EducationListDataSource.php @@ -54,7 +54,7 @@ function (Education $education): EducationListItem { private function chitNumberPrefix(Education $camp): string|null { - $cashbookId = $this->queryBus->handle(new EducationCashbookIdQuery($camp->getId(), $camp->endDate->year)); + $cashbookId = $this->queryBus->handle(new EducationCashbookIdQuery($camp->getId(), $camp->startDate->year)); assert($cashbookId instanceof CashbookId); diff --git a/app/AccountancyModule/EducationModule/presenters/BudgetPresenter.php b/app/AccountancyModule/EducationModule/presenters/BudgetPresenter.php index 391885b90..b04db7f73 100644 --- a/app/AccountancyModule/EducationModule/presenters/BudgetPresenter.php +++ b/app/AccountancyModule/EducationModule/presenters/BudgetPresenter.php @@ -44,12 +44,12 @@ public function renderDefault(int $aid): void $educationId = new SkautisEducationId($aid); - $inconsistentTotals = $this->queryBus->handle(new InconsistentEducationCategoryTotalsQuery($educationId, $this->event->endDate->year)); + $inconsistentTotals = $this->queryBus->handle(new InconsistentEducationCategoryTotalsQuery($educationId, $this->event->startDate->year)); $this->template->setParameters([ 'isConsistent' => count($inconsistentTotals) === 0, 'toRepair' => $inconsistentTotals, 'budgetEntries' => $this->queryBus->handle(new EducationBudgetQuery($educationId, $this->event->grantId)), - 'categoriesSummary' => $this->queryBus->handle(new CategoriesSummaryQuery($this->getCashbookId($aid, $this->event->endDate->year))), + 'categoriesSummary' => $this->queryBus->handle(new CategoriesSummaryQuery($this->getCashbookId($aid, $this->event->startDate->year))), 'isUpdateStatementAllowed' => $this->authorizator->isAllowed(Grant::UPDATE_REAL_BUDGET_SPENDING, $this->event->grantId->toInt()), ]); if (! $this->isAjax()) { @@ -66,7 +66,7 @@ public function handleConvert(int $aid): void { $this->editableOnly(); - $this->commandBus->handle(new UpdateEducationCategoryTotals($this->getCashbookId($aid, $this->event->endDate->year))); + $this->commandBus->handle(new UpdateEducationCategoryTotals($this->getCashbookId($aid, $this->event->startDate->year))); $this->flashMessage('Kategorie byly přepočítány.'); if ($this->isAjax()) { diff --git a/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php b/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php index 2da374073..4a851ff5d 100644 --- a/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php +++ b/app/AccountancyModule/EducationModule/presenters/CashbookPresenter.php @@ -114,7 +114,7 @@ private function formImportHpdSubmitted(BaseForm $form): void $body = new ChitBody(null, $this->event->getStartDate(), null); $categoryId = $this->queryBus->handle( - new EducationParticipantCategoryIdQuery(new SkautisEducationId($this->aid), $this->event->endDate->year), + new EducationParticipantCategoryIdQuery(new SkautisEducationId($this->aid), $this->event->startDate->year), ); $categoriesDto = $this->queryBus->handle(new CategoryListQuery($this->getCashbookId())); @@ -128,7 +128,7 @@ private function formImportHpdSubmitted(BaseForm $form): void private function getCashbookId(): CashbookId { - return $this->queryBus->handle(new EducationCashbookIdQuery(new SkautisEducationId($this->aid), $this->event->endDate->year)); + return $this->queryBus->handle(new EducationCashbookIdQuery(new SkautisEducationId($this->aid), $this->event->startDate->year)); } private function isCashbookEmpty(): bool diff --git a/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php b/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php index 878433011..7516b0bba 100644 --- a/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php +++ b/app/AccountancyModule/EducationModule/presenters/EducationPresenter.php @@ -50,13 +50,13 @@ public function renderDefault(int|null $aid): void $this->redirect('Default:'); } - $cashbook = $this->queryBus->handle(new CashbookQuery($this->getCashbookId($aid, $this->event->endDate->year))); + $cashbook = $this->queryBus->handle(new CashbookQuery($this->getCashbookId($aid, $this->event->startDate->year))); assert($cashbook instanceof Cashbook); $finalRealBalance = null; if ($this->authorizator->isAllowed(Education::ACCESS_BUDGET, $aid)) { try { - $finalRealBalance = $this->queryBus->handle(new FinalRealBalanceQuery($this->getCashbookId($aid, $this->event->endDate->year))); + $finalRealBalance = $this->queryBus->handle(new FinalRealBalanceQuery($this->getCashbookId($aid, $this->event->startDate->year))); } catch (MissingCategory) { } } @@ -134,7 +134,7 @@ public function renderReport(int $aid): void $this->redirect('default', ['aid' => $aid]); } - $template = $this->exportService->getEducationReport(new SkautisEducationId($aid), $this->event->endDate->year); + $template = $this->exportService->getEducationReport(new SkautisEducationId($aid), $this->event->startDate->year); $this->pdf->render($template, 'report.pdf'); $this->terminate(); From 4baf68686366d39d827627c4d2d0d94367a73921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Thu, 26 Oct 2023 15:10:57 +0200 Subject: [PATCH 6/6] Documented why education cashbook table has year column --- app/model/Cashbook/Education.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/model/Cashbook/Education.php b/app/model/Cashbook/Education.php index 39f85dcee..5b96b1a12 100644 --- a/app/model/Cashbook/Education.php +++ b/app/model/Cashbook/Education.php @@ -22,6 +22,8 @@ class Education extends Aggregate private SkautisEducationId $id; /** + * For education events spanning multiple years, a separate cashbook is needed for each year. + * * @ORM\Id() * @ORM\Column(type="integer") */