@extends('layouts.app') @section('title', '交接申請詳情') @section('content')
@php $user = auth()->user(); $sl = $handover->statusLabel(); $stages = \App\Models\Handover::STAGES; $deptLabels = \App\Models\HandoverChecklistTemplate::DEPT_LABELS; @endphp {{-- Flash messages --}} @foreach(['success','error'] as $t) @if(session($t))
{{ session($t) }}
@endif @endforeach @if($errors->any())
{{ $errors->first() }}
@endif {{-- Header --}}

{{ $handover->applicant->name }} 的{{ $handover->type === 'resignation' ? '離職' : '調職' }}交接申請

{{ $sl['label'] }} @if($handover->expected_date) 預計日期:{{ $handover->expected_date->format('Y-m-d') }} @endif
返回列表 @if($user->role === 'admin' || ($viewerDeptKey === null && !$isApplicant)) 匯出 PDF @endif
{{-- Progress pipeline --}} @if($handover->approvals->isNotEmpty())
@foreach($handover->approvals->sortBy('stage_order') as $ap) @php $icon = match($ap->status) { 'approved' => 'bi-check-circle-fill text-success', 'rejected' => 'bi-x-circle-fill text-danger', default => 'bi-circle text-muted' }; $isNow = $currentApproval?->id === $ap->id; @endphp
{{ $ap->stageLabel() }}
{{ $ap->approver?->name ?? '未指定' }}
@if($ap->decided_at)
{{ $ap->decided_at->format('m/d') }}
@endif @if($isNow) 審核中 @endif
@if(!$loop->last) @endif @endforeach
@endif {{-- Approved celebration --}} @if($handover->status === 'approved' && $isApplicant) @php $approvedAt = $handover->approvals->where('status','approved')->sortByDesc('decided_at')->first()?->decided_at; @endphp
{{-- circular check graphic --}}

恭喜你!{{ $handover->type === 'resignation' ? '離職' : '調職' }}申請已全數核准

@if($approvedAt)

核准日期:{{ $approvedAt->format('Y-m-d') }}

@endif
@endif {{-- Basic Info Card --}} @php $applicant = $handover->applicant; $hireDate = $applicant->created_at; $leaveDate = $handover->expected_date; $yearsRaw = $hireDate->diffInMonths($leaveDate ?? now()); $years = intdiv($yearsRaw, 12); $months = $yearsRaw % 12; $tenureStr = $years > 0 ? "{$years} 年 {$months} 個月" : "{$months} 個月"; @endphp
申請人基本資訊
{{-- 第一列:部門 / 職稱 / 申請人 --}}
部門
{{ $applicant->department ?: '—' }}
職稱
{{ $applicant->position ?: '—' }}
申請人 / 帳號
{{ $applicant->name }}
{{ $applicant->email }}
{{-- 第二列:入職日 / 離職日 / 年資 --}}
入職日
{{ $hireDate->format('Y-m-d') }}
{{ $handover->type === 'resignation' ? '離職日' : '調職日' }}
{{ $leaveDate ? $leaveDate->format('Y-m-d') : '—' }}
年資
{{ $tenureStr }}
{{-- 第三列:離職/調職原因 + 門禁卡號 --}}
{{ $handover->type === 'resignation' ? '離職原因' : '調職原因' }}
@if($handover->isEditable() && $isApplicant) @else
{{ $handover->reason ?: '—' }}
@endif
門禁卡號
@if($handover->isEditable() && $isApplicant) @else
{{ $handover->access_card_number ?: '(未填寫)' }}
@endif
{{-- Checklist (full width) --}}
@csrf @method('PUT') {{-- ① 專案交接 --}} @if($projectResponsesByProject->isNotEmpty())
專案交接
@foreach($handover->projects as $hp) @php $projResps = $projectResponsesByProject[$hp->id] ?? collect(); $visibleResps = $viewerDeptKey ? $projResps->filter(fn($r) => $r->template->department === $viewerDeptKey) : $projResps; $confirmedCount = $visibleResps->where('status', 'confirmed')->count(); $filledCount = $visibleResps->whereIn('status', ['filled','confirmed'])->count(); $totalCount = $visibleResps->count(); $allConfirmed = $totalCount > 0 && $confirmedCount === $totalCount; $isThisStage = in_array($currentStage, array_keys( $projResps->mapWithKeys(fn($r) => [$r->template->department => true])->toArray() )); @endphp @if($totalCount === 0) @continue @endif @php $lockedForReceiver = $isReceiver && !$receiverProjectIds->has($hp->id); @endphp

