58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\ProjectManagement\Models;
|
|
|
|
use App\Models\User;
|
|
use App\Traits\HasPublicIdentifier;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Modules\ProjectManagement\Enums\DelayReason;
|
|
use Modules\ProjectManagement\Enums\WeatherCondition;
|
|
|
|
class TaskDelay extends Model
|
|
{
|
|
use HasPublicIdentifier;
|
|
|
|
protected $fillable = [
|
|
'task_id',
|
|
'reason_type',
|
|
'weather_condition',
|
|
'delay_date',
|
|
'lost_hours',
|
|
'notes',
|
|
'reported_by',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'reason_type' => DelayReason::class,
|
|
'weather_condition' => WeatherCondition::class,
|
|
'delay_date' => 'date',
|
|
'lost_hours' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
public function task(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Task::class);
|
|
}
|
|
|
|
public function reporter(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'reported_by');
|
|
}
|
|
|
|
// --- Accessors ---
|
|
|
|
public function getIsWeatherRelatedAttribute(): bool
|
|
{
|
|
return $this->reason_type === DelayReason::Weather;
|
|
}
|
|
|
|
public function getLostDaysAttribute(): float
|
|
{
|
|
return round((float) $this->lost_hours / 8, 1);
|
|
}
|
|
}
|