@extends('layouts.master') @section('title') {{ __('Admin Dashboard') }} @endsection @section('css') @if(request()->query('admin_tab') === 'workflow-templates') @endif @endsection @section('content') @php $activeAdminTab = $adminTab ?? request()->query('admin_tab'); if (!in_array($activeAdminTab, ['users', 'workflow-templates', 'document-types', 'organizations', 'role-permissions', 'audit-trails'], true)) { $activeAdminTab = null; } $adminPageTitle = [ 'users' => 'Users', 'workflow-templates' => 'Workflow Templates', 'document-types' => 'Document Types', 'organizations' => 'Organizations', 'role-permissions' => 'Role Permissions', 'audit-trails' => 'Audit Logs', ][$activeAdminTab] ?? 'Dashboard'; $locale = strtolower((string) app()->getLocale()); $localizedOrganizationName = function ($organization) use ($locale) { $fallback = trim((string) ($organization->name ?? '')); $english = trim((string) ($organization->name_en ?? '')); $khmer = trim((string) ($organization->name_kh ?? '')); if ($locale === 'kh') { return $khmer !== '' ? $khmer : ($english !== '' ? $english : $fallback); } return $english !== '' ? $english : $fallback; }; $activeOrganizations = ($organizations ?? collect()) ->where('is_active', true) ->values(); $activeWorkflowTemplates = ($workflowTemplates ?? collect()) ->where('is_active', true) ->values(); $activeOrganizationOptions = $activeOrganizations ->pluck('name') ->values(); $userOrganizationFilterOptions = ($organizations ?? collect()) ->map(fn ($organization) => [ 'value' => (string) ($organization->name ?? ''), 'label' => $localizedOrganizationName($organization), ]) ->filter(fn ($organization) => trim($organization['value']) !== '') ->values(); $organizationDisplayMap = $activeOrganizations ->mapWithKeys(fn ($organization) => [ (string) $organization->name => $localizedOrganizationName($organization), ]) ->toArray(); $allOrganizationDisplayMap = ($organizations ?? collect()) ->flatMap(function ($organization) use ($localizedOrganizationName) { $label = $localizedOrganizationName($organization); return collect([ (string) ($organization->name ?? '') => $label, (string) ($organization->name_en ?? '') => $label, (string) ($organization->name_kh ?? '') => $label, ])->filter(fn ($value, $key) => trim((string) $key) !== ''); }) ->toArray(); $organizationMap = $activeOrganizations->mapWithKeys(fn ($organization) => [ $organization->name => [ 'id' => $organization->id ?? null, ] ])->toArray(); $generalWorkflowOrganizationOptions = $activeOrganizations ->map(fn ($organization) => [ 'value' => (string) $organization->name, 'label' => $localizedOrganizationName($organization), ]) ->values() ->toArray(); $rectorUserOptionsJs = ($rectorUsers ?? collect()) ->map(fn ($user) => [ 'id' => $user->id, 'name' => $user->name, 'role' => strtolower((string) ($user->role ?? 'rector')), ]) ->values() ->toArray(); $rectorOnlyOptionsJs = collect($rectorUserOptionsJs) ->filter(fn ($user) => ($user['role'] ?? '') === 'rector') ->values() ->toArray(); $viceRectorOnlyOptionsJs = collect($rectorUserOptionsJs) ->filter(fn ($user) => ($user['role'] ?? '') === 'vice_rector') ->values() ->toArray(); $roleOrganizationOfficerMap = collect($userRoleOptions ?? []) ->keys() ->mapWithKeys(fn ($role) => [ (string) $role => \App\Support\WorkflowPermission::canUseAdminPermission( (string) $role, \App\Support\WorkflowPermission::ADMIN_PERMISSION_ORGANIZATION_OFFICER ), ]) ->toArray(); $workflowTemplateKpiCount = (int) ($kpi['workflow_templates'] ?? ($workflowTemplates ?? collect())->count()); $activeWorkflowTemplateKpiCount = (int) ($kpi['active_workflow_templates'] ?? $activeWorkflowTemplates->count()); $rolePermissionKpiCount = (int) ($kpi['role_permissions'] ?? (is_countable($rolePermissionRows ?? null) ? count($rolePermissionRows) : 0)); $auditTrailKpiCount = (int) ($kpi['audit_trails'] ?? (is_countable($auditTrails ?? null) ? count($auditTrails) : 0)); $adminDocumentChartColors = ['primary', 'success', 'warning', 'info', 'danger', 'secondary']; $adminDocumentChartCards = ($requests ?? collect()) ->groupBy(fn ($request) => trim((string) ($request->document_type_label ?: $request->document_type ?: __('N/A')))) ->map(fn ($items, $label) => [ 'label' => $label !== '' ? $label : __('N/A'), 'key' => md5(mb_strtolower((string) ($label !== '' ? $label : __('N/A')))), 'count' => $items->count(), ]) ->sortByDesc('count') ->values() ->map(function ($card, $index) use ($adminDocumentChartColors) { $card['color'] = $adminDocumentChartColors[$index % count($adminDocumentChartColors)]; return $card; }) ->all(); $adminDocumentChartMax = max(1, (int) collect($adminDocumentChartCards)->max('count')); @endphp @component('components.breadcrumb') @slot('li_1') {{ __('admin') }} @endslot @slot('title') {{ __($adminPageTitle) }} @endslot @endcomponent @if(!in_array($activeAdminTab, ['users', 'workflow-templates', 'document-types', 'organizations', 'role-permissions', 'audit-trails'], true))

