101 lines
2.4 KiB
PHP
101 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\ReportPeriodStatus;
|
|
use Database\Factories\ReportPeriodFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable(['team_id', 'year', 'month', 'status'])]
|
|
class ReportPeriod extends Model
|
|
{
|
|
/** @use HasFactory<ReportPeriodFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* Get the team that owns the period.
|
|
*
|
|
* @return BelongsTo<Team, $this>
|
|
*/
|
|
public function team(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Team::class);
|
|
}
|
|
|
|
/**
|
|
* Get the service entries for the period.
|
|
*
|
|
* @return HasMany<ServiceEntry, $this>
|
|
*/
|
|
public function serviceEntries(): HasMany
|
|
{
|
|
return $this->hasMany(ServiceEntry::class);
|
|
}
|
|
|
|
/**
|
|
* Get the medication expense rows for the period.
|
|
*
|
|
* @return HasMany<MedicationExpenseRow, $this>
|
|
*/
|
|
public function medicationExpenseRows(): HasMany
|
|
{
|
|
return $this->hasMany(MedicationExpenseRow::class);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the period can still be edited.
|
|
*/
|
|
public function isEditable(): bool
|
|
{
|
|
return $this->status === ReportPeriodStatus::Draft;
|
|
}
|
|
|
|
/**
|
|
* Get a human-readable label for the period.
|
|
*/
|
|
public function label(): string
|
|
{
|
|
return sprintf('%s %s', $this->monthName(), $this->year);
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'year' => 'integer',
|
|
'month' => 'integer',
|
|
'status' => ReportPeriodStatus::class,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the localized month name.
|
|
*/
|
|
protected function monthName(): string
|
|
{
|
|
return match ($this->month) {
|
|
1 => 'Январь',
|
|
2 => 'Февраль',
|
|
3 => 'Март',
|
|
4 => 'Апрель',
|
|
5 => 'Май',
|
|
6 => 'Июнь',
|
|
7 => 'Июль',
|
|
8 => 'Август',
|
|
9 => 'Сентябрь',
|
|
10 => 'Октябрь',
|
|
11 => 'Ноябрь',
|
|
12 => 'Декабрь',
|
|
default => (string) $this->month,
|
|
};
|
|
}
|
|
}
|