* wip * wip * wip * wip * wip * wip * wip * #5 - bump dependencies * #43 - wip * #43 - add composer script * #43 - fix * #43 - fix * #43 - wip * #43 - ecs fix * #43 - cr fix * #43 - cr fix * #43 - fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
@@ -6,24 +6,41 @@ 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
|
||||
{
|
||||
$this->authorize("manageVacationLimits");
|
||||
|
||||
$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