* #38 - wip * #38 - wip * #38 - fix * #38 - fix * #38 - fix * #38 - fix * Update resources/lang/pl.json Co-authored-by: Krzysztof Rewak <krzysztof.rewak@blumilk.pl> * #38 - cr fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> Co-authored-by: Krzysztof Rewak <krzysztof.rewak@blumilk.pl>
This commit is contained in:
@@ -20,6 +20,12 @@ class HandleCreatedVacationRequest
|
||||
{
|
||||
$vacationRequest = $event->vacationRequest;
|
||||
|
||||
if ($vacationRequest->hasFlowSkipped()) {
|
||||
$this->stateManager->approve($vacationRequest);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->configRetriever->needsTechnicalApproval($vacationRequest->type)) {
|
||||
$this->stateManager->waitForTechnical($vacationRequest);
|
||||
|
||||
|
@@ -6,6 +6,7 @@ namespace Toby\Domain\Listeners;
|
||||
|
||||
use Toby\Domain\Events\VacationRequestCreated;
|
||||
use Toby\Domain\Notifications\VacationRequestCreatedNotification;
|
||||
use Toby\Domain\Notifications\VacationRequestCreatedOnEmployeeBehalf;
|
||||
|
||||
class SendCreatedVacationRequestNotification
|
||||
{
|
||||
@@ -15,6 +16,12 @@ class SendCreatedVacationRequestNotification
|
||||
|
||||
public function handle(VacationRequestCreated $event): void
|
||||
{
|
||||
$event->vacationRequest->user->notify(new VacationRequestCreatedNotification($event->vacationRequest));
|
||||
$vacationRequest = $event->vacationRequest;
|
||||
|
||||
if ($vacationRequest->creator->is($vacationRequest->user)) {
|
||||
$vacationRequest->user->notify(new VacationRequestCreatedNotification($vacationRequest));
|
||||
} else {
|
||||
$vacationRequest->user->notify(new VacationRequestCreatedOnEmployeeBehalf($vacationRequest));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use InvalidArgumentException;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
|
||||
class VacationRequestCreatedOnEmployeeBehalf extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
protected VacationRequest $vacationRequest,
|
||||
) {
|
||||
}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return ["mail"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
$url = route(
|
||||
"vacation.requests.show",
|
||||
[
|
||||
"vacationRequest" => $this->vacationRequest,
|
||||
],
|
||||
);
|
||||
return $this->buildMailMessage($url);
|
||||
}
|
||||
|
||||
protected function buildMailMessage(string $url): MailMessage
|
||||
{
|
||||
$creator = $this->vacationRequest->creator->fullName;
|
||||
$user = $this->vacationRequest->user->first_name;
|
||||
$title = $this->vacationRequest->name;
|
||||
$type = $this->vacationRequest->type->label();
|
||||
$from = $this->vacationRequest->from->toDisplayDate();
|
||||
$to = $this->vacationRequest->to->toDisplayDate();
|
||||
$days = $this->vacationRequest->vacations()->count();
|
||||
$appName = config("app.name");
|
||||
|
||||
return (new MailMessage())
|
||||
->greeting(__("Hi :user!", [
|
||||
"user" => $user,
|
||||
]))
|
||||
->subject(__("Vacation request :title has been created on your behalf", [
|
||||
"title" => $title,
|
||||
]))
|
||||
->line(__("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [
|
||||
"title" => $title,
|
||||
"appName" => $appName,
|
||||
"creator" => $creator,
|
||||
]))
|
||||
->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);
|
||||
}
|
||||
}
|
@@ -58,6 +58,11 @@ class User extends Authenticatable
|
||||
return $this->hasMany(VacationRequest::class);
|
||||
}
|
||||
|
||||
public function createdVacationRequests(): HasMany
|
||||
{
|
||||
return $this->hasMany(VacationRequest::class, "creator_id");
|
||||
}
|
||||
|
||||
public function vacations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vacation::class);
|
||||
|
@@ -22,7 +22,9 @@ use Toby\Domain\Enums\VacationType;
|
||||
* @property Carbon $from
|
||||
* @property Carbon $to
|
||||
* @property string $comment
|
||||
* @property bool $flow_skipped
|
||||
* @property User $user
|
||||
* @property User $creator
|
||||
* @property YearPeriod $yearPeriod
|
||||
* @property Collection $activities
|
||||
* @property Collection $vacations
|
||||
@@ -47,6 +49,11 @@ class VacationRequest extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, "creator_id");
|
||||
}
|
||||
|
||||
public function yearPeriod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(YearPeriod::class);
|
||||
@@ -69,6 +76,11 @@ class VacationRequest extends Model
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function hasFlowSkipped(): bool
|
||||
{
|
||||
return $this->flow_skipped;
|
||||
}
|
||||
|
||||
public function scopeStates(Builder $query, array $states): Builder
|
||||
{
|
||||
return $query->whereIn("state", $states);
|
||||
|
@@ -15,8 +15,10 @@ use Toby\Domain\VacationDaysCalculator;
|
||||
use Toby\Domain\VacationRequestStateManager;
|
||||
use Toby\Domain\Validation\VacationRequestValidator;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Infrastructure\Http\Requests\VacationRequestRequest;
|
||||
use Toby\Infrastructure\Http\Resources\UserResource;
|
||||
use Toby\Infrastructure\Http\Resources\VacationRequestActivityResource;
|
||||
use Toby\Infrastructure\Http\Resources\VacationRequestResource;
|
||||
|
||||
@@ -61,8 +63,14 @@ class VacationRequestController extends Controller
|
||||
|
||||
public function create(): Response
|
||||
{
|
||||
$users = User::query()
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->get();
|
||||
|
||||
return inertia("VacationRequest/Create", [
|
||||
"vacationTypes" => VacationType::casesToSelect(),
|
||||
"users" => UserResource::collection($users),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -73,7 +81,7 @@ class VacationRequestController extends Controller
|
||||
VacationDaysCalculator $vacationDaysCalculator,
|
||||
): RedirectResponse {
|
||||
/** @var VacationRequest $vacationRequest */
|
||||
$vacationRequest = $request->user()->vacationRequests()->make($request->data());
|
||||
$vacationRequest = $request->user()->createdVacationRequests()->make($request->data());
|
||||
$vacationRequestValidator->validate($vacationRequest);
|
||||
|
||||
$vacationRequest->save();
|
||||
|
@@ -16,9 +16,11 @@ class VacationRequestRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
"user" => ["required", "exists:users,id"],
|
||||
"type" => ["required", new Enum(VacationType::class)],
|
||||
"from" => ["required", "date_format:Y-m-d", new YearPeriodExists()],
|
||||
"to" => ["required", "date_format:Y-m-d", new YearPeriodExists()],
|
||||
"flowSkipped" => ["nullable", "boolean"],
|
||||
"comment" => ["nullable"],
|
||||
];
|
||||
}
|
||||
@@ -28,11 +30,13 @@ class VacationRequestRequest extends FormRequest
|
||||
$from = $this->get("from");
|
||||
|
||||
return [
|
||||
"user_id" => $this->get("user"),
|
||||
"type" => $this->get("type"),
|
||||
"from" => $from,
|
||||
"to" => $this->get("to"),
|
||||
"year_period_id" => YearPeriod::findByYear(Carbon::create($from)->year)->id,
|
||||
"comment" => $this->get("comment"),
|
||||
"flow_skipped" => $this->boolean("flowSkipped"),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user