- EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair - equipments 테이블과 FK 참조 관계 → 동일 DB(codebridge)에서 관리
64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Equipment;
|
|
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class EquipmentRepair extends Model
|
|
{
|
|
protected $connection = 'codebridge';
|
|
use BelongsToTenant, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'equipment_id',
|
|
'repair_date',
|
|
'repair_type',
|
|
'repair_hours',
|
|
'description',
|
|
'cost',
|
|
'vendor',
|
|
'repaired_by',
|
|
'memo',
|
|
'created_by',
|
|
'updated_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'repair_date' => 'date',
|
|
'repair_hours' => 'decimal:1',
|
|
'cost' => 'decimal:2',
|
|
];
|
|
|
|
public function equipment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Equipment::class, 'equipment_id');
|
|
}
|
|
|
|
public function repairer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\User::class, 'repaired_by');
|
|
}
|
|
|
|
public function getRepairTypeLabelAttribute(): string
|
|
{
|
|
return match ($this->repair_type) {
|
|
'internal' => '사내',
|
|
'external' => '외주',
|
|
default => $this->repair_type ?? '-',
|
|
};
|
|
}
|
|
|
|
public function getFormattedCostAttribute(): string
|
|
{
|
|
if (! $this->cost) {
|
|
return '-';
|
|
}
|
|
|
|
return number_format($this->cost).'원';
|
|
}
|
|
}
|