#43 - vacation summary for employee #66

Merged
Baakoma merged 19 commits from #43-vacation-summary-for-employee into main 2022-03-03 09:03:17 +01:00
2 changed files with 98 additions and 62 deletions
Showing only changes of commit 2c15cde6c8 - Show all commits

View File

@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
namespace Toby\Domain;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Toby\Domain\Enums\VacationRequestState;
use Toby\Domain\Enums\VacationType;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
class UserVacationStatsRetriever
{
public function __construct(protected VacationTypeConfigRetriever $configRetriever)
{
}
public function getUsedVacationDays(User $user, YearPeriod $yearPeriod): int
{
return $user
->vacations()
->where("year_period_id", $yearPeriod->id)
->whereRelation(
"vacationRequest",
fn(Builder $query) => $query
->whereIn("type", $this->getLimitableVacationTypes())
->states(VacationRequestState::successStates()),
)
->count();
}
public function getPendingVacationDays(User $user, YearPeriod $yearPeriod): int
{
return $user
->vacations()
->where("year_period_id", $yearPeriod->id)
->whereRelation(
"vacationRequest",
fn(Builder $query) => $query
->whereIn("type", $this->getLimitableVacationTypes())
->states(VacationRequestState::pendingStates()),
)
->count();
}
public function getOtherApprovedVacationDays(User $user, YearPeriod $yearPeriod): int
{
return $user
->vacations()
->where("year_period_id", $yearPeriod->id)
->whereRelation(
"vacationRequest",
fn(Builder $query) => $query
->whereIn("type", $this->getNotLimitableVacationTypes())
->states(VacationRequestState::successStates()),
)
->count();
}
public function getVacationDaysLimit(User $user, YearPeriod $yearPeriod): int
{
$limit = $user->vacationLimits()
->where("year_period_id", $yearPeriod->id)
->first()
->days;
return $limit ?? 0;
}
protected function getLimitableVacationTypes(): Collection
{
$types = new Collection(VacationType::cases());
return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
}
protected function getNotLimitableVacationTypes(): Collection
{
$types = new Collection(VacationType::cases());
return $types->filter(fn(VacationType $type) => !$this->configRetriever->hasLimit($type));
}
}

View File

@@ -5,34 +5,30 @@ declare(strict_types=1);
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
namespace Toby\Infrastructure\Http\Controllers;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Inertia\Response;
use Toby\Domain\Enums\VacationRequestState;
use Toby\Domain\Enums\VacationType;
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
use Toby\Domain\VacationTypeConfigRetriever;
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
use Toby\Eloquent\Helpers\YearPeriodRetriever;
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
use Toby\Domain\UserVacationStatsRetriever;
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
use Toby\Eloquent\Models\Holiday;
use Toby\Eloquent\Models\Vacation;
use Toby\Eloquent\Models\VacationRequest;
use Toby\Eloquent\Models\YearPeriod;
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
use Toby\Infrastructure\Http\Resources\AbsenceResource;
use Toby\Infrastructure\Http\Resources\HolidayResource;
use Toby\Infrastructure\Http\Resources\VacationRequestResource;
class DashboardController extends Controller
{
public function __construct(
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
protected VacationTypeConfigRetriever $configRetriever,
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
protected YearPeriodRetriever $yearPeriodRetriever,
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
) {
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
}
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
public function __invoke(Request $request): Response
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
public function __invoke(Request $request, UserVacationStatsRetriever $vacationStatsRetriever): Response
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
{
$user = $request->user();
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$now = Carbon::now();
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$yearPeriod = YearPeriod::findByYear($now->year);
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$absences = Vacation::query()
->with(["user", "vacationRequest"])
->whereDate("date", Carbon::now())
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->whereDate("date", $now)
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->whereRelation(
"vacationRequest",
fn(Builder $query) => $query->states(VacationRequestState::successStates()),
@@ -45,46 +41,15 @@ class DashboardController extends Controller
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->get();
$holidays = Holiday::query()
->whereDate("date", ">=", Carbon::now())
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->whereDate("date", ">=", $now)
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->latest()
->limit(3)
->get();
$limit = $request->user()
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->vacationLimits()
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->where("year_period_id", $this->yearPeriodRetriever->current()->id)
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->first()
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->days ?? 0;
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$used = $request->user()
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->vacations()
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->whereRelation(
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
"vacationRequest",
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
fn(Builder $query) => $query
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->whereIn("type", $this->getLimitableVacationTypes())
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->states(VacationRequestState::successStates()),
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
)
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->count();
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$pending = $request->user()
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->vacations()
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->whereRelation(
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
"vacationRequest",
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
fn(Builder $query) => $query
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->whereIn("type", $this->getLimitableVacationTypes())
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->states(VacationRequestState::pendingStates()),
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
)
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->count();
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$other = $request->user()
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->vacations()
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->whereRelation(
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
"vacationRequest",
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
fn(Builder $query) => $query
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->whereIn("type", $this->getNotLimitableVacationTypes())
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->states(VacationRequestState::successStates()),
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
)
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
->count();
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$limit = $vacationStatsRetriever->getVacationDaysLimit($user, $yearPeriod);
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$used = $vacationStatsRetriever->getUsedVacationDays($user, $yearPeriod);
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$pending = $vacationStatsRetriever->getPendingVacationDays($user, $yearPeriod);
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$other = $vacationStatsRetriever->getOtherApprovedVacationDays($user, $yearPeriod);
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
return inertia("Dashboard", [
"absences" => AbsenceResource::collection($absences),
@@ -99,18 +64,4 @@ class DashboardController extends Controller
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
],
]);
}
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
protected function getLimitableVacationTypes(): Collection
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
{
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$types = new Collection(VacationType::cases());
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
}
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
protected function getNotLimitableVacationTypes(): Collection
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
{
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
$types = new Collection(VacationType::cases());
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
return $types->filter(fn(VacationType $type) => !$this->configRetriever->hasLimit($type));
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
}
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
}
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes:
kamilpiech97 commented 2022-03-02 09:50:37 +01:00 (Migrated from github.com)
Review

👀

:eyes: