import { AlertCircle, CheckCircle, ClipboardList, Download, Eye, FileText, ShieldAlert, ShieldCheck, Upload } from 'lucide-react'; import { toast } from 'sonner'; import { onboardingService } from '@/services/onboarding.service'; import { cn, formatDateTime } from '@/components/ui/utils'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; interface Props { application: any; currentUser: any; documents: any[]; fddAgencies: any[]; selectedAgencyId: string; setSelectedAgencyId: (v: string) => void; isAssigningAgency: boolean; handleAssignAgency: () => void; setPreviewDoc: (d: any) => void; setShowPreviewModal: (v: boolean) => void; setIsUploading: (v: boolean) => void; fetchApplication: () => void; refreshDocuments: () => Promise; } export function ApplicationDetailsFddAuditContent({ application, currentUser, documents, fddAgencies, selectedAgencyId, setSelectedAgencyId, isAssigningAgency, handleAssignAgency, setPreviewDoc, setShowPreviewModal, setIsUploading, fetchApplication, refreshDocuments, }: Props) { const assignments = application?.fddAssignments || []; const fddParticipants = application?.participants?.filter((p: any) => p.user?.role === 'FDD' || p.user?.roleCode === 'FDD' || p.user?.allRoles?.includes('FDD') ) || []; const hasAssignment = assignments.length > 0 || fddParticipants.length > 0; const primaryFddUser = fddParticipants[0]?.user; const mandatoryFinancialDocs = [ { type: 'Bank Statement', label: 'Bank Statements' }, { type: 'Income Tax Returns (ITR)', label: 'ITR (Last 3 Years)' }, { type: 'CIBIL Report', label: 'CIBIL / Credit Reports' }, { type: 'Property Documents', label: 'Property Documents' }, { type: 'Business Valuation Report', label: 'Valuation Reports' }, { type: 'FDD Final Audit Report', label: 'Final Audit Report' }, ]; const getDocByTypeName = (typeName: string) => { const target = typeName.toLowerCase(); return (documents || []).find((d: any) => { const docType = (d.documentType || '').toLowerCase(); const fileName = (d.fileName || '').toLowerCase(); if (docType === target) return true; if (target.includes('itr') && (docType.includes('itr') || fileName.includes('itr'))) return true; if (target.includes('bank statement') && (docType.includes('bank') || fileName.includes('bank'))) return true; if (target.includes('cibil') && (docType.includes('cibil') || fileName.includes('cibil') || docType.includes('credit'))) return true; return false; }); }; const isFddSupportDoc = (d: any) => { const type = (d.documentType || '').toLowerCase(); const stage = (d.stage || '').toLowerCase(); return stage === 'fdd' || type.includes('report') || type.includes('itr') || type.includes('bank') || type.includes('cibil') || type.includes('valuation'); }; if (!hasAssignment && !['FDD Verification', 'LOI In Progress', 'Payment Pending'].includes(application.status)) { return (

No FDD Assignment

The Financial Due Diligence process has not been initiated for this application yet.

{(currentUser?.role === 'DD Admin' || currentUser?.role === 'Super Admin') && ( Initiate FDD Audit
)}
); } return (
{hasAssignment && (

FDD Assignment Active

{primaryFddUser &&

Assigned to: {primaryFddUser.name}

}
)}
Financial Artefacts Checklist
Verify before sign-off
{mandatoryFinancialDocs.map((docType, index) => { const doc = getDocByTypeName(docType.type); return (
{doc ? : }

{docType.label}

{doc ? `Uploaded: ${formatDateTime(doc.createdAt)}` : 'Missing in Documentation'}

{doc ? ( ) : ( )}
); })}

Supporting Audit Documents

{(documents || []).filter(isFddSupportDoc).length} Document(s)
{(documents || []).filter(isFddSupportDoc).map((doc: any, index: number) => (

{doc.fileName}

{doc.documentType}

))} {(documents || []).filter(isFddSupportDoc).length === 0 && (

No supporting audit documents uploaded yet.

)}
); }