@extends('layouts.app', ['class' => 'g-sidenav-show bg-gray-100']) {{-- section content --}} @section('content') @include('layouts.navbars.auth.topnav', ['title' => ''])
@php // Gunakan data dari controller, atau query langsung jika kosong $displayItems = $table_detail_d ?? collect(); $currentUserId = $user_login->id ?? null; $sessionUsername = strtolower(trim((string) (session('username') ?? ''))); $modelUsername = strtolower(trim((string) ($user_login->username ?? ''))); $usernameFromId = $currentUserId ? strtolower((string) (\Illuminate\Support\Facades\DB::table('users')->where('id', $currentUserId)->value('username') ?? '')) : ''; $currentUsername = $sessionUsername !== '' && !is_numeric($sessionUsername) ? $sessionUsername : ($modelUsername !== '' && !is_numeric($modelUsername) ? $modelUsername : $usernameFromId); $hrdUserIds = \Illuminate\Support\Facades\DB::table('users') ->where(function ($q) { $q->whereRaw("FIND_IN_SET('hrdxxx', REPLACE(LOWER(idroles), ' ', ''))") ->orWhereRaw("FIND_IN_SET('hrd', REPLACE(LOWER(idroles), ' ', ''))"); }) ->pluck('id') ->map(fn ($id) => (int) $id) ->all(); $hrdUsernames = \Illuminate\Support\Facades\DB::table('users') ->where(function ($q) { $q->whereRaw("FIND_IN_SET('hrdxxx', REPLACE(LOWER(idroles), ' ', ''))") ->orWhereRaw("FIND_IN_SET('hrd', REPLACE(LOWER(idroles), ' ', ''))"); }) ->pluck('username') ->map(fn ($username) => strtolower((string) $username)) ->all(); $isCurrentViewerHrd = ($currentUserId && in_array((int) $currentUserId, $hrdUserIds, true)) || ($currentUsername !== '' && in_array($currentUsername, $hrdUsernames, true)); $currentUserRoles = array_map('trim', explode(',', strtolower((string) ($user_login->idroles ?? '')))); $isCurrentViewerAdmin = in_array('admins', $currentUserRoles, true) || in_array('admin', $currentUserRoles, true); $isHrdSubmission = function ($item) use ($hrdUserIds, $hrdUsernames) { $uid = isset($item->user_id) ? (string) $item->user_id : ''; $uidInt = is_numeric($uid) ? (int) $uid : null; $createdBy = strtolower((string) ($item->user_create ?? '')); if ($uidInt !== null && in_array($uidInt, $hrdUserIds, true)) { return true; } if ($uid !== '' && !is_numeric($uid) && in_array(strtolower($uid), $hrdUsernames, true)) { return true; } return $createdBy !== '' && in_array($createdBy, $hrdUsernames, true); }; $isVisibleForCurrentUser = function ($item) use ($currentUserId, $currentUsername, $isHrdSubmission, $isCurrentViewerHrd, $isCurrentViewerAdmin) { if ($isCurrentViewerAdmin) { return true; } $uid = isset($item->user_id) ? (string) $item->user_id : ''; $createdBy = strtolower((string) ($item->user_create ?? '')); $isHrd = $isHrdSubmission($item); $byUserId = $currentUserId && $uid !== '' && is_numeric($uid) && (int) $uid === (int) $currentUserId; $byLegacyUserId = $currentUsername !== '' && $uid !== '' && !is_numeric($uid) && strtolower($uid) === $currentUsername; $byUserCreate = $currentUsername !== '' && $createdBy === $currentUsername; if ($isCurrentViewerHrd && $isHrd && ($byUserId || $byLegacyUserId || $byUserCreate)) { return true; } if ($isHrd) { return false; } if ($byUserId) { return true; } if ($byLegacyUserId) { return true; } if ($byUserCreate) { return true; } return false; }; // Jika kosong, query langsung dari database $getPelaksanaLabel = function ($item) { $workType = strtolower(trim((string) ($item->work_type ?? ''))); if ($workType === 'vendor') { return 'Vendor'; } if ($workType === 'internal') { return 'Internal'; } return '-'; }; $filterMonth = request()->input('bulan', date('m')); $filterYear = request()->input('tahun', date('Y')); if ($displayItems->isEmpty()) { $query = \Illuminate\Support\Facades\DB::table('tr_non_periodic') ->leftJoin('ms_area', 'tr_non_periodic.area_id', '=', 'ms_area.id') ->select('tr_non_periodic.*', 'ms_area.nama_area as area_name') ->orderBy('tr_non_periodic.created_at', 'desc'); if ($filterMonth !== 'all') { $query->whereMonth('tr_non_periodic.created_at', $filterMonth); } if ($filterYear !== 'all') { $query->whereYear('tr_non_periodic.created_at', $filterYear); } $displayItems = $query->get(); } else { if ($filterMonth !== 'all') { $displayItems = $displayItems->filter(function($item) use ($filterMonth) { return \Carbon\Carbon::parse($item->created_at ?? $item->tanggal ?? now())->format('m') == str_pad($filterMonth, 2, '0', STR_PAD_LEFT); }); } if ($filterYear !== 'all') { $displayItems = $displayItems->filter(function($item) use ($filterYear) { return \Carbon\Carbon::parse($item->created_at ?? $item->tanggal ?? now())->format('Y') == $filterYear; }); } } $displayItems = $displayItems->filter(function ($item) use ($isVisibleForCurrentUser) { return $isVisibleForCurrentUser($item); })->values(); $statusField = 'request_status'; // VERIFIKASI: pengajuan yang diselesaikan petugas dan perlu verifikasi user $verifikasiItems = $displayItems->filter(function ($item) use ($statusField) { $statusValue = strtolower($item->{$statusField} ?? ''); return $statusValue === 'verifikasi'; }); $verifikasiCount = $verifikasiItems->count(); // PENDING: status review yang belum ada HRD approval (menunggu approval) $pendingCount = $displayItems->filter(function ($item) use ($statusField) { $statusValue = strtolower($item->{$statusField} ?? ''); return in_array($statusValue, ['review', 'pending', 'approved']) && empty($item->hrd_approval_date); })->count(); // DALAM PROSES: review yang sudah approved + pengadaan + pengerjaan + revisi $progressCount = $displayItems->filter(function ($item) use ($statusField) { $statusValue = strtolower($item->{$statusField} ?? ''); $reviewApproved = in_array($statusValue, ['review', 'approved']) && !empty($item->hrd_approval_date); $inProgress = in_array($statusValue, ['pengadaan', 'pengerjaan', 'revisi']); return $reviewApproved || $inProgress; })->count(); $rejectedCount = $displayItems->filter(function ($item) use ($statusField) { $statusValue = strtolower($item->{$statusField} ?? ''); return in_array($statusValue, ['rejected', 'reject']); })->count(); $completedCount = $displayItems->where($statusField, 'completed')->count(); // History items - only show completed, rejected, cancel $historyItems = $displayItems->filter(function ($item) use ($statusField) { $statusValue = strtolower($item->{$statusField} ?? ''); // Normalize status if (in_array($statusValue, ['reject'])) { $statusValue = 'rejected'; } elseif (in_array($statusValue, ['canceled', 'cancelled'])) { $statusValue = 'cancel'; } return in_array($statusValue, ['completed', 'rejected', 'cancel']); }); @endphp
Pengajuan Pekerjaan PU
Tambah Pengajuan

