From 6fbfd584aa81be7444ff6c801472ab15f513e4ab Mon Sep 17 00:00:00 2001 From: suryacp23 Date: Fri, 17 Jul 2026 13:54:51 +0530 Subject: [PATCH] added sales report downloadables and printable --- src/screens/DailySalesReportPage.tsx | 65 +++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/src/screens/DailySalesReportPage.tsx b/src/screens/DailySalesReportPage.tsx index 72f8e1d..76ccf42 100644 --- a/src/screens/DailySalesReportPage.tsx +++ b/src/screens/DailySalesReportPage.tsx @@ -20,7 +20,7 @@ export function DailySalesReportPage() { const [error, setError] = useState(null); const [reportData, setReportData] = useState(null); - const generatePDF = (shouldPrint = false) => { + const downloadPDF = () => { const doc = new jsPDF(); // Headers @@ -35,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); @@ -56,12 +56,57 @@ export function DailySalesReportPage() { headStyles: { fillColor: [243, 244, 246], fontStyle: 'bold', halign: 'center' }, }); - if (shouldPrint) { - doc.autoPrint(); - window.open(doc.output('bloburl'), '_blank'); - } else { - doc.save(`Daily_Sales_Report_${date || 'Draft'}.pdf`); - } + doc.save(`Daily_Sales_Report_${date || 'Draft'}.pdf`); + }; + + const printReport = () => { + const doc = new jsPDF(); + + // Headers + doc.setFontSize(16); + doc.setFont('helvetica', 'bold'); + doc.text('Krishna Flour Mills (Bangalore) Pvt. Limited', 105, 15, { align: 'center' }); + + doc.setFontSize(11); + doc.setFont('helvetica', 'normal'); + doc.text('19, Platform Road, Bengaluru - 560 020', 105, 22, { align: 'center' }); + + 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); + doc.line(105 - textWidth / 2, 31, 105 + textWidth / 2, 31); + + // Meta Info + doc.setFontSize(10); + doc.text(`Distributor Name : ${distributor}`, 14, 40); + doc.text(`Date : ${date}`, 196, 40, { align: 'right' }); + doc.text(`SO Name : ${soName}`, 196, 45, { align: 'right' }); + + // Table + autoTable(doc, { + html: '#report-table', + startY: 50, + theme: 'grid', + styles: { fontSize: 8, textColor: [0, 0, 0], lineColor: [0, 0, 0], lineWidth: 0.2 }, + headStyles: { fillColor: [243, 244, 246], fontStyle: 'bold', halign: 'center' }, + }); + + const blobUrl = doc.output('bloburl'); + const iframe = document.createElement('iframe'); + iframe.style.display = 'none'; + iframe.src = blobUrl.toString(); + document.body.appendChild(iframe); + + iframe.onload = () => { + setTimeout(() => { + iframe.contentWindow?.focus(); + iframe.contentWindow?.print(); + }, 500); + }; }; async function submit(e: FormEvent) { @@ -216,10 +261,10 @@ export function DailySalesReportPage() {
- -