Files
GSB-Construction/Modules/MaterialLogistics/app/Models/ProjectInventory.php

50 lines
1.2 KiB
PHP

<?php
namespace Modules\MaterialLogistics\Models;
use Modules\MasterData\Models\Material;
use Modules\MasterData\Models\MaterialGroup;
use App\Traits\HasPublicIdentifier;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\ProjectManagement\Models\Project;
class ProjectInventory extends Model
{
use HasPublicIdentifier;
protected $table = 'project_inventories';
protected $fillable = [
'project_id', 'material_id',
'on_hand_qty', 'floated_qty', 'allocated_qty', 'consumed_qty', 'unit_cost',
];
protected function casts(): array
{
return [
'on_hand_qty' => 'decimal:2',
'floated_qty' => 'decimal:2',
'allocated_qty' => 'decimal:2',
'consumed_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 getAvailableQtyAttribute(): float
{
return (float) $this->on_hand_qty - (float) $this->allocated_qty;
}
}