Skip to content

Commit

Permalink
Přenos vstupenky - opravy (#1425)
Browse files Browse the repository at this point in the history
* select padding

* paid_canceled state

* do not edit paid applications

* padding

* confirm improved

* cs fix, update

* html in confirm

---------

Co-authored-by: Jan Staněk <[email protected]>
  • Loading branch information
jan-stanek and Jan Staněk authored Nov 13, 2024
1 parent b6279a6 commit 38a24e1
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 100 deletions.
3 changes: 2 additions & 1 deletion app/AdminModule/Forms/EditUserTransferFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public function create(int $id): Form
->setDisabled(! $this->user->isRegistered() || ! $this->user->hasPaidAnyApplication())
->setHtmlAttribute('class', 'btn btn-danger')
->setHtmlAttribute('data-toggle', 'confirmation')
->setHtmlAttribute('data-content', $this->translator->translate('admin.users.users_transfer_confirm'));
->setHtmlAttribute('data-content', $this->translator->translate('admin.users.users_transfer_confirm'))
->setHtmlAttribute('data-html', 'true');

$form->onSuccess[] = [$this, 'processForm'];

Expand Down
6 changes: 6 additions & 0 deletions app/Model/Enums/PaymentState.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class PaymentState
*/
public const PAIRED_MANUAL = 'paired_manual';

/**
* Spárovaná přihláška byla zrušena.
*/
public const PAIRED_CANCELED = 'paired_canceled';

/**
* Nespárováno - nesouhlasí poplatek.
*/
Expand Down Expand Up @@ -45,6 +50,7 @@ class PaymentState
public static array $states = [
self::PAIRED_AUTO,
self::PAIRED_MANUAL,
self::PAIRED_CANCELED,
self::NOT_PAIRED_FEE,
self::NOT_PAIRED_VS,
self::NOT_PAIRED_CANCELED,
Expand Down
9 changes: 4 additions & 5 deletions app/Model/Structure/Subevent.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,10 @@ public function countUsers(): int
//
// return $this->applications->matching($criteria)->count();

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 ||
$application->getState() === ApplicationState::PAID_TRANSFERED))->count();
return $this->applications->filter(
static fn (Application $application) => $application->getValidTo() === null && (
$application->getState() === ApplicationState::WAITING_FOR_PAYMENT || $application->isPaid()),
)->count();
}

public function countUnoccupied(): int|null
Expand Down
8 changes: 3 additions & 5 deletions app/Model/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,9 @@ public function getPaidApplications(): Collection
*/
public function getPaidAndTransferedAndFreeApplications(): Collection
{
return $this->applications->filter(static fn (Application $application) => $application->getValidTo() === null && (
$application->getState() === ApplicationState::PAID ||
$application->getState() === ApplicationState::PAID_FREE ||
$application->getState() === ApplicationState::PAID_TRANSFERED
));
return $this->applications->filter(
static fn (Application $application) => $application->getValidTo() === null && $application->isPaid(),
);
}

