added sales report downloadables and printable

This commit is contained in:
suryacp23 2026-07-17 13:54:51 +05:30
parent 53c3369f61
commit 6fbfd584aa

View File

@ -20,7 +20,7 @@ export function DailySalesReportPage() {
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [reportData, setReportData] = useState<any>(null); const [reportData, setReportData] = useState<any>(null);
const generatePDF = (shouldPrint = false) => { const downloadPDF = () => {
const doc = new jsPDF(); const doc = new jsPDF();
// Headers // Headers
@ -56,12 +56,57 @@ export function DailySalesReportPage() {
headStyles: { fillColor: [243, 244, 246], fontStyle: 'bold', halign: 'center' }, 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) { async function submit(e: FormEvent) {
@ -216,10 +261,10 @@ export function DailySalesReportPage() {
</div> </div>
</div> </div>
<div className="p-4 pt-4 pb-6 flex flex-col gap-4 print:hidden"> <div className="p-4 pt-4 pb-6 flex flex-col gap-4 print:hidden">
<Button type="button" onClick={() => generatePDF(false)} variant="secondary" iconLeft={<Download size={18} />} full> <Button type="button" onClick={downloadPDF} variant="secondary" iconLeft={<Download size={18} />} full>
Download PDF Download PDF
</Button> </Button>
<Button type="button" onClick={() => generatePDF(true)} iconLeft={<Printer size={18} />} full> <Button type="button" onClick={printReport} iconLeft={<Printer size={18} />} full>
Print PDF Print PDF
</Button> </Button>
</div> </div>