diff --git a/src/screens/DailySalesReportPage.tsx b/src/screens/DailySalesReportPage.tsx index 07e7ebe..72f8e1d 100644 --- a/src/screens/DailySalesReportPage.tsx +++ b/src/screens/DailySalesReportPage.tsx @@ -6,6 +6,7 @@ import { SALES_REPORT_DISTRIBUTORS, SALES_REPORT_SO_NAMES } from '../api/config'; +import { Download, Printer } from 'lucide-react'; import jsPDF from 'jspdf'; import autoTable from 'jspdf-autotable'; @@ -19,7 +20,7 @@ export function DailySalesReportPage() { const [error, setError] = useState(null); const [reportData, setReportData] = useState(null); - const printTable = () => { + const generatePDF = (shouldPrint = false) => { const doc = new jsPDF(); // Headers @@ -34,7 +35,7 @@ export function DailySalesReportPage() { doc.setFontSize(12); doc.setFont('helvetica', 'bold'); doc.text('DAILY ORDER REPORT', 105, 30, { align: 'center' }); - + // Simple underline for DAILY ORDER REPORT const textWidth = doc.getTextWidth('DAILY ORDER REPORT'); doc.setLineWidth(0.5); @@ -55,7 +56,12 @@ export function DailySalesReportPage() { headStyles: { fillColor: [243, 244, 246], fontStyle: 'bold', halign: 'center' }, }); - doc.save(`Daily_Sales_Report_${date || 'Draft'}.pdf`); + if (shouldPrint) { + doc.autoPrint(); + window.open(doc.output('bloburl'), '_blank'); + } else { + doc.save(`Daily_Sales_Report_${date || 'Draft'}.pdf`); + } }; async function submit(e: FormEvent) { @@ -148,7 +154,7 @@ export function DailySalesReportPage() {

19, Platform Road, Bengaluru - 560 020

DAILY ORDER REPORT

- +
Distributor Name : {distributor}
@@ -158,59 +164,64 @@ export function DailySalesReportPage() {
- - - - - {reportData.response.headers?.map((h: any) => ( - - ))} - - - - {reportData.response.headers?.flatMap((h: any) => h.skus || []).map((sku: string, idx: number) => ( - - ))} - - - - {reportData.response.rows?.map((row: any) => ( - - - - {reportData.response.headers?.flatMap((h: any) => h.skus || []).map((sku: string, idx: number) => ( - + + + + + {reportData.response.headers?.map((h: any) => ( + ))} - + - ))} - {reportData.response.total_row && ( - - - + {reportData.response.headers?.flatMap((h: any) => h.skus || []).map((sku: string, idx: number) => ( - + ))} - - )} - -
Sl NoStore - {h.br_code} - Total
- {sku} -
{row.sl_no}{row.store} - {row.products?.[sku] ?? 0} -
Sl NoStore + {h.br_code} + {row.total ?? 0}Total
{reportData.response.total_row.sl_no}{reportData.response.total_row.store}
- {reportData.response.total_row.products?.[sku] ?? 0} - + {sku} + {reportData.response.total_row.total ?? 0}
- {(!reportData.response.rows || reportData.response.rows.length === 0) && ( -
No records found.
- )} + + + {reportData.response.rows?.map((row: any) => ( + + {row.sl_no} + {row.store} + {reportData.response.headers?.flatMap((h: any) => h.skus || []).map((sku: string, idx: number) => ( + + {row.products?.[sku] ?? 0} + + ))} + {row.total ?? 0} + + ))} + {reportData.response.total_row && ( + + {reportData.response.total_row.sl_no} + {reportData.response.total_row.store} + {reportData.response.headers?.flatMap((h: any) => h.skus || []).map((sku: string, idx: number) => ( + + {reportData.response.total_row.products?.[sku] ?? 0} + + ))} + {reportData.response.total_row.total ?? 0} + + )} + + + {(!reportData.response.rows || reportData.response.rows.length === 0) && ( +
No records found.
+ )}
-
- +
+ +
)}