Files
GSB-Construction/Modules/ProjectManagement/app/Models/TaskLabor.php
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.0 KiB
PHP

<?php
namespace Modules\ProjectManagement\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\Labors\Models\Labor;
class TaskLabor extends Model
{
protected $table = 'task_labors';
protected $fillable = [
'task_id',
'labor_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 labor(): BelongsTo
{
return $this->belongsTo(Labor::class);
}
public function getEstimatedCostAttribute(): float
{
return (float) $this->estimated_hours * (float) ($this->labor?->hourly_rate ?? 0);
}
public function getActualCostAttribute(): float
{
return (float) $this->actual_hours * (float) ($this->labor?->hourly_rate ?? 0);
}
}