Files
Christopher Boyles 64d4b331a8
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled
Additional Changes
2026-06-02 22:04:03 +08:00

48 lines
1.1 KiB
PHP

<?php
namespace Modules\ProjectManagement\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\Equipments\Models\Equipment;
class TaskEquipment extends Model
{
protected $table = 'task_equipments';
protected $fillable = [
'task_id',
'equipment_id',
'estimated_hours',
'actual_hours',
];
protected function casts(): array
{
return [
'estimated_hours' => 'decimal:2',
'actual_hours' => 'decimal:2',
];
}
public function task(): BelongsTo
{
return $this->belongsTo(Task::class);
}
public function equipment(): BelongsTo
{
return $this->belongsTo(Equipment::class);
}
public function getEstimatedCostAttribute(): float
{
return (float) $this->estimated_hours * (float) ($this->equipment?->hourly_rate ?? 0);
}
public function getActualCostAttribute(): float
{
return (float) $this->actual_hours * (float) ($this->equipment?->hourly_rate ?? 0);
}
}