Merge branch '#22-vacation-calendar' into #41-email-notifications
This commit is contained in:
commit
40226305fb
80
app/Domain/CalendarGenerator.php
Normal file
80
app/Domain/CalendarGenerator.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterface;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class CalendarGenerator
|
||||
{
|
||||
public function __construct(
|
||||
protected YearPeriodRetriever $yearPeriodRetriever,
|
||||
) {
|
||||
}
|
||||
|
||||
public function generate(YearPeriod $yearPeriod, string $month): array
|
||||
{
|
||||
$date = CarbonImmutable::create($yearPeriod->year, $this->monthNameToNumber($month));
|
||||
$period = CarbonPeriod::create($date->startOfMonth(), $date->endOfMonth());
|
||||
$holidays = $yearPeriod->holidays()->pluck("date");
|
||||
|
||||
return $this->generateCalendar($period, $holidays);
|
||||
}
|
||||
|
||||
protected function monthNameToNumber($name): int
|
||||
{
|
||||
return match ($name) {
|
||||
default => CarbonInterface::JANUARY,
|
||||
"february" => CarbonInterface::FEBRUARY,
|
||||
"march" => CarbonInterface::MARCH,
|
||||
"april" => CarbonInterface::APRIL,
|
||||
"may" => CarbonInterface::MAY,
|
||||
"june" => CarbonInterface::JUNE,
|
||||
"july" => CarbonInterface::JULY,
|
||||
"august" => CarbonInterface::AUGUST,
|
||||
"september" => CarbonInterface::SEPTEMBER,
|
||||
"october" => CarbonInterface::OCTOBER,
|
||||
"november" => CarbonInterface::NOVEMBER,
|
||||
"december" => CarbonInterface::DECEMBER,
|
||||
};
|
||||
}
|
||||
|
||||
protected function generateCalendar(CarbonPeriod $period, Collection $holidays): array
|
||||
{
|
||||
$calendar = [];
|
||||
$vacations = $this->getVacationsForPeriod($period);
|
||||
|
||||
foreach ($period as $day) {
|
||||
$vacationsForDay = $vacations[$day->toDateString()] ?? new Collection();
|
||||
|
||||
$calendar[] = [
|
||||
"date" => $day->toDateString(),
|
||||
"dayOfMonth" => $day->translatedFormat("j"),
|
||||
"dayOfWeek" => $day->translatedFormat("D"),
|
||||
"isToday" => $day->isToday(),
|
||||
"isWeekend" => $day->isWeekend(),
|
||||
"isHoliday" => $holidays->contains($day),
|
||||
"vacations" => $vacationsForDay->pluck("user_id"),
|
||||
];
|
||||
}
|
||||
|
||||
return $calendar;
|
||||
}
|
||||
|
||||
protected function getVacationsForPeriod(CarbonPeriod $period): Collection
|
||||
{
|
||||
return Vacation::query()
|
||||
->whereBetween("date", [$period->start, $period->end])
|
||||
->whereRelation("vacationRequest", "state", VacationRequestState::APPROVED->value)
|
||||
->get()
|
||||
->groupBy(fn(Vacation $vacation) => $vacation->date->toDateString());
|
||||
}
|
||||
}
|
@ -4,23 +4,64 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Validation\Rules;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\VacationDaysCalculator;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class DoesNotExceedLimitRule implements VacationRequestRule
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
protected VacationDaysCalculator $vacationDaysCalculator,
|
||||
) {
|
||||
}
|
||||
|
||||
public function check(VacationRequest $vacationRequest): bool
|
||||
{
|
||||
return true;
|
||||
if (!$this->configRetriever->hasLimit($vacationRequest->type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$limit = $this->getUserVacationLimit($vacationRequest->user, $vacationRequest->yearPeriod);
|
||||
$vacationDays = $this->getVacationDaysWithLimit($vacationRequest->user, $vacationRequest->yearPeriod);
|
||||
$estimatedDays = $this->vacationDaysCalculator->calculateDays($vacationRequest->yearPeriod, $vacationRequest->from, $vacationRequest->to)->count();
|
||||
|
||||
return $limit >= ($vacationDays + $estimatedDays);
|
||||
}
|
||||
|
||||
public function errorMessage(): string
|
||||
{
|
||||
return __("You have exceeded your vacation limit.");
|
||||
return __("Vacation limit has been exceeded.");
|
||||
}
|
||||
|
||||
protected function getUserVacationLimit(User $user, YearPeriod $yearPeriod): int
|
||||
{
|
||||
return $user->vacationLimits()->where("year_period_id", $yearPeriod->id)->first()->days ?? 0;
|
||||
}
|
||||
|
||||
protected function getVacationDaysWithLimit(User $user, YearPeriod $yearPeriod): int
|
||||
{
|
||||
return $user->vacations()
|
||||
->where("year_period_id", $yearPeriod->id)
|
||||
->whereRelation(
|
||||
"vacationRequest",
|
||||
fn(Builder $query) => $query
|
||||
->whereIn("type", $this->getLimitableVacationTypes())
|
||||
->noStates(VacationRequestState::failedStates()),
|
||||
)
|
||||
->count();
|
||||
}
|
||||
|
||||
protected function getLimitableVacationTypes(): Collection
|
||||
{
|
||||
$types = new Collection(VacationType::cases());
|
||||
|
||||
return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ use Illuminate\Support\Carbon;
|
||||
* @property Carbon $date
|
||||
* @property User $user
|
||||
* @property VacationRequest $vacationRequest
|
||||
* @property YearPeriod $yearPeriod
|
||||
*/
|
||||
class Vacation extends Model
|
||||
{
|
||||
@ -34,4 +35,9 @@ class Vacation extends Model
|
||||
{
|
||||
return $this->belongsTo(VacationRequest::class);
|
||||
}
|
||||
|
||||
public function yearPeriod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ use Toby\Domain\Enums\VacationType;
|
||||
* @property VacationRequestState $state
|
||||
* @property Carbon $from
|
||||
* @property Carbon $to
|
||||
* @property int $estimated_days
|
||||
* @property string $comment
|
||||
* @property User $user
|
||||
* @property YearPeriod $yearPeriod
|
||||
@ -75,6 +74,11 @@ class VacationRequest extends Model
|
||||
return $query->whereIn("state", $states);
|
||||
}
|
||||
|
||||
public function scopeNoStates(Builder $query, array $states): Builder
|
||||
{
|
||||
return $query->whereNotIn("state", $states);
|
||||
}
|
||||
|
||||
public function scopeOverlapsWith(Builder $query, self $vacationRequest): Builder
|
||||
{
|
||||
return $query->where("from", "<=", $vacationRequest->to)
|
||||
|
@ -4,81 +4,35 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterface;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Domain\CalendarGenerator;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
|
||||
class VacationCalendarController extends Controller
|
||||
{
|
||||
public function index(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response
|
||||
{
|
||||
$month = $request->query("month", "february");
|
||||
public function index(
|
||||
Request $request,
|
||||
YearPeriodRetriever $yearPeriodRetriever,
|
||||
CalendarGenerator $calendarGenerator,
|
||||
): Response {
|
||||
$month = Str::lower($request->query("month", Carbon::now()->englishMonth));
|
||||
$yearPeriod = $yearPeriodRetriever->selected();
|
||||
$date = CarbonImmutable::create($yearPeriod->year, $this->monthNameToNumber($month));
|
||||
$period = CarbonPeriod::create($date->startOfMonth(), $date->endOfMonth());
|
||||
$holidays = $yearPeriod->holidays()->pluck("date");
|
||||
$users = User::query()
|
||||
->with([
|
||||
"vacations" => fn($query) => $query
|
||||
->whereBetween("date", [$period->start, $period->end])
|
||||
->whereRelation("vacationRequest", "state", VacationRequestState::APPROVED->value),
|
||||
])
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->get();
|
||||
|
||||
$calendar = [];
|
||||
|
||||
foreach ($period as $day) {
|
||||
$calendar[] = [
|
||||
"date" => $day->toDateString(),
|
||||
"dayOfMonth" => $day->translatedFormat("j"),
|
||||
"dayOfWeek" => $day->translatedFormat("D"),
|
||||
"isToday" => $day->isToday(),
|
||||
"isWeekend" => $day->isWeekend(),
|
||||
"isHoliday" => $holidays->contains($day),
|
||||
];
|
||||
}
|
||||
|
||||
$userVacations = [];
|
||||
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$userVacations[] = [
|
||||
"user" => new UserResource($user),
|
||||
"vacations" => $user->vacations->map(fn(Vacation $vacation) => $vacation->date->toDateString()),
|
||||
];
|
||||
}
|
||||
$calendar = $calendarGenerator->generate($yearPeriod, $month);
|
||||
|
||||
return inertia("Calendar", [
|
||||
"calendar" => $calendar,
|
||||
"currentMonth" => $month,
|
||||
"userVacations" => $userVacations,
|
||||
"users" => UserResource::collection($users),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function monthNameToNumber(?string $name): int
|
||||
{
|
||||
return match ($name) {
|
||||
default => CarbonInterface::JANUARY,
|
||||
"february" => CarbonInterface::FEBRUARY,
|
||||
"march" => CarbonInterface::MARCH,
|
||||
"april" => CarbonInterface::APRIL,
|
||||
"may" => CarbonInterface::MAY,
|
||||
"june" => CarbonInterface::JUNE,
|
||||
"july" => CarbonInterface::JULY,
|
||||
"august" => CarbonInterface::AUGUST,
|
||||
"september" => CarbonInterface::SEPTEMBER,
|
||||
"october" => CarbonInterface::OCTOBER,
|
||||
"november" => CarbonInterface::NOVEMBER,
|
||||
"december" => CarbonInterface::DECEMBER,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ class VacationRequestController extends Controller
|
||||
/** @var VacationRequest $vacationRequest */
|
||||
$vacationRequest = $request->user()->vacationRequests()->make($request->data());
|
||||
$vacationRequestValidator->validate($vacationRequest);
|
||||
|
||||
$vacationRequest->save();
|
||||
|
||||
$days = $vacationDaysCalculator->calculateDays(
|
||||
@ -86,7 +87,8 @@ class VacationRequestController extends Controller
|
||||
foreach ($days as $day) {
|
||||
$vacationRequest->vacations()->create([
|
||||
"date" => $day,
|
||||
"user_id" => $vacationRequest->user_id,
|
||||
"user_id" => $vacationRequest->user->id,
|
||||
"year_period_id" => $vacationRequest->yearPeriod->id,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -8,15 +8,8 @@ use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class VacationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
return new class() extends Migration {
|
||||
public function up(): void
|
||||
@ -15,6 +16,7 @@ return new class() extends Migration {
|
||||
$table->id();
|
||||
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignIdFor(VacationRequest::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete();
|
||||
$table->date("date");
|
||||
});
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ class DatabaseSeeder extends Seeder
|
||||
$vacationRequest->vacations()->create([
|
||||
"date" => $day,
|
||||
"user_id" => $vacationRequest->user->id,
|
||||
"year_period_id" => $vacationRequest->yearPeriod->id,
|
||||
]);
|
||||
}
|
||||
})
|
||||
|
128
resources/js/Composables/statusInfo.js
Normal file
128
resources/js/Composables/statusInfo.js
Normal file
@ -0,0 +1,128 @@
|
||||
import {
|
||||
CheckIcon as OutlineCheckIcon,
|
||||
ClockIcon as OutlineClockIcon,
|
||||
DocumentTextIcon as OutlineDocumentTextIcon,
|
||||
ThumbDownIcon as OutlineThumbDownIcon,
|
||||
ThumbUpIcon as OutlineThumbUpIcon,
|
||||
XIcon as OutlineXIcon,
|
||||
} from '@heroicons/vue/outline'
|
||||
|
||||
import {
|
||||
CheckIcon as SolidCheckIcon,
|
||||
ClockIcon as SolidClockIcon,
|
||||
DocumentTextIcon as SolidDocumentTextIcon,
|
||||
ThumbDownIcon as SolidThumbDownIcon,
|
||||
ThumbUpIcon as SolidThumbUpIcon,
|
||||
XIcon as SolidXIcon,
|
||||
} from '@heroicons/vue/solid'
|
||||
|
||||
const statuses = [
|
||||
{
|
||||
text: 'Utworzony',
|
||||
value: 'created',
|
||||
outline: {
|
||||
icon: OutlineDocumentTextIcon,
|
||||
foreground: 'text-white',
|
||||
background: 'bg-gray-400',
|
||||
},
|
||||
solid: {
|
||||
icon: SolidDocumentTextIcon,
|
||||
color: 'text-gray-400',
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Czeka na akceptację od technicznego',
|
||||
value: 'waiting_for_technical',
|
||||
outline: {
|
||||
icon: OutlineClockIcon,
|
||||
foreground: 'text-white',
|
||||
background: 'bg-amber-400',
|
||||
},
|
||||
solid: {
|
||||
icon: SolidClockIcon,
|
||||
color: 'text-amber-400',
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Czeka na akceptację od administracyjnego',
|
||||
value: 'waiting_for_administrative',
|
||||
outline: {
|
||||
icon: OutlineClockIcon,
|
||||
foreground: 'text-white',
|
||||
background: 'bg-amber-400',
|
||||
},
|
||||
solid: {
|
||||
icon: SolidClockIcon,
|
||||
color: 'text-amber-400',
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Odrzucony',
|
||||
value: 'rejected',
|
||||
outline: {
|
||||
icon: OutlineThumbDownIcon,
|
||||
foreground: 'text-white',
|
||||
background: 'bg-rose-600',
|
||||
},
|
||||
solid: {
|
||||
icon: SolidThumbDownIcon,
|
||||
color: 'text-rose-600',
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Zaakceptowany przez technicznego',
|
||||
value: 'accepted_by_technical',
|
||||
outline: {
|
||||
icon: OutlineThumbUpIcon,
|
||||
foreground: 'text-white',
|
||||
background: 'bg-green-500',
|
||||
},
|
||||
solid: {
|
||||
icon: SolidThumbUpIcon,
|
||||
color: 'text-green-500',
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Zaakceptowany przez administracyjnego',
|
||||
value: 'accepted_by_administrative',
|
||||
outline: {
|
||||
icon: OutlineThumbUpIcon,
|
||||
foreground: 'text-white',
|
||||
background: 'bg-green-500',
|
||||
},
|
||||
solid: {
|
||||
icon: SolidThumbUpIcon,
|
||||
color: 'text-green-500',
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Zatwierdzony',
|
||||
value: 'approved',
|
||||
outline: {
|
||||
icon: OutlineCheckIcon,
|
||||
foreground: 'text-white',
|
||||
background: 'bg-blumilk-500',
|
||||
},
|
||||
solid: {
|
||||
icon: SolidCheckIcon,
|
||||
color: 'text-blumilk-500',
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Anulowany',
|
||||
value: 'canceled',
|
||||
outline: {
|
||||
icon: OutlineXIcon,
|
||||
foreground: 'text-white',
|
||||
background: 'bg-gray-900',
|
||||
},
|
||||
solid: {
|
||||
icon: SolidXIcon,
|
||||
color: 'text-gray-900',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
export function useStatusInfo(status) {
|
||||
return statuses.find(statusInfo => statusInfo.value === status)
|
||||
}
|
@ -62,7 +62,7 @@
|
||||
v-for="day in calendar"
|
||||
:key="day.dayOfMonth"
|
||||
class="border border-gray-300 text-lg font-semibold text-gray-900 py-4 px-2"
|
||||
:class="{ 'text-blumilk-600 bg-blumilk-25 font-black': day.isToday}"
|
||||
:class="{ 'text-blumilk-600 bg-blumilk-25 font-black': day.isToday }"
|
||||
>
|
||||
<div>
|
||||
{{ day.dayOfMonth }}
|
||||
@ -75,21 +75,20 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="userVacation in userVacations"
|
||||
:key="userVacation.user.id"
|
||||
v-for="user in users.data"
|
||||
:key="user.id"
|
||||
>
|
||||
<th class="border border-gray-300 py-2 px-4">
|
||||
<div class="flex justify-start items-center">
|
||||
<span class="inline-flex items-center justify-center h-10 w-10 rounded-full">
|
||||
<img
|
||||
class="h-10 w-10 rounded-full"
|
||||
:src="userVacation.user.avatar"
|
||||
alt=""
|
||||
:src="user.avatar"
|
||||
>
|
||||
</span>
|
||||
<div class="ml-3">
|
||||
<div class="text-sm font-medium text-gray-900">
|
||||
{{ userVacation.user.name }}
|
||||
{{ user.name }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -98,10 +97,10 @@
|
||||
v-for="day in calendar"
|
||||
:key="day.dayOfMonth"
|
||||
class="border border-gray-300"
|
||||
:class="{'bg-gray-100': day.isWeekend, 'bg-green-100': day.isHoliday, 'bg-blumilk-500': userVacation.vacations.includes(day.date) }"
|
||||
:class="{'bg-red-100': day.isWeekend || day.isHoliday, 'bg-blumilk-500': day.vacations.includes(user.id) }"
|
||||
>
|
||||
<div
|
||||
v-if="userVacation.vacations.includes(day.date)"
|
||||
v-if="day.vacations.includes(user.id)"
|
||||
class="flex justify-center items-center"
|
||||
>
|
||||
<svg
|
||||
@ -139,7 +138,7 @@ export default {
|
||||
ChevronDownIcon,
|
||||
},
|
||||
props: {
|
||||
userVacations: {
|
||||
users: {
|
||||
type: Object,
|
||||
default: () => null,
|
||||
},
|
||||
|
@ -257,7 +257,7 @@ import {computed} from 'vue'
|
||||
import {usePage} from '@inertiajs/inertia-vue3'
|
||||
|
||||
export default {
|
||||
name: 'Dashboard',
|
||||
name: 'DashboardPage',
|
||||
setup() {
|
||||
const user = computed(() => usePage().props.value.auth.user)
|
||||
const stats = [
|
||||
|
@ -18,6 +18,14 @@
|
||||
{{ request.name }}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium text-gray-500">
|
||||
Pracownik
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ request.user.name }}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium text-gray-500">
|
||||
Rodzaj urlopu
|
||||
|
@ -6,9 +6,9 @@
|
||||
/>
|
||||
<div class="relative flex space-x-3">
|
||||
<div>
|
||||
<span :class="[statusInfo.iconBackground, statusInfo.iconForeground, 'h-8 w-8 rounded-full flex items-center justify-center ring-8 ring-white']">
|
||||
<span :class="[statusInfo.outline.background, statusInfo.outline.foreground, 'h-8 w-8 rounded-full flex items-center justify-center ring-8 ring-white']">
|
||||
<component
|
||||
:is="statusInfo.icon"
|
||||
:is="statusInfo.outline.icon"
|
||||
class="w-5 h-5 text-white"
|
||||
/>
|
||||
</span>
|
||||
@ -32,8 +32,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {CheckIcon, ClockIcon, DocumentTextIcon, ThumbDownIcon, ThumbUpIcon, XIcon} from '@heroicons/vue/outline'
|
||||
import {computed} from 'vue'
|
||||
import {useStatusInfo} from '@/Composables/statusInfo'
|
||||
|
||||
export default {
|
||||
name: 'VacationRequestActivity',
|
||||
@ -48,65 +48,7 @@ export default {
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const statuses = [
|
||||
{
|
||||
text: 'Utworzony',
|
||||
icon: DocumentTextIcon,
|
||||
value: 'created',
|
||||
iconForeground: 'text-white',
|
||||
iconBackground: 'bg-gray-400',
|
||||
},
|
||||
{
|
||||
text: 'Czeka na akceptację od technicznego',
|
||||
icon: ClockIcon,
|
||||
value: 'waiting_for_technical',
|
||||
iconForeground: 'text-white',
|
||||
iconBackground: 'bg-amber-400',
|
||||
},
|
||||
{
|
||||
text: 'Czeka na akceptację od administracyjnego',
|
||||
icon: ClockIcon,
|
||||
value: 'waiting_for_administrative',
|
||||
iconForeground: 'text-white',
|
||||
iconBackground: 'bg-amber-400',
|
||||
},
|
||||
{
|
||||
text: 'Odrzucony',
|
||||
icon: ThumbDownIcon,
|
||||
value: 'rejected',
|
||||
iconForeground: 'text-white',
|
||||
iconBackground: 'bg-rose-600',
|
||||
},
|
||||
{
|
||||
text: 'Zaakceptowany przez technicznego',
|
||||
icon: ThumbUpIcon,
|
||||
value: 'accepted_by_technical',
|
||||
iconForeground: 'text-white',
|
||||
iconBackground: 'bg-green-500',
|
||||
},
|
||||
{
|
||||
text: 'Zaakceptowany przez administracyjnego',
|
||||
icon: ThumbUpIcon,
|
||||
value: 'accepted_by_administrative',
|
||||
iconForeground: 'text-white',
|
||||
iconBackground: 'bg-green-500',
|
||||
},
|
||||
{
|
||||
text: 'Zatwierdzony',
|
||||
icon: CheckIcon,
|
||||
value: 'approved',
|
||||
iconForeground: 'text-white',
|
||||
iconBackground: 'bg-blumilk-500',
|
||||
},
|
||||
{
|
||||
text: 'Anulowany',
|
||||
icon: XIcon,
|
||||
value: 'canceled',
|
||||
iconForeground: 'text-white',
|
||||
iconBackground: 'bg-gray-900',
|
||||
},
|
||||
]
|
||||
const statusInfo = computed(() => statuses.find(status => status.value === props.activity.state))
|
||||
const statusInfo = computed(() => useStatusInfo(props.activity.state))
|
||||
|
||||
return {
|
||||
statusInfo,
|
||||
|
@ -1,16 +1,16 @@
|
||||
<template>
|
||||
<div class="flex items-center">
|
||||
<component
|
||||
:is="statusInfo.icon"
|
||||
:class="[statusInfo.color ,'w-5 h-5 mr-1']"
|
||||
:is="statusInfo.solid.icon"
|
||||
:class="[statusInfo.solid.color ,'w-5 h-5 mr-1']"
|
||||
/>
|
||||
<span>{{ statusInfo.text }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {CheckIcon, ClockIcon, DocumentTextIcon, ThumbDownIcon, ThumbUpIcon, XIcon} from '@heroicons/vue/solid'
|
||||
import {computed} from 'vue'
|
||||
import {useStatusInfo} from '@/Composables/statusInfo'
|
||||
|
||||
export default {
|
||||
name: 'VacationRequestStatus',
|
||||
@ -25,57 +25,7 @@ export default {
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const statuses = [
|
||||
{
|
||||
text: 'Utworzony',
|
||||
icon: DocumentTextIcon,
|
||||
value: 'created',
|
||||
color: 'text-gray-400',
|
||||
},
|
||||
{
|
||||
text: 'Czeka na akceptację od technicznego',
|
||||
icon: ClockIcon,
|
||||
value: 'waiting_for_technical',
|
||||
color: 'text-amber-400',
|
||||
},
|
||||
{
|
||||
text: 'Czeka na akceptację od administracyjnego',
|
||||
icon: ClockIcon,
|
||||
value: 'waiting_for_administrative',
|
||||
color: 'text-amber-400',
|
||||
},
|
||||
{
|
||||
text: 'Odrzucony',
|
||||
icon: ThumbDownIcon,
|
||||
value: 'rejected',
|
||||
color: 'text-rose-600',
|
||||
},
|
||||
{
|
||||
text: 'Zaakceptowany przez technicznego',
|
||||
icon: ThumbUpIcon,
|
||||
value: 'accepted_by_technical',
|
||||
color: 'text-green-500',
|
||||
},
|
||||
{
|
||||
text: 'Zaakceptowany przez administracyjnego',
|
||||
icon: ThumbUpIcon,
|
||||
value: 'accepted_by_administrative',
|
||||
color: 'text-green-500',
|
||||
},
|
||||
{
|
||||
text: 'Zatwierdzony',
|
||||
icon: CheckIcon,
|
||||
value: 'approved',
|
||||
color: 'text-blumilk-500',
|
||||
},
|
||||
{
|
||||
text: 'Anulowany',
|
||||
icon: XIcon,
|
||||
value: 'canceled',
|
||||
color: 'text-gray-900',
|
||||
},
|
||||
]
|
||||
const statusInfo = computed(() => statuses.find(status => status.value === props.status))
|
||||
const statusInfo = computed(() => useStatusInfo(props.status))
|
||||
|
||||
return {
|
||||
statusInfo,
|
||||
|
@ -28,7 +28,7 @@
|
||||
"accepted_by_administrative": "Zaakceptowany przez administracyjnego",
|
||||
"You have pending vacation request in this range.": "Masz oczekujący wniosek urlopowy w tym zakresie dat.",
|
||||
"You have approved vacation request in this range.": "Masz zaakceptowany wniosek urlopowy w tym zakresie dat.",
|
||||
"You have exceeded your vacation limit.": "Przekroczyłeś/aś limit urlopu.",
|
||||
"Vacation limit has been exceeded.": "Limit urlopu został przekroczony.",
|
||||
"Vacation needs minimum one day.": "Urlop musi być co najmniej na jeden dzień.",
|
||||
"The vacation request cannot be created at the turn of the year.": "Wniosek urlopowy nie może zostać złożony na przełomie roku.",
|
||||
"Hi :user!": "Cześć :user!",
|
||||
|
@ -3,6 +3,7 @@ const defaultTheme = require('tailwindcss/defaultTheme')
|
||||
module.exports = {
|
||||
content: [
|
||||
'./resources/**/*.vue',
|
||||
'./resources/**/*.js',
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
|
@ -12,6 +12,7 @@ use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\PolishHolidaysRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationLimit;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
@ -55,6 +56,13 @@ class VacationRequestTest extends FeatureTestCase
|
||||
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
"days" => 20,
|
||||
])
|
||||
->for($user)
|
||||
->for($currentYearPeriod)
|
||||
->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
"type" => VacationType::VACATION->value,
|
||||
@ -128,6 +136,13 @@ class VacationRequestTest extends FeatureTestCase
|
||||
$technicalApprover = User::factory()->createQuietly();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
$vacationLimit = VacationLimit::factory([
|
||||
"days" => 20,
|
||||
])
|
||||
->for($user)
|
||||
->for($currentYearPeriod)
|
||||
->create();
|
||||
|
||||
$vacationRequest = VacationRequest::factory([
|
||||
"state" => VacationRequestState::WAITING_FOR_TECHNICAL,
|
||||
"type" => VacationType::VACATION,
|
||||
@ -145,11 +160,42 @@ class VacationRequestTest extends FeatureTestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUserCannotCreateVacationRequestIfHeExceedsHisVacationLimit(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
"days" => 3,
|
||||
])
|
||||
->for($user)
|
||||
->for($currentYearPeriod)
|
||||
->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
"type" => VacationType::VACATION->value,
|
||||
"from" => Carbon::create($currentYearPeriod->year, 2, 7)->toDateString(),
|
||||
"to" => Carbon::create($currentYearPeriod->year, 2, 11)->toDateString(),
|
||||
"comment" => "Comment for the vacation request.",
|
||||
])
|
||||
->assertSessionHasErrors([
|
||||
"vacationRequest" => __("Vacation limit has been exceeded."),
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUserCannotCreateVacationRequestAtWeekend(): void
|
||||
{
|
||||
$user = User::factory()->createQuietly();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
"days" => 20,
|
||||
])
|
||||
->for($user)
|
||||
->for($currentYearPeriod)
|
||||
->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->post("/vacation-requests", [
|
||||
"type" => VacationType::VACATION->value,
|
||||
@ -158,7 +204,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
"comment" => "Vacation at weekend.",
|
||||
])
|
||||
->assertSessionHasErrors([
|
||||
"vacationRequest" => trans("Vacation needs minimum one day."),
|
||||
"vacationRequest" => __("Vacation needs minimum one day."),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -167,6 +213,13 @@ class VacationRequestTest extends FeatureTestCase
|
||||
$user = User::factory()->createQuietly();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
"days" => 20,
|
||||
])
|
||||
->for($user)
|
||||
->for($currentYearPeriod)
|
||||
->create();
|
||||
|
||||
foreach ($this->polishHolidaysRetriever->getForYearPeriod($currentYearPeriod) as $holiday) {
|
||||
$currentYearPeriod->holidays()->create([
|
||||
"name" => $holiday["name"],
|
||||
@ -182,7 +235,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
"comment" => "Vacation at holiday.",
|
||||
])
|
||||
->assertSessionHasErrors([
|
||||
"vacationRequest" => trans("Vacation needs minimum one day."),
|
||||
"vacationRequest" => __("Vacation needs minimum one day."),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -191,6 +244,13 @@ class VacationRequestTest extends FeatureTestCase
|
||||
$user = User::factory()->createQuietly();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
VacationLimit::factory([
|
||||
"days" => 20,
|
||||
])
|
||||
->for($user)
|
||||
->for($currentYearPeriod)
|
||||
->create();
|
||||
|
||||
VacationRequest::factory([
|
||||
"type" => VacationType::VACATION->value,
|
||||
"state" => VacationRequestState::WAITING_FOR_TECHNICAL,
|
||||
@ -210,8 +270,9 @@ class VacationRequestTest extends FeatureTestCase
|
||||
"comment" => "Another comment for the another vacation request.",
|
||||
])
|
||||
->assertSessionHasErrors([
|
||||
"vacationRequest" => trans("You have pending vacation request in this range."),
|
||||
]);
|
||||
"vacationRequest" => __("You have pending vacation request in this range."),
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function testUserCannotCreateVacationRequestIfHeHasApprovedVacationRequestInThisRange(): void
|
||||
@ -219,6 +280,13 @@ class VacationRequestTest extends FeatureTestCase
|
||||
$user = User::factory()->createQuietly();
|
||||
$currentYearPeriod = YearPeriod::current();
|
||||
|
||||
$vacationLimit = VacationLimit::factory([
|
||||
"days" => 20,
|
||||
])
|
||||
->for($user)
|
||||
->for($currentYearPeriod)
|
||||
->create();
|
||||
|
||||
VacationRequest::factory([
|
||||
"type" => VacationType::VACATION->value,
|
||||
"state" => VacationRequestState::APPROVED,
|
||||
@ -238,7 +306,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
"comment" => "Another comment for the another vacation request.",
|
||||
])
|
||||
->assertSessionHasErrors([
|
||||
"vacationRequest" => trans("You have approved vacation request in this range."),
|
||||
"vacationRequest" => __("You have approved vacation request in this range."),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -254,7 +322,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
"comment" => "Comment for the vacation request.",
|
||||
])
|
||||
->assertSessionHasErrors([
|
||||
"vacationRequest" => trans("Vacation needs minimum one day."),
|
||||
"vacationRequest" => __("Vacation needs minimum one day."),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -271,7 +339,7 @@ class VacationRequestTest extends FeatureTestCase
|
||||
"comment" => "Comment for the vacation request.",
|
||||
])
|
||||
->assertSessionHasErrors([
|
||||
"vacationRequest" => trans("The vacation request cannot be created at the turn of the year."),
|
||||
"vacationRequest" => __("The vacation request cannot be created at the turn of the year."),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
const mix = require('laravel-mix');
|
||||
const webpackConfig = require('./webpack.config');
|
||||
const mix = require('laravel-mix')
|
||||
const webpackConfig = require('./webpack.config')
|
||||
|
||||
mix.js("resources/js/app.js", "public/js")
|
||||
.vue(3)
|
||||
.postCss("resources/css/app.css", "public/css", [
|
||||
require("tailwindcss"),
|
||||
])
|
||||
.webpackConfig(webpackConfig)
|
||||
.sourceMaps();
|
||||
mix.js('resources/js/app.js', 'public/js')
|
||||
.vue(3)
|
||||
.postCss('resources/css/app.css', 'public/css', [
|
||||
require('tailwindcss'),
|
||||
])
|
||||
.webpackConfig(webpackConfig)
|
||||
.sourceMaps()
|
||||
|
Loading…
x
Reference in New Issue
Block a user