@if(($viewerDeptKey || $isApplicant || $user->role === 'admin') && $hp->receiver_id)
交接給:{{ $hp->receiver?->name }} @if($hp->receiver_confirmed_at) — 已於 {{ $hp->receiver_confirmed_at->format('Y-m-d H:i') }} 確認交接完成 @else — 尚未確認交接完成 @endif @if(!$hp->receiver_confirmed_at && ($isApplicant || $viewerDeptKey || $user->role === 'admin') && !in_array($handover->status, ['draft','approved','rejected'])) @csrf @endif
@endif @if($isApplicant || $user->role === 'admin')
@if($handover->isEditable() && $isApplicant) @else
{{ $hp->receiver?->name ?? '—' }}
@endif
@if($handover->isEditable() && $isApplicant) @else
{{ $hp->notes ?? '—' }}
@endif
@endif @if(isset($receiverProjectIds) && $receiverProjectIds->has($hp->id))
@if($hp->receiver_confirmed_at)
{{ $hp->receiverConfirmer?->name }} 已於 {{ $hp->receiver_confirmed_at->format('Y-m-d H:i') }} 確認交接完成
@else
尚未確認交接完成
@endif
@endif @php $projRespsByDept = $projResps->groupBy(fn($r) => $r->template->department); @endphp @foreach(['business'=>'專案業務組','rd'=>'軟體開發組','systems'=>'系統資安組','admin'=>'人事'] as $dept => $deptLabel) @php $dRs = $projRespsByDept[$dept] ?? collect(); $isDeptStage = $currentStage === $dept; $canConfirmItem = !$isApplicant && !in_array($handover->status, ['draft','rejected']) && ($user->role === 'admin' || $viewerDeptKey === $dept); @endphp @if($viewerDeptKey && $viewerDeptKey !== $dept) @continue @endif @if($dRs->isNotEmpty())
{{ $deptLabel }}
    @foreach($dRs as $resp) @include('handovers._response_item', ['resp'=>$resp,'handover'=>$handover,'isApplicant'=>$isApplicant,'isThisStage'=>$isDeptStage,'canApprove'=>$canApprove,'canConfirmItem'=>$canConfirmItem]) @endforeach
