This commit is contained in:
Adrian Hopek 2022-04-05 14:21:32 +02:00
parent 3ab02f1df4
commit 5122b5b70b
13 changed files with 157 additions and 31 deletions

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Toby\Domain\Enums;
use Illuminate\Support\Collection;
enum VacationType: string
{
case Vacation = "vacation";
@ -15,6 +17,7 @@ enum VacationType: string
case Volunteering = "volunteering_vacation";
case TimeInLieu = "time_in_lieu";
case Sick = "sick_vacation";
case Absence = "absence";
public function label(): string
{
@ -23,7 +26,7 @@ enum VacationType: string
public static function casesToSelect(): array
{
$cases = collect(VacationType::cases());
$cases = VacationType::all();
return $cases->map(
fn(VacationType $enum) => [
@ -32,4 +35,9 @@ enum VacationType: string
],
)->toArray();
}
public static function all(): Collection
{
return new Collection(VacationType::cases());
}
}

View File

@ -95,14 +95,14 @@ class UserVacationStatsRetriever
protected function getLimitableVacationTypes(): Collection
{
$types = new Collection(VacationType::cases());
$types = VacationType::all();
return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
}
protected function getNotLimitableVacationTypes(): Collection
{
$types = new Collection(VacationType::cases());
$types = VacationType::all();
return $types->filter(fn(VacationType $type) => !$this->configRetriever->hasLimit($type));
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Toby\Domain;
use Illuminate\Contracts\Config\Repository;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Domain\Enums\VacationType;
class VacationTypeConfigRetriever
@ -13,6 +14,7 @@ class VacationTypeConfigRetriever
public const KEY_ADMINISTRATIVE_APPROVAL = "administrative_approval";
public const KEY_BILLABLE = "billable";
public const KEY_HAS_LIMIT = "has_limit";
public const KEY_AVAILABLE_FOR = "available_for";
public function __construct(
protected Repository $config,
@ -38,6 +40,11 @@ class VacationTypeConfigRetriever
return $this->getConfigFor($type)[static::KEY_HAS_LIMIT];
}
public function isAvailableFor(VacationType $type, EmploymentForm $employmentForm): bool
{
return in_array($employmentForm, $this->getConfigFor($type)[static::KEY_AVAILABLE_FOR], true);
}
protected function getConfigFor(VacationType $type): array
{
return $this->config->get("vacation_types.{$type->value}");

View File

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Toby\Domain\Validation\Rules;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Collection;
use Toby\Domain\Enums\VacationType;
use Toby\Domain\VacationDaysCalculator;
use Toby\Domain\VacationRequestStatesRetriever;
@ -59,7 +59,7 @@ class DoesNotExceedLimitRule implements VacationRequestRule
protected function getLimitableVacationTypes(): Collection
{
$types = new Collection(VacationType::cases());
$types = VacationType::all();
return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
}

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Controllers\Api;
use Illuminate\Http\JsonResponse;
use Toby\Domain\Enums\VacationType;
use Toby\Domain\VacationTypeConfigRetriever;
use Toby\Eloquent\Models\User;
use Toby\Infrastructure\Http\Controllers\Controller;
use Toby\Infrastructure\Http\Requests\Api\GetAvailableVacationTypesRequest;
class GetAvailableVacationTypesController extends Controller
{
public function __invoke(
GetAvailableVacationTypesRequest $request,
VacationTypeConfigRetriever $configRetriever,
): JsonResponse {
/** @var User $user */
$user = User::query()->find($request->get("user"));
$types = VacationType::all()
->filter(fn(VacationType $type) => $configRetriever->isAvailableFor($type, $user->employment_form))
->map(fn(VacationType $type) => [
"label" => $type->label(),
"value" => $type->value,
])
->values();
return new JsonResponse($types);
}
}

View File

@ -158,10 +158,7 @@ class VacationRequestController extends Controller
public function create(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response
{
$yearPeriod = $yearPeriodRetriever->selected();
$users = User::query()
->withVacationLimitIn($yearPeriod)
->orderBy("last_name")
->orderBy("first_name")
->get();

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Requests\Api;
use Illuminate\Foundation\Http\FormRequest;
class GetAvailableVacationTypesRequest extends FormRequest
{
public function rules(): array
{
return [
"user" => ["required", "exists:users,id"],
];
}
}

View File

@ -2,6 +2,7 @@
declare(strict_types=1);
use Toby\Domain\Enums\EmploymentForm;
use Toby\Domain\Enums\VacationType;
use Toby\Domain\VacationTypeConfigRetriever;
@ -11,53 +12,100 @@ return [
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => true,
VacationTypeConfigRetriever::KEY_BILLABLE => true,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => true,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::EmploymentContract,
],
],
VacationType::OnRequest->value => [
VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true,
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => true,
VacationTypeConfigRetriever::KEY_BILLABLE => true,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => true,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::EmploymentContract,
],
],
VacationType::TimeInLieu->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,
],
],
VacationType::Sick->value => [
VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => false,
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => true,
VacationTypeConfigRetriever::KEY_BILLABLE => true,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => false,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::EmploymentContract,
],
],
VacationType::Unpaid->value => [
VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true,
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => true,
VacationTypeConfigRetriever::KEY_BILLABLE => false,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => false,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::EmploymentContract,
],
],
VacationType::Special->value => [
VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true,
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => true,
VacationTypeConfigRetriever::KEY_BILLABLE => false,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => false,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::EmploymentContract,
],
],
VacationType::Childcare->value => [
VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true,
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => true,
VacationTypeConfigRetriever::KEY_BILLABLE => false,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => false,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::EmploymentContract,
],
],
VacationType::Training->value => [
VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true,
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => true,
VacationTypeConfigRetriever::KEY_BILLABLE => true,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => false,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::EmploymentContract,
],
],
VacationType::Volunteering->value => [
VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true,
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => true,
VacationTypeConfigRetriever::KEY_BILLABLE => true,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => false,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::EmploymentContract,
],
],
VacationType::Volunteering->value => [
VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true,
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => true,
VacationTypeConfigRetriever::KEY_BILLABLE => true,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => false,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::EmploymentContract,
],
],
VacationType::Absence->value => [
VacationTypeConfigRetriever::KEY_TECHNICAL_APPROVAL => true,
VacationTypeConfigRetriever::KEY_ADMINISTRATIVE_APPROVAL => false,
VacationTypeConfigRetriever::KEY_BILLABLE => false,
VacationTypeConfigRetriever::KEY_HAS_LIMIT => false,
VacationTypeConfigRetriever::KEY_AVAILABLE_FOR => [
EmploymentForm::CommissionContract,
EmploymentForm::B2bContract,
EmploymentForm::BoardMemberContract,
],
],
];

