diff --git a/app/Domain/MonthWorkingHoursCalculator.php b/app/Domain/MonthWorkingHoursCalculator.php new file mode 100644 index 00000000..575e0487 --- /dev/null +++ b/app/Domain/MonthWorkingHoursCalculator.php @@ -0,0 +1,25 @@ +filter( + fn(array $day): bool => !$day["isWeekend"] + && !$day["isHoliday"] + && (( + isset($day["vacations"][$user->id]) + && in_array($day["vacations"][$user->id]["type"]->value, [VacationType::RemoteWork->value, VacationType::Delegation->value], true) + ) || !isset($day["vacations"][$user->id])), + ) + ->count(); + } +} diff --git a/app/Http/Controllers/VacationCalendarController.php b/app/Http/Controllers/VacationCalendarController.php index add605fc..67f404b8 100644 --- a/app/Http/Controllers/VacationCalendarController.php +++ b/app/Http/Controllers/VacationCalendarController.php @@ -9,6 +9,7 @@ use Illuminate\Support\Carbon; use Inertia\Response; use Toby\Domain\CalendarGenerator; +use Toby\Domain\MonthWorkingHoursCalculator; use Toby\Enums\Month; use Toby\Helpers\YearPeriodRetriever; use Toby\Http\Resources\SimpleUserResource; @@ -21,6 +22,7 @@ public function index( Request $request, YearPeriodRetriever $yearPeriodRetriever, CalendarGenerator $calendarGenerator, + MonthWorkingHoursCalculator $monthWorkingHoursCalculator, ?string $month = null, ?int $year = null, ): Response|RedirectResponse { @@ -29,6 +31,7 @@ public function index( } $month = Month::fromNameOrCurrent((string)$month); + /** @var User $currentUser */ $currentUser = $request->user(); $withTrashedUsers = $currentUser->canSeeInactiveUsers(); @@ -53,9 +56,13 @@ public function index( $users->prepend($currentUser); $calendar = $calendarGenerator->generate($carbonMonth); + $workingHours = $currentUser->isEmployedOnEmploymentForm() + ? $monthWorkingHoursCalculator->calculateHours($calendar, $currentUser) * config("toby.number_of_hours_on_employment_contract.full_time") + : null; return inertia("Calendar", [ "calendar" => $calendar, + "workingHours" => $workingHours, "currentMonth" => Month::current(), "currentYear" => Carbon::now()->year, "selectedMonth" => $month->value, diff --git a/app/Models/User.php b/app/Models/User.php index 9bf6b9b9..d4b5f565 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -17,6 +17,7 @@ use Illuminate\Support\Facades\DB; use Laravel\Sanctum\HasApiTokens; use Spatie\Permission\Traits\HasRoles; +use Toby\Enums\EmploymentForm; use Toby\Enums\Role; use Toby\Enums\UserHistoryType; use Toby\Notifications\Notifiable as NotifiableInterface; @@ -257,6 +258,11 @@ public function isWorkAnniversaryToday(): bool return $workAnniversary?->isToday() ?? false; } + public function isEmployedOnEmploymentForm(EmploymentForm $employmentForm = EmploymentForm::EmploymentContract): bool + { + return $this->profile->employment_form === $employmentForm; + } + protected static function newFactory(): UserFactory { return UserFactory::new(); diff --git a/config/toby.php b/config/toby.php new file mode 100644 index 00000000..41b97673 --- /dev/null +++ b/config/toby.php @@ -0,0 +1,9 @@ + [ + "full_time" => 8, + ], +]; diff --git a/resources/js/Pages/Calendar.vue b/resources/js/Pages/Calendar.vue index d8385b7b..ec8f7ab2 100644 --- a/resources/js/Pages/Calendar.vue +++ b/resources/js/Pages/Calendar.vue @@ -1,5 +1,12 @@