78 lines
1.6 KiB
PHP
78 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class AssetMaintenance extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'asset_id',
|
|
'maintenance_type',
|
|
'start_date',
|
|
'end_date',
|
|
'cost',
|
|
'status',
|
|
'details',
|
|
'completion_notes',
|
|
'supplier',
|
|
'created_by'
|
|
];
|
|
|
|
protected $casts = [
|
|
'start_date' => 'date',
|
|
'end_date' => 'date',
|
|
'cost' => 'decimal:2',
|
|
];
|
|
|
|
/**
|
|
* Get the asset that is being maintained.
|
|
*/
|
|
public function asset()
|
|
{
|
|
return $this->belongsTo(Asset::class);
|
|
}
|
|
|
|
/**
|
|
* Get the user who created this maintenance record.
|
|
*/
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include scheduled maintenances.
|
|
*/
|
|
public function scopeScheduled($query)
|
|
{
|
|
return $query->where('status', 'scheduled');
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include in-progress maintenances.
|
|
*/
|
|
public function scopeInProgress($query)
|
|
{
|
|
return $query->where('status', 'in_progress');
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include completed maintenances.
|
|
*/
|
|
public function scopeCompleted($query)
|
|
{
|
|
return $query->where('status', 'completed');
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include cancelled maintenances.
|
|
*/
|
|
public function scopeCancelled($query)
|
|
{
|
|
return $query->where('status', 'cancelled');
|
|
}
|
|
} |