'use client'; import { useEffect, useState } from 'react'; import { createPortal } from 'react-dom'; import { Printer, X, Download, ShieldCheck, FileText, CheckCircle2 } from 'lucide-react'; export interface PrintableQuoteItem { description: string; sku?: string; hsn_sac_code?: string; quantity: number; unit_price: number; tax_percent?: number; total_price: number; } export interface PrintableQuoteData { quote_number: string; created_at: string; valid_until?: string; status: string; customer_name?: string; customer_phone?: string; customer_email?: string; company_name?: string; gst_number?: string; device_info?: string; job_no?: string; subtotal: number; discount_amount?: number; tax_amount: number; grand_total: number; notes?: string; terms?: string; items: PrintableQuoteItem[]; is_interstate?: boolean; // false/undefined = Tamil Nadu (CGST+SGST), true = Outside TN (IGST) } interface PrintableQuotationModalProps { isOpen: boolean; onClose: () => void; data: PrintableQuoteData | null; } export function PrintableQuotationModal({ isOpen, onClose, data }: PrintableQuotationModalProps) { const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); }, []); if (!mounted || !isOpen || !data) return null; const handlePrint = () => { window.print(); }; const GST_RATE = 18; const grossTotal = Number(data.grand_total || 0); const discount = Number(data.discount_amount || 0); const taxableSub = Math.round((grossTotal / (1 + GST_RATE / 100)) * 100) / 100; const totalGst = Math.round((grossTotal - taxableSub) * 100) / 100; const isInterstate = data.is_interstate || false; const cgst = isInterstate ? 0 : Math.round((totalGst / 2) * 100) / 100; const sgst = isInterstate ? 0 : Math.round((totalGst / 2) * 100) / 100; const igst = isInterstate ? totalGst : 0; const roundedFinal = Math.round(grossTotal); const roundOff = Math.round((roundedFinal - grossTotal) * 100) / 100; const formattedDate = data.created_at ? new Date(data.created_at).toLocaleDateString('en-IN', { day: '2-digit', month: 'short', year: 'numeric' }) : '—'; const validUntilDate = data.valid_until ? new Date(data.valid_until).toLocaleDateString('en-IN', { day: '2-digit', month: 'short', year: 'numeric' }) : 'Valid for 15 days'; const printCss = ` @media print { @page { size: A4 portrait; margin: 8mm; } body > *:not(#printable-quote-portal-container) { display: none !important; } #printable-quote-portal-container { display: block !important; position: absolute !important; left: 0 !important; top: 0 !important; width: 100% !important; margin: 0 !important; padding: 0 !important; background: white !important; color: black !important; } #printable-quotation-modal { position: static !important; box-shadow: none !important; border: none !important; margin: 0 !important; padding: 0 !important; width: 100% !important; max-width: 100% !important; background: white !important; } .print\\:hidden { display: none !important; } } `; return createPortal( (
Unified Commerce & Repair Service Platform
GSTIN: 33ABCDE1234F1Z5 | Reg: IFK-TN-2026-8899
No. 142, Tech Park Avenue, OMR, Chennai - 600096 | Ph: +91 9080323589
Quote #{data.quote_number}
Date: {formattedDate}
Valid Until: {validUntilDate}
{data.customer_name || 'Valued Customer'}
{data.company_name && ({data.company_name}
)} {data.customer_phone && (Phone: {data.customer_phone}
)} {data.customer_email && (Email: {data.customer_email}
)} {data.gst_number && (Customer GSTIN: {data.gst_number}
)}{data.device_info}
) : (Standard Product / Service Catalog Order
)} {data.job_no && (Service Job No: #{data.job_no}
)}| # | Item Description | HSN/SAC | Qty | Unit Price (₹) | GST % | Total (₹) |
|---|---|---|---|---|---|---|
| {idx + 1} | {item.description} {item.sku && ( SKU: {item.sku} )} | {hsn} | {qty} | ₹{price.toLocaleString('en-IN')} | {item.tax_percent || 18}% | ₹{lineTotal.toLocaleString('en-IN')} |
{data.terms || data.notes || '6-Month Warranty included. Free express doorstep pickup & return. Quote valid for 15 days.'}
Note: This is a computer-generated official price estimate quotation.
iFixKart Support Hotline
Email: support@ifixkart.com | Web: https://ifixkart.com
Authorized Signatory
iFixKart Billing & Finance Department