Skip to content

Commit

Permalink
uprava podakci
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-stanek committed Dec 27, 2017
1 parent a13a0b5 commit a178837
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 170 deletions.
2 changes: 1 addition & 1 deletion app/AdminModule/ConfigurationModule/forms/SubeventForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function create($id)
->setAttribute('title', $form->getTranslator()->translate('admin.configuration.subevents_capacity_note'));

$form->addText('fee', 'admin.configuration.subevents_fee')
->addCondition(Form::FILLED)
->addRule(Form::FILLED, 'admin.configuration.subevents_fee_empty')
->addRule(Form::INTEGER, 'admin.configuration.subevents_fee_format');

if ($this->subevent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function createComponentProgramAttendeesGrid($name)
->innerJoin('a.subevents', 's')
->where('per.name = :permission')
->andWhere('s.id = :sid')
->andWhere('a.validTo IS NULL')
->andWhere('(a.state = \'' . ApplicationState::PAID . '\' OR a.state = \'' . ApplicationState::PAID_FREE
. '\' OR a.state = \'' . ApplicationState::WAITING_FOR_PAYMENT . '\')')
->setParameter('pid', $program->getId())
Expand Down
43 changes: 30 additions & 13 deletions app/AdminModule/components/ApplicationsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ public function createComponentApplicationsGrid($name)
$container->addMultiSelect('subevents', '',
$this->subeventRepository->getSubeventsOptionsWithCapacity()
)
->setAttribute('class', 'datagrid-multiselect')
->addRule(Form::FILLED, 'admin.users.users_applications_subevents_empty');
->setAttribute('class', 'datagrid-multiselect');

$container->addText('variableSymbol', 'admin.users.users_variable_symbol')
->addRule(Form::FILLED, 'admin.users.users_applications_variable_symbol_empty')
Expand All @@ -205,10 +204,10 @@ public function createComponentApplicationsGrid($name)

$container->addDatePicker('maturityDate', 'admin.users.users_maturity_date');
};
$grid->getInlineEdit()->onSetDefaults[] = function ($container, $item) {
$grid->getInlineEdit()->onSetDefaults[] = function ($container, Application $item) {
$container->setDefaults([
'subevents' => $this->subeventRepository->findSubeventsIds($item->getSubevents()),
'variableSymbol' => $item->getVariableSymbol(),
'variableSymbol' => $item->getVariableSymbolText(),
'paymentMethod' => $item->getPaymentMethod(),
'paymentDate' => $item->getPaymentDate(),
'incomeProofPrintedDate' => $item->getIncomeProofPrintedDate(),
Expand Down Expand Up @@ -261,21 +260,23 @@ public function add($values)
{
$selectedSubevents = $this->subeventRepository->findSubeventsByIds($values['subevents']);

$p = $this->getPresenter();

if (!$this->validators->validateSubeventsCapacities($selectedSubevents, $this->user)) {
$this->getPresenter()->flashMessage('admin.users.users_applications_subevents_occupied', 'danger');
$p->flashMessage('admin.users.users_applications_subevents_occupied', 'danger');
$this->redirect('this');
}

if (!$this->validators->validateSubeventsRegistered($selectedSubevents, $this->user)) {
$this->getPresenter()->flashMessage('admin.users.users_applications_subevents_registered', 'danger');
$p->flashMessage('admin.users.users_applications_subevents_registered', 'danger');
$this->redirect('this');
}

$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);

$this->applicationService->addSubeventsApplication($this->user, $selectedSubevents, $loggedUser);

$this->getPresenter()->flashMessage('admin.users.users_applications_saved', 'success');
$p->flashMessage('admin.users.users_applications_saved', 'success');
$this->redirect('this');
}

Expand All @@ -293,25 +294,41 @@ public function edit($id, $values)

$selectedSubevents = $this->subeventRepository->findSubeventsByIds($values['subevents']);

$p = $this->getPresenter();

if ($application->getType() == Application::ROLES) {
if (!$selectedSubevents->isEmpty()) {
$p->flashMessage('admin.users.users_applications_subevents_not_empty', 'danger');
$this->redirect('this');
}
} else {
if ($selectedSubevents->isEmpty()) {
$p->flashMessage('admin.users.users_applications_subevents_empty', 'danger');
$this->redirect('this');
}
}

if (!$this->validators->validateSubeventsCapacities($selectedSubevents, $this->user)) {
$this->getPresenter()->flashMessage('admin.users.users_applications_subevents_occupied', 'danger');
$p->flashMessage('admin.users.users_applications_subevents_occupied', 'danger');
$this->redirect('this');
}

if (!$this->validators->validateSubeventsRegistered($selectedSubevents, $this->user, $application)) {
$this->getPresenter()->flashMessage('admin.users.users_applications_subevents_registered', 'danger');
$p->flashMessage('admin.users.users_applications_subevents_registered', 'danger');
$this->redirect('this');
}

$loggedUser = $this->userRepository->findById($this->getPresenter()->user->id);

$this->applicationRepository->getEntityManager()->transactional(function ($em) use ($application, $selectedSubevents, $values, $loggedUser) {
$this->applicationService->updateSubeventsApplication($application, $selectedSubevents, $loggedUser);
$this->applicationService->updatePayment($application, $values['variableSymbol'], $values['paymentMethod'],
$values['paymentDate'], $values['incomeProofPrintedDate'], $values['maturityDate'], $loggedUser);
if ($application->getType() == Application::SUBEVENTS)
$this->applicationService->updateSubeventsApplication($application, $selectedSubevents, $loggedUser);
$this->applicationService->updatePayment($application, $values['variableSymbol'],
$values['paymentMethod'] ?: NULL, $values['paymentDate'],
$values['incomeProofPrintedDate'], $values['maturityDate'], $loggedUser);
});

$this->getPresenter()->flashMessage('admin.users.users_applications_saved', 'success');
$p->flashMessage('admin.users.users_applications_saved', 'success');
$this->redirect('this');
}

Expand Down
22 changes: 9 additions & 13 deletions app/AdminModule/components/UsersGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use App\Model\Settings\Settings;
use App\Model\Settings\SettingsRepository;
use App\Model\Structure\SubeventRepository;
use App\Model\User\Application;
use App\Model\User\ApplicationRepository;
use App\Model\User\User;
use App\Model\User\UserRepository;
Expand Down Expand Up @@ -180,22 +181,22 @@ public function createComponentUsersGrid($name)
->onSelect[] = [$this, 'groupMarkAttended'];

$grid->addGroupAction('admin.users.users_group_action_mark_paid_today', $this->preparePaymentMethodOptionsWithoutEmpty())
->onSelect[] = [$this, 'groupMarkPaidToday']; //TODO kontrola
->onSelect[] = [$this, 'groupMarkPaidToday'];

$grid->addGroupAction('admin.users.users_group_action_generate_payment_proofs')
->onSelect[] = [$this, 'groupGeneratePaymentProofs']; //TODO kontrola
->onSelect[] = [$this, 'groupGeneratePaymentProofs'];

$grid->addGroupAction('admin.users.users_group_action_export_users')
->onSelect[] = [$this, 'groupExportUsers']; //TODO kontrola
->onSelect[] = [$this, 'groupExportUsers'];

$grid->addGroupAction('admin.users.users_group_action_export_subevents_and_categories')
->onSelect[] = [$this, 'groupExportSubeventsAndCategories']; //TODO kontrola
->onSelect[] = [$this, 'groupExportSubeventsAndCategories'];

$grid->addGroupAction('admin.users.users_group_action_export_roles')
->onSelect[] = [$this, 'groupExportRoles']; //TODO kontrola
->onSelect[] = [$this, 'groupExportRoles'];

$grid->addGroupAction('admin.users.users_group_action_export_schedules')
->onSelect[] = [$this, 'groupExportSchedules']; //TODO kontrola
->onSelect[] = [$this, 'groupExportSchedules'];


$grid->addColumnText('displayName', 'admin.users.users_name')
Expand Down Expand Up @@ -281,14 +282,9 @@ public function createComponentUsersGrid($name)
return $this->userService->getPaymentMethodText($row);
});

