@extends('layouts.app') @section('title', 'View Enquiry') @section('content')

{{ ucfirst(str_replace('_', ' ', $enquiry->type)) }} Details

Complete enquiry information and processing status

@if($enquiry->registered_by == auth()->user()->id && $enquiry->status == 'pending') Edit Enquiry @endif
APPLICANT INFORMATION
@if(auth()->user()->hasRole('registrar_hq')) @if(in_array($enquiry->status, ['pending', 'pending_overdue'])) @elseif(in_array($enquiry->status, ['assigned', 'pending_overdue'])) @endif @endif @if($enquiry->registered_by == auth()->user()->id && $enquiry->status == 'pending') Edit @endif @if($enquiry->registered_by == auth()->user()->id && in_array($enquiry->status, ['pending', 'rejected']) && $enquiry->status != 'assigned')
@csrf @method('DELETE')
@endif
Full Name {{ $enquiry->full_name }}
Force Number {{ $enquiry->force_no }}
Phone {{ $enquiry->phone }}
Date Received {{ $enquiry->date_received }}
Check Number {{ $enquiry->check_number }}
Enquiry Type {{ ucfirst(str_replace('_', ' ', $enquiry->type)) }}
Account Number {{ $enquiry->account_number }}
Bank Name {{ $enquiry->bank_name }}
Region {{ $enquiry->region->name ?? 'No Region' }}
District {{ $enquiry->district->name ?? 'No District' }}
Attached Documents
@if ($enquiry->folios->isNotEmpty())
@foreach ($enquiry->folios as $index => $folio) @if (strtolower(pathinfo($folio->file_path, PATHINFO_EXTENSION)) === 'pdf')

{{ basename($folio->file_path) }}

Download
@else
📎

{{ basename($folio->file_path) }}

Download
@endif @endforeach
@else
📭

No documents

