#71 - annual summary #113
@@ -8,6 +8,7 @@ use Illuminate\Bus\Queueable;
|
|||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
use Illuminate\Notifications\Notification;
|
use Illuminate\Notifications\Notification;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use Toby\Domain\States\VacationRequest\WaitingForTechnical;
|
||||||
use Toby\Eloquent\Models\User;
|
use Toby\Eloquent\Models\User;
|
||||||
use Toby\Eloquent\Models\VacationRequest;
|
use Toby\Eloquent\Models\VacationRequest;
|
||||||
|
|
||||||
@@ -43,8 +44,6 @@ class VacationRequestWaitsForApprovalNotification extends Notification
|
|||||||
protected function buildMailMessage(string $url): MailMessage
|
protected function buildMailMessage(string $url): MailMessage
|
||||||
{
|
{
|
||||||
$user = $this->user->first_name;
|
$user = $this->user->first_name;
|
||||||
$requester = $this->vacationRequest->user->fullName;
|
|
||||||
$title = $this->vacationRequest->name;
|
|
||||||
$type = $this->vacationRequest->type->label();
|
$type = $this->vacationRequest->type->label();
|
||||||
$from = $this->vacationRequest->from->toDisplayString();
|
$from = $this->vacationRequest->from->toDisplayString();
|
||||||
$to = $this->vacationRequest->to->toDisplayString();
|
$to = $this->vacationRequest->to->toDisplayString();
|
||||||
@@ -54,13 +53,8 @@ class VacationRequestWaitsForApprovalNotification extends Notification
|
|||||||
->greeting(__("Hi :user!", [
|
->greeting(__("Hi :user!", [
|
||||||
"user" => $user,
|
"user" => $user,
|
||||||
]))
|
]))
|
||||||
->subject(__("Vacation request :title is waiting for your approval", [
|
->subject($this->buildSubject())
|
||||||
"title" => $title,
|
->line($this->buildDescription())
|
||||||
]))
|
|
||||||
->line(__("The vacation request :title from user: :requester is waiting for your approval.", [
|
|
||||||
"title" => $title,
|
|
||||||
"requester" => $requester,
|
|
||||||
]))
|
|
||||||
->line(__("Vacation type: :type", [
|
->line(__("Vacation type: :type", [
|
||||||
"type" => $type,
|
"type" => $type,
|
||||||
]))
|
]))
|
||||||
@@ -71,4 +65,37 @@ class VacationRequestWaitsForApprovalNotification extends Notification
|
|||||||
]))
|
]))
|
||||||
->action(__("Click here for details"), $url);
|
->action(__("Click here for details"), $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function buildSubject(): string
|
||||||
|
{
|
||||||
|
$title = $this->vacationRequest->name;
|
||||||
|
|
||||||
|
if ($this->vacationRequest->state->equals(WaitingForTechnical::class)) {
|
||||||
|
return __("Vacation request :title is waiting for your technical approval", [
|
||||||
|
"title" => $title,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return __("Vacation request :title is waiting for your administrative approval", [
|
||||||
|
"title" => $title,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildDescription(): string
|
||||||
|
{
|
||||||
|
$title = $this->vacationRequest->name;
|
||||||
|
$requester = $this->vacationRequest->user->name;
|
||||||
|
|
||||||
|
if ($this->vacationRequest->state->equals(WaitingForTechnical::class)) {
|
||||||
|
return __("The vacation request :title from user: :requester is waiting for your technical approval.", [
|
||||||
|
"title" => $title,
|
||||||
|
"requester" => $requester,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return __("The vacation request :title from user: :requester is waiting for your administrative approval.", [
|
||||||
|
"title" => $title,
|
||||||
|
"requester" => $requester,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With
|
|||||||
{
|
{
|
||||||
return $user->vacations()
|
return $user->vacations()
|
||||||
->with("vacationRequest")
|
->with("vacationRequest")
|
||||||
->whereRelation("vacationRequest", fn(Builder $query) => $query->whereIn("type", $this->types))
|
->whereRelation("vacationRequest", fn(Builder $query): Builder => $query->whereIn("type", $this->types))
|
||||||
->whereBetween("date", [$period->start, $period->end])
|
->whereBetween("date", [$period->start, $period->end])
|
||||||
->approved()
|
->approved()
|
||||||
->get()
|
->get()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class UserVacationStatsRetriever
|
|||||||
->whereBelongsTo($yearPeriod)
|
->whereBelongsTo($yearPeriod)
|
||||||
->whereRelation(
|
->whereRelation(
|
||||||
"vacationRequest",
|
"vacationRequest",
|
||||||
fn(Builder $query) => $query
|
fn(Builder $query): Builder => $query
|
||||||
->whereIn("type", $this->getLimitableVacationTypes())
|
->whereIn("type", $this->getLimitableVacationTypes())
|
||||||
->states(VacationRequestStatesRetriever::successStates()),
|
->states(VacationRequestStatesRetriever::successStates()),
|
||||||
)
|
)
|
||||||
@@ -36,7 +36,7 @@ class UserVacationStatsRetriever
|
|||||||
return $user->vacations()
|
return $user->vacations()
|
||||||
->whereRelation(
|
->whereRelation(
|
||||||
"vacationRequest",
|
"vacationRequest",
|
||||||
fn(Builder $query) => $query
|
fn(Builder $query): Builder => $query
|
||||||
->whereBelongsTo($yearPeriod)
|
->whereBelongsTo($yearPeriod)
|
||||||
->whereIn("type", $this->getLimitableVacationTypes())
|
->whereIn("type", $this->getLimitableVacationTypes())
|
||||||
->states(VacationRequestStatesRetriever::successStates()),
|
->states(VacationRequestStatesRetriever::successStates()),
|
||||||
@@ -53,7 +53,7 @@ class UserVacationStatsRetriever
|
|||||||
->whereBelongsTo($yearPeriod)
|
->whereBelongsTo($yearPeriod)
|
||||||
->whereRelation(
|
->whereRelation(
|
||||||
"vacationRequest",
|
"vacationRequest",
|
||||||
fn(Builder $query) => $query
|
fn(Builder $query): Builder => $query
|
||||||
->whereIn("type", $this->getLimitableVacationTypes())
|
->whereIn("type", $this->getLimitableVacationTypes())
|
||||||
->states(VacationRequestStatesRetriever::pendingStates()),
|
->states(VacationRequestStatesRetriever::pendingStates()),
|
||||||
)
|
)
|
||||||
@@ -67,7 +67,7 @@ class UserVacationStatsRetriever
|
|||||||
->whereBelongsTo($yearPeriod)
|
->whereBelongsTo($yearPeriod)
|
||||||
->whereRelation(
|
->whereRelation(
|
||||||
"vacationRequest",
|
"vacationRequest",
|
||||||
fn(Builder $query) => $query
|
fn(Builder $query): Builder => $query
|
||||||
->whereIn("type", $this->getNotLimitableVacationTypes())
|
->whereIn("type", $this->getNotLimitableVacationTypes())
|
||||||
->states(VacationRequestStatesRetriever::successStates()),
|
->states(VacationRequestStatesRetriever::successStates()),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class DoesNotExceedLimitRule implements VacationRequestRule
|
|||||||
return $user->vacationLimits()
|
return $user->vacationLimits()
|
||||||
->whereBelongsTo($yearPeriod)
|
->whereBelongsTo($yearPeriod)
|
||||||
->first()
|
->first()
|
||||||
->days ?? 0;
|
?->days ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getVacationDaysWithLimit(User $user, YearPeriod $yearPeriod): int
|
protected function getVacationDaysWithLimit(User $user, YearPeriod $yearPeriod): int
|
||||||
@@ -53,7 +53,7 @@ class DoesNotExceedLimitRule implements VacationRequestRule
|
|||||||
->whereBelongsTo($yearPeriod)
|
->whereBelongsTo($yearPeriod)
|
||||||
->whereRelation(
|
->whereRelation(
|
||||||
"vacationRequest",
|
"vacationRequest",
|
||||||
fn(Builder $query) => $query
|
fn(Builder $query): Builder => $query
|
||||||
->whereIn("type", $this->getLimitableVacationTypes())
|
->whereIn("type", $this->getLimitableVacationTypes())
|
||||||
->noStates(VacationRequestStatesRetriever::failedStates()),
|
->noStates(VacationRequestStatesRetriever::failedStates()),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class User extends Authenticatable
|
|||||||
{
|
{
|
||||||
return $query->whereRelation(
|
return $query->whereRelation(
|
||||||
"vacationlimits",
|
"vacationlimits",
|
||||||
fn(Builder $query) => $query
|
fn(Builder $query): Builder => $query
|
||||||
->whereBelongsTo($yearPeriod)
|
->whereBelongsTo($yearPeriod)
|
||||||
->whereNotNull("days"),
|
->whereNotNull("days"),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class Vacation extends Model
|
|||||||
{
|
{
|
||||||
return $query->whereRelation(
|
return $query->whereRelation(
|
||||||
"vacationRequest",
|
"vacationRequest",
|
||||||
|
|
|||||||
fn(Builder $query) => $query->states(VacationRequestStatesRetriever::successStates()),
|
fn(Builder $query): Builder => $query->states(VacationRequestStatesRetriever::successStates()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ class Vacation extends Model
|
|||||||
{
|
{
|
||||||
return $query->whereRelation(
|
return $query->whereRelation(
|
||||||
"vacationRequest",
|
"vacationRequest",
|
||||||
fn(Builder $query) => $query->states(VacationRequestStatesRetriever::pendingStates()),
|
fn(Builder $query): Builder => $query->states(VacationRequestStatesRetriever::pendingStates()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,19 @@ class AnnualSummaryController extends Controller
|
|||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
return inertia("AnnualSummary", [
|
return inertia("AnnualSummary", [
|
||||||
"holidays" => $holidays->mapWithKeys(fn(Holiday $holiday) => [$holiday->date->toDateString() => $holiday->name]),
|
"holidays" => $holidays->mapWithKeys(
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
"vacations" => $vacations->mapWithKeys(fn(Vacation $vacation) => [$vacation->date->toDateString() => new SimpleVacationRequestResource($vacation->vacationRequest)]),
|
fn(Holiday $holiday): array => [$holiday->date->toDateString() => $holiday->name],
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
"pendingVacations" => $pendingVacations->mapWithKeys(fn(Vacation $vacation) => [$vacation->date->toDateString() => new SimpleVacationRequestResource($vacation->vacationRequest)]),
|
),
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
"vacations" => $vacations->mapWithKeys(
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
fn(Vacation $vacation): array => [
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
$vacation->date->toDateString() => new SimpleVacationRequestResource($vacation->vacationRequest),
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
],
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
),
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
"pendingVacations" => $pendingVacations->mapWithKeys(
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
fn(Vacation $vacation): array => [
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
$vacation->date->toDateString() => new SimpleVacationRequestResource($vacation->vacationRequest),
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
],
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
|
),
|
||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
Could you add return types for arrow functions? Could you add return types for arrow functions?
Could you add return types for arrow functions? Could you add return types for arrow functions?
|
|||||||
@@ -30,13 +30,13 @@ class CalculateUserUnavailableDaysController extends Controller
|
|||||||
->whereBelongsTo($yearPeriod)
|
->whereBelongsTo($yearPeriod)
|
||||||
->whereRelation(
|
->whereRelation(
|
||||||
"vacationRequest",
|
"vacationRequest",
|
||||||
fn(Builder $query) => $query->noStates(VacationRequestStatesRetriever::failedStates()),
|
fn(Builder $query): Builder => $query->noStates(VacationRequestStatesRetriever::failedStates()),
|
||||||
)
|
)
|
||||||
->pluck("date");
|
->pluck("date");
|
||||||
|
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
...$holidays->map(fn(Carbon $date) => $date->toDateString()),
|
...$holidays->map(fn(Carbon $date): string => $date->toDateString()),
|
||||||
...$vacationDays->map(fn(Carbon $date) => $date->toDateString()),
|
...$vacationDays->map(fn(Carbon $date): string => $date->toDateString()),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ class VacationRequestController extends Controller
|
|||||||
$vacationRequests = VacationRequest::query()
|
$vacationRequests = VacationRequest::query()
|
||||||
->with(["user", "vacations"])
|
->with(["user", "vacations"])
|
||||||
->whereBelongsTo($yearPeriod)
|
->whereBelongsTo($yearPeriod)
|
||||||
->when($user !== null, fn(Builder $query) => $query->where("user_id", $user))
|
->when($user !== null, fn(Builder $query): Builder => $query->where("user_id", $user))
|
||||||
->when(
|
->when(
|
||||||
$status !== null,
|
$status !== null,
|
||||||
fn(Builder $query) => $query->states(
|
fn(Builder $query): Builder => $query->states(
|
||||||
VacationRequestStatesRetriever::filterByStatusGroup($status, $request->user()),
|
VacationRequestStatesRetriever::filterByStatusGroup($status, $request->user()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
Could you add return type of arrow function?