From ba792a0fccc7dfa75c70effc46d515cbe19d95d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Sat, 28 Feb 2026 15:29:56 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[equipment]=20=EC=A0=90=EA=B2=80?= =?UTF-8?q?=ED=91=9C=20=ED=9C=B4=EC=9D=BC=20=ED=91=9C=EC=8B=9C=20=EB=B0=8F?= =?UTF-8?q?=20=EC=A3=BC=EA=B0=84=201=EC=A3=BC=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 점검 그리드에 holidays 테이블 기반 휴일 표시 (빨간 배경) - 휴일/주말 셀 클릭 차단 (UI + 서버 양쪽) - 자동 판정에서 휴일 제외 (기존 주말만 제외 → 주말+휴일) - 주간 1주 열 저장 누락 수정 (resolvePeriod에서 isoWeekYear 사용) - toggleDetail, setResult에 비근무일 검증 추가 - 범례에 '휴일/주말 (점검 불가)' 안내 추가 --- app/Enums/InspectionCycle.php | 45 +++++++++++++++++++ .../Admin/EquipmentInspectionController.php | 3 ++ app/Services/EquipmentInspectionService.php | 14 +++++- .../partials/inspection-grid.blade.php | 23 ++++++---- 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/app/Enums/InspectionCycle.php b/app/Enums/InspectionCycle.php index 4a9e08ba..9b35a1c8 100644 --- a/app/Enums/InspectionCycle.php +++ b/app/Enums/InspectionCycle.php @@ -92,6 +92,7 @@ public static function resolvePeriod(string $cycle, string $checkDate): string return match ($cycle) { self::DAILY => $date->format('Y-m'), + self::WEEKLY => (string) $date->isoWeekYear, default => $date->format('Y'), }; } @@ -114,6 +115,50 @@ public static function isWeekend(string $period, int $colIndex): bool return in_array($date->dayOfWeek, [0, 6]); } + /** + * 해당 기간의 휴일 날짜 목록 반환 (date string Set) + */ + public static function getHolidayDates(string $cycle, string $period): array + { + $tenantId = session('selected_tenant_id', 1); + + if ($cycle === self::DAILY) { + $start = Carbon::createFromFormat('Y-m', $period)->startOfMonth(); + $end = $start->copy()->endOfMonth(); + } else { + $start = Carbon::create((int) $period, 1, 1); + $end = Carbon::create((int) $period, 12, 31); + } + + $holidays = \App\Models\System\Holiday::where('tenant_id', $tenantId) + ->where('start_date', '<=', $end->toDateString()) + ->where('end_date', '>=', $start->toDateString()) + ->get(); + + $dates = []; + foreach ($holidays as $holiday) { + $hStart = $holiday->start_date->copy()->max($start); + $hEnd = $holiday->end_date->copy()->min($end); + $current = $hStart->copy(); + while ($current->lte($hEnd)) { + $dates[$current->format('Y-m-d')] = true; + $current->addDay(); + } + } + + return $dates; + } + + /** + * 비근무일 여부 (주말 또는 휴일) + */ + public static function isNonWorkingDay(string $checkDate, array $holidayDates = []): bool + { + $date = Carbon::parse($checkDate); + + return $date->isWeekend() || isset($holidayDates[$checkDate]); + } + // --- Daily --- private static function dailyLabels(?string $period): array { diff --git a/app/Http/Controllers/Api/Admin/EquipmentInspectionController.php b/app/Http/Controllers/Api/Admin/EquipmentInspectionController.php index 06960b37..dac92965 100644 --- a/app/Http/Controllers/Api/Admin/EquipmentInspectionController.php +++ b/app/Http/Controllers/Api/Admin/EquipmentInspectionController.php @@ -35,10 +35,13 @@ public function index(Request $request) ); if ($request->header('HX-Request')) { + $holidayDates = InspectionCycle::getHolidayDates($cycle, $period); + return view('equipment.partials.inspection-grid', [ 'inspections' => $inspections, 'cycle' => $cycle, 'period' => $period, + 'holidayDates' => $holidayDates, ]); } diff --git a/app/Services/EquipmentInspectionService.php b/app/Services/EquipmentInspectionService.php index 9fc1c76b..91648655 100644 --- a/app/Services/EquipmentInspectionService.php +++ b/app/Services/EquipmentInspectionService.php @@ -92,8 +92,13 @@ public function toggleDetail(int $equipmentId, int $templateItemId, string $chec throw new \Exception('점검 권한이 없습니다.'); } - $tenantId = session('selected_tenant_id', 1); $period = InspectionCycle::resolvePeriod($cycle, $checkDate); + $holidayDates = InspectionCycle::getHolidayDates($cycle, $period); + if (InspectionCycle::isNonWorkingDay($checkDate, $holidayDates)) { + throw new \Exception('휴일/주말에는 점검을 기록할 수 없습니다.'); + } + + $tenantId = session('selected_tenant_id', 1); $inspection = EquipmentInspection::firstOrCreate( [ @@ -147,8 +152,13 @@ public function setResult(int $equipmentId, int $templateItemId, string $checkDa throw new \Exception('점검 권한이 없습니다.'); } - $tenantId = session('selected_tenant_id', 1); $period = InspectionCycle::resolvePeriod($cycle, $checkDate); + $holidayDates = InspectionCycle::getHolidayDates($cycle, $period); + if (InspectionCycle::isNonWorkingDay($checkDate, $holidayDates)) { + throw new \Exception('휴일/주말에는 점검을 기록할 수 없습니다.'); + } + + $tenantId = session('selected_tenant_id', 1); $inspection = EquipmentInspection::firstOrCreate( [ diff --git a/resources/views/equipment/partials/inspection-grid.blade.php b/resources/views/equipment/partials/inspection-grid.blade.php index de790fc3..569413e3 100644 --- a/resources/views/equipment/partials/inspection-grid.blade.php +++ b/resources/views/equipment/partials/inspection-grid.blade.php @@ -9,6 +9,7 @@ $isDaily = $cycle === 'daily'; // 첫 번째 설비의 labels 사용 $labels = $inspections[0]['labels'] ?? []; + $holidayDates = $holidayDates ?? []; @endphp
@@ -19,9 +20,12 @@ 점검항목 @foreach($labels as $colIndex => $label) @php - $isWeekend = $isDaily && \App\Enums\InspectionCycle::isWeekend($period, $colIndex); + $colDate = \App\Enums\InspectionCycle::resolveCheckDate($cycle, $period, $colIndex); + $isWeekend = $isDaily && in_array(\Carbon\Carbon::parse($colDate)->dayOfWeek, [0, 6]); + $isHoliday = isset($holidayDates[$colDate]); + $isOff = $isWeekend || $isHoliday; @endphp - + {{ $label }} @endforeach @@ -40,16 +44,16 @@ @endphp @php - // 자동 판정: 주말(daily) 제외, 오늘까지 도래한 날짜만 검사 + // 자동 판정: 비근무일(주말+휴일) 제외, 오늘까지 도래한 날짜만 검사 $today = now()->format('Y-m-d'); $totalChecks = 0; $passedChecks = 0; foreach ($templates as $tmpl) { foreach ($labels as $ci => $lbl) { - if ($isDaily && \App\Enums\InspectionCycle::isWeekend($period, $ci)) { + $cd = \App\Enums\InspectionCycle::resolveCheckDate($cycle, $period, $ci); + if (\App\Enums\InspectionCycle::isNonWorkingDay($cd, $holidayDates)) { continue; } - $cd = \App\Enums\InspectionCycle::resolveCheckDate($cycle, $period, $ci); if ($cd > $today) { continue; } @@ -84,16 +88,16 @@ $detail = isset($details[$key]) ? $details[$key]->first() : null; $symbol = $detail ? $detail->result_symbol : ''; $color = $detail ? $detail->result_color : 'text-gray-400'; - $isWeekend = $isDaily && \App\Enums\InspectionCycle::isWeekend($period, $colIndex); + $isOff = \App\Enums\InspectionCycle::isNonWorkingDay($checkDate, $holidayDates); @endphp - @if($canInspect) - {{ $symbol }} @else - {{ $symbol }} @@ -125,5 +129,6 @@ X 이상 수리완료 셀 클릭: 빈칸 → ○ → X → △ → 빈칸 + ■ 휴일/주말 (점검 불가)
@endif