{{ __('Total Documents') }}

{{ (int) ($kpi['total_documents'] ?? 0) }}

{{ __('All records') }}

{{ __('In Progress') }}

{{ (int) ($kpi['in_progress'] ?? 0) }}

{{ __('In progress') }}

{{ __('Approved') }}

{{ (int) ($kpi['approved_documents'] ?? 0) }}

{{ __('Approved documents') }}

{{ __('Overdue SLA') }}

{{ (int) ($kpi['overdue'] ?? 0) }}

{{ __('Past SLA time') }}

{{ __('Completed') }}

{{ (int) ($kpi['completed_documents'] ?? 0) }}

{{ __('Completed workflow') }}

{{ __('Rejected') }}

{{ (int) ($kpi['rejected'] ?? 0) }}

{{ __('Rejected documents') }}

@endif @if($activeAdminTab === 'role-permissions')

{{ __('Role Permissions') }}

{{ __('Enable or disable admin features for each role from one place.') }}

@php $permissionRows = $rolePermissionRows ?? []; $permissionLabels = $rolePermissionLabels ?? []; $roleNames = $roleDisplayNames ?? []; $roleStates = $roleActiveStates ?? []; $roleMeta = $rolePermissionMeta ?? []; $systemRoleKeys = \App\Support\WorkflowPermission::systemRoleKeys(); $permissionLockedRoleKeys = \App\Support\WorkflowPermission::permissionLockedRoleKeys(); $permissionSubtitles = [ 'can_request_document' => __('Create and submit new document requests.'), 'can_review_document' => __('Read and approve/reject a document at the assigned workflow step.'), 'is_organization_officer' => __('Requires an organization assignment and receives organization-routed workflow work.'), 'register_document_number' => __('Register registry and finished document numbers for requests.'), 'manage_users' => __('Manage user accounts, status, and role assignments.'), 'manage_organizations' => __('Create and maintain organization entries.'), 'manage_document_types' => __('Set document types, forms, and submitter roles.'), 'manage_workflow_templates' => __('Configure workflow paths and approval steps.'), 'manage_role_permissions' => __('Control which roles can use each admin feature.'), 'view_audit_trails' => __('View admin, workflow, and system activity history.'), 'use_priority_handling' => __('Enable priority processing for urgent requests.'), ]; $permissionSections = [ __('Document Access') => [ 'can_request_document', 'can_review_document', 'is_organization_officer', 'register_document_number', ], __('Admin Management') => [ 'manage_users', 'manage_organizations', 'manage_document_types', 'manage_workflow_templates', 'manage_role_permissions', 'view_audit_trails', ], __('Workflow Tools') => [ 'use_priority_handling', ], ]; @endphp
@csrf @php $filteredPermissionRows = $permissionRows; @endphp {{ __('Permission') }}
{{ __('Enable or disable each permission by role.') }}
@foreach($filteredPermissionRows as $roleKey => $permissions) @php $isSystemRole = in_array($roleKey, $systemRoleKeys, true); $isPermissionLockedRole = in_array($roleKey, $permissionLockedRoleKeys, true); $isActiveRole = (bool) ($roleStates[$roleKey] ?? true); $roleFormId = 'roleActionForm' . md5($roleKey); @endphp
{{ __($roleNames[$roleKey] ?? $roleKey) }}
@endforeach @if(empty($filteredPermissionRows)) {{ __('No roles available for permission editing.') }} @else @foreach($permissionSections as $sectionLabel => $sectionPermissions) @php $sectionKey = md5((string) $sectionLabel); $visibleSectionPermissions = collect($sectionPermissions) ->filter(fn ($permissionKey) => array_key_exists($permissionKey, $permissionLabels) && $permissionKey !== 'manage_role_permissions') ->values(); @endphp @continue($visibleSectionPermissions->isEmpty()) {{ $sectionLabel }} @foreach($visibleSectionPermissions as $permissionKey) @php $permissionLabel = $permissionLabels[$permissionKey]; @endphp {{ __($permissionLabel) }}
{{ $permissionSubtitles[$permissionKey] ?? __('Configure access for this feature.') }}
@foreach($filteredPermissionRows as $roleKey => $permissions) @php $isPermissionLockedRole = in_array($roleKey, $permissionLockedRoleKeys, true); $isInactiveRole = !(bool) ($roleStates[$roleKey] ?? true); $checked = (bool) ($permissions[$permissionKey] ?? false); @endphp
@endforeach @endforeach @endforeach @endif
@foreach($filteredPermissionRows as $roleKey => $permissions) @continue(in_array($roleKey, $systemRoleKeys, true)) @php $roleFormId = 'roleActionForm' . md5($roleKey); @endphp
@csrf @method('PATCH')
@csrf @method('DELETE')
@endforeach
@elseif($activeAdminTab === 'audit-trails')

