From 11db171de05207cbbadcde02cc3cc2d1b229ba67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Sat, 9 Nov 2024 19:11:14 +0100 Subject: [PATCH] fixes --- .../Components/UsersGridControl.php | 2 +- .../Forms/EditUserTransferFormFactory.php | 64 +---- app/AdminModule/Presenters/UsersPresenter.php | 13 +- app/Model/Structure/Subevent.php | 3 +- .../User/Repositories/UserRepository.php | 2 +- app/Model/User/User.php | 29 +- app/Services/ApplicationService.php | 254 +++++++++++------- app/WebModule/Presenters/WebBasePresenter.php | 1 - .../templates/Profile/default.latte | 2 +- app/lang/admin.cs_CZ.neon | 9 +- app/lang/common.cs_CZ.neon | 2 + 11 files changed, 210 insertions(+), 171 deletions(-) diff --git a/app/AdminModule/Components/UsersGridControl.php b/app/AdminModule/Components/UsersGridControl.php index 4fa519f03..247a39a70 100644 --- a/app/AdminModule/Components/UsersGridControl.php +++ b/app/AdminModule/Components/UsersGridControl.php @@ -176,7 +176,7 @@ public function createComponentUsersGrid(string $name): DataGrid ->andWhere('uA.validTo IS NULL') ->andWhere('uA.state IN (:states)') ->setParameter('sids', (array) $values) - ->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::WAITING_FOR_PAYMENT]); + ->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::PAID_TRANSFERED, ApplicationState::WAITING_FOR_PAYMENT]); }); $columnApproved = $grid->addColumnStatus('approved', 'admin.users.users_approved'); diff --git a/app/AdminModule/Forms/EditUserTransferFormFactory.php b/app/AdminModule/Forms/EditUserTransferFormFactory.php index 6d2ba2ea5..109951cb2 100644 --- a/app/AdminModule/Forms/EditUserTransferFormFactory.php +++ b/app/AdminModule/Forms/EditUserTransferFormFactory.php @@ -46,9 +46,11 @@ public function create(int $id): Form $form->addSelect('targetUser', 'admin.users.users_target_user', $this->userRepository->getUsersOptions(true)) ->addRule(Form::NOT_EQUAL, 'admin.users.users_target_user_empty', 0) + ->addRule(Form::NOT_EQUAL, 'admin.users.users_target_user_same', $this->user->getId()) ->setHtmlAttribute('data-live-search', 'true'); $form->addSubmit('submit', 'admin.users.users_transfer') + ->setDisabled(! $this->user->isRegistered()) ->setHtmlAttribute('class', 'btn btn-danger') ->setHtmlAttribute('data-toggle', 'confirmation') ->setHtmlAttribute('data-content', $this->translator->translate('admin.users.users_transfer_confirm')); @@ -67,68 +69,8 @@ public function create(int $id): Form public function processForm(Form $form, stdClass $values): void { $targetUser = $this->userRepository->findById($values->targetUser); - - $userRoles = $this->user->getRoles(); - $targetUserRoles = $targetUser->getRoles(); - - $targetRoles = new ArrayCollection(); - foreach ($userRoles as $role) { - if (!$targetRoles->contains($role)) { - $targetRoles->add($role); - } - } - foreach ($targetUserRoles as $role) { - if (!$targetRoles->contains($role) && $role->getSystemName() !== Role::NONREGISTERED) { - $targetRoles->add($role); - } - } - - $userSubevents = $this->user->getSubevents(); - $targetUserSubevents = $this->user->getSubevents(); - - $targetSubevents = new ArrayCollection(); - foreach ($userSubevents as $subevent) { - if (!$targetSubevents->contains($subevent)) { - $targetSubevents->add($subevent); - } - } - foreach ($targetUserSubevents as $subevent) { - if (!$targetSubevents->contains($subevent)) { - $targetSubevents->add($subevent); - } - } - $loggedUser = $form->getPresenter()->getDbUser(); - $this->applicationService->cancelRegistration($this->user, ApplicationState::CANCELED_TRANSFERED, $loggedUser); - $this->applicationService->updateRoles($targetUser, $targetRoles, $form->getPresenter()->getDbUser(), $loggedUser); - $this->applicationService->addSubeventsApplication($targetUser, $targetSubevents, $loggedUser); - - // todo: pridani platby za vsechny role a podakce (i ty ktere uz mel) - -// $this->user->setFirstName($values->firstName); -// $this->user->setLastName($values->lastName); -// $this->user->setNickName($values->nickName); -// $this->user->setDegreePre($values->degreePre); -// $this->user->setDegreePost($values->degreePost); -// $this->user->setEmail($values->email); -// $this->user->setPhone($values->phone); -// $this->user->setBirthdate($values->birthdate); -// $this->user->setStreet($values->street); -// $this->user->setCity($values->city); -// $this->user->setPostcode($values->postcode); -// -// $photo = $values->photo; -// if ($photo->getError() === UPLOAD_ERR_OK) { -// $photoExtension = image_type_to_extension(getimagesizefromstring($photo->getContents())[2]); -// $photoName = 'ext_' . $this->user->getId() . $photoExtension; -// -// $path = $this->filesService->save($photo, User::PHOTO_PATH, false, $photoName); -// $this->filesService->resizeAndCropImage($path, 135, 180); -// -// $this->user->setPhoto($path); -// } -// -// $this->userRepository->save($this->user); + $this->applicationService->transferRegistration($this->user, $targetUser, $loggedUser); } } diff --git a/app/AdminModule/Presenters/UsersPresenter.php b/app/AdminModule/Presenters/UsersPresenter.php index 70dc01111..f7304519b 100644 --- a/app/AdminModule/Presenters/UsersPresenter.php +++ b/app/AdminModule/Presenters/UsersPresenter.php @@ -227,19 +227,8 @@ protected function createComponentEditUserTransferForm(): Form { $form = $this->editUserTransferFormFactory->create((int) $this->getParameter('id')); -// $form->onError[] = function (Form $form): void { -// foreach ($form->errors as $error) { -// $this->flashMessage($error, 'danger'); -// } -// -// $this->redirect('this'); -// }; - $form->onSuccess[] = function (Form $form, stdClass $values): void { - if ($form->isSubmitted() != $form['cancel']) { - $this->flashMessage('admin.users.users_saved', 'success'); - } - + $this->flashMessage('admin.users.users_transfered', 'success'); $this->redirect('this'); }; diff --git a/app/Model/Structure/Subevent.php b/app/Model/Structure/Subevent.php index 4d8fc182e..182a7740c 100644 --- a/app/Model/Structure/Subevent.php +++ b/app/Model/Structure/Subevent.php @@ -432,7 +432,8 @@ public function countUsers(): int return $this->applications->filter(static fn (Application $application) => $application->getValidTo() === null && ( $application->getState() === ApplicationState::WAITING_FOR_PAYMENT || $application->getState() === ApplicationState::PAID_FREE || - $application->getState() === ApplicationState::PAID))->count(); + $application->getState() === ApplicationState::PAID || + $application->getState() === ApplicationState::PAID_TRANSFERED))->count(); } public function countUnoccupied(): int|null diff --git a/app/Model/User/Repositories/UserRepository.php b/app/Model/User/Repositories/UserRepository.php index c7a4b1a3d..2415bcc09 100644 --- a/app/Model/User/Repositories/UserRepository.php +++ b/app/Model/User/Repositories/UserRepository.php @@ -131,7 +131,7 @@ public function findAllWithSubevents(array $subeventsIds): Collection ->where('a.validTo IS NULL') ->andWhere('a.state IN (:states)') ->andWhere('s.id IN (:ids)') - ->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::WAITING_FOR_PAYMENT]) + ->setParameter('states', [ApplicationState::PAID, ApplicationState::PAID_FREE, ApplicationState::PAID_TRANSFERED, ApplicationState::WAITING_FOR_PAYMENT]) ->setParameter('ids', $subeventsIds) ->getQuery() ->getResult(); diff --git a/app/Model/User/User.php b/app/Model/User/User.php index 674c4a06e..e82f2ca2d 100644 --- a/app/Model/User/User.php +++ b/app/Model/User/User.php @@ -677,6 +677,11 @@ public function isInRoleWithSystemName(string $name): bool return $this->roles->exists(static fn (int $key, Role $role) => $role->getSystemName() === $name); } + public function isRegistered(): bool + { + return ! $this->isInRoleWithSystemName(Role::NONREGISTERED); + } + /** * Vrací, zda má uživatel nějakou roli, která nemá cenu podle podakcí. */ @@ -808,7 +813,9 @@ public function getPaidAndFreeApplications(): Collection { return $this->applications->filter(static fn (Application $application) => $application->getValidTo() === null && ( $application->getState() === ApplicationState::PAID_FREE || - $application->getState() === ApplicationState::PAID)); + $application->getState() === ApplicationState::PAID || + $application->getState() === ApplicationState::PAID_TRANSFERED + )); } /** @@ -1089,6 +1096,26 @@ public function hasSubevent(Subevent $subevent): bool return $this->getSubevents()->contains($subevent); } + /** + * Vrací zaplacné podakce uživatele. + * + * @return Collection + */ + public function getPaidSubevents(): Collection + { + $subevents = new ArrayCollection(); + + foreach ($this->getPaidAndFreeApplications() as $application) { + if ($application instanceof SubeventsApplication) { + foreach ($application->getSubevents() as $subevent) { + $subevents->add($subevent); + } + } + } + + return $subevents; + } + /** * Vrácí, zda má uživatel zaplacenou přihlášku s podakcí. */ diff --git a/app/Services/ApplicationService.php b/app/Services/ApplicationService.php index 6cf54860e..056e3281b 100644 --- a/app/Services/ApplicationService.php +++ b/app/Services/ApplicationService.php @@ -64,47 +64,49 @@ class ApplicationService use Nette\SmartObject; public function __construct( - private readonly CommandBus $commandBus, - private readonly QueryBus $queryBus, - private readonly EntityManagerInterface $em, - private readonly ApplicationRepository $applicationRepository, - private readonly UserRepository $userRepository, - private readonly AclService $aclService, - private readonly RoleRepository $roleRepository, - private readonly SubeventRepository $subeventRepository, - private readonly DiscountService $discountService, + private readonly CommandBus $commandBus, + private readonly QueryBus $queryBus, + private readonly EntityManagerInterface $em, + private readonly ApplicationRepository $applicationRepository, + private readonly UserRepository $userRepository, + private readonly AclService $aclService, + private readonly RoleRepository $roleRepository, + private readonly SubeventRepository $subeventRepository, + private readonly DiscountService $discountService, private readonly VariableSymbolRepository $variableSymbolRepository, - private readonly UserService $userService, - private readonly Translator $translator, - private readonly PaymentRepository $paymentRepository, - private readonly IncomeProofRepository $incomeProofRepository, - private readonly EventBus $eventBus, - ) { + private readonly UserService $userService, + private readonly Translator $translator, + private readonly PaymentRepository $paymentRepository, + private readonly IncomeProofRepository $incomeProofRepository, + private readonly EventBus $eventBus, + ) + { } /** * Zaregistruje uživatele (vyplnění přihlášky / přidání role v administraci). * - * @param Collection $roles + * @param Collection $roles * @param Collection $subevents * * @throws Throwable */ public function register( - User $user, + User $user, Collection $roles, Collection $subevents, - User $createdBy, - bool $approve = false, - ): void { - $rolesApplication = $this->createRolesApplication($user, $roles, $createdBy, $approve); + User $createdBy, + bool $approve = false, + ): void + { + $rolesApplication = $this->createRolesApplication($user, $roles, $createdBy, $approve); $subeventsApplication = $this->createSubeventsApplication($user, $subevents, $createdBy); $this->eventBus->handle(new ApplicationUpdatedEvent($user)); $this->updateUserPaymentInfo($user); - $applicatonMaturity = '-'; - $applicationFee = '0'; + $applicatonMaturity = '-'; + $applicationFee = '0'; $applicationVariableSymbol = '-'; if ($rolesApplication->getFee() > 0 && $subeventsApplication->getFee() > 0) { @@ -112,21 +114,21 @@ public function register( $applicatonMaturity = $rolesApplication->getMaturityDateText(); } - $applicationFee = $rolesApplication->getFee() . ', ' . $subeventsApplication->getFee(); + $applicationFee = $rolesApplication->getFee() . ', ' . $subeventsApplication->getFee(); $applicationVariableSymbol = $rolesApplication->getVariableSymbolText() . ', ' . $subeventsApplication->getVariableSymbolText(); } elseif ($rolesApplication->getFee() > 0) { if ($rolesApplication->getMaturityDate()) { $applicatonMaturity = $rolesApplication->getMaturityDateText(); } - $applicationFee = $rolesApplication->getFee(); + $applicationFee = $rolesApplication->getFee(); $applicationVariableSymbol = $rolesApplication->getVariableSymbolText(); } elseif ($subeventsApplication->getFee() > 0) { if ($subeventsApplication->getMaturityDate()) { $applicatonMaturity = $subeventsApplication->getMaturityDateText(); } - $applicationFee = $subeventsApplication->getFee(); + $applicationFee = $subeventsApplication->getFee(); $applicationVariableSymbol = $subeventsApplication->getVariableSymbolText(); } @@ -162,7 +164,7 @@ public function register( * @throws Throwable * @throws MailingMailCreationException */ - public function updateRoles(User $user, Collection $roles, User|null $createdBy, bool $approve = false): void + public function updateRoles(User $user, Collection $roles, User|null $createdBy, bool $approve = false, bool $transfered = false): void { $rolesOld = clone $user->getRoles(); @@ -170,7 +172,7 @@ public function updateRoles(User $user, Collection $roles, User|null $createdBy, return; } - $this->em->wrapInTransaction(function () use ($user, $roles, $createdBy, $approve, $rolesOld): void { + $this->em->wrapInTransaction(function () use ($user, $roles, $createdBy, $approve, $transfered, $rolesOld): void { if ($rolesOld->contains($this->roleRepository->findBySystemName(Role::NONREGISTERED))) { $this->createRolesApplication($user, $roles, $createdBy, $approve); $this->createSubeventsApplication( @@ -188,14 +190,14 @@ public function updateRoles(User $user, Collection $roles, User|null $createdBy, if ( $roles->forAll( - static fn (int $key, Role $role) => $role->isApprovedAfterRegistration(), + static fn(int $key, Role $role) => $role->isApprovedAfterRegistration(), ) ) { $user->setApproved(true); } elseif ( - ! $approve + !$approve && $roles->exists( - static fn (int $key, Role $role) => ! $role->isApprovedAfterRegistration() && ! $rolesOld->contains($role), + static fn(int $key, Role $role) => !$role->isApprovedAfterRegistration() && !$rolesOld->contains($role), ) ) { $user->setApproved(false); @@ -206,7 +208,7 @@ public function updateRoles(User $user, Collection $roles, User|null $createdBy, $newApplication = clone $application; $newApplication->setRoles($roles); $newApplication->setFee($this->countRolesFee($roles)); - $newApplication->setState($this->getApplicationState($newApplication)); + $newApplication->setState($this->getApplicationState($newApplication, $transfered)); $newApplication->setCreatedBy($createdBy); $newApplication->setValidFrom(new DateTimeImmutable()); $this->applicationRepository->save($newApplication); @@ -247,7 +249,7 @@ public function updateRoles(User $user, Collection $roles, User|null $createdBy, Template::ROLES_CHANGED, [ TemplateVariable::SEMINAR_NAME => $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_NAME)), - TemplateVariable::USERS_ROLES => implode(', ', $roles->map(static fn (Role $role) => $role->getName())->toArray()), + TemplateVariable::USERS_ROLES => implode(', ', $roles->map(static fn(Role $role) => $role->getName())->toArray()), ], )); } @@ -338,13 +340,10 @@ public function cancelRegistration(User $user, string $state, User|null $created * * @throws Throwable */ - public function addSubeventsApplication(User $user, Collection $subevents, User $createdBy): void + public function addSubeventsApplication(User $user, Collection $subevents, User $createdBy, bool $transfered = false): void { - $this->em->wrapInTransaction(function () use ($user, $subevents, $createdBy): void { - $this->incrementSubeventsOccupancy($subevents); - - $this->createSubeventsApplication($user, $subevents, $createdBy); - + $this->em->wrapInTransaction(function () use ($user, $subevents, $createdBy, $transfered): void { + $this->createSubeventsApplication($user, $subevents, $createdBy, $transfered); $this->eventBus->handle(new ApplicationUpdatedEvent($user)); $this->updateUserPaymentInfo($user); }); @@ -375,7 +374,7 @@ public function addSubeventsApplication(User $user, Collection $subevents, User */ public function updateSubeventsApplication(SubeventsApplication $application, Collection $subevents, User $createdBy): void { - if (! $application->isValid()) { + if (!$application->isValid()) { return; } @@ -431,7 +430,7 @@ public function updateSubeventsApplication(SubeventsApplication $application, Co */ public function cancelSubeventsApplication(SubeventsApplication $application, string $state, User|null $createdBy): void { - if (! $application->isValid()) { + if (!$application->isValid()) { return; } @@ -483,15 +482,16 @@ public function cancelSubeventsApplication(SubeventsApplication $application, st * @throws Throwable */ public function updateApplicationPayment( - Application $application, - string|null $paymentMethod, + Application $application, + string|null $paymentMethod, DateTimeImmutable|null $paymentDate, DateTimeImmutable|null $maturityDate, - User|null $createdBy, - ): void { + User|null $createdBy, + ): void + { $oldPaymentMethod = $application->getPaymentMethod(); - $oldPaymentDate = $application->getPaymentDate(); - $oldMaturityDate = $application->getMaturityDate(); + $oldPaymentDate = $application->getPaymentDate(); + $oldMaturityDate = $application->getMaturityDate(); // pokud neni zmena, nic se neprovede if ($paymentMethod === $oldPaymentMethod && $paymentDate == $oldPaymentDate && $maturityDate == $oldMaturityDate) { @@ -543,14 +543,15 @@ public function updateApplicationPayment( */ public function createPayment( DateTimeImmutable $date, - float $amount, - string|null $variableSymbol, - string|null $transactionId, - string|null $accountNumber, - string|null $accountName, - string|null $message, - User|null $createdBy = null, - ): void { + float $amount, + string|null $variableSymbol, + string|null $transactionId, + string|null $accountNumber, + string|null $accountName, + string|null $message, + User|null $createdBy = null, + ): void + { $this->em->wrapInTransaction(function () use ($date, $amount, $variableSymbol, $transactionId, $accountNumber, $accountName, $message, $createdBy): void { $payment = new Payment(); @@ -567,12 +568,14 @@ public function createPayment( if ($pairedApplication) { if ( $pairedApplication->getState() === ApplicationState::PAID || - $pairedApplication->getState() === ApplicationState::PAID_FREE + $pairedApplication->getState() === ApplicationState::PAID_FREE || + $pairedApplication->getState() === ApplicationState::PAID_TRANSFERED ) { $payment->setState(PaymentState::NOT_PAIRED_PAID); } elseif ( $pairedApplication->getState() === ApplicationState::CANCELED || - $pairedApplication->getState() === ApplicationState::CANCELED_NOT_PAID + $pairedApplication->getState() === ApplicationState::CANCELED_NOT_PAID || + $pairedApplication->getState() === ApplicationState::CANCELED_TRANSFERED ) { $payment->setState(PaymentState::NOT_PAIRED_CANCELED); } elseif (abs($pairedApplication->getFee() - $amount) >= 0.01) { @@ -597,10 +600,11 @@ public function createPayment( */ public function createPaymentManual( DateTimeImmutable $date, - float $amount, - string $variableSymbol, - User $createdBy, - ): void { + float $amount, + string $variableSymbol, + User $createdBy, + ): void + { $this->createPayment($date, $amount, $variableSymbol, null, null, null, null, $createdBy); } @@ -612,13 +616,14 @@ public function createPaymentManual( * @throws Throwable */ public function updatePayment( - Payment $payment, + Payment $payment, DateTimeImmutable|null $date, - float|null $amount, - string|null $variableSymbol, - Collection $pairedApplications, - User $createdBy, - ): void { + float|null $amount, + string|null $variableSymbol, + Collection $pairedApplications, + User $createdBy, + ): void + { $this->em->wrapInTransaction(function () use ($payment, $date, $amount, $variableSymbol, $pairedApplications, $createdBy): void { if ($date !== null) { $payment->setDate($date); @@ -638,7 +643,7 @@ public function updatePayment( $pairedApplicationsModified = false; foreach ($oldPairedApplications as $pairedApplication) { - if (! $newPairedApplications->contains($pairedApplication)) { + if (!$newPairedApplications->contains($pairedApplication)) { $pairedApplication->setPayment(null); $this->updateApplicationPayment($pairedApplication, null, null, $pairedApplication->getMaturityDate(), $createdBy); $pairedApplicationsModified = true; @@ -646,7 +651,7 @@ public function updatePayment( } foreach ($newPairedApplications as $pairedApplication) { - if (! $oldPairedApplications->contains($pairedApplication)) { + if (!$oldPairedApplications->contains($pairedApplication)) { $pairedApplication->setPayment($payment); $this->updateApplicationPayment($pairedApplication, PaymentType::BANK, $payment->getDate(), $pairedApplication->getMaturityDate(), $createdBy); $pairedApplicationsModified = true; @@ -726,8 +731,8 @@ public function getStateText(Application $application): string */ public function isAllowedEditRegistration(User $user): bool { - return ! $user->isInRoleWithSystemName(Role::NONREGISTERED) - && ! $user->hasPaidAnyApplication() + return $user->isRegistered() + && !$user->hasPaidAnyApplication() && $this->queryBus->handle( new SettingDateValueQuery(Settings::EDIT_REGISTRATION_TO), ) >= (new DateTimeImmutable()) @@ -742,7 +747,7 @@ public function isAllowedEditRegistration(User $user): bool public function isAllowedEditApplication(Application $application): bool { return $application instanceof SubeventsApplication - && ! $application->isCanceled() + && !$application->isCanceled() && $application->getState() !== ApplicationState::PAID && $this->queryBus->handle( new SettingDateValueQuery(Settings::EDIT_REGISTRATION_TO), @@ -757,7 +762,7 @@ public function isAllowedEditApplication(Application $application): bool */ public function isAllowedAddApplication(User $user): bool { - return ! $user->isInRoleWithSystemName(Role::NONREGISTERED) + return $user->isRegistered() && $user->hasPaidEveryApplication() && $this->queryBus->handle( new SettingBoolValueQuery(Settings::IS_ALLOWED_ADD_SUBEVENTS_AFTER_PAYMENT), @@ -768,6 +773,63 @@ public function isAllowedAddApplication(User $user): bool ->setTime(0, 0); } + public function transferRegistration(User $sourceUser, User $targetUser, User $createdBy): void + { + $this->em->wrapInTransaction(function () use ($sourceUser, $targetUser, $createdBy): void { + $sourceUserRoles = $sourceUser->getRoles(); + $targetUserRoles = $targetUser->getRoles(); + + // přidání všech rolí zdrojového uživatele + $targetRoles = new ArrayCollection(); + foreach ($sourceUserRoles as $role) { + if (!$targetRoles->contains($role)) { + $targetRoles->add($role); + } + } + + // přidání zaplacených rolí (kromě role neregistrovaný) cílového uživatele + if ($targetUser->hasPaidRolesApplication()) { + foreach ($targetUserRoles as $role) { + if (!$targetRoles->contains($role) && $role->getSystemName() !== Role::NONREGISTERED) { + $targetRoles->add($role); + } + } + } + + $sourceUserPaidSubevents = $sourceUser->getPaidSubevents(); + + // přidání zaplacených podakcí zdrojového uživatele + $targetSubevents = new ArrayCollection(); + foreach ($sourceUserPaidSubevents as $subevent) { + if (!$targetSubevents->contains($subevent)) { + $targetSubevents->add($subevent); + } + } + + // odebrání podakcí, které už cílový uživatel má, ale budou mu přidány převodem + foreach ($targetUser->getNotCanceledSubeventsApplications() as $application) { + $remainingSubevents = new ArrayCollection(); + + foreach ($application->getSubevents() as $subevent) { + if (!$targetSubevents->contains($subevent)) { + $remainingSubevents->add($subevent); + } + } + + if ($remainingSubevents->isEmpty()) { + $this->cancelSubeventsApplication($application, ApplicationState::CANCELED, $createdBy); + } else { + $this->updateSubeventsApplication($application, $remainingSubevents, $createdBy); + } + } + + $this->addSubeventsApplication($targetUser, $targetSubevents, $createdBy, true); + $this->updateRoles($targetUser, $targetRoles, $createdBy, false, true); + + $this->cancelRegistration($sourceUser, ApplicationState::CANCELED_TRANSFERED, $createdBy); + }); + } + /** * Může uživatel upravovat vlastní pole přihlášky? * @@ -776,9 +838,9 @@ public function isAllowedAddApplication(User $user): bool public function isAllowedEditCustomInputs(): bool { return $this->queryBus->handle( - new SettingDateValueQuery(Settings::EDIT_CUSTOM_INPUTS_TO), - ) >= (new DateTimeImmutable()) - ->setTime(0, 0); + new SettingDateValueQuery(Settings::EDIT_CUSTOM_INPUTS_TO), + ) >= (new DateTimeImmutable()) + ->setTime(0, 0); } /** @@ -791,7 +853,7 @@ public function isAllowedEditCustomInputs(): bool */ private function createRolesApplication(User $user, Collection $roles, User $createdBy, bool $approve = false): RolesApplication { - if (! $user->isInRoleWithSystemName(Role::NONREGISTERED)) { + if ($user->isRegistered()) { throw new InvalidArgumentException('User is already registered.'); } @@ -800,8 +862,8 @@ private function createRolesApplication(User $user, Collection $roles, User $cre $user->setApproved(true); if ( - ! $approve && $roles->exists( - static fn (int $key, Role $role) => ! $role->isApprovedAfterRegistration(), + !$approve && $roles->exists( + static fn(int $key, Role $role) => !$role->isApprovedAfterRegistration(), ) ) { $user->setApproved(false); @@ -841,10 +903,12 @@ private function createRolesApplication(User $user, Collection $roles, User $cre * @throws Throwable */ private function createSubeventsApplication( - User $user, + User $user, Collection $subevents, - User $createdBy, - ): SubeventsApplication { + User $createdBy, + bool $transfered = false + ): SubeventsApplication + { $this->incrementSubeventsOccupancy($subevents); $application = new SubeventsApplication($user); @@ -852,7 +916,7 @@ private function createSubeventsApplication( $application->setApplicationDate(new DateTimeImmutable()); $application->setFee($this->countSubeventsFee($user->getRoles(), $subevents)); $application->setMaturityDate($this->countMaturityDate()); - $application->setState($this->getApplicationState($application)); + $application->setState($this->getApplicationState($application, $transfered)); $application->setCreatedBy($createdBy); $application->setValidFrom(new DateTimeImmutable()); $application->setVariableSymbol($this->generateVariableSymbol()); @@ -888,9 +952,9 @@ private function generateVariableSymbol(): VariableSymbol private function countMaturityDate(): DateTimeImmutable|null { switch ( - $this->queryBus->handle( - new SettingStringValueQuery(Settings::MATURITY_TYPE), - ) + $this->queryBus->handle( + new SettingStringValueQuery(Settings::MATURITY_TYPE), + ) ) { case MaturityType::DATE: return $this->queryBus->handle(new SettingDateValueQuery(Settings::MATURITY_DATE)); @@ -900,11 +964,11 @@ private function countMaturityDate(): DateTimeImmutable|null case MaturityType::WORK_DAYS: $workDays = $this->queryBus->handle(new SettingIntValueQuery(Settings::MATURITY_WORK_DAYS)); - $date = new DateTimeImmutable(); + $date = new DateTimeImmutable(); for ($i = 0; $i < $workDays;) { - $date = $date->modify('+1 days'); - $holidays = Yasumi::create('CzechRepublic', (int) $date->format('Y')); + $date = $date->modify('+1 days'); + $holidays = Yasumi::create('CzechRepublic', (int)$date->format('Y')); if ($holidays->isWorkingDay($date)) { $i++; @@ -940,7 +1004,7 @@ private function countRolesFee(Collection $roles): int /** * Vypočítá poplatek za podakce přihlášky. * - * @param Collection $roles + * @param Collection $roles * @param Collection $subevents */ private function countSubeventsFee(Collection $roles, Collection $subevents): int @@ -971,7 +1035,7 @@ private function countSubeventsFee(Collection $roles, Collection $subevents): in /** * Určí stav přihlášky. */ - private function getApplicationState(Application $application): string + private function getApplicationState(Application $application, bool $transfered = false): string { if ($application->getState() === ApplicationState::CANCELED) { return ApplicationState::CANCELED; @@ -981,6 +1045,14 @@ private function getApplicationState(Application $application): string return ApplicationState::CANCELED_NOT_PAID; } + if ($application->getState() === ApplicationState::CANCELED_TRANSFERED) { + return ApplicationState::CANCELED_TRANSFERED; + } + + if ($transfered || $application->getState() === ApplicationState::PAID_TRANSFERED) { + return ApplicationState::PAID_TRANSFERED; + } + if ($application->getFee() === 0) { return ApplicationState::PAID_FREE; } diff --git a/app/WebModule/Presenters/WebBasePresenter.php b/app/WebModule/Presenters/WebBasePresenter.php index 5bbdb1f8c..fa7eb938b 100644 --- a/app/WebModule/Presenters/WebBasePresenter.php +++ b/app/WebModule/Presenters/WebBasePresenter.php @@ -89,7 +89,6 @@ public function beforeRender(): void $this->template->seminarName = $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_NAME)); $this->template->trackingCode = $this->queryBus->handle(new SettingStringValueQuery(Settings::TRACKING_CODE)); - $this->template->nonregisteredRole = Role::NONREGISTERED; $this->template->testRole = Role::TEST; $this->template->adminAccess = $this->user->isAllowed(SrsResource::ADMIN, Permission::ACCESS); diff --git a/app/WebModule/Presenters/templates/Profile/default.latte b/app/WebModule/Presenters/templates/Profile/default.latte index 2a0e5d03e..435eb7ea2 100644 --- a/app/WebModule/Presenters/templates/Profile/default.latte +++ b/app/WebModule/Presenters/templates/Profile/default.latte @@ -21,7 +21,7 @@ {_web.profile.seminar.attendance}
- {if $dbUser->isInRoleWithSystemName($nonregisteredRole)} + {if !$dbUser->isRegistered()} {_web.profile.seminar.nonregistered} {elseif !$dbUser->isApproved()} {_web.profile.seminar.unapproved} diff --git a/app/lang/admin.cs_CZ.neon b/app/lang/admin.cs_CZ.neon index 5c066933e..59fee6829 100644 --- a/app/lang/admin.cs_CZ.neon +++ b/app/lang/admin.cs_CZ.neon @@ -435,6 +435,9 @@ users: users_attended_detail: "Přítomen" users_private_note: "Neveřejná poznámka" users_not_registered_mandatory_blocks: "Nepřihlášené povinné bloky" + users_target_user: "Cílový uživatel" + users_target_user_empty: "Vyberte cílového uživatele." + users_target_user_same: "Cílový uživatel nesmí být stejný." users_from: "Od" users_to: "Do" users_program_name: "Program" @@ -442,6 +445,7 @@ users: users_lectors: "Lektoři" users_changed_attended: "Účast uživatele byla úspěšně upravena." users_saved: "Uživatel byl úspěšně uložen." + users_transfered: "Registrace byla úspěšně převedena." users_group_action_approve: "Schválit" users_group_action_approved: "Vybraní uživatelé byli úspěšně schváleni." users_group_action_mark_paid_today: "Označit jako zaplacené dnes" @@ -474,6 +478,8 @@ users: users_edit_roles_empty: "Musí být vybrána alespoň jedna role." users_edit_roles_occupied: "Všechna místa v některé roli jsou obsazena." users_edit_roles_nonregistered: "Roli \"Nepřihlášený\" není možné nastavit, použijte odhlášení ze semináře." + users_transfer: "Převést registraci" + users_transfer_confirm: "Opravdu chcete registraci převést na nového uživatele?" users_applications_application_date: "Čas přihlášení" users_applications_roles: "Role" @@ -502,8 +508,9 @@ users: users_applications_application_canceled: "Dodatečná přihláška byla úspěšně zrušena." users_detail_heading: "Detail uživatele: %name%" users_detail_personal_details: "Osobní údaje" - users_detail_seminar: "Účast na semináři" users_detail_applications: "Role a platby" + users_detail_seminar: "Účast na semináři" + users_detail_transfer: "Převod registrace" users_detail_schedule: "Harmonogram" users_detail_birthdate_age: "%birthdate% (%age% let)" diff --git a/app/lang/common.cs_CZ.neon b/app/lang/common.cs_CZ.neon index 525c31ce5..1ffee829d 100644 --- a/app/lang/common.cs_CZ.neon +++ b/app/lang/common.cs_CZ.neon @@ -116,9 +116,11 @@ skautis_event_insert_type: application_state: waiting_for_payment: "Čeká na platbu" canceled_not_paid: "Zrušeno (nezaplaceno)" + canceled_transfered: "Zrušeno (převedeno)" canceled: "Zrušeno" paid: "Zaplaceno" paid_free: "Zaplaceno (zdarma)" + paid_transfered: "Zaplaceno (převedeno)" calendar_view: timeGridSeminar: "Na výšku"