fix: [equipment] 점검표 휴일 표시 및 주간 1주 저장 버그 수정

- 점검 그리드에 holidays 테이블 기반 휴일 표시 (빨간 배경)
- 휴일/주말 셀 클릭 차단 (UI + 서버 양쪽)
- 자동 판정에서 휴일 제외 (기존 주말만 제외 → 주말+휴일)
- 주간 1주 열 저장 누락 수정 (resolvePeriod에서 isoWeekYear 사용)
- toggleDetail, setResult에 비근무일 검증 추가
- 범례에 '휴일/주말 (점검 불가)' 안내 추가
This commit is contained in:
김보곤
2026-02-28 15:29:56 +09:00
parent 69718e7c18
commit ba792a0fcc
4 changed files with 74 additions and 11 deletions

View File

@@ -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
{

View File

@@ -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,
]);
}

View File

@@ -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(
[

View File

@@ -9,6 +9,7 @@
$isDaily = $cycle === 'daily';
// 첫 번째 설비의 labels 사용
$labels = $inspections[0]['labels'] ?? [];
$holidayDates = $holidayDates ?? [];
@endphp
<div class="overflow-x-auto">
@@ -19,9 +20,12 @@
<th class="border border-gray-300 px-2 py-1 text-center whitespace-nowrap sticky bg-gray-100 z-10" style="left: 80px; min-width: 80px;">점검항목</th>
@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
<th class="border border-gray-300 px-1 py-1 text-center {{ $isWeekend ? 'bg-red-50 text-red-600' : '' }}" style="min-width: 32px;">
<th class="border border-gray-300 px-1 py-1 text-center {{ $isOff ? 'bg-red-50 text-red-600' : '' }}" style="min-width: 32px;">
{{ $label }}
</th>
@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)
<td class="border border-gray-300 text-center cursor-pointer select-none {{ $isWeekend ? 'bg-red-50' : '' }}"
@if($canInspect && !$isOff)
<td class="border border-gray-300 text-center cursor-pointer select-none"
style="min-width: 32px; padding: 2px;"
onclick="toggleCell({{ $equipment->id }}, {{ $tmpl->id }}, '{{ $checkDate }}', this)">
<span class="inspection-cell text-lg font-bold {{ $color }}">{{ $symbol }}</span>
</td>
@else
<td class="border border-gray-300 text-center select-none cursor-not-allowed opacity-50 {{ $isWeekend ? 'bg-red-50' : '' }}"
<td class="border border-gray-300 text-center select-none {{ $isOff ? 'bg-red-50' : 'cursor-not-allowed opacity-50' }}"
style="min-width: 32px; padding: 2px;">
<span class="inspection-cell text-lg font-bold {{ $color }}">{{ $symbol }}</span>
</td>
@@ -125,5 +129,6 @@
<span><span class="text-red-600 font-bold text-lg">X</span> 이상</span>
<span><span class="text-yellow-600 font-bold text-lg"></span> 수리완료</span>
<span class="text-gray-400"> 클릭: 빈칸 X 빈칸</span>
<span class="text-red-400"> 휴일/주말 (점검 불가)</span>
</div>
@endif