{{ __('Audit Logs') }}

{{ __('Review important system, admin, and workflow actions.') }}

{{ __('Date') }} {{ __('Username') }} {{ __('Action Type') }} {{ __('Activity Type') }} {{ __('Detail') }} @forelse(($auditTrails ?? collect()) as $audit) @php $oldValues = is_array($audit->old_values) ? $audit->old_values : []; $newValues = is_array($audit->new_values) ? $audit->new_values : []; $metadata = is_array($audit->metadata) ? $audit->metadata : []; $action = (string) $audit->action; $actorName = $audit->actor_name ?: optional($audit->actor)->name ?: __('System'); $targetType = trim((string) ($audit->target_type ?? '')); $targetUser = $targetType === 'User' ? ($auditTargetUsers[$audit->target_id] ?? null) : null; $localizedTargetNames = $locale === 'kh' ? [ $newValues['name_kh'] ?? null, $oldValues['name_kh'] ?? null, $newValues['name_en'] ?? null, $oldValues['name_en'] ?? null, $newValues['name'] ?? null, $oldValues['name'] ?? null, ] : [ $newValues['name_en'] ?? null, $oldValues['name_en'] ?? null, $newValues['name'] ?? null, $oldValues['name'] ?? null, $newValues['name_kh'] ?? null, $oldValues['name_kh'] ?? null, ]; $targetName = trim((string) collect($localizedTargetNames) ->first(fn ($value) => trim((string) $value) !== '', ( $newValues['email'] ?? $oldValues['email'] ?? $newValues['role'] ?? $oldValues['role'] ?? optional($targetUser)->name ?? optional($targetUser)->email ?? optional($targetUser)->role ?? $metadata['document_name'] ?? $metadata['document_code'] ?? '' ))); $targetLabel = $targetName !== '' ? $targetName : ($targetType !== '' ? __($targetType) : __('N/A')); $actionLabel = __(ucwords(str_replace('_', ' ', $action))); $formatAuditField = function ($field) { return match ((string) $field) { 'name_en' => __('English Name'), 'name_kh' => __('Khmer Name'), default => __(ucwords(str_replace(['_', '-'], ' ', (string) $field))), }; }; $formatAuditValue = function ($value) { if (is_bool($value)) { return __($value ? 'Yes' : 'No'); } if ($value === null || $value === '') { return __('Empty'); } if (is_array($value)) { return implode(', ', array_map(fn ($item) => is_scalar($item) ? (string) $item : json_encode($item, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), $value)); } return (string) $value; }; $changedFieldKey = collect($newValues) ->keys() ->first(function ($key) use ($oldValues, $newValues) { return !in_array((string) $key, ['created_at', 'updated_at'], true) && array_key_exists($key, $oldValues) && $oldValues[$key] !== $newValues[$key]; }); $changeText = $changedFieldKey !== null ? __(':field changed from :old to :new.', [ 'field' => $formatAuditField($changedFieldKey), 'old' => $formatAuditValue($oldValues[$changedFieldKey] ?? null), 'new' => $formatAuditValue($newValues[$changedFieldKey] ?? null), ]) : ''; $workflowAction = strtolower((string) ($newValues['action'] ?? $metadata['action'] ?? '')); if ((bool) ($metadata['returned_back'] ?? false)) { $workflowAction = 'return_back'; } $workflowVerb = match ($workflowAction) { 'forward', 'forward_to_rector' => __('forwarded'), 'send_back', 'request_revision' => __('sent back'), 'return_back' => __('returned back'), 'approve', 'approve_document' => __('approved'), 'reject', 'reject_document' => __('rejected'), 'complete', 'complete_post_approval_processing', 'mark_requirements_done' => __('completed'), 'request_more_information' => __('requested more information for'), default => __('updated'), }; $formatWorkflowState = function ($state) { $state = trim((string) $state); if ($state === '') { return __('Unknown Step'); } return __(ucwords(str_replace(['_', '-'], ' ', $state))); }; $fromStateLabel = $formatWorkflowState($metadata['from_state'] ?? ''); $toStateLabel = $formatWorkflowState($metadata['to_state'] ?? ''); $workflowText = match ($workflowAction) { 'forward', 'forward_to_rector', 'send_back', 'request_revision', 'return_back', 'approve', 'approve_document', 'reject', 'reject_document', 'complete', 'complete_post_approval_processing', 'mark_requirements_done', 'request_more_information' => __(':action document :document from :from to :to.', [ 'action' => $workflowVerb, 'document' => $targetLabel, 'from' => $fromStateLabel, 'to' => $toStateLabel, ]), default => __('Updated workflow for document :document.', ['document' => $targetLabel]), }; $workflowText = trim($workflowText); $actionType = match ($action) { 'user_created', 'role_created', 'organization_created', 'document_type_created', 'workflow_template_created', 'document_request_created' => __('Create'), 'user_updated', 'role_updated', 'role_permissions_updated', 'role_permissions_bulk_updated', 'register_document_number', 'organization_updated', 'document_type_updated', 'workflow_template_updated' => __('Update'), 'user_status_toggled', 'role_status_toggled', 'organization_status_toggled', 'document_type_status_toggled', 'workflow_template_status_toggled' => __('Status Change'), 'user_password_reset' => __('Reset Password'), 'user_deleted', 'role_deleted', 'organization_deleted', 'document_type_deleted', 'workflow_template_deleted' => __('Delete'), 'workflow_transition' => match ($workflowAction) { 'forward', 'forward_to_rector' => __('Forwarded'), 'send_back', 'request_revision' => __('Sent Back'), 'return_back' => __('Returned Back'), 'approve', 'approve_document' => __('Approved'), 'reject', 'reject_document' => __('Rejected'), 'complete', 'complete_post_approval_processing', 'mark_requirements_done' => __('Completed'), 'request_more_information' => __('Requested More Information'), default => __('Update'), }, default => $actionLabel, }; $activityType = match ($action) { 'user_created', 'user_updated', 'user_status_toggled', 'user_password_reset', 'user_deleted' => __('User'), 'role_created', 'role_updated', 'role_status_toggled', 'role_deleted', 'role_permissions_updated', 'role_permissions_bulk_updated' => __('Role'), 'organization_created', 'organization_updated', 'organization_status_toggled', 'organization_deleted' => __('Organization'), 'document_type_created', 'document_type_updated', 'document_type_status_toggled', 'document_type_deleted' => __('Document Type'), 'workflow_template_created', 'workflow_template_updated', 'workflow_template_status_toggled', 'workflow_template_deleted' => __('Workflow Template'), 'workflow_transition', 'document_request_created', 'register_document_number' => __('Document'), default => $targetType !== '' ? __($targetType) : __('System'), }; $actionBadgeKey = match ($action) { 'user_created', 'role_created', 'organization_created', 'document_type_created', 'workflow_template_created', 'document_request_created' => 'create', 'user_updated', 'role_updated', 'role_permissions_updated', 'role_permissions_bulk_updated', 'register_document_number', 'organization_updated', 'document_type_updated', 'workflow_template_updated' => 'update', 'user_status_toggled', 'role_status_toggled', 'organization_status_toggled', 'document_type_status_toggled', 'workflow_template_status_toggled' => 'status_change', 'user_password_reset' => 'reset_password', 'user_deleted', 'role_deleted', 'organization_deleted', 'document_type_deleted', 'workflow_template_deleted' => 'delete', 'workflow_transition' => match ($workflowAction) { 'forward', 'forward_to_rector' => 'forwarded', 'send_back', 'request_revision' => 'send_back', 'return_back' => 'returned_back', 'approve', 'approve_document' => 'approved', 'reject', 'reject_document' => 'rejected', 'complete', 'complete_post_approval_processing', 'mark_requirements_done' => 'completed', 'request_more_information' => 'commented', default => 'update', }, default => $action, }; $activityBadgeKey = match ($action) { 'user_created', 'user_updated', 'user_status_toggled', 'user_password_reset', 'user_deleted' => 'user', 'role_created', 'role_updated', 'role_status_toggled', 'role_deleted', 'role_permissions_updated', 'role_permissions_bulk_updated' => 'role', 'organization_created', 'organization_updated', 'organization_status_toggled', 'organization_deleted' => 'organization', 'document_type_created', 'document_type_updated', 'document_type_status_toggled', 'document_type_deleted' => 'document_type', 'workflow_template_created', 'workflow_template_updated', 'workflow_template_status_toggled', 'workflow_template_deleted' => 'workflow_template', 'workflow_transition', 'document_request_created', 'register_document_number' => 'document', default => $targetType !== '' ? $targetType : 'audit', }; $changedFieldLabel = $changedFieldKey !== null ? $formatAuditField($changedFieldKey) : ''; $detailText = match ($action) { 'user_created' => __('Created user [:target]', ['target' => $targetLabel]), 'user_updated' => $changedFieldLabel !== '' ? __('Updated user :field [:target]', ['field' => strtolower($changedFieldLabel), 'target' => $targetLabel]) : __('Updated user [:target]', ['target' => $targetLabel]), 'user_status_toggled' => __('Changed user status [:target]', ['target' => $targetLabel]), 'user_password_reset' => __('Reset password for user [:target]', ['target' => $targetLabel]), 'user_deleted' => __('Deleted user [:target]', ['target' => $targetLabel]), 'role_created' => __('Created role [:target]', ['target' => $targetLabel]), 'role_updated' => $changedFieldLabel !== '' ? __('Updated role :field [:target]', ['field' => strtolower($changedFieldLabel), 'target' => $targetLabel]) : __('Updated role [:target]', ['target' => $targetLabel]), 'role_status_toggled' => __('Changed role status [:target]', ['target' => $targetLabel]), 'role_deleted' => __('Deleted role [:target]', ['target' => $targetLabel]), 'role_permissions_updated', 'role_permissions_bulk_updated' => __('Updated role permissions'), 'organization_created' => __('Created organization [:target]', ['target' => $targetLabel]), 'organization_updated' => $changedFieldLabel !== '' ? __('Updated organization :field [:target]', ['field' => strtolower($changedFieldLabel), 'target' => $targetLabel]) : __('Updated organization [:target]', ['target' => $targetLabel]), 'organization_status_toggled' => __('Changed organization status [:target]', ['target' => $targetLabel]), 'organization_deleted' => __('Deleted organization [:target]', ['target' => $targetLabel]), 'document_type_created' => __('Created document type [:target]', ['target' => $targetLabel]), 'document_type_updated' => $changedFieldLabel !== '' ? __('Updated document type :field [:target]', ['field' => strtolower($changedFieldLabel), 'target' => $targetLabel]) : __('Updated document type [:target]', ['target' => $targetLabel]), 'document_type_status_toggled' => __('Changed document type status [:target]', ['target' => $targetLabel]), 'document_type_deleted' => __('Deleted document type [:target]', ['target' => $targetLabel]), 'workflow_template_created' => __('Created workflow template [:target]', ['target' => $targetLabel]), 'workflow_template_updated' => $changedFieldLabel !== '' ? __('Updated workflow template :field [:target]', ['field' => strtolower($changedFieldLabel), 'target' => $targetLabel]) : __('Updated workflow template [:target]', ['target' => $targetLabel]), 'workflow_template_status_toggled' => __('Changed workflow template status [:target]', ['target' => $targetLabel]), 'workflow_template_deleted' => __('Deleted workflow template [:target]', ['target' => $targetLabel]), 'workflow_transition' => __(':action document [:document] from :from to :to', [ 'action' => ucfirst((string) $workflowVerb), 'document' => $targetLabel, 'from' => $fromStateLabel, 'to' => $toStateLabel, ]), 'document_request_created' => __('Created document request [:target]', ['target' => $targetLabel]), 'register_document_number' => __('Registered document number [:number] for document [:target]', [ 'number' => (string) data_get($newValues, 'registry_document_number', ''), 'target' => $targetLabel, ]), default => __('Performed :action [:target]', [ 'action' => strtolower($actionLabel), 'target' => $targetLabel, ]), }; @endphp {{ \App\Support\DateFormatter::localized($audit->created_at, 'd F, Y h:i A') }}
{{ $actorName }}
{{ $detailText }}
@empty {{ __('No audit trail records yet.') }} @endforelse
@elseif($activeAdminTab === 'users')

