* google calendar improvements * fix * change vacation request name * #85 - google calendar improvements * #85 - fix * #85 - fix * #85 - fix
This commit is contained in:
@@ -12,7 +12,6 @@ use Illuminate\Support\Carbon;
|
||||
/**
|
||||
* @property int $id
|
||||
* @property Carbon $date
|
||||
* @property string $event_id
|
||||
* @property User $user
|
||||
* @property VacationRequest $vacationRequest
|
||||
* @property YearPeriod $yearPeriod
|
||||
|
@@ -6,6 +6,7 @@ namespace Toby\Eloquent\Models;
|
||||
|
||||
use Database\Factories\VacationRequestFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\AsCollection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -18,6 +19,7 @@ use Toby\Domain\States\VacationRequest\VacationRequestState;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property VacationType $type
|
||||
* @property VacationRequestState $state
|
||||
* @property Carbon $from
|
||||
@@ -29,6 +31,7 @@ use Toby\Domain\States\VacationRequest\VacationRequestState;
|
||||
* @property YearPeriod $yearPeriod
|
||||
* @property Collection $activities
|
||||
* @property Collection $vacations
|
||||
* @property Collection $event_ids
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*/
|
||||
@@ -44,6 +47,7 @@ class VacationRequest extends Model
|
||||
"state" => VacationRequestState::class,
|
||||
"from" => "date",
|
||||
"to" => "date",
|
||||
"event_ids" => AsCollection::class,
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
@@ -87,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;
|
||||
|
@@ -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}";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user