64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Maintenance\Models;
|
|
|
|
use App\Business;
|
|
use App\BusinessLocation;
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class MaterialList extends Model
|
|
{
|
|
protected $table = 'maintenance_material_lists';
|
|
|
|
protected $fillable = [
|
|
'business_id',
|
|
'source_type',
|
|
'source_id',
|
|
'destination_location_id',
|
|
'status',
|
|
'notes',
|
|
'created_by',
|
|
];
|
|
|
|
public function business()
|
|
{
|
|
return $this->belongsTo(Business::class);
|
|
}
|
|
|
|
public function destinationLocation()
|
|
{
|
|
return $this->belongsTo(BusinessLocation::class, 'destination_location_id');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function lines()
|
|
{
|
|
return $this->hasMany(MaterialLine::class, 'material_list_id');
|
|
}
|
|
|
|
public function repairLines()
|
|
{
|
|
return $this->hasMany(MaterialLine::class, 'material_list_id')->where('line_type', 'repair');
|
|
}
|
|
|
|
public function repairDispatches()
|
|
{
|
|
return $this->hasMany(RepairDispatch::class, 'material_list_id');
|
|
}
|
|
|
|
public function source()
|
|
{
|
|
return match ($this->source_type) {
|
|
'overhaul' => $this->belongsTo(Overhaul::class, 'source_id'),
|
|
'rebuild' => $this->belongsTo(RebuildProject::class, 'source_id'),
|
|
'work_order' => $this->belongsTo(WorkOrder::class, 'source_id'),
|
|
default => null,
|
|
};
|
|
}
|
|
}
|