From 75567772e267496db615ce3625c88b1ca57066af Mon Sep 17 00:00:00 2001 From: Mateusz Lencki Date: Thu, 7 Sep 2023 12:04:34 +0200 Subject: [PATCH 1/3] #177 - Delegations --- .../Actions/VacationRequest/CreateAction.php | 2 +- app/Domain/Enums/VacationType.php | 1 + app/Domain/UnavailableDaysRetriever.php | 37 +++ app/Domain/UserVacationStatsRetriever.php | 1 + app/Domain/VacationTypeConfigRetriever.php | 13 + .../Rules/DoesNotExceedLimitRule.php | 2 +- .../Rules/MinimumOneVacationDayRule.php | 2 +- app/Domain/WorkDaysCalculator.php | 19 +- app/Eloquent/Models/YearPeriod.php | 18 ++ ...CalculateUserUnavailableDaysController.php | 23 +- .../Api/CalculateVacationDaysController.php | 2 +- .../GetAvailableVacationTypesController.php | 1 + .../CalculateUserUnavailableDaysRequest.php | 10 + .../Api/CalculateVacationDaysRequest.php | 8 + config/vacation_types.php | 103 +++++++ database/seeders/DatabaseSeeder.php | 1 + database/seeders/DemoSeeder.php | 3 + resources/js/Composables/vacationTypeInfo.js | 8 + resources/js/Pages/VacationRequest/Create.vue | 289 +++++++++--------- 19 files changed, 376 insertions(+), 167 deletions(-) create mode 100644 app/Domain/UnavailableDaysRetriever.php diff --git a/app/Domain/Actions/VacationRequest/CreateAction.php b/app/Domain/Actions/VacationRequest/CreateAction.php index d3e0389a..679b220c 100644 --- a/app/Domain/Actions/VacationRequest/CreateAction.php +++ b/app/Domain/Actions/VacationRequest/CreateAction.php @@ -52,7 +52,7 @@ protected function createVacationRequest(array $data, User $creator): VacationRe $vacationRequest->save(); - $days = $this->workDaysCalculator->calculateDays($vacationRequest->from, $vacationRequest->to); + $days = $this->workDaysCalculator->calculateDays($vacationRequest->type, $vacationRequest->from, $vacationRequest->to); foreach ($days as $day) { $vacationRequest->vacations()->create([ diff --git a/app/Domain/Enums/VacationType.php b/app/Domain/Enums/VacationType.php index 0c377f34..0c2082d2 100644 --- a/app/Domain/Enums/VacationType.php +++ b/app/Domain/Enums/VacationType.php @@ -19,6 +19,7 @@ enum VacationType: string case Sick = "sick_vacation"; case Absence = "absence"; case RemoteWork = "remote_work"; + case Delegation = "delegation"; public function label(): string { diff --git a/app/Domain/UnavailableDaysRetriever.php b/app/Domain/UnavailableDaysRetriever.php new file mode 100644 index 00000000..9d0c9fe9 --- /dev/null +++ b/app/Domain/UnavailableDaysRetriever.php @@ -0,0 +1,37 @@ +vacations() + ->whereBelongsTo($yearPeriod) + ->whereRelation( + "vacationRequest", + fn(Builder $query): Builder => $query->noStates(VacationRequestStatesRetriever::failedStates()), + ) + ->pluck("date"); + + if (!$vacationType || !$this->configRetriever->isDuringNonWorkDays($vacationType)) { + $unavailableDays->push(...$yearPeriod->weekends()); + $unavailableDays->push(...$yearPeriod->holidays()->pluck("date")); + } + + return $unavailableDays->map(fn(Carbon $date): string => $date->toDateString())->toArray(); + } +} diff --git a/app/Domain/UserVacationStatsRetriever.php b/app/Domain/UserVacationStatsRetriever.php index 775ed707..117175dc 100644 --- a/app/Domain/UserVacationStatsRetriever.php +++ b/app/Domain/UserVacationStatsRetriever.php @@ -70,6 +70,7 @@ public function getOtherApprovedVacationDays(User $user, YearPeriod $yearPeriod) fn(Builder $query): Builder => $query ->whereIn("type", $this->getNotLimitableVacationTypes()) ->whereNot("type", VacationType::RemoteWork) + ->whereNot("type", VacationType::Delegation) ->states(VacationRequestStatesRetriever::successStates()), ) ->count(); diff --git a/app/Domain/VacationTypeConfigRetriever.php b/app/Domain/VacationTypeConfigRetriever.php index 7865d413..5ee7d0d9 100644 --- a/app/Domain/VacationTypeConfigRetriever.php +++ b/app/Domain/VacationTypeConfigRetriever.php @@ -6,6 +6,7 @@ use Illuminate\Contracts\Config\Repository; use Toby\Domain\Enums\EmploymentForm; +use Toby\Domain\Enums\Role; use Toby\Domain\Enums\VacationType; class VacationTypeConfigRetriever @@ -16,6 +17,8 @@ class VacationTypeConfigRetriever public const KEY_HAS_LIMIT = "has_limit"; public const KEY_AVAILABLE_FOR = "available_for"; public const KEY_IS_VACATION = "is_vacation"; + public const KEY_DURING_NON_WORKDAYS = "during_non_workdays"; + public const KEY_REQUEST_ALLOWED_FOR = "request_allowed_for"; public function __construct( protected Repository $config, @@ -46,11 +49,21 @@ public function isVacation(VacationType $type): bool return $this->getConfigFor($type)[static::KEY_IS_VACATION]; } + public function isDuringNonWorkDays(VacationType $type): bool + { + return $this->getConfigFor($type)[static::KEY_DURING_NON_WORKDAYS]; + } + public function isAvailableFor(VacationType $type, EmploymentForm $employmentForm): bool { return in_array($employmentForm, $this->getConfigFor($type)[static::KEY_AVAILABLE_FOR], true); } + public function isRequestAllowedFor(VacationType $type, Role $role): bool + { + return in_array($role, $this->getConfigFor($type)[static::KEY_REQUEST_ALLOWED_FOR], true); + } + protected function getConfigFor(VacationType $type): array { return $this->config->get("vacation_types.{$type->value}"); diff --git a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php index 8ce82b55..f03ca21f 100644 --- a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php +++ b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php @@ -30,7 +30,7 @@ public function check(VacationRequest $vacationRequest): bool $limit = $this->getUserVacationLimit($vacationRequest->user, $vacationRequest->yearPeriod); $vacationDays = $this->getVacationDaysWithLimit($vacationRequest->user, $vacationRequest->yearPeriod); $estimatedDays = $this->workDaysCalculator - ->calculateDays($vacationRequest->from, $vacationRequest->to) + ->calculateDays($vacationRequest->type, $vacationRequest->from, $vacationRequest->to) ->count(); return $limit >= ($vacationDays + $estimatedDays); diff --git a/app/Domain/Validation/Rules/MinimumOneVacationDayRule.php b/app/Domain/Validation/Rules/MinimumOneVacationDayRule.php index 6a38f408..a8ae284c 100644 --- a/app/Domain/Validation/Rules/MinimumOneVacationDayRule.php +++ b/app/Domain/Validation/Rules/MinimumOneVacationDayRule.php @@ -16,7 +16,7 @@ public function __construct( public function check(VacationRequest $vacationRequest): bool { return $this->workDaysCalculator - ->calculateDays($vacationRequest->from, $vacationRequest->to) + ->calculateDays($vacationRequest->type, $vacationRequest->from, $vacationRequest->to) ->isNotEmpty(); } diff --git a/app/Domain/WorkDaysCalculator.php b/app/Domain/WorkDaysCalculator.php index 3dd3c5ff..83fb84b5 100644 --- a/app/Domain/WorkDaysCalculator.php +++ b/app/Domain/WorkDaysCalculator.php @@ -7,11 +7,20 @@ use Carbon\CarbonInterface; use Carbon\CarbonPeriod; use Illuminate\Support\Collection; +use Toby\Domain\Enums\VacationType; use Toby\Eloquent\Models\YearPeriod; class WorkDaysCalculator { - public function calculateDays(CarbonInterface $from, CarbonInterface $to): Collection + public function __construct( + protected VacationTypeConfigRetriever $configRetriever, + ) {} + + public function calculateDays( + VacationType $vacationType, + CarbonInterface $from, + CarbonInterface $to, + ): Collection { $period = CarbonPeriod::create($from, $to); $yearPeriod = YearPeriod::findByYear($from->year); @@ -20,7 +29,7 @@ public function calculateDays(CarbonInterface $from, CarbonInterface $to): Colle $validDays = new Collection(); foreach ($period as $day) { - if ($this->passes($day, $holidays)) { + if ($this->passes($vacationType, $day, $holidays)) { $validDays->add($day); } } @@ -28,13 +37,13 @@ public function calculateDays(CarbonInterface $from, CarbonInterface $to): Colle return $validDays; } - protected function passes(CarbonInterface $day, Collection $holidays): bool + protected function passes(VacationType $vacationType, CarbonInterface $day, Collection $holidays): bool { - if ($day->isWeekend()) { + if ($day->isWeekend() && !$this->configRetriever->isDuringNonWorkDays($vacationType)) { return false; } - if ($holidays->contains($day)) { + if ($holidays->contains($day) && !$this->configRetriever->isDuringNonWorkDays($vacationType)) { return false; } diff --git a/app/Eloquent/Models/YearPeriod.php b/app/Eloquent/Models/YearPeriod.php index 7976fca8..8d3311b0 100644 --- a/app/Eloquent/Models/YearPeriod.php +++ b/app/Eloquent/Models/YearPeriod.php @@ -52,6 +52,24 @@ public function holidays(): HasMany return $this->hasMany(Holiday::class); } + public function weekends(): Collection + { + $start = Carbon::create($this->year); + $end = Carbon::create($this->year)->endOfYear(); + + $weekends = collect(); + + while ($start->lte($end)) { + if ($start->isWeekend()) { + $weekends->push($start->copy()); + } + + $start->addDay(); + } + + return $weekends; + } + protected static function newFactory(): YearPeriodFactory { return YearPeriodFactory::new(); diff --git a/app/Infrastructure/Http/Controllers/Api/CalculateUserUnavailableDaysController.php b/app/Infrastructure/Http/Controllers/Api/CalculateUserUnavailableDaysController.php index 5e4afe52..3198748b 100644 --- a/app/Infrastructure/Http/Controllers/Api/CalculateUserUnavailableDaysController.php +++ b/app/Infrastructure/Http/Controllers/Api/CalculateUserUnavailableDaysController.php @@ -4,11 +4,9 @@ namespace Toby\Infrastructure\Http\Controllers\Api; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\JsonResponse; -use Illuminate\Support\Carbon; +use Toby\Domain\UnavailableDaysRetriever; use Toby\Domain\UserVacationStatsRetriever; -use Toby\Domain\VacationRequestStatesRetriever; use Toby\Eloquent\Helpers\YearPeriodRetriever; use Toby\Eloquent\Models\User; use Toby\Infrastructure\Http\Controllers\Controller; @@ -20,23 +18,18 @@ public function __invoke( CalculateUserUnavailableDaysRequest $request, UserVacationStatsRetriever $vacationStatsRetriever, YearPeriodRetriever $yearPeriodRetriever, + UnavailableDaysRetriever $unavailableDaysRetriever, ): JsonResponse { /** @var User $user */ $user = User::query()->find($request->get("user")); $yearPeriod = $yearPeriodRetriever->selected(); - $holidays = $yearPeriod->holidays()->pluck("date"); - $vacationDays = $user->vacations() - ->whereBelongsTo($yearPeriod) - ->whereRelation( - "vacationRequest", - fn(Builder $query): Builder => $query->noStates(VacationRequestStatesRetriever::failedStates()), - ) - ->pluck("date"); + $unavailableDays = $unavailableDaysRetriever->getUnavailableDays( + $user, + $yearPeriod, + $request->vacationType(), + ); - return new JsonResponse([ - ...$holidays->map(fn(Carbon $date): string => $date->toDateString()), - ...$vacationDays->map(fn(Carbon $date): string => $date->toDateString()), - ]); + return new JsonResponse($unavailableDays); } } diff --git a/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php index be7348c8..5adb084d 100644 --- a/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php +++ b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php @@ -14,7 +14,7 @@ class CalculateVacationDaysController extends Controller { public function __invoke(CalculateVacationDaysRequest $request, WorkDaysCalculator $calculator): JsonResponse { - $days = $calculator->calculateDays($request->from(), $request->to()); + $days = $calculator->calculateDays($request->vacationType(), $request->from(), $request->to()); return new JsonResponse($days->map(fn(Carbon $day): string => $day->toDateString())->all()); } diff --git a/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php b/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php index 48a92a2a..95699f4d 100644 --- a/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php +++ b/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php @@ -22,6 +22,7 @@ public function __invoke( $types = VacationType::all() ->filter(fn(VacationType $type): bool => $configRetriever->isAvailableFor($type, $user->profile->employment_form)) + ->filter(fn(VacationType $type): bool => $configRetriever->isRequestAllowedFor($type, $request->user()->role)) ->map(fn(VacationType $type): array => [ "label" => $type->label(), "value" => $type->value, diff --git a/app/Infrastructure/Http/Requests/Api/CalculateUserUnavailableDaysRequest.php b/app/Infrastructure/Http/Requests/Api/CalculateUserUnavailableDaysRequest.php index 03a6c9cd..dfcfdf8c 100644 --- a/app/Infrastructure/Http/Requests/Api/CalculateUserUnavailableDaysRequest.php +++ b/app/Infrastructure/Http/Requests/Api/CalculateUserUnavailableDaysRequest.php @@ -5,13 +5,23 @@ namespace Toby\Infrastructure\Http\Requests\Api; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Rules\Enum; +use Toby\Domain\Enums\VacationType; class CalculateUserUnavailableDaysRequest extends FormRequest { public function rules(): array { return [ + "vacationType" => [new Enum(VacationType::class)], "user" => ["required", "exists:users,id"], ]; } + + public function vacationType(): ?VacationType + { + return $this->request->has("vacationType") + ? VacationType::from($this->request->get("vacationType")) + : null; + } } diff --git a/app/Infrastructure/Http/Requests/Api/CalculateVacationDaysRequest.php b/app/Infrastructure/Http/Requests/Api/CalculateVacationDaysRequest.php index 72e37dea..94ded88b 100644 --- a/app/Infrastructure/Http/Requests/Api/CalculateVacationDaysRequest.php +++ b/app/Infrastructure/Http/Requests/Api/CalculateVacationDaysRequest.php @@ -6,6 +6,8 @@ use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Carbon; +use Illuminate\Validation\Rules\Enum; +use Toby\Domain\Enums\VacationType; use Toby\Eloquent\Models\YearPeriod; use Toby\Infrastructure\Http\Rules\YearPeriodExists; @@ -14,11 +16,17 @@ class CalculateVacationDaysRequest extends FormRequest public function rules(): array { return [ + "vacationType" => ["required", new Enum(VacationType::class)], "from" => ["required", "date_format:Y-m-d", new YearPeriodExists()], "to" => ["required", "date_format:Y-m-d", new YearPeriodExists()], ]; } + public function vacationType(): VacationType + { + return VacationType::from($this->request->get("vacationType")); + } + public function from(): Carbon { return Carbon::create($this->request->get("from")); diff --git a/config/vacation_types.php b/config/vacation_types.php index fbd62d46..76f955a6 100644 --- a/config/vacation_types.php +++ b/config/vacation_types.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Toby\Domain\Enums\EmploymentForm; +use Toby\Domain\Enums\Role; use Toby\Domain\Enums\VacationType; use Toby\Domain\VacationTypeConfigRetriever; @@ -15,7 +16,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::OnRequest->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true, @@ -25,7 +33,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::TimeInLieu->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => false, @@ -35,7 +50,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::Sick->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => false, @@ -45,7 +67,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::Unpaid->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true, @@ -55,7 +84,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::Special->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true, @@ -65,7 +101,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::Childcare->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true, @@ -75,7 +118,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::Training->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true, @@ -85,7 +135,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, VacationType::Volunteering->value => [ @@ -96,7 +153,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::Volunteering->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true, @@ -106,7 +170,14 @@ VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ EmploymentForm::EmploymentContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::Absence->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => false, @@ -118,7 +189,14 @@ EmploymentForm::B2bContract, EmploymentForm::BoardMemberContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => true, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, ], VacationType::RemoteWork->value => [ VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => false, @@ -131,6 +209,31 @@ EmploymentForm::B2bContract, EmploymentForm::BoardMemberContract, ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Employee, + Role::Administrator, + Role::AdministrativeApprover, + Role::TechnicalApprover, + ], + VacationTypeConfigRetriever::KEY_IS_VACATION => false, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => false, + ], + VacationType::Delegation->value => [ + VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => false, + VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => false, + VacationTypeConfigRetriever::KEY_BILLABLE => true, + VacationTypeConfigRetriever::KEY_HAS_LIMIT => false, + VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [ + EmploymentForm::EmploymentContract, + EmploymentForm::CommissionContract, + EmploymentForm::B2bContract, + EmploymentForm::BoardMemberContract, + ], + VacationTypeConfigRetriever::KEY_REQUEST_ALLOWED_FOR => [ + Role::Administrator, + Role::AdministrativeApprover, + ], VacationTypeConfigRetriever::KEY_IS_VACATION => false, + VacationTypeConfigRetriever::KEY_DURING_NON_WORKDAYS => true, ], ]; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 27618cf6..459a8995 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -75,6 +75,7 @@ public function run(): void ]) ->afterCreating(function (VacationRequest $vacationRequest): void { $days = app(WorkDaysCalculator::class)->calculateDays( + $vacationRequest->type, $vacationRequest->from, $vacationRequest->to, ); diff --git a/database/seeders/DemoSeeder.php b/database/seeders/DemoSeeder.php index f9bc4c02..d6b9130e 100644 --- a/database/seeders/DemoSeeder.php +++ b/database/seeders/DemoSeeder.php @@ -172,6 +172,7 @@ public function run(): void ->for($currentYearPeriod) ->afterCreating(function (VacationRequest $vacationRequest): void { $days = app(WorkDaysCalculator::class)->calculateDays( + $vacationRequest->type, $vacationRequest->from, $vacationRequest->to, ); @@ -241,6 +242,7 @@ public function run(): void ->for($currentYearPeriod) ->afterCreating(function (VacationRequest $vacationRequest): void { $days = app(WorkDaysCalculator::class)->calculateDays( + $vacationRequest->type, $vacationRequest->from, $vacationRequest->to, ); @@ -299,6 +301,7 @@ public function run(): void ->for($currentYearPeriod) ->afterCreating(function (VacationRequest $vacationRequest): void { $days = app(WorkDaysCalculator::class)->calculateDays( + $vacationRequest->type, $vacationRequest->from, $vacationRequest->to, ); diff --git a/resources/js/Composables/vacationTypeInfo.js b/resources/js/Composables/vacationTypeInfo.js index 2d643262..d2b90635 100644 --- a/resources/js/Composables/vacationTypeInfo.js +++ b/resources/js/Composables/vacationTypeInfo.js @@ -10,6 +10,7 @@ import MedicalBagIcon from 'vue-material-design-icons/MedicalBag.vue' import CalendarRemoveIcon from 'vue-material-design-icons/CalendarRemove.vue' import HomeCityIcon from 'vue-material-design-icons/HomeCity.vue' import PlusIcon from 'vue-material-design-icons/Plus.vue' +import PlaneTrainIcon from 'vue-material-design-icons/PlaneTrain.vue' const types = [ { @@ -89,6 +90,13 @@ const types = [ color: 'text-lime-500', border: 'border-lime-500', }, + { + text: 'Delegacja', + value: 'delegation', + icon: PlaneTrainIcon, + color: 'text-sky-500', + border: 'border-sky-500', + }, { text: 'Dodaj wniosek', value: 'create', diff --git a/resources/js/Pages/VacationRequest/Create.vue b/resources/js/Pages/VacationRequest/Create.vue index 8e57bd14..2d2af619 100644 --- a/resources/js/Pages/VacationRequest/Create.vue +++ b/resources/js/Pages/VacationRequest/Create.vue @@ -1,9 +1,9 @@