@endif @endforeach
@endforeach
@endif {{-- ② 各組交接項目 --}} @php $globalDepts = ['business'=>'專案業務組','rd'=>'軟體開發組','systems'=>'系統資安組','admin'=>'人事']; $hasGlobal = collect($globalDepts)->keys()->contains(fn($d) => ($globalResponsesByDept[$d] ?? collect())->isNotEmpty() && (!$viewerDeptKey || $viewerDeptKey === $d)); @endphp @if($hasGlobal)
各組交接項目
@foreach($globalDepts as $dept => $deptLabel) @php $deptResps = $globalResponsesByDept[$dept] ?? collect(); $isThisStage = $currentStage === $dept; $canConfirmItem = !$isApplicant && !in_array($handover->status, ['draft','rejected']) && ($user->role === 'admin' || $viewerDeptKey === $dept); @endphp @if($viewerDeptKey && $viewerDeptKey !== $dept) @continue @endif @if($deptResps->isNotEmpty())
{{ $deptLabel }} @if($isThisStage)審核中@endif
@endif @endforeach
@endif {{-- ③ 設備交接 --}} @php $canSeeAssets = $isApplicant || $user->role === 'admin' || $viewerDeptKey === 'systems' || $viewerDeptKey === 'admin'; $deptLabels = \App\Models\Asset::CONFIRM_DEPTS; @endphp @if($canSeeAssets)
設備交接({{ $handover->assets->count() }}) @php $unreturnedCount = $handover->assets->where('returned', false)->count(); @endphp @if($unreturnedCount > 0) {{ $unreturnedCount }} 項未歸還 @else 全部歸還 @endif
@if($handover->assets->isEmpty())
無需歸還設備
@else
@if($user->role !== 'user' || $viewerDeptKey)@endif @foreach($handover->assets as $ha) @php $canConfirmThis = $user->role === 'admin' || ($viewerDeptKey === $ha->confirm_dept); @endphp @if($user->role !== 'user' || $viewerDeptKey) @endif @endforeach
資產名稱序號負責組狀態確認人
{{ $ha->asset->asset_name }} {{ $ha->asset->asset_sn ?? '—' }} {{ $deptLabels[$ha->confirm_dept] ?? $ha->confirm_dept }} @if($ha->returned) 已歸還 @else 待歸還 @endif {{ $ha->confirmer?->name ?? '—' }} @if($ha->confirmed_at)
{{ $ha->confirmed_at->format('m/d H:i') }}
@endif
@if(!$ha->returned && $canConfirmThis) @endif
@endif
@endif {{-- ④ 門禁卡 --}} @php $canSeeCard = $isApplicant || $user->role === 'admin' || $viewerDeptKey === null || $viewerDeptKey === 'admin'; // 門禁卡由營運長確認:admin role 或 boss stage 指定審核人(viewerDeptKey=null, 非申請人) $canConfirmCard = ($user->role === 'admin' || ($viewerDeptKey === null && !$isApplicant)) && !in_array($handover->status, ['draft','rejected']); @endphp @if($canSeeCard)
門禁卡 @if($handover->access_card_returned) 已繳回 @else 未繳回 @endif
卡號
{{ $handover->access_card_number ?: '(未填寫)' }}
狀態
@if($handover->access_card_returned) 已繳回 @if($handover->access_card_returned_at) {{ $handover->access_card_returned_at->format('Y-m-d H:i') }} @endif @if($confirmer = \App\Models\User::find($handover->access_card_confirmed_by)) ({{ $confirmer->name }} 確認) @endif @else 尚未繳回 @endif
@if($canConfirmCard && !$handover->access_card_returned)
@csrf
@endif
@endif @if($handover->isEditable() && $isApplicant)
@if(in_array($handover->status, ['draft', 'rejected'])) @php $confirmMsg = $handover->status === 'rejected' ? '確定重新送出?將從專案業務組重新開始審核。' : '確定送出交接申請?送出後若第一關已開始審核即無法修改。'; @endphp @endif
@endif {{-- Approval action (for supervisor / boss) --}} @if($canApprove && $currentApproval) @php $assetsBlocking = in_array($currentApproval->stage, ['systems','admin']) && $handover->assets->where('confirm_dept', $currentApproval->stage)->where('returned', false)->count() > 0; $blockingCount = $assetsBlocking ? $handover->assets->where('confirm_dept', $currentApproval->stage)->where('returned', false)->count() : 0; @endphp
審核操作({{ $currentApproval->stageLabel() }})
@if($assetsBlocking)
需確認本組負責的資產全數歸還後方可核准。尚有 {{ $blockingCount }} 項未歸還。
@endif {{-- Single form, two submit buttons with different formaction --}}
@csrf
@error('comment')
{{ $message }}
@enderror
@endif {{-- Approval history --}} @if($handover->approvals->where('status','!=','pending')->isNotEmpty())
審核紀錄
@foreach($handover->approvals->where('status','!=','pending') as $ap) @endforeach
關卡審核人結果意見時間
{{ $ap->stageLabel() }} {{ $ap->approver?->name ?? '—' }} @if($ap->status === 'approved') 核准 @else 退回 @endif {{ $ap->comment ?? '—' }} {{ $ap->decided_at?->format('Y-m-d H:i') }}
@endif @if($handover->excluded_projects && count($handover->excluded_projects) > 0)
申請人已排除以下專案(不納入本次交接):
@endif
@push('styles') @endpush @push('scripts') @endpush @endsection