{{ __('Users') }}

{{ __('Manage user accounts, roles, organizations, and status.') }}

{{ __('Name') }} {{ __('Email') }} {{ __('Role') }} {{ __('Organization') }} {{ __('Status') }} {{ __('Actions') }} @forelse(($users ?? collect()) as $userItem) @php $roleKey = \App\Support\WorkflowPermission::normalizeRole((string) ($userItem->role ?? 'user')); $organizationRaw = trim((string) ($userItem->organization_name ?? '')); $organizationLabel = $organizationRaw !== '' ? ($allOrganizationDisplayMap[$organizationRaw] ?? $organizationRaw) : '-'; $roleLabel = __($userRoleOptions[$roleKey] ?? ucwords(str_replace(['-', '_'], ' ', $roleKey))); $employeeCode = (string) $userItem->id; @endphp

{{ $userItem->name }}

{{ $userItem->email }} {{ $organizationLabel }} @php $activeLabel = ($userItem->is_active ?? true) ? 'Active' : 'Disabled'; @endphp @empty {{ __('No users found.') }} @endforelse
{{-- Edit User Modal --}} {{-- Reset User Password Modal --}} {{-- Hidden form for toggle status --}} {{-- Hidden form for delete user --}} @elseif($activeAdminTab === 'organizations') {{-- Organizations Tab --}}