@endif
REGISTRAR & ASSIGNED USERS
REGISTRAR
Name {{ $enquiry->registeredBy->name ?? 'N/A' }}
Command {{ $enquiry->registeredBy->command->name ?? 'N/A' }}
Phone {{ $enquiry->registeredBy->phone_number ?? 'N/A' }}
Region {{ $enquiry->registeredBy->region->name ?? 'N/A' }}
District {{ $enquiry->registeredBy->district->name ?? 'N/A' }}
ASSIGNED TO
@if ($enquiry->assignedUsers->isNotEmpty()) @foreach ($enquiry->assignedUsers as $assignedUser)
Name {{ $assignedUser->name }}
Phone {{ $assignedUser->phone_number ?? 'N/A' }}
Region {{ $assignedUser->region->name ?? 'N/A' }}
District {{ $assignedUser->district->name ?? 'N/A' }}
Role {{ $enquiry->users->first()->getRoleNames()->first() ?? 'N/A' }}
@endforeach @else
Not yet assigned
@endif
@if ($enquiry->folios->isNotEmpty()) @foreach ($enquiry->folios as $index => $folio) @if (strtolower(pathinfo($folio->file_path, PATHINFO_EXTENSION)) === 'pdf') @endif @endforeach @endif @if($enquiry->childData)
{{ ucfirst(str_replace('_', ' ', $enquiry->type)) }} Specific Details
@switch($enquiry->type) @case('loan_application') @if($enquiry->loanApplication)
Requested Amount {{ number_format($enquiry->loanApplication->requested_amount ?? 0, 0) }} TZS
Processed Amount {{ number_format($enquiry->loanApplication->loan_amount ?? 0, 0) }} TZS
Loan Duration {{ $enquiry->loanApplication->loan_duration ?? 'N/A' }} months
Interest Rate {{ $enquiry->loanApplication->interest_rate ?? 'N/A' }}%
Monthly Deduction {{ number_format($enquiry->loanApplication->monthly_deduction ?? 0, 0) }} TZS
Total Loan with Interest {{ number_format($enquiry->loanApplication->total_loan_with_interest ?? 0, 0) }} TZS
Total Interest {{ number_format($enquiry->loanApplication->total_interest ?? 0, 0) }} TZS
Processing Fee {{ number_format($enquiry->loanApplication->processing_fee ?? 0, 0) }} TZS
Insurance {{ number_format($enquiry->loanApplication->insurance ?? 0, 0) }} TZS
Disbursement Amount {{ number_format($enquiry->loanApplication->disbursement_amount ?? 0, 0) }} TZS
Loan Purpose {{ $enquiry->loanApplication->loan_type ?? 'N/A' }}
@endif @break @case('refund') @if($enquiry->refund)
Refund Amount {{ number_format($enquiry->refund->refund_amount ?? 0, 0) }} TZS
Refund Duration {{ $enquiry->refund->refund_duration ?? 'N/A' }} months
@endif @break @case('retirement') @if($enquiry->retirement)
Date of Retirement: {{ $enquiry->retirement->date_of_retirement ?? 'N/A' }}
@endif @break @case('condolences') @if($enquiry->condolence)
Gender: {{ ucfirst($enquiry->condolence->gender ?? 'N/A') }}
Dependent Member Type: {{ ucfirst($enquiry->condolence->dependent_member_type ?? 'N/A') }}
@endif @break @case('deduction_add') @if($enquiry->deduction)
From Amount: {{ number_format($enquiry->deduction->from_amount ?? 0, 0) }} TZS
To Amount: {{ number_format($enquiry->deduction->to_amount ?? 0, 0) }} TZS
Change: {{ number_format($enquiry->deduction->changes ?? 0, 0) }} TZS
Status: {{$enquiry->deduction->status ?? 'N/A' }}
@endif @break @case('injured_at_work') @if($enquiry->injury)
@if($enquiry->injury->description)
Injury Description: {{ $enquiry->injury->description }}
@endif
@endif @break @case('share_enquiry') @case('withdraw_savings') @case('withdraw_deposit') {{-- Hizi kesi zina data nyingi, List Group Items zinafaa zaidi kutumika bila gridi ili zionekane vizuri wima. Lakini kwa kuwa tayari ulikuwa na gridi, nitaziweka kwenye List Group Items za kiwango kimoja kwa kila kisa cha kujirudia ili kufanya iwe wima. --}} {{-- Kwa case ya 'share_enquiry' --}} @if($enquiry->type == 'share_enquiry' && $enquiry->share)
Share Amount: {{ number_format($enquiry->share->share_amount ?? 0, 0) }} TZS
@endif {{-- Kwa case ya 'withdraw_savings' au 'withdraw_deposit' (Zote zina data sawa) --}} @if(($enquiry->type == 'withdraw_savings' || $enquiry->type == 'withdraw_deposit') && $enquiry->withdrawal)
Withdrawal Amount: {{ number_format($enquiry->withdrawal->amount ?? 0, 0) }} TZS
Withdrawal Type: {{ ucfirst($enquiry->withdrawal->type ?? str_replace('_', ' ', $enquiry->type)) }}
Request Date: {{ $enquiry->withdrawal->created_at?? 'N/A' }}
Reason: {{ $enquiry->withdrawal->reason?? 'N/A' }}
Days: {{ $enquiry->withdrawal->days?? 'N/A' }}
@endif @break {{-- break inafaa hapa baada ya kumaliza 'withdraw' cases zote --}} @case('join_membership') @case('unjoin_membership') @if($enquiry->membershipChange)
Category: {{ ucfirst($enquiry->membershipChange->category ?? 'N/A') }}
Action: {{ ucfirst($enquiry->membershipChange->action ?? 'N/A') }}
@endif @break @case('sick_for_30_days') @if($enquiry->sickLeave)
Start Date: {{ $enquiry->sickLeave->startdate ?? 'N/A' }}
End Date: {{ $enquiry->sickLeave->enddate ?? 'N/A' }}
Total Days: {{ $enquiry->sickLeave->days ?? 'N/A' }}
@endif @break @case('ura_mobile') @if($enquiry->uraMobile)
Service Type: {{ $enquiry->uraMobile->service_type ?? 'N/A' }}
Phone Number: {{ $enquiry->uraMobile->phone_number ?? 'N/A' }}
@endif @break @case('residential_disaster') @if($enquiry->residentialDisaster)
Disaster Type: {{ ucfirst($enquiry->residentialDisaster->disaster_type ?? 'N/A') }}
@endif @break @default
No specific details available for this enquiry type

General enquiry information is displayed in the sections above.

