Files

55 lines
1.2 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',
'allocation_type',
'bundle_name',
'bundle_unit',
'bundle_quantity',
'bundle_unit_rate',
'estimated_hours',
'actual_hours',
];
protected function casts(): array
{
return [
'estimated_hours' => 'decimal:2',
'actual_hours' => 'decimal:2',
'bundle_quantity' => 'decimal:2',
'bundle_unit_rate' => '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);
}
}