41 lines
869 B
PHP
41 lines
869 B
PHP
<?php
|
|
|
|
namespace Modules\ProjectManagement\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Modules\MasterData\Models\Material;
|
|
|
|
class ProjectMaterialsEstimate extends Model
|
|
{
|
|
protected $fillable = [
|
|
'project_id',
|
|
'material_id',
|
|
'estimated_qty',
|
|
'unit_cost',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'estimated_qty' => 'decimal:2',
|
|
'unit_cost' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
public function project(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
public function material(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Material::class);
|
|
}
|
|
|
|
public function getLineTotalAttribute(): float
|
|
{
|
|
return (float) $this->estimated_qty * (float) $this->unit_cost;
|
|
}
|
|
}
|