48 lines
1.1 KiB
PHP
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);
|
|
}
|
|
}
|