{{ __('Organizations') }}

{{ __('Manage the organizations used by users and workflow routing.') }}

{{ __('Name') }} {{ __('Officers') }} {{ __('Status') }} {{ __('Actions') }} @forelse(($organizations ?? collect())->values() as $organization) @php $organizationNameEn = trim((string) ($organization->name_en ?? $organization->name ?? '')); $organizationNameKh = trim((string) ($organization->name_kh ?? '')); $organizationDisplayName = $locale === 'kh' && $organizationNameKh !== '' ? $organizationNameKh : $organizationNameEn; @endphp

{{ $organizationDisplayName }}

@if($organizationNameEn !== '' && $organizationNameKh !== '' && $organizationNameEn !== $organizationDisplayName) {{ $organizationNameEn }} @endif {{ $organization->users_count ?? 0 }} {{ __($organization->is_active ? 'Active' : 'Inactive') }} @empty {{ __('No organizations found.') }} @endforelse
@elseif($activeAdminTab === 'document-types') {{-- Document Types Tab --}}

{{ __('Document Types') }}

{{ __('Manage document categories, SLAs, and linked workflows.') }}

@php $submitterRoleShortNames = [ \App\Support\WorkflowPermission::ROLE_REQUESTER => 'USR', \App\Support\WorkflowPermission::ROLE_VICE_RECTOR => 'V-R', \App\Support\WorkflowPermission::ROLE_RECTOR => 'R', \App\Support\WorkflowPermission::ROLE_ADMIN => 'ADM', ]; $defaultSubmitterRoles = array_keys((array) ($submitterRoleOptions ?? [])); @endphp {{ __('Name') }} {{ __('Workflow Template') }} {{ __('Submitters') }} {{ __('Status') }} {{ __('Actions') }} @forelse(($documentTypes ?? collect()) as $dt) @php $dtNameEn = trim((string) ($dt->name_en ?? $dt->name ?? '')); $dtNameKh = trim((string) ($dt->name_kh ?? '')); $dtDisplayName = $locale === 'kh' && $dtNameKh !== '' ? $dtNameKh : $dtNameEn; $allowedSubmitterRoles = collect($dt->allowed_submitter_roles ?? $defaultSubmitterRoles) ->map(fn ($role) => (string) $role) ->filter(fn ($role) => $role !== '') ->unique() ->values(); if ($allowedSubmitterRoles->isEmpty()) { $allowedSubmitterRoles = collect($defaultSubmitterRoles); } @endphp

