chore: update document approval workflow and bug fixes
This commit is contained in:
63
Modules/ProjectManagement/app/Models/TaskMaterial.php
Normal file
63
Modules/ProjectManagement/app/Models/TaskMaterial.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user