- InspectionCycle enum: 6종 점검주기 상수, 열 라벨, check_date 계산 - Equipment 모델: subManager 관계, canInspect() 권한 체크 - Template/Inspection 모델: inspection_cycle fillable 추가 - EquipmentInspectionService: 주기별 점검 조회/토글/권한 체크 - 점검표 UI: 주기 탭, 동적 필터(월/연도), 주기별 그리드 열 - 점검항목 템플릿: 주기별 탭 그룹핑, 모달에 주기 선택 - 설비 등록/수정/상세: 부 담당자 필드 추가 - 권한 없는 장비 셀 비활성(cursor-not-allowed, opacity-50)
161 lines
4.1 KiB
PHP
161 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Equipment;
|
|
|
|
use App\Models\Boards\File;
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Equipment extends Model
|
|
{
|
|
use BelongsToTenant, SoftDeletes;
|
|
|
|
protected $table = 'equipments';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'equipment_code',
|
|
'name',
|
|
'equipment_type',
|
|
'specification',
|
|
'manufacturer',
|
|
'model_name',
|
|
'serial_no',
|
|
'location',
|
|
'production_line',
|
|
'purchase_date',
|
|
'install_date',
|
|
'purchase_price',
|
|
'useful_life',
|
|
'status',
|
|
'disposed_date',
|
|
'manager_id',
|
|
'sub_manager_id',
|
|
'photo_path',
|
|
'memo',
|
|
'is_active',
|
|
'sort_order',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'purchase_date' => 'date',
|
|
'install_date' => 'date',
|
|
'disposed_date' => 'date',
|
|
'purchase_price' => 'decimal:2',
|
|
'is_active' => 'boolean',
|
|
];
|
|
|
|
public function manager(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\User::class, 'manager_id');
|
|
}
|
|
|
|
public function subManager(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\User::class, 'sub_manager_id');
|
|
}
|
|
|
|
/**
|
|
* 해당 유저가 이 설비의 점검 권한이 있는지 확인
|
|
*/
|
|
public function canInspect(?int $userId = null): bool
|
|
{
|
|
$userId = $userId ?? auth()->id();
|
|
if (auth()->user()?->isAdmin()) {
|
|
return true;
|
|
}
|
|
|
|
return $this->manager_id === $userId || $this->sub_manager_id === $userId;
|
|
}
|
|
|
|
public function inspectionTemplates(): HasMany
|
|
{
|
|
return $this->hasMany(EquipmentInspectionTemplate::class, 'equipment_id')->orderBy('sort_order');
|
|
}
|
|
|
|
public function inspections(): HasMany
|
|
{
|
|
return $this->hasMany(EquipmentInspection::class, 'equipment_id');
|
|
}
|
|
|
|
public function repairs(): HasMany
|
|
{
|
|
return $this->hasMany(EquipmentRepair::class, 'equipment_id');
|
|
}
|
|
|
|
public function photos(): HasMany
|
|
{
|
|
return $this->hasMany(File::class, 'document_id')
|
|
->where('document_type', 'equipment')
|
|
->orderBy('id');
|
|
}
|
|
|
|
public function processes(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(\App\Models\Process::class, 'equipment_process')
|
|
->withPivot('is_primary')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('status', 'active');
|
|
}
|
|
|
|
public function scopeByLine($query, string $line)
|
|
{
|
|
return $query->where('production_line', $line);
|
|
}
|
|
|
|
public function scopeByType($query, string $type)
|
|
{
|
|
return $query->where('equipment_type', $type);
|
|
}
|
|
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return match ($this->status) {
|
|
'active' => '가동',
|
|
'idle' => '유휴',
|
|
'disposed' => '폐기',
|
|
default => $this->status,
|
|
};
|
|
}
|
|
|
|
public function getStatusColorAttribute(): string
|
|
{
|
|
return match ($this->status) {
|
|
'active' => 'bg-green-100 text-green-800',
|
|
'idle' => 'bg-yellow-100 text-yellow-800',
|
|
'disposed' => 'bg-gray-100 text-gray-800',
|
|
default => 'bg-gray-100 text-gray-800',
|
|
};
|
|
}
|
|
|
|
public static function getEquipmentTypes(): array
|
|
{
|
|
return ['포밍기', '미싱기', '샤링기', 'V컷팅기', '절곡기', '프레스', '드릴', '기타'];
|
|
}
|
|
|
|
public static function getProductionLines(): array
|
|
{
|
|
return ['스라트', '스크린', '절곡', '기타'];
|
|
}
|
|
|
|
public static function getStatuses(): array
|
|
{
|
|
return [
|
|
'active' => '가동',
|
|
'idle' => '유휴',
|
|
'disposed' => '폐기',
|
|
];
|
|
}
|
|
}
|