$grid->addColumnDateTime('lastPaymentDate', 'admin.users.users_last_payment_date'); //TODO kontrola
$grid->addColumnDateTime('lastPaymentDate', 'admin.users.users_last_payment_date');

$grid->addColumnDateTime('firstApplicationDate', 'admin.users.users_first_application_date')
->setSortable()
->setSortableCallback(function ($qb, $sort) { //TODO kontrola
$qb->leftJoin('u.applications', 'aFirstApplicationDate', Expr\Join::WITH, 'aFirstApplicationDate.first = true')
->orderBy('aFirstApplicationDate.applicationDate', $sort['firstApplicationDate']);
})
$grid->addColumnDateTime('rolesApplicationDate', 'admin.users.users_roles_application_date')
->setFormat('j. n. Y H:i');

$columnAttended = $grid->addColumnStatus('attended', 'admin.users.users_attended');
Expand Down
6 changes: 3 additions & 3 deletions app/ApiModule/services/ScheduleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function getProgramsAdmin()
*/
public function getProgramsWeb()
{
$programs = $this->programRepository->findUserAllowed($this->user);
$programs = $this->programService->getUserAllowedPrograms($this->user);
$programDetailDTOs = [];
foreach ($programs as $program) {
$programDetailDTO = $this->convertProgramToProgramDetailDTO($program);
Expand Down Expand Up @@ -295,7 +295,7 @@ public function attendProgram($programId)
$responseDTO->setMessage($this->translator->translate('common.api.schedule_program_already_registered'));
elseif ($program->getCapacity() !== NULL && $program->getCapacity() <= $program->getAttendeesCount())
$responseDTO->setMessage($this->translator->translate('common.api.schedule_program_no_vacancies'));
elseif (!(new ArrayCollection($this->programRepository->findUserAllowed($this->user)))->contains($program))
elseif (!($this->programService->getUserAllowedPrograms($this->user))->contains($program))
$responseDTO->setMessage($this->translator->translate('common.api.schedule_program_category_not_allowed'));
elseif (count(
array_intersect($this->programRepository->findBlockedProgramsIdsByProgram($program),
Expand Down Expand Up @@ -396,7 +396,7 @@ private function convertBlockToBlockDetailDTO(Block $block)
$blockDetailDTO->setDescription($block->getDescription());
$blockDetailDTO->setProgramsCount($block->getProgramsCount());
$blockDetailDTO->setUserAttends($block->isAttendee($this->user));
$blockDetailDTO->setUserAllowed($block->isAllowed($this->user)); //TODO kontrola povolení zapisování před zaplacením
$blockDetailDTO->setUserAllowed($block->isAllowed($this->user));

return $blockDetailDTO;
}
Expand Down
18 changes: 15 additions & 3 deletions app/WebModule/components/ApplicationContentControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,27 @@ public function render($content)
$template->guestRole = $user->isInRole($this->roleRepository->findBySystemName(Role::GUEST)->getName());
$template->testRole = Role::TEST;

$explicitSubeventsExists = $this->subeventRepository->explicitSubeventsExists();

if ($user->isLoggedIn()) {
$dbuser = $this->userRepository->findById($user->id);
$userHasFixedFeeRole = $dbuser->hasFixedFeeRole();

$template->unapprovedRole = $user->isInRole($this->roleRepository->findBySystemName(Role::UNAPPROVED)->getName());
$template->nonregisteredRole = $user->isInRole($this->roleRepository->findBySystemName(Role::NONREGISTERED)->getName());
$template->bankAccount = $this->settingsRepository->getValue(Settings::ACCOUNT_NUMBER);
$template->subeventsExists = $this->subeventRepository->explicitSubeventsExists();
$template->dbuser = $this->userRepository->findById($user->id);
$template->dbuser = $dbuser;
$template->userHasFixedFeeRole = $userHasFixedFeeRole;

$template->usersApplications = $explicitSubeventsExists && $userHasFixedFeeRole
? $dbuser->getNotCanceledApplications()
: ($explicitSubeventsExists
? $dbuser->getNotCanceledSubeventsApplications()
: $dbuser->getNotCanceledRolesApplications()
);
}

$template->explicitSubeventsExists = $this->subeventRepository->explicitSubeventsExists();
$template->explicitSubeventsExists = $explicitSubeventsExists;
$template->rolesWithSubevents = json_encode($this->roleRepository->findRolesIds($this->roleRepository->findAllWithSubevents()));

$template->render();
Expand Down
30 changes: 21 additions & 9 deletions app/WebModule/components/ApplicationsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use App\Model\User\ApplicationRepository;
use App\Model\User\RolesApplicationRepository;
use App\Model\User\SubeventsApplication;
use App\Model\User\SubeventsApplicationRepository;
use App\Model\User\User;
use App\Model\User\UserRepository;
use App\Services\ApplicationService;
Expand Down Expand Up @@ -88,6 +89,9 @@ class ApplicationsGridControl extends Control
/** @var RolesApplicationRepository */
private $rolesApplicationRepository;

/** @var SubeventsApplicationRepository */
private $subeventsApplicationRepository;


/**
* ApplicationsGridControl constructor.
Expand All @@ -112,7 +116,8 @@ public function __construct(Translator $translator, ApplicationRepository $appli
SettingsRepository $settingsRepository, Authenticator $authenticator,
PdfExportService $pdfExportService, ProgramService $programService,
UserService $userService, Validators $validators,
RolesApplicationRepository $rolesApplicationRepository)
RolesApplicationRepository $rolesApplicationRepository,
SubeventsApplicationRepository $subeventsApplicationRepository)
{
parent::__construct();

Expand All @@ -131,6 +136,7 @@ public function __construct(Translator $translator, ApplicationRepository $appli
$this->userService = $userService;
$this->validators = $validators;
$this->rolesApplicationRepository = $rolesApplicationRepository;
$this->subeventsApplicationRepository = $subeventsApplicationRepository;
}

/**
Expand Down Expand Up @@ -264,8 +270,10 @@ public function add($values)
foreach ($selectedSubevents as $subevent)
$selectedAndUsersSubevents->add($subevent);

$p = $this->getPresenter();

if (!$this->validators->validateSubeventsCapacities($selectedSubevents, $this->user)) {
$this->getPresenter()->flashMessage('web.profile.applications_subevents_capacity_occupied', 'danger');
$p->flashMessage('web.profile.applications_subevents_capacity_occupied', 'danger');
$this->redirect('this');
}

Expand All @@ -274,21 +282,21 @@ public function add($values)
$message = $this->translator->translate('web.profile.applications_incompatible_subevents_selected', NULL,
['subevent' => $subevent->getName(), 'incompatibleSubevents' => $subevent->getIncompatibleSubeventsText()]
);
$this->getPresenter()->flashMessage($message, 'danger');
$p->flashMessage($message, 'danger');
$this->redirect('this');
}
if (!$this->validators->validateSubeventsRequired($selectedAndUsersSubevents, $subevent)) {
$message = $this->translator->translate('web.profile.applications_required_subevents_not_selected', NULL,
['subevent' => $subevent->getName(), 'requiredSubevents' => $subevent->getRequiredSubeventsTransitiveText()]
);
$this->getPresenter()->flashMessage($message, 'danger');
$p->flashMessage($message, 'danger');
$this->redirect('this');
}
}

$this->applicationService->addSubeventsApplication($this->user, $selectedSubevents, $this->user);

$this->getPresenter()->flashMessage('web.profile.applications_add_subevents_successful', 'success');
$p->flashMessage('web.profile.applications_add_subevents_successful', 'success');
$this->redirect('this');
}

Expand All @@ -308,9 +316,13 @@ public function edit($id, $values)
$selectedAndUsersSubevents = clone $this->user->getSubevents();
foreach ($selectedSubevents as $subevent)
$selectedAndUsersSubevents->add($subevent);
foreach ($application->getSubevents() as $subevent)
$selectedAndUsersSubevents->removeElement($subevent);

$p = $this->getPresenter();

if (!$this->validators->validateSubeventsCapacities($selectedSubevents, $this->user)) {
$this->getPresenter()->flashMessage('web.profile.applications_subevents_capacity_occupied', 'danger');
$p->flashMessage('web.profile.applications_subevents_capacity_occupied', 'danger');
$this->redirect('this');
}

Expand All @@ -319,21 +331,21 @@ public function edit($id, $values)
$message = $this->translator->translate('web.profile.applications_incompatible_subevents_selected', NULL,
['subevent' => $subevent->getName(), 'incompatibleSubevents' => $subevent->getIncompatibleSubeventsText()]
);
$this->getPresenter()->flashMessage($message, 'danger');
$p->flashMessage($message, 'danger');
$this->redirect('this');
}
if (!$this->validators->validateSubeventsRequired($selectedAndUsersSubevents, $subevent)) {
$message = $this->translator->translate('web.profile.applications_required_subevents_not_selected', NULL,
['subevent' => $subevent->getName(), 'requiredSubevents' => $subevent->getRequiredSubeventsTransitiveText()]
);
$this->getPresenter()->flashMessage($message, 'danger');
$p->flashMessage($message, 'danger');
$this->redirect('this');
}
}

$this->applicationService->updateSubeventsApplication($application, $selectedSubevents, $this->user);

$this->getPresenter()->flashMessage('web.profile.applications_edit_successful', 'success');
$p->flashMessage('web.profile.applications_edit_successful', 'success');
$this->redirect('this');
}

Expand Down
Loading

0 comments on commit a178837

Please sign in to comment.