@endswitch
@endif
Enquiry Timeline & Status History
@php $now = now(); $isOverdue = $enquiry->status == 'pending' && $enquiry->created_at->diffInWeekdays($now) >= 3; $hasAssignment = $enquiry->users->count() > 0; $isLoanType = $enquiry->type == 'loan_application'; // Calculate progress percentage based on type and status $progressPercent = 0; $totalSteps = 0; $currentStep = 0; $isRejected = false; if ($isLoanType) { // For loan applications, check loan_application status $loanStatus = $enquiry->loanApplication ? $enquiry->loanApplication->status : $enquiry->status; $isRejected = $loanStatus == 'rejected'; if ($isRejected) { // If rejected, progress is 100% but with red color $progressPercent = 100; } else { $totalSteps = 5; // pending, assigned, processed, approved, paid if ($loanStatus == 'pending') { $currentStep = 1; } elseif ($loanStatus == 'assigned') { $currentStep = 2; } elseif ($loanStatus == 'processed') { $currentStep = 3; } elseif ($loanStatus == 'approved') { $currentStep = 4; } elseif ($loanStatus == 'paid') { $currentStep = 5; } $progressPercent = ($currentStep / $totalSteps) * 100; } } else { // For payments, check payment status $paymentStatus = isset($enquiry->payment) ? $enquiry->payment->status : $enquiry->status; $isRejected = $paymentStatus == 'rejected' || $enquiry->status == 'rejected'; if ($isRejected) { // If rejected, progress is 100% but with red color $progressPercent = 100; } else { $totalSteps = 5; // pending, assigned, initiated, approved, paid if ($enquiry->status == 'pending') { $currentStep = 1; } elseif ($enquiry->status == 'assigned') { $currentStep = 2; } elseif (isset($enquiry->payment) && $enquiry->payment->status == 'initiated') { $currentStep = 3; } elseif (isset($enquiry->payment) && $enquiry->payment->status == 'approved') { $currentStep = 4; } elseif (isset($enquiry->payment) && $enquiry->payment->status == 'paid') { $currentStep = 5; } $progressPercent = ($currentStep / $totalSteps) * 100; } } @endphp
Processing Progress
{{ number_format($progressPercent, 0) }}% {{ $isRejected ? '- REJECTED' : '' }}
@if($isRejected) {{ $isLoanType ? 'Loan Application' : 'Payment Request' }} Rejected @else Step {{ $currentStep }} of {{ $totalSteps }} @endif
Enquiry Registered (Pending)
{{ $enquiry->created_at->format('M d, Y - H:i') }}

Enquiry submitted by {{ $enquiry->registeredBy->name ?? 'System' }}

Type: {{ ucfirst(str_replace('_', ' ', $enquiry->type)) }}
@if($hasAssignment) Assigned to User @else Awaiting Assignment @endif
@if($hasAssignment) {{ $enquiry->updated_at->format('M d, Y - H:i') }} @endif
@if($hasAssignment)

Assigned to {{ $enquiry->users->first()->name }} {{ $enquiry->users->first()->getRoleNames()->first() }}

@else

Waiting for assignment to appropriate officer

@if($isOverdue) Overdue ({{ $enquiry->created_at->diffInWeekdays($now) }} days) @endif
@endif
@php // Check rejection based on type if ($isLoanType) { $isStatusRejected = $enquiry->loanApplication && $enquiry->loanApplication->status == 'rejected'; } else { $isStatusRejected = (isset($enquiry->payment) && $enquiry->payment->status == 'rejected') || $enquiry->status == 'rejected'; } @endphp @if($isStatusRejected)
{{ $isLoanType ? 'Loan' : 'Payment' }} Rejected
{{ $enquiry->updated_at->format('M d, Y - H:i') }}
@php $rejection = \App\Models\Rejection::where('enquiry_id', $enquiry->id)->latest()->first(); @endphp @if($isLoanType && $enquiry->loanApplication && $enquiry->loanApplication->rejectedBy)

Loan rejected by {{ $enquiry->loanApplication->rejectedBy->name }} {{ $enquiry->loanApplication->rejectedBy->getRoleNames()->first() ?? 'N/A' }}

@elseif(!$isLoanType && isset($enquiry->payment) && $enquiry->payment->rejectedBy)

Payment rejected by {{ $enquiry->payment->rejectedBy->name }} {{ $enquiry->payment->rejectedBy->getRoleNames()->first() ?? 'N/A' }}

@else

{{ $isLoanType ? 'Loan application' : 'Payment request' }} has been rejected

@endif @if($rejection)
Rejection Reason:

{{ $rejection->reason_text ?? $rejection->rejection_reason }}

