This commit is contained in:
Adrian Hopek
2022-04-20 10:48:09 +02:00
parent 889af3aaa2
commit a149f05b9b
4 changed files with 29 additions and 2 deletions

View File

@@ -34,10 +34,10 @@ class UserVacationStatsRetriever
public function getUsedVacationDaysByMonth(User $user, YearPeriod $yearPeriod): Collection
{
return $user->vacations()
->whereBelongsTo($yearPeriod)
->whereRelation(
"vacationRequest",
fn(Builder $query): Builder => $query
->whereBelongsTo($yearPeriod)
->whereIn("type", $this->getLimitableVacationTypes())
->states(VacationRequestStatesRetriever::successStates()),
)
@@ -69,11 +69,21 @@ class UserVacationStatsRetriever
"vacationRequest",
fn(Builder $query): Builder => $query
->whereIn("type", $this->getNotLimitableVacationTypes())
->whereNot("type", VacationType::HomeOffice)
->states(VacationRequestStatesRetriever::successStates()),
)
->count();
}
public function getHomeOfficeDays(User $user, YearPeriod $yearPeriod): int
{
return $user
->vacations()
->whereBelongsTo($yearPeriod)
->whereRelation("vacationRequest", "type", VacationType::HomeOffice)
->count();
}
public function getRemainingVacationDays(User $user, YearPeriod $yearPeriod): int
{
$limit = $this->getVacationDaysLimit($user, $yearPeriod);
@@ -106,4 +116,5 @@ class UserVacationStatsRetriever
return $types->filter(fn(VacationType $type) => !$this->configRetriever->hasLimit($type));
}
}