* #126 - vacation request reminders * #126 - fix workdays * #126 - changes * #126 - cs fix * #5 - bump codestyle * #126 - fix * #126 - fix * #126 - fix * #126 - fix * #126 - tests * #126 - fix * #126 - fix * #126 - fix seeders * #126 - fix * #126 - tests Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
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,10 +52,7 @@ class CreateAction
|
||||
|
||||
$vacationRequest->save();
|
||||
|
||||
$days = $this->vacationDaysCalculator->calculateDays(
|
||||
$vacationRequest->from,
|
||||
$vacationRequest->to,
|
||||
);
|
||||
$days = $this->workDaysCalculator->calculateDays($vacationRequest->from, $vacationRequest->to);
|
||||
|
||||
foreach ($days as $day) {
|
||||
$vacationRequest->vacations()->create([
|
||||
|
@@ -7,6 +7,7 @@ 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
|
||||
{
|
||||
@@ -22,13 +23,14 @@ class KeyHasBeenGivenNotification extends Notification
|
||||
return [Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(Notifiable $notifiable): string
|
||||
public function toSlack(Notifiable $notifiable): SlackMessage
|
||||
{
|
||||
return __(":sender gives key no :key to :recipient", [
|
||||
"sender" => $this->getName($this->sender),
|
||||
"recipient" => $this->getName($this->recipient),
|
||||
"key" => $notifiable->id,
|
||||
]);
|
||||
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
|
||||
|
@@ -7,6 +7,7 @@ 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
|
||||
{
|
||||
@@ -22,13 +23,14 @@ class KeyHasBeenTakenNotification extends Notification
|
||||
return [Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(Notifiable $notifiable): string
|
||||
public function toSlack(Notifiable $notifiable): SlackMessage
|
||||
{
|
||||
return __(":recipient takes key no :key from :sender", [
|
||||
"recipient" => $this->getName($this->recipient),
|
||||
"sender" => $this->getName($this->sender),
|
||||
"key" => $notifiable->id,
|
||||
]);
|
||||
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
|
||||
|
@@ -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
|
||||
{
|
||||
@@ -23,14 +24,12 @@ class VacationRequestCreatedNotification extends Notification
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): string
|
||||
public function toSlack(): SlackMessage
|
||||
{
|
||||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
|
||||
|
||||
return implode("\n", [
|
||||
$this->buildDescription(),
|
||||
"<${url}|Zobacz szczegóły>",
|
||||
]);
|
||||
return (new SlackMessage())
|
||||
->text("{$this->buildDescription()}\n <${url}|Zobacz szczegóły>");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,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);
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
{
|
||||
@@ -25,14 +26,12 @@ class VacationRequestStatusChangedNotification extends Notification
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): string
|
||||
public function toSlack(): SlackMessage
|
||||
{
|
||||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
|
||||
|
||||
return implode("\n", [
|
||||
$this->buildDescription(),
|
||||
"<${url}|Zobacz szczegóły>",
|
||||
]);
|
||||
return (new SlackMessage())
|
||||
->text("{$this->buildDescription()}\n <${url}|Zobacz szczegóły>");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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
|
||||
{
|
||||
@@ -26,14 +27,12 @@ class VacationRequestWaitsForApprovalNotification extends Notification
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): string
|
||||
public function toSlack(): SlackMessage
|
||||
{
|
||||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
|
||||
|
||||
return implode("\n", [
|
||||
$this->buildDescription(),
|
||||
"<${url}|Zobacz szczegóły>",
|
||||
]);
|
||||
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);
|
||||
}
|
||||
}
|
@@ -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->from, $vacationRequest->to)->count();
|
||||
$estimatedDays = $this->workDaysCalculator
|
||||
->calculateDays($vacationRequest->from, $vacationRequest->to)
|
||||
->count();
|
||||
|
||||
return $limit >= ($vacationDays + $estimatedDays);
|
||||
}
|
||||
|
@@ -4,18 +4,18 @@ 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
|
||||
return $this->workDaysCalculator
|
||||
->calculateDays($vacationRequest->from, $vacationRequest->to)
|
||||
->isNotEmpty();
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ use Carbon\CarbonPeriod;
|
||||
use Illuminate\Support\Collection;
|
||||
use Toby\Eloquent\Models\YearPeriod;
|
||||
|
||||
class VacationDaysCalculator
|
||||
class WorkDaysCalculator
|
||||
{
|
||||
public function calculateDays(CarbonInterface $from, CarbonInterface $to): Collection
|
||||
{
|
Reference in New Issue
Block a user