Merge branch 'main' into #134-fill-users-data-for-resume
# Conflicts: # .eslintrc.js # composer.lock # package-lock.json # package.json
This commit is contained in:
@@ -6,10 +6,10 @@ namespace Toby\Domain\Actions\VacationRequest;
|
||||
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Toby\Domain\Notifications\VacationRequestCreatedNotification;
|
||||
use Toby\Domain\VacationDaysCalculator;
|
||||
use Toby\Domain\VacationRequestStateManager;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
use Toby\Domain\Validation\VacationRequestValidator;
|
||||
use Toby\Domain\WorkDaysCalculator;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
|
||||
@@ -19,7 +19,7 @@ class CreateAction
|
||||
protected VacationRequestStateManager $stateManager,
|
||||
protected VacationRequestValidator $vacationRequestValidator,
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
protected VacationDaysCalculator $vacationDaysCalculator,
|
||||
protected WorkDaysCalculator $workDaysCalculator,
|
||||
protected WaitForTechApprovalAction $waitForTechApprovalAction,
|
||||
protected WaitForAdminApprovalAction $waitForAdminApprovalAction,
|
||||
protected ApproveAction $approveAction,
|
||||
@@ -52,11 +52,7 @@ class CreateAction
|
||||
|
||||
$vacationRequest->save();
|
||||
|
||||
$days = $this->vacationDaysCalculator->calculateDays(
|
||||
$vacationRequest->yearPeriod,
|
||||
$vacationRequest->from,
|
||||
$vacationRequest->to,
|
||||
);
|
||||
$days = $this->workDaysCalculator->calculateDays($vacationRequest->from, $vacationRequest->to);
|
||||
|
||||
foreach ($days as $day) {
|
||||
$vacationRequest->vacations()->create([
|
||||
|
@@ -57,6 +57,6 @@ class CalendarGenerator
|
||||
->approved()
|
||||
->with("vacationRequest")
|
||||
->get()
|
||||
->groupBy(fn(Vacation $vacation) => $vacation->date->toDateString());
|
||||
->groupBy(fn(Vacation $vacation): string => $vacation->date->toDateString());
|
||||
}
|
||||
}
|
||||
|
49
app/Domain/DailySummaryRetriever.php
Normal file
49
app/Domain/DailySummaryRetriever.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
|
||||
class DailySummaryRetriever
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
) {}
|
||||
|
||||
public function getAbsences(Carbon $date): Collection
|
||||
{
|
||||
return Vacation::query()
|
||||
->with(["user", "vacationRequest"])
|
||||
->whereDate("date", $date)
|
||||
->approved()
|
||||
->whereTypes(
|
||||
VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)),
|
||||
)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getRemoteDays(Carbon $date): Collection
|
||||
{
|
||||
return Vacation::query()
|
||||
->with(["user", "vacationRequest"])
|
||||
->whereDate("date", $date)
|
||||
->approved()
|
||||
->whereTypes(
|
||||
VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)),
|
||||
)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getBirthdays(Carbon $date): Collection
|
||||
{
|
||||
return User::query()
|
||||
->whereRelation("profile", "birthday", $date)
|
||||
->get();
|
||||
}
|
||||
}
|
@@ -21,7 +21,7 @@ enum EmploymentForm: string
|
||||
$cases = collect(EmploymentForm::cases());
|
||||
|
||||
return $cases->map(
|
||||
fn(EmploymentForm $enum) => [
|
||||
fn(EmploymentForm $enum): array => [
|
||||
"label" => $enum->label(),
|
||||
"value" => $enum->value,
|
||||
],
|
||||
|
@@ -21,7 +21,7 @@ enum Role: string
|
||||
$cases = collect(Role::cases());
|
||||
|
||||
return $cases->map(
|
||||
fn(Role $enum) => [
|
||||
fn(Role $enum): array => [
|
||||
"label" => $enum->label(),
|
||||
"value" => $enum->value,
|
||||
],
|
||||
|
@@ -30,7 +30,7 @@ enum VacationType: string
|
||||
$cases = VacationType::all();
|
||||
|
||||
return $cases->map(
|
||||
fn(VacationType $enum) => [
|
||||
fn(VacationType $enum): array => [
|
||||
"label" => $enum->label(),
|
||||
"value" => $enum->value,
|
||||
],
|
||||
|
11
app/Domain/Notifications/Channels.php
Normal file
11
app/Domain/Notifications/Channels.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
class Channels
|
||||
{
|
||||
public const MAIL = "mail";
|
||||
public const SLACK = "slack";
|
||||
}
|
44
app/Domain/Notifications/KeyHasBeenGivenNotification.php
Normal file
44
app/Domain/Notifications/KeyHasBeenGivenNotification.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Infrastructure\Slack\Elements\SlackMessage;
|
||||
|
||||
class KeyHasBeenGivenNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
protected User $sender,
|
||||
protected User $recipient,
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return [Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(Notifiable $notifiable): SlackMessage
|
||||
{
|
||||
return (new SlackMessage())
|
||||
->text(__(":sender gives key no :key to :recipient", [
|
||||
"sender" => $this->getName($this->sender),
|
||||
"recipient" => $this->getName($this->recipient),
|
||||
"key" => $notifiable->id,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function getName(User $user): string
|
||||
{
|
||||
if ($user->profile->slack_id !== null) {
|
||||
return "<@{$user->profile->slack_id}>";
|
||||
}
|
||||
|
||||
return $user->profile->full_name;
|
||||
}
|
||||
}
|
44
app/Domain/Notifications/KeyHasBeenTakenNotification.php
Normal file
44
app/Domain/Notifications/KeyHasBeenTakenNotification.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Infrastructure\Slack\Elements\SlackMessage;
|
||||
|
||||
class KeyHasBeenTakenNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
protected User $recipient,
|
||||
protected User $sender,
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return [Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(Notifiable $notifiable): SlackMessage
|
||||
{
|
||||
return (new SlackMessage())
|
||||
->text(__(":recipient takes key no :key from :sender", [
|
||||
"recipient" => $this->getName($this->recipient),
|
||||
"sender" => $this->getName($this->sender),
|
||||
"key" => $notifiable->id,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function getName(User $user): string
|
||||
{
|
||||
if ($user->profile->slack_id !== null) {
|
||||
return "<@{$user->profile->slack_id}>";
|
||||
}
|
||||
|
||||
return $user->profile->full_name;
|
||||
}
|
||||
}
|
10
app/Domain/Notifications/Notifiable.php
Normal file
10
app/Domain/Notifications/Notifiable.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
interface Notifiable
|
||||
{
|
||||
public function notify($instance);
|
||||
}
|
@@ -9,6 +9,7 @@ use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use InvalidArgumentException;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Infrastructure\Slack\Elements\SlackMessage;
|
||||
|
||||
class VacationRequestCreatedNotification extends Notification
|
||||
{
|
||||
@@ -20,7 +21,15 @@ class VacationRequestCreatedNotification extends Notification
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return ["mail"];
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): SlackMessage
|
||||
{
|
||||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
|
||||
|
||||
return (new SlackMessage())
|
||||
->text("{$this->buildDescription()}\n <${url}|Zobacz szczegóły>");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,19 +55,25 @@ class VacationRequestCreatedNotification extends Notification
|
||||
$days = $this->vacationRequest->vacations()->count();
|
||||
|
||||
return (new MailMessage())
|
||||
->greeting(__("Hi :user!", [
|
||||
"user" => $user,
|
||||
]))
|
||||
->greeting(
|
||||
__("Hi :user!", [
|
||||
"user" => $user,
|
||||
]),
|
||||
)
|
||||
->subject($this->buildSubject())
|
||||
->line($this->buildDescription())
|
||||
->line(__("Vacation type: :type", [
|
||||
"type" => $type,
|
||||
]))
|
||||
->line(__("From :from to :to (number of days: :days)", [
|
||||
"from" => $from,
|
||||
"to" => $to,
|
||||
"days" => $days,
|
||||
]))
|
||||
->line(
|
||||
__("Vacation type: :type", [
|
||||
"type" => $type,
|
||||
]),
|
||||
)
|
||||
->line(
|
||||
__("From :from to :to (number of days: :days)", [
|
||||
"from" => $from,
|
||||
"to" => $to,
|
||||
"days" => $days,
|
||||
]),
|
||||
)
|
||||
->action(__("Click here for details"), $url);
|
||||
}
|
||||
|
||||
@@ -80,18 +95,16 @@ class VacationRequestCreatedNotification extends Notification
|
||||
protected function buildDescription(): string
|
||||
{
|
||||
$name = $this->vacationRequest->name;
|
||||
$appName = config("app.name");
|
||||
|
||||
if ($this->vacationRequest->creator()->is($this->vacationRequest->user)) {
|
||||
return __("The vacation request :title has been created correctly in the :appName.", [
|
||||
return __("The vacation request :title from user :user has been created successfully.", [
|
||||
"user" => $this->vacationRequest->user->profile->full_name,
|
||||
"title" => $name,
|
||||
"appName" => $appName,
|
||||
]);
|
||||
}
|
||||
|
||||
return __("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [
|
||||
return __("The vacation request :title has been created successfully by user :creator on your behalf.", [
|
||||
"title" => $this->vacationRequest->name,
|
||||
"appName" => $appName,
|
||||
"creator" => $this->vacationRequest->creator->profile->full_name,
|
||||
]);
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ use Illuminate\Notifications\Notification;
|
||||
use InvalidArgumentException;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Infrastructure\Slack\Elements\SlackMessage;
|
||||
|
||||
class VacationRequestStatusChangedNotification extends Notification
|
||||
{
|
||||
@@ -22,7 +23,15 @@ class VacationRequestStatusChangedNotification extends Notification
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return ["mail"];
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): SlackMessage
|
||||
{
|
||||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
|
||||
|
||||
return (new SlackMessage())
|
||||
->text("{$this->buildDescription()}\n <${url}|Zobacz szczegóły>");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,27 +52,17 @@ class VacationRequestStatusChangedNotification extends Notification
|
||||
protected function buildMailMessage(string $url): MailMessage
|
||||
{
|
||||
$user = $this->user->profile->first_name;
|
||||
$title = $this->vacationRequest->name;
|
||||
$type = $this->vacationRequest->type->label();
|
||||
$status = $this->vacationRequest->state->label();
|
||||
$from = $this->vacationRequest->from->toDisplayString();
|
||||
$to = $this->vacationRequest->to->toDisplayString();
|
||||
$days = $this->vacationRequest->vacations()->count();
|
||||
$requester = $this->vacationRequest->user->profile->full_name;
|
||||
|
||||
return (new MailMessage())
|
||||
->greeting(__("Hi :user!", [
|
||||
"user" => $user,
|
||||
]))
|
||||
->subject(__("Vacation request :title has been :status", [
|
||||
"title" => $title,
|
||||
"status" => $status,
|
||||
]))
|
||||
->line(__("The vacation request :title from user :requester has been :status.", [
|
||||
"title" => $title,
|
||||
"requester" => $requester,
|
||||
"status" => $status,
|
||||
]))
|
||||
->subject($this->buildSubject())
|
||||
->line($this->buildDescription())
|
||||
->line(__("Vacation type: :type", [
|
||||
"type" => $type,
|
||||
]))
|
||||
@@ -74,4 +73,21 @@ class VacationRequestStatusChangedNotification extends Notification
|
||||
]))
|
||||
->action(__("Click here for details"), $url);
|
||||
}
|
||||
|
||||
protected function buildSubject(): string
|
||||
{
|
||||
return __("Vacation request :title has been :status", [
|
||||
"title" => $this->vacationRequest->name,
|
||||
"status" => $this->vacationRequest->state->label(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function buildDescription(): string
|
||||
{
|
||||
return __("The vacation request :title from user :requester has been :status.", [
|
||||
"title" => $this->vacationRequest->name,
|
||||
"requester" => $this->vacationRequest->user->profile->full_name,
|
||||
"status" => $this->vacationRequest->state->label(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ use InvalidArgumentException;
|
||||
use Toby\Domain\States\VacationRequest\WaitingForTechnical;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Infrastructure\Slack\Elements\SlackMessage;
|
||||
|
||||
class VacationRequestWaitsForApprovalNotification extends Notification
|
||||
{
|
||||
@@ -23,7 +24,15 @@ class VacationRequestWaitsForApprovalNotification extends Notification
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return ["mail"];
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): SlackMessage
|
||||
{
|
||||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
|
||||
|
||||
return (new SlackMessage())
|
||||
->text("{$this->buildDescription()}\n <${url}|Zobacz szczegóły>");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Infrastructure\Slack\Elements\SlackMessage;
|
||||
use Toby\Infrastructure\Slack\Elements\VacationRequestsAttachment;
|
||||
|
||||
class VacationRequestsSummaryNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
protected Carbon $day,
|
||||
protected Collection $vacationRequests,
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): SlackMessage
|
||||
{
|
||||
return (new SlackMessage())
|
||||
->text("Wnioski oczekujące na Twoją akcję - stan na dzień {$this->day->toDisplayString()}:")
|
||||
->withAttachment(new VacationRequestsAttachment($this->vacationRequests));
|
||||
}
|
||||
|
||||
public function toMail(Notifiable $notifiable): MailMessage
|
||||
{
|
||||
$url = route(
|
||||
"vacation.requests.indexForApprovers",
|
||||
[
|
||||
"status" => "waiting_for_action",
|
||||
],
|
||||
);
|
||||
|
||||
return $this->buildMailMessage($notifiable, $url);
|
||||
}
|
||||
|
||||
protected function buildMailMessage(Notifiable $notifiable, string $url): MailMessage
|
||||
{
|
||||
$user = $notifiable->profile->first_name;
|
||||
|
||||
$message = (new MailMessage())
|
||||
->greeting(
|
||||
__("Hi :user!", [
|
||||
"user" => $user,
|
||||
]),
|
||||
)
|
||||
->line("Lista wniosków oczekujących na Twoją akcję - stan na dzień {$this->day->toDisplayString()}:")
|
||||
->subject("Wnioski oczekujące na akcje - stan na dzień {$this->day->toDisplayString()}");
|
||||
|
||||
foreach ($this->vacationRequests as $request) {
|
||||
$message->line(
|
||||
"Wniosek nr {$request->name} użytkownika {$request->user->profile->full_name} ({$request->from->toDisplayString()} - {$request->to->toDisplayString()})",
|
||||
);
|
||||
}
|
||||
|
||||
return $message
|
||||
->action("Przejdź do wniosków", $url);
|
||||
}
|
||||
}
|
@@ -26,7 +26,7 @@ class PolishHolidaysRetriever
|
||||
|
||||
protected function prepareHolidays(array $holidays): Collection
|
||||
{
|
||||
return collect($holidays)->map(fn(Holiday $holiday) => [
|
||||
return collect($holidays)->map(fn(Holiday $holiday): array => [
|
||||
"name" => $holiday->getName([static::LANG_KEY]),
|
||||
"date" => Carbon::createFromTimestamp($holiday->getTimestamp()),
|
||||
])->values();
|
||||
|
@@ -18,7 +18,7 @@ class TimesheetExport implements WithMultipleSheets
|
||||
public function sheets(): array
|
||||
{
|
||||
return $this->users
|
||||
->map(fn(User $user) => new TimesheetPerUserSheet($user, $this->month, $this->types))
|
||||
->map(fn(User $user): TimesheetPerUserSheet => new TimesheetPerUserSheet($user, $this->month, $this->types))
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@@ -193,8 +193,8 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With
|
||||
->get()
|
||||
->groupBy(
|
||||
[
|
||||
fn(Vacation $vacation) => $vacation->date->toDateString(),
|
||||
fn(Vacation $vacation) => $vacation->vacationRequest->type->value,
|
||||
fn(Vacation $vacation): string => $vacation->date->toDateString(),
|
||||
fn(Vacation $vacation): string => $vacation->vacationRequest->type->value,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@@ -42,8 +42,8 @@ class UserVacationStatsRetriever
|
||||
->states(VacationRequestStatesRetriever::successStates()),
|
||||
)
|
||||
->get()
|
||||
->groupBy(fn(Vacation $vacation) => strtolower($vacation->date->englishMonth))
|
||||
->map(fn(Collection $items) => $items->count());
|
||||
->groupBy(fn(Vacation $vacation): string => strtolower($vacation->date->englishMonth))
|
||||
->map(fn(Collection $items): int => $items->count());
|
||||
}
|
||||
|
||||
public function getPendingVacationDays(User $user, YearPeriod $yearPeriod): int
|
||||
@@ -107,13 +107,13 @@ class UserVacationStatsRetriever
|
||||
{
|
||||
$types = VacationType::all();
|
||||
|
||||
return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
|
||||
return $types->filter(fn(VacationType $type): bool => $this->configRetriever->hasLimit($type));
|
||||
}
|
||||
|
||||
protected function getNotLimitableVacationTypes(): Collection
|
||||
{
|
||||
$types = VacationType::all();
|
||||
|
||||
return $types->filter(fn(VacationType $type) => !$this->configRetriever->hasLimit($type));
|
||||
return $types->filter(fn(VacationType $type): bool => !$this->configRetriever->hasLimit($type));
|
||||
}
|
||||
}
|
||||
|
@@ -7,9 +7,9 @@ namespace Toby\Domain\Validation\Rules;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\VacationDaysCalculator;
|
||||
use Toby\Domain\VacationRequestStatesRetriever;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
use Toby\Domain\WorkDaysCalculator;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
@@ -18,7 +18,7 @@ class DoesNotExceedLimitRule implements VacationRequestRule
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
protected VacationDaysCalculator $vacationDaysCalculator,
|
||||
protected WorkDaysCalculator $workDaysCalculator,
|
||||
) {}
|
||||
|
||||
public function check(VacationRequest $vacationRequest): bool
|
||||
@@ -29,7 +29,9 @@ class DoesNotExceedLimitRule implements VacationRequestRule
|
||||
|
||||
$limit = $this->getUserVacationLimit($vacationRequest->user, $vacationRequest->yearPeriod);
|
||||
$vacationDays = $this->getVacationDaysWithLimit($vacationRequest->user, $vacationRequest->yearPeriod);
|
||||
$estimatedDays = $this->vacationDaysCalculator->calculateDays($vacationRequest->yearPeriod, $vacationRequest->from, $vacationRequest->to)->count();
|
||||
$estimatedDays = $this->workDaysCalculator
|
||||
->calculateDays($vacationRequest->from, $vacationRequest->to)
|
||||
->count();
|
||||
|
||||
return $limit >= ($vacationDays + $estimatedDays);
|
||||
}
|
||||
@@ -64,6 +66,6 @@ class DoesNotExceedLimitRule implements VacationRequestRule
|
||||
{
|
||||
$types = VacationType::all();
|
||||
|
||||
return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
|
||||
return $types->filter(fn(VacationType $type): bool => $this->configRetriever->hasLimit($type));
|
||||
}
|
||||
}
|
||||
|
@@ -4,19 +4,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Validation\Rules;
|
||||
|
||||
use Toby\Domain\VacationDaysCalculator;
|
||||
use Toby\Domain\WorkDaysCalculator;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
|
||||
class MinimumOneVacationDayRule implements VacationRequestRule
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationDaysCalculator $vacationDaysCalculator,
|
||||
protected WorkDaysCalculator $workDaysCalculator,
|
||||
) {}
|
||||
|
||||
public function check(VacationRequest $vacationRequest): bool
|
||||
{
|
||||
return $this->vacationDaysCalculator
|
||||
->calculateDays($vacationRequest->yearPeriod, $vacationRequest->from, $vacationRequest->to)
|
||||
return $this->workDaysCalculator
|
||||
->calculateDays($vacationRequest->from, $vacationRequest->to)
|
||||
->isNotEmpty();
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ class VacationTypeCanBeSelected implements VacationRequestRule
|
||||
$employmentForm = $vacationRequest->user->profile->employment_form;
|
||||
|
||||
$availableTypes = VacationType::all()
|
||||
->filter(fn(VacationType $type) => $this->configRetriever->isAvailableFor($type, $employmentForm));
|
||||
->filter(fn(VacationType $type): bool => $this->configRetriever->isAvailableFor($type, $employmentForm));
|
||||
|
||||
return $availableTypes->contains($vacationRequest->type);
|
||||
}
|
||||
|
@@ -9,11 +9,12 @@ use Carbon\CarbonPeriod;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class VacationDaysCalculator
|
||||
class WorkDaysCalculator
|
||||
{
|
||||
public function calculateDays(YearPeriod $yearPeriod, CarbonInterface $from, CarbonInterface $to): Collection
|
||||
public function calculateDays(CarbonInterface $from, CarbonInterface $to): Collection
|
||||
{
|
||||
$period = CarbonPeriod::create($from, $to);
|
||||
$yearPeriod = YearPeriod::findByYear($from->year);
|
||||
$holidays = $yearPeriod->holidays()->pluck("date");
|
||||
|
||||
$validDays = new Collection();
|
Reference in New Issue
Block a user