feat: [equipment] 설비관리 모듈 구현
- 모델 6개 (Equipment, InspectionTemplate, Inspection, InspectionDetail, Repair, Process) - 서비스 3개 (Equipment, Inspection, Repair) - API 컨트롤러 3개 + FormRequest 4개 - Blade 컨트롤러 + 라우트 등록 - 뷰: 대시보드, 등록대장(CRUD), 일상점검표(캘린더 그리드), 수리이력
This commit is contained in:
133
app/Models/Equipment/Equipment.php
Normal file
133
app/Models/Equipment/Equipment.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Equipment;
|
||||
|
||||
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',
|
||||
'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 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 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' => '폐기',
|
||||
];
|
||||
}
|
||||
}
|
||||
58
app/Models/Equipment/EquipmentInspection.php
Normal file
58
app/Models/Equipment/EquipmentInspection.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Equipment;
|
||||
|
||||
use App\Traits\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class EquipmentInspection extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'equipment_id',
|
||||
'year_month',
|
||||
'overall_judgment',
|
||||
'inspector_id',
|
||||
'repair_note',
|
||||
'issue_note',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
public function equipment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Equipment::class, 'equipment_id');
|
||||
}
|
||||
|
||||
public function inspector(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class, 'inspector_id');
|
||||
}
|
||||
|
||||
public function details(): HasMany
|
||||
{
|
||||
return $this->hasMany(EquipmentInspectionDetail::class, 'inspection_id');
|
||||
}
|
||||
|
||||
public function getJudgmentLabelAttribute(): string
|
||||
{
|
||||
return match ($this->overall_judgment) {
|
||||
'OK' => '양호',
|
||||
'NG' => '이상',
|
||||
default => '-',
|
||||
};
|
||||
}
|
||||
|
||||
public function getJudgmentColorAttribute(): string
|
||||
{
|
||||
return match ($this->overall_judgment) {
|
||||
'OK' => 'bg-green-100 text-green-800',
|
||||
'NG' => 'bg-red-100 text-red-800',
|
||||
default => 'bg-gray-100 text-gray-800',
|
||||
};
|
||||
}
|
||||
}
|
||||
62
app/Models/Equipment/EquipmentInspectionDetail.php
Normal file
62
app/Models/Equipment/EquipmentInspectionDetail.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Equipment;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class EquipmentInspectionDetail extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'inspection_id',
|
||||
'template_item_id',
|
||||
'check_date',
|
||||
'result',
|
||||
'note',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'check_date' => 'date',
|
||||
];
|
||||
|
||||
public function inspection(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EquipmentInspection::class, 'inspection_id');
|
||||
}
|
||||
|
||||
public function templateItem(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EquipmentInspectionTemplate::class, 'template_item_id');
|
||||
}
|
||||
|
||||
public function getResultSymbolAttribute(): string
|
||||
{
|
||||
return match ($this->result) {
|
||||
'good' => '○',
|
||||
'bad' => 'X',
|
||||
'repaired' => '△',
|
||||
default => '',
|
||||
};
|
||||
}
|
||||
|
||||
public function getResultColorAttribute(): string
|
||||
{
|
||||
return match ($this->result) {
|
||||
'good' => 'text-green-600',
|
||||
'bad' => 'text-red-600',
|
||||
'repaired' => 'text-yellow-600',
|
||||
default => 'text-gray-400',
|
||||
};
|
||||
}
|
||||
|
||||
public static function getNextResult(?string $current): ?string
|
||||
{
|
||||
return match ($current) {
|
||||
null, '' => 'good',
|
||||
'good' => 'bad',
|
||||
'bad' => 'repaired',
|
||||
'repaired' => null,
|
||||
default => 'good',
|
||||
};
|
||||
}
|
||||
}
|
||||
48
app/Models/Equipment/EquipmentInspectionTemplate.php
Normal file
48
app/Models/Equipment/EquipmentInspectionTemplate.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Equipment;
|
||||
|
||||
use App\Traits\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class EquipmentInspectionTemplate extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'equipment_id',
|
||||
'item_no',
|
||||
'check_point',
|
||||
'check_item',
|
||||
'check_timing',
|
||||
'check_frequency',
|
||||
'check_method',
|
||||
'sort_order',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public function equipment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Equipment::class, 'equipment_id');
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
public function getTimingLabelAttribute(): string
|
||||
{
|
||||
return match ($this->check_timing) {
|
||||
'operating' => '가동 중',
|
||||
'stopped' => '정지 시',
|
||||
default => $this->check_timing ?? '-',
|
||||
};
|
||||
}
|
||||
}
|
||||
31
app/Models/Equipment/EquipmentProcess.php
Normal file
31
app/Models/Equipment/EquipmentProcess.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Equipment;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class EquipmentProcess extends Model
|
||||
{
|
||||
protected $table = 'equipment_process';
|
||||
|
||||
protected $fillable = [
|
||||
'equipment_id',
|
||||
'process_id',
|
||||
'is_primary',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_primary' => 'boolean',
|
||||
];
|
||||
|
||||
public function equipment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Equipment::class, 'equipment_id');
|
||||
}
|
||||
|
||||
public function process(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Process::class, 'process_id');
|
||||
}
|
||||
}
|
||||
62
app/Models/Equipment/EquipmentRepair.php
Normal file
62
app/Models/Equipment/EquipmentRepair.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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
|
||||
{
|
||||
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).'원';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user