- Backend: FastAPI app with all models, services, schemas, routes - Admin Panel: Next.js dashboard with all modules (CRM, POS, repairs, warranties, billing, notifications, etc.) - Ecommerce: storefront (submodule) + product catalog - AI Agents: .agents/ skill library for Antigravity IDE - Docs: architecture, billing, notification gateway markdown - Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
357 lines
15 KiB
TypeScript
357 lines
15 KiB
TypeScript
'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(
|
|
(
|
|
<div id="printable-quote-portal-container">
|
|
<style dangerouslySetInnerHTML={{ __html: printCss }} />
|
|
<div className="fixed inset-0 z-[100] bg-black/80 backdrop-blur-xs flex items-center justify-center p-4 overflow-y-auto print:p-0 print:bg-white print:static">
|
|
{/* Modal Container */}
|
|
<div id="printable-quotation-modal" className="bg-card border border-border rounded-xl shadow-2xl max-w-4xl w-full overflow-hidden flex flex-col my-6 print:border-none print:shadow-none print:max-w-none print:w-full print:m-0">
|
|
|
|
{/* Modal Toolbar (Hidden during print) */}
|
|
<div className="flex items-center justify-between bg-muted/80 px-6 py-4 border-b border-border print:hidden">
|
|
<div className="flex items-center gap-2">
|
|
<FileText className="w-5 h-5 text-primary" />
|
|
<h3 className="font-bold text-base text-foreground">
|
|
Official Quotation Preview: #{data.quote_number}
|
|
</h3>
|
|
<span className="px-2.5 py-0.5 rounded-full text-xs font-extrabold bg-primary/10 text-primary border border-primary/20">
|
|
{data.status}
|
|
</span>
|
|
</div>
|
|
|
|
<div className="flex items-center gap-3">
|
|
<button
|
|
onClick={handlePrint}
|
|
className="inline-flex items-center gap-2 bg-primary hover:bg-primary/90 text-white font-semibold text-xs px-4 py-2 rounded-lg transition-colors cursor-pointer shadow-xs"
|
|
>
|
|
<Printer className="w-4 h-4" />
|
|
Print / Download PDF
|
|
</button>
|
|
<button
|
|
onClick={onClose}
|
|
className="p-2 text-muted-foreground hover:text-foreground rounded-lg hover:bg-muted transition-colors cursor-pointer"
|
|
>
|
|
<X className="w-5 h-5" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Printable Quotation Content */}
|
|
<div className="p-8 bg-white text-slate-900 space-y-6 print:p-8 print:w-full font-sans text-xs">
|
|
|
|
{/* Header & Logo */}
|
|
<div className="flex justify-between items-start border-b border-slate-200 pb-6">
|
|
<div>
|
|
<div className="flex items-center gap-2">
|
|
<div className="w-8 h-8 rounded-lg bg-blue-600 text-white flex items-center justify-center font-black text-lg">
|
|
iK
|
|
</div>
|
|
<h1 className="text-2xl font-black text-slate-900 tracking-tight">iFixKart</h1>
|
|
</div>
|
|
<p className="text-slate-500 font-medium text-[11px] mt-1">
|
|
Unified Commerce & Repair Service Platform
|
|
</p>
|
|
<p className="text-slate-500 text-[10px] mt-0.5">
|
|
GSTIN: 33ABCDE1234F1Z5 | Reg: IFK-TN-2026-8899
|
|
</p>
|
|
<p className="text-slate-500 text-[10px]">
|
|
No. 142, Tech Park Avenue, OMR, Chennai - 600096 | Ph: +91 9080323589
|
|
</p>
|
|
</div>
|
|
|
|
<div className="text-right space-y-1">
|
|
<span className="inline-block px-3 py-1 rounded bg-blue-50 text-blue-700 font-bold text-xs uppercase tracking-wider border border-blue-200">
|
|
Official Sales & Repair Quotation
|
|
</span>
|
|
<p className="text-base font-bold text-slate-900 pt-1">
|
|
Quote #{data.quote_number}
|
|
</p>
|
|
<p className="text-slate-500 text-[11px]">
|
|
Date: <strong className="text-slate-700">{formattedDate}</strong>
|
|
</p>
|
|
<p className="text-slate-500 text-[11px]">
|
|
Valid Until: <strong className="text-slate-700">{validUntilDate}</strong>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Customer & Job Info Grid */}
|
|
<div className="grid grid-cols-2 gap-6 bg-slate-50 p-4 rounded-lg border border-slate-200">
|
|
<div>
|
|
<h4 className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-1">
|
|
CUSTOMER DETAILS (BILLED TO)
|
|
</h4>
|
|
<p className="font-bold text-sm text-slate-900">{data.customer_name || 'Valued Customer'}</p>
|
|
{data.company_name && (
|
|
<p className="font-semibold text-slate-700">{data.company_name}</p>
|
|
)}
|
|
{data.customer_phone && (
|
|
<p className="text-slate-600">Phone: {data.customer_phone}</p>
|
|
)}
|
|
{data.customer_email && (
|
|
<p className="text-slate-600">Email: {data.customer_email}</p>
|
|
)}
|
|
{data.gst_number && (
|
|
<p className="text-slate-600 font-medium">Customer GSTIN: {data.gst_number}</p>
|
|
)}
|
|
</div>
|
|
|
|
<div>
|
|
<h4 className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-1">
|
|
SERVICE & DEVICE SPECIFICATIONS
|
|
</h4>
|
|
{data.device_info ? (
|
|
<p className="font-bold text-slate-800">{data.device_info}</p>
|
|
) : (
|
|
<p className="text-slate-600">Standard Product / Service Catalog Order</p>
|
|
)}
|
|
{data.job_no && (
|
|
<p className="text-slate-600 font-semibold">Service Job No: #{data.job_no}</p>
|
|
)}
|
|
<div className="mt-2 inline-flex items-center gap-1.5 px-2.5 py-1 rounded bg-emerald-50 text-emerald-700 text-[10px] font-bold border border-emerald-200">
|
|
<ShieldCheck className="w-3.5 h-3.5 text-emerald-600" />
|
|
6-Month iFixKart IMEI Warranty Included
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Itemized Line Items Table */}
|
|
<div className="border border-slate-200 rounded-lg overflow-hidden">
|
|
<table className="w-full text-left border-collapse">
|
|
<thead>
|
|
<tr className="bg-slate-100 text-slate-700 text-[11px] font-bold uppercase tracking-wider border-b border-slate-200">
|
|
<th className="py-2.5 px-3">#</th>
|
|
<th className="py-2.5 px-3">Item Description</th>
|
|
<th className="py-2.5 px-3 text-center">HSN/SAC</th>
|
|
<th className="py-2.5 px-3 text-center">Qty</th>
|
|
<th className="py-2.5 px-3 text-right">Unit Price (₹)</th>
|
|
<th className="py-2.5 px-3 text-right">GST %</th>
|
|
<th className="py-2.5 px-3 text-right">Total (₹)</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-slate-200">
|
|
{data.items.map((item, idx) => {
|
|
const qty = Number(item.quantity || 1);
|
|
const price = Number(item.unit_price || 0);
|
|
const lineTotal = Number(item.total_price || (qty * price));
|
|
const hsn = item.hsn_sac_code || (item.sku?.startsWith('SVC') ? '998729' : '8517');
|
|
|
|
return (
|
|
<tr key={idx} className="text-slate-800">
|
|
<td className="py-2.5 px-3 text-slate-500 font-medium">{idx + 1}</td>
|
|
<td className="py-2.5 px-3 font-semibold">
|
|
{item.description}
|
|
{item.sku && (
|
|
<span className="block text-[10px] font-mono text-slate-400">SKU: {item.sku}</span>
|
|
)}
|
|
</td>
|
|
<td className="py-2.5 px-3 text-center text-slate-600 font-mono">{hsn}</td>
|
|
<td className="py-2.5 px-3 text-center font-bold">{qty}</td>
|
|
<td className="py-2.5 px-3 text-right">₹{price.toLocaleString('en-IN')}</td>
|
|
<td className="py-2.5 px-3 text-right text-slate-600">{item.tax_percent || 18}%</td>
|
|
<td className="py-2.5 px-3 text-right font-bold">₹{lineTotal.toLocaleString('en-IN')}</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
{/* Tax Calculation & Financial Summary */}
|
|
<div className="flex justify-between items-start pt-2">
|
|
<div className="max-w-md space-y-2">
|
|
<div className="p-3 bg-blue-50/50 border border-blue-100 rounded-lg space-y-1 text-[11px]">
|
|
<p className="font-bold text-blue-900 flex items-center gap-1">
|
|
<CheckCircle2 className="w-3.5 h-3.5 text-blue-600" />
|
|
Warranty & Terms of Service:
|
|
</p>
|
|
<p className="text-slate-600 leading-tight">
|
|
{data.terms || data.notes || '6-Month Warranty included. Free express doorstep pickup & return. Quote valid for 15 days.'}
|
|
</p>
|
|
</div>
|
|
|
|
<p className="text-[10px] text-slate-400 italic">
|
|
Note: This is a computer-generated official price estimate quotation.
|
|
</p>
|
|
</div>
|
|
|
|
<div className="w-72 bg-slate-50 p-4 rounded-lg border border-slate-200 space-y-2 text-xs">
|
|
<div className="flex justify-between text-slate-600">
|
|
<span>Taxable Value (Excl. GST):</span>
|
|
<span className="font-semibold">₹{taxableSub.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}</span>
|
|
</div>
|
|
|
|
{discount > 0 && (
|
|
<div className="flex justify-between text-emerald-600 font-medium">
|
|
<span>Special Discount:</span>
|
|
<span>- ₹{discount.toLocaleString('en-IN')}</span>
|
|
</div>
|
|
)}
|
|
|
|
{isInterstate ? (
|
|
<div className="flex justify-between text-slate-600">
|
|
<span>IGST ({GST_RATE}%):</span>
|
|
<span className="font-semibold">₹{igst.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}</span>
|
|
</div>
|
|
) : (
|
|
<>
|
|
<div className="flex justify-between text-slate-600">
|
|
<span>CGST ({GST_RATE / 2}%):</span>
|
|
<span className="font-semibold">₹{cgst.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}</span>
|
|
</div>
|
|
|
|
<div className="flex justify-between text-slate-600">
|
|
<span>SGST ({GST_RATE / 2}%):</span>
|
|
<span className="font-semibold">₹{sgst.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}</span>
|
|
</div>
|
|
</>
|
|
)}
|
|
|
|
{roundOff !== 0 && (
|
|
<div className="flex justify-between text-slate-500">
|
|
<span>Round Off:</span>
|
|
<span className="font-semibold">{roundOff > 0 ? '+' : ''}₹{roundOff.toFixed(2)}</span>
|
|
</div>
|
|
)}
|
|
|
|
<div className="border-t border-slate-300 pt-2 flex justify-between items-center text-sm font-black text-slate-900">
|
|
<span>Grand Total Amount:</span>
|
|
<span className="text-blue-700 text-base">₹{roundedFinal.toLocaleString('en-IN')}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Signature Block */}
|
|
<div className="pt-8 flex justify-between items-end border-t border-slate-200">
|
|
<div className="text-[10px] text-slate-500">
|
|
<p className="font-bold text-slate-700">iFixKart Support Hotline</p>
|
|
<p>Email: support@ifixkart.com | Web: https://ifixkart.com</p>
|
|
</div>
|
|
|
|
<div className="text-center space-y-1">
|
|
<div className="w-40 h-10 border-b border-dashed border-slate-400 mx-auto" />
|
|
<p className="font-bold text-slate-800 text-[11px]">Authorized Signatory</p>
|
|
<p className="text-[10px] text-slate-400">iFixKart Billing & Finance Department</p>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>),
|
|
document.body
|
|
);
|
|
}
|