Total Pengajuan

{{ $displayItems->count() }}

Menunggu Verifikasi

{{ $verifikasiCount }}

Dalam Proses

{{ $progressCount }}

Completed

{{ $completedCount }}
{{-- Verifikasi Section --}} @if($verifikasiCount > 0)
Verifikasi Pekerjaan

Pekerjaan yang diselesaikan petugas dan memerlukan verifikasi Anda

{{ $verifikasiCount }} Task
@forelse ($verifikasiItems as $detail) @php $primary = ''; if (isset($table_primary_d) && count($table_primary_d) > 0) { foreach ($table_primary_d as $p) { $primary = $primary == '' ? $detail->{$p->field} : $primary . ':' . $detail->{$p->field}; } } if ($primary == '' && isset($detail->id)) { $primary = $detail->id; } $dateValue = $detail->created_at ?? $detail->tanggal ?? $detail->date ?? null; $displayDate = $dateValue ? \Illuminate\Support\Carbon::parse($dateValue)->format('d-m-Y') : '-'; // Get documentation for this non-periodic item $allDocs = \Illuminate\Support\Facades\DB::table('tr_documentation') ->where('non_periodic_id', $detail->id) ->where('is_active', '1') ->whereNotNull('file') ->whereNotIn('file', ['', '0', 'null']) ->orderBy('created_at', 'desc') ->get(); $documentation = $allDocs->first(); @endphp @empty @endforelse
Aksi No ID Trans Tanggal Pengajuan Area Deskripsi Pelaksana Dokumentasi
{{ $loop->iteration }} {{ $detail->id_trans ?: '-' }} {{ $displayDate }} {{ $detail->area_name ?? $detail->area ?? '-' }} {{ Str::limit($detail->job_description ?? $detail->description ?? '-', 50) }} {{ $getPelaksanaLabel($detail) }} @if($allDocs->count() > 0) @php // Helper function untuk generate URL file $getFileUrl = function($filePath) { $normalizedPath = trim((string) $filePath); $normalizedPath = str_replace('\\', '/', $normalizedPath); if ($normalizedPath === '') { return ''; } if (preg_match('/^https?:\/\//i', $normalizedPath)) { return $normalizedPath; } $normalizedPath = preg_replace('#^/?public/#', '', $normalizedPath); $normalizedPath = preg_replace('#^/?storage/#', '', $normalizedPath); $normalizedPath = ltrim($normalizedPath, '/'); return asset('storage/' . $normalizedPath); }; // Check if file is image $isImage = function($filePath) { $normalizedPath = str_replace('\\', '/', trim((string) $filePath)); $pathOnly = parse_url($normalizedPath, PHP_URL_PATH) ?? $normalizedPath; $ext = strtolower(pathinfo($pathOnly, PATHINFO_EXTENSION)); return in_array($ext, ['jpg', 'jpeg', 'png', 'gif']); }; $fileName = $detail->job_description ?? 'Dokumentasi'; @endphp {{-- Simple Button untuk buka semua lampiran --}} {{-- Modal untuk semua dokumentasi --}} @else Belum ada dokumentasi @endif
Belum ada pekerjaan yang perlu diverifikasi.
@endif
Pengajuan Aktif
@php $activeItems = $displayItems->filter(function ($item) use ($statusField) { $statusValue = strtolower($item->{$statusField} ?? ''); // Normalize status if (in_array($statusValue, ['reject'])) { $statusValue = 'rejected'; } elseif (in_array($statusValue, ['canceled', 'cancelled'])) { $statusValue = 'cancel'; } // Active = everything except finished (completed, rejected, cancel) return !in_array($statusValue, ['completed', 'rejected', 'cancel']); }); @endphp @forelse ($activeItems as $detail) @php $primary = ''; if (isset($table_primary_d) && count($table_primary_d) > 0) { foreach ($table_primary_d as $p) { $primary = $primary == '' ? $detail->{$p->field} : $primary . ':' . $detail->{$p->field}; } } if ($primary == '' && isset($detail->id)) { $primary = $detail->id; } $rawStatus = $detail->{$statusField} ?? ''; $status = strtolower($rawStatus); if (in_array($status, ['approved'], true)) { $status = 'review'; } elseif ($status === 'reject') { $status = 'rejected'; } elseif (in_array($status, ['canceled', 'cancelled'], true)) { $status = 'cancel'; } $badgeClass = 'status-badge status-' . ($status ?: 'pending'); @endphp @empty @endforelse
Aksi No ID Trans Tanggal Pengajuan Area Deskripsi Pelaksana Status Catatan Head Catatan HRD
@if ($primary != '')
@if ($authorize->edit == '1') @endif
@else @endif
{{ $loop->iteration }} {{ $detail->id_trans ?: '-' }} {{ \Carbon\Carbon::parse($detail->created_at)->format('d-m-Y') ?? '-' }} {{ $detail->area_name ?? $detail->area ?? $detail->area_id ?? '-' }} {{ $detail->job_description ?? $detail->description ?? '-' }} {{ $getPelaksanaLabel($detail) }} {{ $status ?: 'pending' }} {{ $detail->head_note ?? $detail->catatan_head ?? '-' }} {{ $detail->hrd_note ?? $detail->catatan_hrd ?? '-' }}
Tidak ada pengajuan aktif
Riwayat Pengajuan
@forelse ($historyItems as $detail) @php $primary = ''; if (isset($table_primary_d) && count($table_primary_d) > 0) { foreach ($table_primary_d as $p) { $primary = $primary == '' ? $detail->{$p->field} : $primary . ':' . $detail->{$p->field}; } } if ($primary == '' && isset($detail->id)) { $primary = $detail->id; } $rawStatus = $detail->{$statusField} ?? ''; $status = strtolower($rawStatus); if (in_array($status, ['approved'], true)) { $status = 'review'; } elseif ($status === 'reject') { $status = 'rejected'; } elseif (in_array($status, ['canceled', 'cancelled'], true)) { $status = 'cancel'; } $badgeClass = 'status-badge status-' . ($status ?: 'pending'); @endphp @empty @endforelse
Aksi No ID Trans Tanggal Pengajuan Area Deskripsi Pelaksana Status Catatan Head Catatan HRD
@if ($primary != '')
@if ($authorize->edit == '1') @endif
@else @endif
{{ $loop->iteration }} {{ $detail->id_trans ?: '-' }} {{ \Carbon\Carbon::parse($detail->created_at)->format('d-m-Y') ?? '-' }} {{ $detail->area_name ?? $detail->area ?? $detail->area_id ?? '-' }} {{ $detail->job_description ?? $detail->description ?? '-' }} {{ $getPelaksanaLabel($detail) }} {{ $status ?: '-' }} {{ $detail->head_note ?? '-' }} {{ $detail->hrd_note ?? '-' }}
{{-- Image Modal Lightbox --}}
× Preview
{{-- Modal Verifikasi --}}
{{-- Debug counts (visible while troubleshooting) --}}
@php $activeCountDebug = $displayItems->filter(function ($item) use ($statusField) { $s = strtolower($item->{$statusField} ?? ''); if (in_array($s, ['reject'])) $s = 'rejected'; if (in_array($s, ['canceled','cancelled'])) $s = 'cancel'; return !in_array($s, ['completed','rejected','cancel']); })->count(); $historyCountDebug = $displayItems->filter(function ($item) use ($statusField) { $s = strtolower($item->{$statusField} ?? ''); if (in_array($s, ['reject'])) $s = 'rejected'; if (in_array($s, ['canceled','cancelled'])) $s = 'cancel'; return in_array($s, ['completed','rejected','cancel']); })->count(); @endphp
DEBUG: Active items = {{ $activeCountDebug }}, History items = {{ $historyCountDebug }}
@push('js') @endpush @endsection