pdf downloading and printing fixed
This commit is contained in:
parent
654a569002
commit
53c3369f61
@ -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<string | null>(null);
|
||||
const [reportData, setReportData] = useState<any>(null);
|
||||
|
||||
const printTable = () => {
|
||||
const generatePDF = (shouldPrint = false) => {
|
||||
const doc = new jsPDF();
|
||||
|
||||
// Headers
|
||||
@ -55,7 +56,12 @@ 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`);
|
||||
}
|
||||
};
|
||||
|
||||
async function submit(e: FormEvent) {
|
||||
@ -209,8 +215,13 @@ export function DailySalesReportPage() {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="p-4 pt-2 flex justify-center print:hidden">
|
||||
<Button type="button" onClick={printTable} full>Print / Save PDF</Button>
|
||||
<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>
|
||||
Download PDF
|
||||
</Button>
|
||||
<Button type="button" onClick={() => generatePDF(true)} iconLeft={<Printer size={18} />} full>
|
||||
Print PDF
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user