@if($rejection->rejection_detail) Details: {{ $rejection->rejection_detail }} @endif
@endif
@elseif($isLoanType) @php $loanStatus = $enquiry->loanApplication ? $enquiry->loanApplication->status : 'pending'; @endphp
@if(in_array($loanStatus, ['processed', 'approved', 'paid'])) Loan Processed @else Awaiting Processing @endif
@if(in_array($loanStatus, ['processed', 'approved', 'paid'])) {{ $enquiry->loanApplication->updated_at->format('M d, Y - H:i') }} @endif
@if(in_array($loanStatus, ['processed', 'approved', 'paid'])) @if($enquiry->loanApplication && $enquiry->loanApplication->processedBy)

Loan processed by {{ $enquiry->loanApplication->processedBy->name }} {{ $enquiry->loanApplication->processedBy->getRoleNames()->first() ?? 'N/A' }}

@else

Loan has been processed by loan officer

@endif @else

Pending processing by loan officer

@endif
@if(in_array($loanStatus, ['approved', 'paid'])) Loan Approved @else Awaiting Approval @endif
@if(in_array($loanStatus, ['approved', 'paid'])) {{ $enquiry->loanApplication->updated_at->format('M d, Y - H:i') }} @endif
@if(in_array($loanStatus, ['approved', 'paid'])) @if($enquiry->loanApplication && $enquiry->loanApplication->approvedBy)

Loan approved by {{ $enquiry->loanApplication->approvedBy->name }} {{ $enquiry->loanApplication->approvedBy->getRoleNames()->first() ?? 'N/A' }}

@else

Loan application has been approved by manager

@endif @else

Awaiting manager approval

@endif
@if($loanStatus == 'paid') Paid (Completed) @else Awaiting Payment @endif
@if($loanStatus == 'paid') {{ $enquiry->loanApplication->updated_at->format('M d, Y - H:i') }} @endif
@if($loanStatus == 'paid') @if($enquiry->loanApplication && $enquiry->loanApplication->paidBy)

Payment completed by {{ $enquiry->loanApplication->paidBy->name }} {{ $enquiry->loanApplication->paidBy->getRoleNames()->first() ?? 'N/A' }}

@else

Payment has been completed

@endif Loan disbursed • Enquiry status: Completed @else

Awaiting payment processing

@endif
@else @php $paymentInitiated = isset($enquiry->payment) && in_array($enquiry->payment->status, ['initiated', 'approved', 'paid']); @endphp
@if($paymentInitiated) Payment Initiated @else Awaiting Payment Initiation @endif
@if($paymentInitiated) {{ $enquiry->payment->created_at->format('M d, Y - H:i') }} @endif
@if($paymentInitiated) @if($enquiry->payment->initiatedBy)

Payment initiated by {{ $enquiry->payment->initiatedBy->name }} {{ $enquiry->payment->initiatedBy->getRoleNames()->first() ?? 'N/A' }}

@else

Payment has been initiated

@endif @else

Waiting for payment initiation

@endif
@php $paymentApproved = isset($enquiry->payment) && in_array($enquiry->payment->status, ['approved', 'paid']); @endphp
@if($paymentApproved) Payment Approved @else Awaiting Payment Approval @endif
@if($paymentApproved) {{ $enquiry->payment->updated_at->format('M d, Y - H:i') }} @endif
@if($paymentApproved) @if($enquiry->payment->approvedBy)

Payment approved by {{ $enquiry->payment->approvedBy->name }} {{ $enquiry->payment->approvedBy->getRoleNames()->first() ?? 'N/A' }}

@else

Payment has been approved

@endif @else

Waiting for payment approval

@endif
@php $paymentPaid = isset($enquiry->payment) && $enquiry->payment->status == 'paid'; @endphp
@if($paymentPaid) Paid @else Awaiting Payment @endif
@if($paymentPaid) {{ $enquiry->payment->updated_at->format('M d, Y - H:i') }} @endif
@if($paymentPaid) @if($enquiry->payment->paidBy)

Payment completed by {{ $enquiry->payment->paidBy->name }} {{ $enquiry->payment->paidBy->getRoleNames()->first() ?? 'N/A' }}

@else

Payment has been completed

@endif All steps completed @else

Awaiting final payment

@endif
@endif
Current Status
Last updated: {{ $enquiry->updated_at->diffForHumans() }}
@if($isOverdue) Overdue ({{ $enquiry->created_at->diffInWeekdays($now) }} days) @else {{ ucwords($enquiry->status) }} @endif
@include('modals.assign_enquries') @if($enquiry->users->count() > 0) @include('modals.reassign_enquiry') @endif @endsection