{{ $dtDisplayName }}

@if($dtNameEn !== '' && $dtNameKh !== '' && $dtNameEn !== $dtDisplayName) {{ $dtNameEn }} @endif @if($dt->workflowTemplate) {{ $dt->workflowTemplate->name }} @else -- @endif
@foreach($allowedSubmitterRoles as $submitterRole) @php $submitterRoleLabel = $submitterRoleOptions[$submitterRole] ?? ucwords(str_replace(['_', '-'], ' ', $submitterRole)); $submitterRoleShort = $submitterRoleShortNames[$submitterRole] ?? strtoupper(substr(preg_replace('/[^A-Za-z0-9]/', '', $submitterRole), 0, 3)); @endphp {{ $submitterRoleShort }} @endforeach
{{ __($dt->is_active ? 'Active' : 'Inactive') }} @empty {{ __('No document types found.') }} @endforelse
{{-- Create Document Type Modal --}} {{-- Edit Document Type Modal --}} {{-- Hidden toggle form --}} {{-- Hidden delete form --}} @elseif($activeAdminTab === 'workflow-templates') {{-- Workflow Templates Tab --}}

{{ __('Workflow Templates') }}

{{ __('Manage reusable routing flows that can be linked to document types.') }}

{{ __('Name') }} {{ __('Used By Document Types') }} {{ __('Stages') }} {{ __('Status') }} {{ __('Actions') }} @forelse(($workflowTemplates ?? collect()) as $wft)

