/** * Form 16 Details – Workflow tab. * Shows the Form 16 process: Dealer submits → OCR extracts → 26AS match → Credit note. * RE actions (cancel, resubmission needed, generate credit note) are in the Quick Actions sidebar. */ import { useState, useEffect } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { CheckCircle, Circle, XCircle, FileText, RefreshCw, Loader2, Receipt } from 'lucide-react'; import { getCreditNoteByRequestId, type Form16CreditNoteItem } from '@/services/form16Api'; interface Form16WorkflowTabProps { request: any; requestId: string; isReUser: boolean; onRefresh?: () => void; } const steps = [ { key: 'submit', label: 'Dealer submits Form 16', icon: FileText }, { key: 'ocr', label: 'OCR extracts', icon: FileText }, { key: 'match', label: 'Matching with 26AS', icon: RefreshCw }, { key: 'success', label: 'Successfully match', icon: CheckCircle }, { key: 'credit', label: 'Credit note generated', icon: Receipt }, ]; export function Form16WorkflowTab({ request, requestId }: Form16WorkflowTabProps) { const [creditNote, setCreditNote] = useState(null); const [loading, setLoading] = useState(true); const form16 = request?.form16Submission; const hasSubmission = !!form16; const hasCreditNote = !!creditNote && creditNote.status !== 'withdrawn'; const creditNoteWithdrawn = !!creditNote && creditNote.status === 'withdrawn'; const validationStatus = form16?.validationStatus ?? null; const validationFailed = validationStatus === 'failed' || validationStatus === 'mismatch' || validationStatus === 'duplicate'; const validationSuccess = hasCreditNote || validationStatus === 'success' || validationStatus === 'manually_approved'; useEffect(() => { if (!requestId) { setLoading(false); return; } let cancelled = false; (async () => { try { const note = await getCreditNoteByRequestId(requestId); if (!cancelled) setCreditNote(note); } catch { if (!cancelled) setCreditNote(null); } finally { if (!cancelled) setLoading(false); } })(); return () => { cancelled = true; }; }, [requestId]); const stepStatus: Record = { submit: true, ocr: hasSubmission, match: validationSuccess, success: validationSuccess, credit: hasCreditNote || creditNoteWithdrawn, }; const stepFailed: Record = { submit: false, ocr: false, match: validationFailed, success: validationFailed, credit: false, }; return (
Form 16 process {steps.map((step) => { const done = stepStatus[step.key]; const failed = stepFailed[step.key]; return (
{failed ? : done ? : }

{step.label}

{step.key === 'credit' && hasCreditNote && creditNote && (

Credit note: {creditNote.creditNoteNumber} {creditNote.amount != null && ` · ${new Intl.NumberFormat('en-IN', { style: 'currency', currency: 'INR', maximumFractionDigits: 0 }).format(Number(creditNote.amount))}`} {validationStatus === 'manually_approved' && ( (Manually approved Form 16) )}

)} {step.key === 'credit' && creditNoteWithdrawn && (

Withdrawn

)}
); })}
{loading && (
Loading credit note…
)} {!hasCreditNote && !loading && hasSubmission && (

No credit note has been generated for this submission yet. Use Quick Actions (sidebar) for RE actions.

)}
); }