@extends('layouts.app') @section('title', '特休天數試算表') @section('content')
{{-- 標題列 --}}

特休天數試算表

依勞基法年資比例計算 {{ $year }} 年度應得特休天數
@foreach([now()->year+1, now()->year, now()->year-1] as $y) {{ $y }} @endforeach 假別管理
@foreach(['success','error'] as $t) @if(session($t))
{{ session($t) }}
@endif @endforeach @if($balanceTypes->isEmpty())
尚無需配額的假別
前往假別管理 →
@else {{-- 主區域:左側表格 + 右側說明 --}}
{{-- 左:配額表 --}}
@csrf
@foreach($balanceTypes as $bt) @endforeach @foreach($balanceTypes as $bt) @endforeach @foreach($users as $u) @php $leaveCalc = $u->annualLeaveForYear($year); $asOf = $year >= now()->year ? now() : \Carbon\Carbon::create($year, 12, 31); $months = $u->joined_at ? $u->joined_at->diffInMonths($asOf) : null; $yrs = $months !== null ? intdiv($months, 12) : null; $remMos = $months !== null ? $months % 12 : null; $senPart = ($months !== null) ? (($yrs > 0 ? "{$yrs}年" : '') . ($remMos > 0 ? "{$remMos}月" : '')) : null; $seniority = $months === null ? '—' : ($senPart ?: '< 1月'); $legalDays = $leaveCalc ? $leaveCalc['days'] : null; // 核定 input 的 tooltip 內容 if ($leaveCalc) { $lc = $leaveCalc; if (!empty($lc['formula'])) { $tipHtml = "法定 {$lc['days']} 日" . "
{$year}/01/01 起 {$lc['oldDays']}日×{$lc['oldMonths']}月 = {$lc['oldPart']}日" . "
{$year}/{$lc['annivMonth']}/{$lc['annivDay']} 起 {$lc['newDays']}日×{$lc['newMonths']}月 = {$lc['newPart']}日" . "
{$lc['oldDays']}×{$lc['oldMonths']}/12 + {$lc['newDays']}×{$lc['newMonths']}/12 = {$lc['oldPart']} + {$lc['newPart']} = {$lc['days']}"; } else { $tipHtml = htmlspecialchars($lc['detail'] ?? ''); } } else { $tipHtml = ''; } @endphp @foreach($balanceTypes as $bt) @php $b = $balances[$u->id][$bt->id] ?? null; $savedDays = $b !== null ? (float)$b->total_days : null; $used = $b ? $b->used_days : 0; // 有存過就顯示存過的值;尚未存過才用法定計算預填 $inputVal = $savedDays !== null ? $savedDays : ($legalDays ?? 0); $rem = max(0, $inputVal - $used); // 若曾存過且與法定計算不同,顯示提示 $mismatch = $savedDays !== null && $legalDays !== null && abs($savedDays - $legalDays) >= 0.01; @endphp @endforeach @endforeach
工號 部門 職稱 姓名 到職日 年資 {{ $bt->name }}
核定 已用 剩餘
{{ $u->employee_no ?: '—' }} {{ $u->department ?: '—' }} {{ $u->position ?: '—' }} {{ $u->name }} {{ $u->joined_at ? $u->joined_at->format('Y-m-d') : '—' }} {{ $seniority }}
@if($mismatch)
已存:{{ $savedDays }}
@endif
{{ $used > 0 ? number_format((float)$used, 2) : '—' }} {{ $inputVal > 0 ? number_format((float)$rem, 2) : '—' }}
{{-- 右:說明卡片(sticky) --}}
⏱️ 勞基法法定特休天數
6 個月以上未滿 1 年3 日 1 年以上未滿 2 年7 日 2 年以上未滿 3 年10 日 3 年以上未滿 5 年14 日 5 年以上未滿 10 年15 日 10 年以上(每年 +1)≤ 30 日

比例分攤公式
舊年資 × (週年月 − 1) / 12
+ 新年資 × (13 − 週年月) / 12
例:年資 21 年,到職月 9 月
27 × 8/12 + 28 × 4/12
27.33 日
@endif
@push('scripts') @endpush @endsection