{{ $wft->name }}

@if($wft->description) {{ $wft->description }} @endif @if($wft->documentTypes->count())
@foreach($wft->documentTypes as $documentType) {{ $documentType->name }} @endforeach
@else {{ __('Not linked yet') }} @endif @php $steps = $wft->steps ?? []; @endphp @if(count($steps)) @php $visibleSteps = array_values($steps); @endphp
@foreach($visibleSteps as $index => $step) @php $stepType = $step['step_type'] ?? ''; $stepOrganizationName = $step['organization_name'] ?? ''; $stepTypeLabel = match($stepType) { 'start_organization' => __('Submission Stage'), 'vice_rector' => __('Vice Rector Review'), 'approval' => __('Rector Review'), default => null, }; if ($stepTypeLabel !== null) { $stageDisplay = $stepTypeLabel; } elseif ($stepOrganizationName !== '') { // Resolve localized organization name from the map $stageDisplay = $allOrganizationDisplayMap[$stepOrganizationName] ?? $stepOrganizationName; } else { $stageDisplay = __($step['label'] ?? \App\Models\WorkflowTemplate::stateLabel($step['from_state'] ?? '')); } @endphp {{ $stageDisplay }} @if(!$loop->last) @endif @endforeach
@else {{ __('No stages defined') }} @endif {{ __($wft->is_active ? 'Active' : 'Inactive') }} @empty {{ __('No workflow templates found.') }} @endforelse
{{-- Create Workflow Template Modal --}} {{-- Edit Workflow Template Modal --}} {{-- Hidden toggle form --}} {{-- Hidden delete form --}} @else @php $adminDocumentStatusFilterMap = collect(\App\Support\WorkflowPermission::dashboardStatusFilterMap('admin')) ->except('Total Documents') ->all(); $adminDocumentStatusResolver = fn ($request) => \App\Support\WorkflowPermission::dashboardStatus( $request, (string) (Auth::user()->role ?? 'admin'), (int) (Auth::id() ?? 0) ); @endphp @endif @endsection @section('script') @if(session('success')) @endif @if(session('error')) @endif @if($activeAdminTab === 'role-permissions') @endif @endsection