64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\ProjectManagement\Models;
|
|
|
|
use App\Traits\HasPublicIdentifier;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Modules\MasterData\Models\Material;
|
|
|
|
class TaskMaterial extends Model
|
|
{
|
|
use HasPublicIdentifier;
|
|
|
|
protected $fillable = [
|
|
'task_id',
|
|
'material_id',
|
|
'planned_qty',
|
|
'actual_qty',
|
|
'unit_cost',
|
|
'notes',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'planned_qty' => 'decimal:2',
|
|
'actual_qty' => 'decimal:2',
|
|
'unit_cost' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
public function task(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Task::class);
|
|
}
|
|
|
|
public function material(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Material::class);
|
|
}
|
|
|
|
|
|
|
|
public function getPlannedCostAttribute(): float
|
|
{
|
|
return (float) $this->planned_qty * (float) $this->unit_cost;
|
|
}
|
|
|
|
public function getActualCostAttribute(): float
|
|
{
|
|
return (float) $this->actual_qty * (float) $this->unit_cost;
|
|
}
|
|
|
|
public function getEffectiveCostAttribute(): float
|
|
{
|
|
return $this->actual_qty > 0 ? $this->actual_cost : $this->planned_cost;
|
|
}
|
|
|
|
public function getVarianceAttribute(): float
|
|
{
|
|
return $this->planned_cost - $this->actual_cost;
|
|
}
|
|
}
|