#43 - wip
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers\Api;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Toby\Domain\UserVacationStatsRetriever;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Infrastructure\Http\Controllers\Controller;
|
||||
use Toby\Infrastructure\Http\Requests\Api\CalculateVacationStatsRequest;
|
||||
|
||||
class CalculateUserVacationStatsController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
CalculateVacationStatsRequest $request,
|
||||
UserVacationStatsRetriever $vacationStatsRetriever,
|
||||
YearPeriodRetriever $yearPeriodRetriever,
|
||||
): JsonResponse {
|
||||
/** @var User $user */
|
||||
$user = User::query()->find($request->get("user"));
|
||||
$yearPeriod = $yearPeriodRetriever->selected();
|
||||
|
||||
$limit = $vacationStatsRetriever->getVacationDaysLimit($user, $yearPeriod);
|
||||
$used = $vacationStatsRetriever->getUsedVacationDays($user, $yearPeriod);
|
||||
$pending = $vacationStatsRetriever->getPendingVacationDays($user, $yearPeriod);
|
||||
$other = $vacationStatsRetriever->getOtherApprovedVacationDays($user, $yearPeriod);
|
||||
|
||||
return new JsonResponse([
|
||||
"limit" => $limit,
|
||||
"remaining" => $limit - $used - $pending,
|
||||
"used" => $used,
|
||||
"pending" => $pending,
|
||||
"other" => $other,
|
||||
]);
|
||||
}
|
||||
}
|
@@ -6,6 +6,7 @@ namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Response;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
use Toby\Infrastructure\Http\Requests\HolidayRequest;
|
||||
use Toby\Infrastructure\Http\Resources\HolidayFormDataResource;
|
||||
@@ -13,9 +14,12 @@ use Toby\Infrastructure\Http\Resources\HolidayResource;
|
||||
|
||||
class HolidayController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
public function index(YearPeriodRetriever $yearPeriodRetriever): Response
|
||||
{
|
||||
$holidays = Holiday::query()
|
||||
$yearPeriod = $yearPeriodRetriever->selected();
|
||||
|
||||
$holidays = $yearPeriod
|
||||
->holidays()
|
||||
->orderBy("date")
|
||||
->get();
|
||||
|
||||
|
@@ -6,22 +6,39 @@ namespace Toby\Infrastructure\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\UserVacationStatsRetriever;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\VacationLimit;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
use Toby\Infrastructure\Http\Requests\VacationLimitRequest;
|
||||
use Toby\Infrastructure\Http\Resources\VacationLimitResource;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
|
||||
class VacationLimitController extends Controller
|
||||
{
|
||||
public function edit(): Response
|
||||
public function edit(YearPeriodRetriever $yearPeriodRetriever, UserVacationStatsRetriever $statsRetriever): Response
|
||||
{
|
||||
$limits = VacationLimit::query()
|
||||
$yearPeriod = $yearPeriodRetriever->selected();
|
||||
$previousYearPeriod = YearPeriod::findByYear($yearPeriod->year - 1);
|
||||
|
||||
$limits = $yearPeriod
|
||||
->vacationLimits()
|
||||
->with("user")
|
||||
->orderByUserField("last_name")
|
||||
->orderByUserField("first_name")
|
||||
->get();
|
||||
|
||||
$limitsResource = $limits->map(fn(VacationLimit $limit) => [
|
||||
"id" => $limit->id,
|
||||
"user" => new UserResource($limit->user),
|
||||
"hasVacation" => $limit->hasVacation(),
|
||||
"days" => $limit->days,
|
||||
"remainingLastYear" => $previousYearPeriod
|
||||
? $statsRetriever->getRemainingVacationDays($limit->user, $previousYearPeriod)
|
||||
: 0,
|
||||
]);
|
||||
|
||||
return inertia("VacationLimits", [
|
||||
"limits" => VacationLimitResource::collection($limits),
|
||||
"limits" => $limitsResource,
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user