/**
Expand Down
56 changes: 26 additions & 30 deletions app/Services/ApplicationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,8 @@ public function cancelRegistration(User $user, string $state, User|null $created

if ($newApplication->getPayment() !== null) {
if ($newApplication->getPayment()->getPairedValidApplications()->count() === 1) {
$newApplication->getPayment()->setState(PaymentState::NOT_PAIRED_CANCELED);
$newApplication->getPayment()->setState(PaymentState::PAIRED_CANCELED);
}

$newApplication->setPayment(null);
}

$this->applicationRepository->save($newApplication);
Expand Down Expand Up @@ -448,10 +446,8 @@ public function cancelSubeventsApplication(SubeventsApplication $application, st

if ($newApplication->getPayment() !== null) {
if ($newApplication->getPayment()->getPairedValidApplications()->count() === 1) {
$newApplication->getPayment()->setState(PaymentState::NOT_PAIRED_CANCELED);
$newApplication->getPayment()->setState(PaymentState::PAIRED_CANCELED);
}

$newApplication->setPayment(null);
}

$this->applicationRepository->save($newApplication);
Expand Down Expand Up @@ -568,17 +564,9 @@ public function createPayment(
$pairedApplication = $this->applicationRepository->findValidByVariableSymbol($variableSymbol);

if ($pairedApplication) {
if (
$pairedApplication->getState() === ApplicationState::PAID ||
$pairedApplication->getState() === ApplicationState::PAID_FREE ||
$pairedApplication->getState() === ApplicationState::PAID_TRANSFERED
) {
if ($pairedApplication->isPaid()) {
$payment->setState(PaymentState::NOT_PAIRED_PAID);
} elseif (
$pairedApplication->getState() === ApplicationState::CANCELED ||
$pairedApplication->getState() === ApplicationState::CANCELED_NOT_PAID ||
$pairedApplication->getState() === ApplicationState::CANCELED_TRANSFERED
) {
} elseif ($pairedApplication->isCanceled()) {
$payment->setState(PaymentState::NOT_PAIRED_CANCELED);
} elseif (abs($pairedApplication->getFee() - $amount) >= 0.01) {
$payment->setState(PaymentState::NOT_PAIRED_FEE);
Expand Down Expand Up @@ -812,39 +800,47 @@ public function transferRegistration(User $sourceUser, User $targetUser, User $c
$targetUserPaidSubevents = $targetUser->getPaidSubevents();

// přidání zaplacených podakcí od zdrojového uživatele (kromě podakcí nekompatibilních s jeho stávajícími)
/** @var ArrayCollection<int, Subevent> $targetSubevents */
$targetSubevents = new ArrayCollection();
/** @var ArrayCollection<int, Subevent> $addSubevents */
$addSubevents = new ArrayCollection();
foreach ($sourceUserPaidSubevents as $subevent) {
if (! $targetSubevents->contains($subevent)) {
if (! $addSubevents->contains($subevent)) {
foreach ($subevent->getIncompatibleSubevents() as $incompatibleSubevent) {
if ($targetUserPaidSubevents->contains($incompatibleSubevent)) {
continue 2;
}
}

$targetSubevents->add($subevent);
$addSubevents->add($subevent);
}
}

$addSubeventsFiltered = clone$addSubevents;

// 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();
if ($application->isPaid()) {
foreach ($application->getSubevents() as $subevent) {
$addSubeventsFiltered->removeElement($subevent);
}
} else {
$remainingApplicationSubevents = new ArrayCollection();

foreach ($application->getSubevents() as $subevent) {
if (! $targetSubevents->contains($subevent)) {
$remainingSubevents->add($subevent);
foreach ($application->getSubevents() as $subevent) {
if (! $addSubevents->contains($subevent)) {
$remainingApplicationSubevents->add($subevent);
}
}
}

if ($remainingSubevents->isEmpty()) {
$this->cancelSubeventsApplication($application, ApplicationState::CANCELED, $createdBy);
} else {
$this->updateSubeventsApplication($application, $remainingSubevents, $createdBy);
if ($remainingApplicationSubevents->isEmpty()) {
$this->cancelSubeventsApplication($application, ApplicationState::CANCELED, $createdBy);
} else {
$this->updateSubeventsApplication($application, $remainingApplicationSubevents, $createdBy);
}
}
}

$this->updateRoles($targetUser, $targetRoles, $createdBy, false, true);
$this->addSubeventsApplication($targetUser, $targetSubevents, $createdBy, true);
$this->addSubeventsApplication($targetUser, $addSubeventsFiltered, $createdBy, true);

$this->cancelRegistration($sourceUser, ApplicationState::CANCELED_TRANSFERED, $createdBy);
});
Expand Down
3 changes: 2 additions & 1 deletion app/assets/common/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ function initSelects() {
actionsBox: true,
iconBase: 'fa',
tickIcon: 'fa-check',
style: 'btn-light'
style: 'btn-light',
windowPadding: [50, 0, 0, 0]
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/lang/admin.cs_CZ.neon
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ users:
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_transfer_confirm: "Opravdu chcete registraci převést na nového uživatele?<br>Pokud cílový uživatel už má zaplacené některé z převáděných podakcí nebo nekompatibilní podakce, budou mu přidány jen ostatní a tyto budou uvolněny."

users_applications_application_date: "Čas přihlášení"
users_applications_roles: "Role"
Expand Down
1 change: 1 addition & 0 deletions app/lang/common.cs_CZ.neon
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ payment:
payment_state:
paired_auto: "Spárována (automaticky)"
paired_manual: "Spárována (ručně)"
paired_canceled: "Spárována (přihláška zrušena)"
not_paired_fee: "Nespárována (nesouhlasí částka)"
not_paired_vs: "Nespárována (neexistuje variabilní symbol)"
not_paired_canceled: "Nespárována (přihláška zrušena)"
Expand Down
Loading

0 comments on commit 38a24e1

Please sign in to comment.