2026-05-07 23:31:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-06-16 18:05:53 +02:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
use App\Traits\LogsActivity;
|
2026-05-07 23:31:33 +02:00
|
|
|
|
|
|
|
|
class Inspection extends Model
|
|
|
|
|
{
|
2026-06-16 18:05:53 +02:00
|
|
|
use SoftDeletes, LogsActivity;
|
2026-05-07 23:31:33 +02:00
|
|
|
|
2026-06-16 18:05:53 +02:00
|
|
|
const STATUSES = ['pending', 'in_progress', 'completed', 'approved', 'rejected'];
|
|
|
|
|
const RESULTS = ['pass', 'fail', 'conditional'];
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'project_id', 'layer_id', 'feature_id', 'template_id', 'user_id',
|
|
|
|
|
'data', 'status', 'inspector_user_id', 'completed_at', 'result', 'notes',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'data' => 'array',
|
|
|
|
|
'completed_at' => 'datetime',
|
|
|
|
|
];
|
2026-05-07 23:31:33 +02:00
|
|
|
|
|
|
|
|
public function project()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Project::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function layer()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Layer::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function template()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(InspectionTemplate::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
2026-05-11 10:58:25 +02:00
|
|
|
|
2026-06-16 18:05:53 +02:00
|
|
|
public function inspector()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'inspector_user_id');
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 10:58:25 +02:00
|
|
|
public function feature()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Feature::class, 'feature_id');
|
|
|
|
|
}
|
2026-06-16 18:05:53 +02:00
|
|
|
|
|
|
|
|
public function issues()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Issue::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopePending($q) { return $q->where('status', 'pending'); }
|
|
|
|
|
public function scopeCompleted($q) { return $q->where('status', 'completed'); }
|
|
|
|
|
public function scopeRejected($q) { return $q->where('status', 'rejected'); }
|
2026-05-07 23:31:33 +02:00
|
|
|
}
|