From f05b8f460bf5880537b0e9a5821d602ce7a21919 Mon Sep 17 00:00:00 2001 From: Kamil Niemczycki Date: Thu, 7 Jul 2022 11:49:18 +0200 Subject: [PATCH] #152 - updated vacation stats --- app/Domain/UserVacationStatsRetriever.php | 9 + .../Http/Controllers/DashboardController.php | 2 + resources/js/Shared/Widgets/VacationStats.vue | 166 ++++++++++-------- 3 files changed, 108 insertions(+), 69 deletions(-) diff --git a/app/Domain/UserVacationStatsRetriever.php b/app/Domain/UserVacationStatsRetriever.php index 42fdf50..37dcae4 100644 --- a/app/Domain/UserVacationStatsRetriever.php +++ b/app/Domain/UserVacationStatsRetriever.php @@ -103,6 +103,15 @@ class UserVacationStatsRetriever return $limit ?? 0; } + public function hasVacationDaysLimit(User $user, YearPeriod $yearPeriod): bool + { + $limit = $user->vacationLimits() + ->whereBelongsTo($yearPeriod) + ->first()?->days; + + return $limit !== null; + } + protected function getLimitableVacationTypes(): Collection { $types = VacationType::all(); diff --git a/app/Infrastructure/Http/Controllers/DashboardController.php b/app/Infrastructure/Http/Controllers/DashboardController.php index 317fd22..c76e37d 100644 --- a/app/Infrastructure/Http/Controllers/DashboardController.php +++ b/app/Infrastructure/Http/Controllers/DashboardController.php @@ -74,6 +74,7 @@ class DashboardController extends Controller ->get(); $limit = $vacationStatsRetriever->getVacationDaysLimit($user, $yearPeriod); + $hasLimit = $vacationStatsRetriever->hasVacationDaysLimit($user, $yearPeriod); $used = $vacationStatsRetriever->getUsedVacationDays($user, $yearPeriod); $pending = $vacationStatsRetriever->getPendingVacationDays($user, $yearPeriod); $homeOffice = $vacationStatsRetriever->getHomeOfficeDays($user, $yearPeriod); @@ -99,6 +100,7 @@ class DashboardController extends Controller ], ), "stats" => [ + "hasLimit" => $hasLimit, "limit" => $limit, "remaining" => $remaining, "used" => $used, diff --git a/resources/js/Shared/Widgets/VacationStats.vue b/resources/js/Shared/Widgets/VacationStats.vue index ad9bff5..6f80494 100644 --- a/resources/js/Shared/Widgets/VacationStats.vue +++ b/resources/js/Shared/Widgets/VacationStats.vue @@ -1,73 +1,101 @@