@extends('Admin.layout') @php $loan = $loan ?? null; $loanDetails = []; if ($loan && !empty($loan->loan_details)) { $loanDetails = is_array($loan->loan_details) ? $loan->loan_details : (json_decode($loan->loan_details, true) ?? []); } if (!is_array($loanDetails)) { $loanDetails = []; } /* |-------------------------------------------------------------------------- | DECODE DOCUMENT COLLECTION |-------------------------------------------------------------------------- */ $documentCollection = []; if ($loan && !empty($loan->document_collection)) { $documentCollection = is_array($loan->document_collection) ? $loan->document_collection : (json_decode($loan->document_collection, true) ?? []); } if (!is_array($documentCollection)) { $documentCollection = []; } /* |-------------------------------------------------------------------------- | GET LOAN DETAIL |-------------------------------------------------------------------------- */ $getLoanDetail = function ($key, $default = '') use ($loanDetails) { return old($key, $loanDetails[$key] ?? $default); }; /* |-------------------------------------------------------------------------- | GET DOCUMENT STATUS / REMARKS |-------------------------------------------------------------------------- */ $getDocumentValue = function ($key, $field, $default = '') use ($documentCollection) { return old( "documents.$key.$field", data_get($documentCollection, $key . '.' . $field, $default) ); }; /* |-------------------------------------------------------------------------- | EXISTING DOCUMENT FILES |-------------------------------------------------------------------------- */ $existingDocumentFiles = []; foreach ($documentCollection as $docKey => $docData) { if (!is_array($docData)) { continue; } $existingFiles = $docData['files'] ?? []; if (!is_array($existingFiles)) { continue; } $existingDocumentFiles[$docKey] = []; foreach ($existingFiles as $file) { if (!is_array($file) || empty($file['path'])) { continue; } $path = $file['path']; $extension = strtolower( pathinfo($path, PATHINFO_EXTENSION) ); $isPdf = $extension === 'pdf'; $existingDocumentFiles[$docKey][] = [ 'existing' => true, 'name' => $file['original_name'] ?? basename($path), 'path' => $path, 'url' => asset('storage/' . ltrim($path, '/')), 'size' => $file['size'] ?? 0, 'mime_type' => $file['mime_type'] ?? '', 'isPdf' => $isPdf, ]; } } /* |-------------------------------------------------------------------------- | VALUES |-------------------------------------------------------------------------- */ $selectedLoanType = old('loan_type', $loan->loan_type ?? ''); $loanDate = old( 'loan_date', $loan && $loan->loan_date ? \Illuminate\Support\Carbon::parse($loan->loan_date)->format('Y-m-d') : date('Y-m-d') ); $collectionRemarks = old( 'collection_remarks', $documentCollection['collection_remarks'] ?? '' ); $collectionStatus = old( 'collection_status', $documentCollection['collection_status'] ?? 'Pending' ); $applicationStatus = old( 'application_status', $loan->application_status ?? 'New' ); $nextFollowupDate = old( 'next_followup_date', $loan->next_followup_date ?? '' ); @endphp @section('content')