#44 - vacation summary of all employees (#92)

* #44 - ui for summary

* #44 - vacation monthly usage

* #44 - fix

* #44 - fix

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
Adrian Hopek
2022-03-24 10:33:34 +01:00
committed by GitHub
parent dcda8c6255
commit 957b07b3eb
18 changed files with 710 additions and 1019 deletions

View File

@@ -5,9 +5,10 @@ declare(strict_types=1);
namespace Toby\Domain;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Collection;
use Toby\Domain\Enums\VacationType;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\Vacation;
use Toby\Eloquent\Models\YearPeriod;
class UserVacationStatsRetriever
@@ -30,6 +31,21 @@ class UserVacationStatsRetriever
->count();
}
public function getUsedVacationDaysByMonth(User $user, YearPeriod $yearPeriod): Collection
{
return $user->vacations()
->whereRelation(
"vacationRequest",
fn(Builder $query) => $query
->where("year_period_id", $yearPeriod->id)
->whereIn("type", $this->getLimitableVacationTypes())
->states(VacationRequestStatesRetriever::successStates()),
)
->get()
->groupBy(fn(Vacation $vacation) => strtolower($vacation->date->englishMonth))
->map(fn(Collection $items) => $items->count());
}
public function getPendingVacationDays(User $user, YearPeriod $yearPeriod): int
{
return $user