change vacation request name

This commit is contained in:
Adrian Hopek
2022-03-17 13:32:38 +01:00
parent dc77292278
commit 4f6883b451
6 changed files with 11 additions and 42 deletions

View File

@@ -19,6 +19,7 @@ use Toby\Domain\States\VacationRequest\VacationRequestState;
/**
* @property int $id
* @property string $name
* @property VacationType $type
* @property VacationRequestState $state
* @property Carbon $from
@@ -90,6 +91,11 @@ class VacationRequest extends Model
->where("to", ">=", $vacationRequest->from);
}
public function getNameAttribute(): string
{
return "{$this->id}/{$this->yearPeriod->year}";
}
public function hasFlowSkipped(): bool
{
return $this->flow_skipped;

View File

@@ -1,28 +0,0 @@
<?php
declare(strict_types=1);
namespace Toby\Eloquent\Observers;
use Illuminate\Contracts\Auth\Factory as Auth;
use Illuminate\Contracts\Events\Dispatcher;
use Toby\Eloquent\Models\VacationRequest;
class VacationRequestObserver
{
public function __construct(
protected Auth $auth,
protected Dispatcher $dispatcher,
) {}
public function creating(VacationRequest $vacationRequest): void
{
$year = $vacationRequest->from->year;
$vacationRequestNumber = $vacationRequest->user->vacationRequests()
->whereYear("from", $year)
->count() + 1;
$vacationRequest->name = "{$vacationRequestNumber}/${year}";
}
}