@php // Use $user_login from controller (already passed to all views) $currentUser = $user_login ?? auth()->user(); if (!$currentUser && session()->has('username')) { $currentUser = \Illuminate\Support\Facades\DB::table('users') ->where('username', session('username')) ->first(); } $currentUserId = $currentUser ? $currentUser->id : null; $currentUserRoles = $currentUser ? (string) ($currentUser->idroles ?? '') : ''; $normalizedRoles = ',' . str_replace(' ', '', strtolower($currentUserRoles)) . ','; $isPetugasOffice = str_contains($normalizedRoles, ',ptgoff,'); $isPetugasPU = str_contains($normalizedRoles, ',ptgspu,'); // Get all user IDs with ptgoff role for Office filtering $officeRoleUserIds = []; if ($isPetugasOffice) { $officeRoleUserIds = \Illuminate\Support\Facades\DB::table('users') ->whereRaw("FIND_IN_SET('ptgoff', REPLACE(idroles, ' ', ''))") ->where('isactive', '1') ->pluck('id') ->toArray(); } $nonPeriodicItems = \Illuminate\Support\Facades\DB::table('tr_non_periodic') ->leftJoin('ms_area', 'tr_non_periodic.area_id', '=', 'ms_area.id') ->select( 'tr_non_periodic.id', 'tr_non_periodic.request_status', 'tr_non_periodic.job_description', 'tr_non_periodic.work_type', 'tr_non_periodic.*', 'ms_area.nama_area as area_name' ) ->whereIn('tr_non_periodic.request_status', ['pengadaan', 'pengerjaan', 'revisi']) ->where('tr_non_periodic.is_active', '1'); // Apply role-based filter: Petugas Office only sees assigned tasks, Petugas PU sees all if ($isPetugasOffice && !empty($officeRoleUserIds)) { $nonPeriodicItems->whereIn('tr_non_periodic.worker_id', $officeRoleUserIds); } $nonPeriodicItems = $nonPeriodicItems->orderBy('tr_non_periodic.created_at', 'desc')->get(); // Parse attachment files from each item $nonPeriodicItems = $nonPeriodicItems->map(function ($item) { $attachments = []; if (!empty($item->attachment)) { $rawAttachment = $item->attachment; $decoded = json_decode($rawAttachment, true); if (is_array($decoded)) { $attachments = $decoded; } else { $parts = array_map('trim', explode(',', $rawAttachment)); $attachments = array_filter($parts); } } $revisionAttachments = []; if (!empty($item->revision_attachment)) { $rawRevisionAttachment = $item->revision_attachment; $decodedRevision = json_decode($rawRevisionAttachment, true); if (is_array($decodedRevision)) { $revisionAttachments = $decodedRevision; } else { $partsRevision = array_map('trim', explode(',', $rawRevisionAttachment)); $revisionAttachments = array_filter($partsRevision); } } $item->attachments = array_values($attachments); $item->revision_attachments = array_values($revisionAttachments); return $item; }); $getPelaksanaLabel = function ($item) { $workType = strtolower(trim((string) ($item->work_type ?? ''))); if ($workType === 'internal') return 'Internal'; if ($workType === 'vendor') return 'Vendor'; return '-'; }; $getPelaksanaClass = function ($item) { $workType = strtolower(trim((string) ($item->work_type ?? ''))); if ($workType === 'internal') return 'pu-badge-internal'; if ($workType === 'vendor') return 'pu-badge-vendor'; return 'pu-badge-muted'; }; @endphp
Daftar Pekerjaan
@forelse ($nonPeriodicItems as $detail) @php $rawStatus = $detail->request_status ?? ''; $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'; } $dateValue = $detail->created_at ?? $detail->tanggal ?? $detail->date ?? null; $displayDate = $dateValue ? \Illuminate\Support\Carbon::parse($dateValue)->format('d-m-Y') : '-'; @endphp @empty @endforelse
Aksi Tanggal Pengajuan Area Deskripsi Pelaksana Status Catatan Revisi
@php $fmtEst = fn($v) => $v ? \Illuminate\Support\Carbon::parse($v)->format('d-m-Y') : '-'; @endphp @if ($status !== 'pengadaan') @else @endif
{{ $displayDate }} {{ $detail->area_name ?? $detail->area ?? $detail->area_id ?? '-' }} {{ $detail->job_description ?? $detail->description ?? '-' }} {{ $getPelaksanaLabel($detail) }} @php $statusNormalized = strtolower(trim($status ?? '')); $badgeClass = 'status-badge status-' . ($statusNormalized ?: 'pending'); $statusLabel = $statusNormalized ? ucfirst($statusNormalized) : 'Pending'; @endphp {{ $statusLabel }} @php $requesterNote = data_get($detail, 'requester_note'); @endphp @if($status === 'revisi' && !empty($requesterNote)) {{ $requesterNote }} @else - @endif
@php $petugasList = \Illuminate\Support\Facades\DB::table('ms_employee') ->where('is_active', '1') ->where('role', 'ptgspu') ->whereNotNull('nama') ->whereRaw("TRIM(nama) <> ''") ->orderBy('nama') ->pluck('nama') ->filter(fn ($nama) => is_string($nama) && trim($nama) !== '') ->unique() ->values(); @endphp @push('js') @endpush