View File

@ -4,7 +4,7 @@
<div class="flex justify-between items-center p-4 sm:px-6">
<div class="flex items-center">
<h2 class="text-lg font-medium leading-6 text-gray-900">
Wykorzystanie miesięczne urlopu wypoczynkowego
Wykorzystanie miesięczne urlopu
</h2>
</div>
</div>

View File

@ -30,7 +30,7 @@
scope="col"
class="py-3 px-4 text-xs font-semibold tracking-wider text-left text-gray-500 uppercase whitespace-nowrap"
>
Posiada urlop?
Posiada limit?
</th>
<th
scope="col"

View File

@ -4,7 +4,7 @@
<div class="flex flex-col h-full bg-white shadow-md xl:col-span-2">
<div class="p-4 sm:px-6">
<h2 class="text-lg font-medium leading-6 text-gray-900">
Złóż wniosek urlopowy
Złóż wniosek
</h2>
</div>
<form
@ -42,8 +42,8 @@
</ListboxLabel>
<div class="relative mt-1 sm:col-span-2 sm:mt-0">
<ListboxButton
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.user, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.user }"
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:ring-red-500 focus:border-red-500': form.errors.user, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.user }"
>
<span class="flex items-center">
<img
@ -63,7 +63,7 @@
leave-to-class="opacity-0"
>
<ListboxOptions
class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 ring-black ring-opacity-5 shadow-lg sm:text-sm"
class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 focus:ring-blumilk-500 ring-opacity-5 shadow-lg sm:text-sm"
>
<ListboxOption
v-for="user in users.data"
@ -134,24 +134,29 @@
class="items-center py-4 sm:grid sm:grid-cols-3"
>
<ListboxLabel class="block text-sm font-medium text-gray-700">
Rodzaj urlopu
Typ wniosku
</ListboxLabel>
<div class="relative mt-1 sm:col-span-2 sm:mt-0">
<ListboxButton
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:ring-1 shadow-sm cursor-default sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.type, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.type }"
class="relative py-2 pr-10 pl-3 w-full max-w-lg text-left bg-white rounded-md border focus:outline-none focus:ring-1 shadow-sm cursor-default sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:ring-red-500 focus:border-red-500': form.errors.type, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.type }"
>
<span class="block truncate">{{ form.vacationType.label }}</span>
<span class="flex absolute inset-y-0 right-0 items-center pr-2 pointer-events-none">
<SelectorIcon class="w-5 h-5 text-gray-400" />
</span>
<template v-if="form.vacationType">
<span class="block truncate">{{ form.vacationType.label }}</span>
<span class="flex absolute inset-y-0 right-0 items-center pr-2 pointer-events-none">
<SelectorIcon class="w-5 h-5 text-gray-400" />
</span>
</template>
<template v-else>
Ładowanie...
</template>
</ListboxButton>
<transition
leave-active-class="transition ease-in duration-100"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<ListboxOptions class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 ring-black ring-opacity-5 shadow-lg sm:text-sm">
<ListboxOptions class="overflow-auto absolute z-10 py-1 mt-1 w-full max-w-lg max-h-60 text-base bg-white rounded-md focus:outline-none ring-1 focus:ring-blumilk-500 ring-opacity-5 shadow-lg sm:text-sm">
<ListboxOption
v-for="vacationType in vacationTypes"
:key="vacationType.value"
@ -187,7 +192,7 @@
for="date_from"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Planowany urlop od
Data od
</label>
<div class="mt-1 sm:col-span-2 sm:mt-0">
<FlatPickr
@ -212,7 +217,7 @@
for="date_from"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Planowany urlop do
Data do
</label>
<div class="mt-1 sm:col-span-2 sm:mt-0">
<FlatPickr
@ -233,7 +238,7 @@
</div>
</div>
<div class="items-center py-4 sm:grid sm:grid-cols-3">
<span class="block text-sm font-medium text-gray-700 sm:mt-px">Liczba dni urlopu</span>
<span class="block text-sm font-medium text-gray-700 sm:mt-px">Liczba dni</span>
<div
class="inline-flex items-center py-2 px-4 mt-1 w-full max-w-lg text-gray-500 bg-gray-50 rounded-md border border-gray-300 sm:col-span-2 sm:mt-0 sm:text-sm"
>
@ -303,10 +308,10 @@
<div class="p-4 sm:px-6">
<h2 class="text-lg font-medium leading-6 text-gray-900">
<span v-if="auth.user.id !== form.user.id">
Urlop wypoczynkowy, dane dla: {{ form.user.name }}
Dane urlopowe dla: {{ form.user.name }}
</span>
<span v-else>
Twoje dane o urlopie wypoczynkowym
Twoje dane o urlopie
</span>
</h2>
</div>
@ -330,7 +335,6 @@ import VacationChart from '@/Shared/VacationChart'
const props = defineProps({
auth: Object,
users: Object,
vacationTypes: Object,
holidays: Object,
can: Object,
})
@ -341,12 +345,13 @@ const form = useForm({
: props.auth.user,
from: null,
to: null,
vacationType: props.vacationTypes[0],
vacationType: null,
comment: null,
flowSkipped: false,
})
const estimatedDays = ref([])
const vacationTypes = ref([])
const stats = ref({
used: 0,
@ -372,8 +377,9 @@ const toInputConfig = reactive({
watch(() => form.user, user => {
resetForm()
refreshVacationStats(user)
refreshAvailableTypes(user)
refreshUnavailableDays(user)
refreshVacationStats(user)
}, { immediate: true })
function createForm() {
@ -406,7 +412,7 @@ function onToChange(selectedDates, dateStr) {
}
function resetForm() {
form.reset('type', 'to', 'from', 'comment', 'flowSkipped')
form.reset('to', 'from', 'comment', 'flowSkipped')
form.clearErrors()
estimatedDays.value = []
}
@ -440,4 +446,11 @@ async function refreshUnavailableDays(user) {
]
}
async function refreshAvailableTypes(user) {
const res = await axios.post('/api/vacation/get-available-vacation-types', { user: user.id })
vacationTypes.value = res.data
form.vacationType = vacationTypes.value[0]
}
</script>

View File

@ -14,6 +14,7 @@
"look_for_work_vacation": "Urlop na poszukiwanie pracy",
"time_in_lieu": "Odbiór za święto",
"sick_vacation": "Zwolnienie lekarskie",
"absence": "Nieobecność",
"employee": "Pracownik",
"administrator": "Administrator",
"technical_approver": "Techniczny akceptujący",

View File

@ -6,9 +6,11 @@ use Illuminate\Support\Facades\Route;
use Toby\Infrastructure\Http\Controllers\Api\CalculateUserUnavailableDaysController;
use Toby\Infrastructure\Http\Controllers\Api\CalculateUserVacationStatsController;
use Toby\Infrastructure\Http\Controllers\Api\CalculateVacationDaysController;
use Toby\Infrastructure\Http\Controllers\Api\GetAvailableVacationTypesController;
Route::middleware("auth:sanctum")->group(function (): void {
Route::post("vacation/calculate-days", CalculateVacationDaysController::class);
Route::post("vacation/calculate-stats", CalculateUserVacationStatsController::class);
Route::post("vacation/calculate-unavailable-days", CalculateUserUnavailableDaysController::class);
Route::post("vacation/get-available-vacation-types", GetAvailableVacationTypesController::class);
});