ultimatepos/Modules/Maintenance/Models/Equipment.php

171 lines
4.0 KiB
PHP

<?php
namespace Modules\Maintenance\Models;
use App\Business;
use App\Contact;
use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Project\Entities\Project;
class Equipment extends Model
{
use SoftDeletes;
protected $table = 'maintenance_equipment';
protected $fillable = [
'business_id',
'site_id',
'branch_id',
'category_id',
'production_line_id',
'project_id',
'customer_id',
'client_type',
'department_id',
'fixed_asset_id',
'code',
'name',
'asset_number',
'manufacturer',
'model',
'serial_number',
'capacity',
'installation_date',
'warranty_expires_at',
'location',
'qr_code',
'barcode',
'status',
'working_hours',
'last_service_date',
'next_service_date',
'last_overhaul_date',
'next_overhaul_date',
'priority',
'criticality',
'risk_level',
'health_percentage',
'technical_documents',
'images',
'videos',
'user_manual',
'notes',
'created_by',
'updated_by',
];
protected $casts = [
'installation_date' => 'date',
'warranty_expires_at' => 'date',
'last_service_date' => 'date',
'next_service_date' => 'date',
'last_overhaul_date' => 'date',
'next_overhaul_date' => 'date',
'working_hours' => 'decimal:2',
'health_percentage' => 'decimal:2',
'technical_documents' => 'array',
'images' => 'array',
'videos' => 'array',
'user_manual' => 'array',
];
public function business()
{
return $this->belongsTo(Business::class);
}
public function category()
{
return $this->belongsTo(EquipmentCategory::class, 'category_id');
}
public function fixedAsset()
{
return $this->belongsTo(\Modules\AssetManagement\Entities\Asset::class, 'fixed_asset_id');
}
public function productionLine()
{
return $this->belongsTo(ProductionLine::class, 'production_line_id');
}
public function project()
{
return $this->belongsTo(Project::class, 'project_id');
}
public function customer()
{
return $this->belongsTo(Contact::class, 'customer_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function preventiveSchedules()
{
return $this->hasMany(PreventiveSchedule::class, 'equipment_id');
}
public function overhauls()
{
return $this->hasMany(Overhaul::class, 'equipment_id');
}
public function workOrders()
{
return $this->hasMany(WorkOrder::class, 'equipment_id');
}
public function failureReports()
{
return $this->hasMany(FailureReport::class, 'equipment_id');
}
public function historyEntries()
{
return $this->hasMany(HistoryEntry::class, 'equipment_id')->orderByDesc('performed_at');
}
public function equipmentParts()
{
return $this->hasMany(EquipmentPart::class, 'equipment_id');
}
/** Legacy alias used by IE integration code. */
public function parts()
{
return $this->equipmentParts();
}
public function documents()
{
return $this->morphMany(AssetDocument::class, 'documentable')->orderBy('sort_order');
}
public function inspectionVisits()
{
return $this->hasMany(InspectionVisit::class, 'equipment_id')->orderByDesc('visit_date');
}
public function serviceRecords()
{
return $this->hasMany(ServiceRecord::class, 'equipment_id')->orderByDesc('started_at');
}
public function partReplacements()
{
return $this->hasMany(PartReplacement::class, 'equipment_id')->orderByDesc('replaced_at');
}
public function checklistTemplates()
{
return $this->hasMany(ChecklistTemplate::class, 'equipment_id');
}
}