79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\MasterData\Models;
|
|
|
|
use App\Traits\BelongsToTenant;
|
|
use App\Traits\HasPublicIdentifier;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
use Modules\MaterialLogistics\Models\WarehouseStock;
|
|
use Modules\MaterialLogistics\Models\ProjectInventory;
|
|
use Modules\MaterialLogistics\Models\MaterialRequirement;
|
|
use Modules\MaterialLogistics\Models\MaterialDeployment;
|
|
|
|
class Material extends Model
|
|
{
|
|
use BelongsToTenant, HasFactory, HasPublicIdentifier;
|
|
|
|
protected static function newFactory()
|
|
{
|
|
return \Modules\MasterData\Database\Factories\MaterialFactory::new();
|
|
}
|
|
|
|
protected $fillable = [
|
|
'name', 'sku', 'category', 'unit',
|
|
'unit_cost', 'description', 'status', 'type', 'contractor_id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'unit_cost' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
public function components(): HasMany
|
|
{
|
|
return $this->hasMany(MaterialComponent::class, 'parent_id');
|
|
}
|
|
|
|
public function parentKits(): HasMany
|
|
{
|
|
return $this->hasMany(MaterialComponent::class, 'component_id');
|
|
}
|
|
|
|
public function warehouseStocks(): HasMany
|
|
{
|
|
return $this->hasMany(WarehouseStock::class);
|
|
}
|
|
|
|
public function projectInventories(): HasMany
|
|
{
|
|
return $this->hasMany(ProjectInventory::class);
|
|
}
|
|
|
|
public function inventories(): HasMany
|
|
{
|
|
return $this->hasMany(ProjectInventory::class);
|
|
}
|
|
|
|
public function requirements(): HasMany
|
|
{
|
|
return $this->hasMany(MaterialRequirement::class);
|
|
}
|
|
|
|
public function deployments(): HasMany
|
|
{
|
|
return $this->hasMany(MaterialDeployment::class);
|
|
}
|
|
|
|
public function groups(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(MaterialGroup::class, 'material_group_items')
|
|
->withTimestamps();
|
|
}
|
|
}
|