pdf downloading and printing fixed
This commit is contained in:
parent
654a569002
commit
53c3369f61
@ -6,6 +6,7 @@ import {
|
|||||||
SALES_REPORT_DISTRIBUTORS,
|
SALES_REPORT_DISTRIBUTORS,
|
||||||
SALES_REPORT_SO_NAMES
|
SALES_REPORT_SO_NAMES
|
||||||
} from '../api/config';
|
} from '../api/config';
|
||||||
|
import { Download, Printer } from 'lucide-react';
|
||||||
import jsPDF from 'jspdf';
|
import jsPDF from 'jspdf';
|
||||||
import autoTable from 'jspdf-autotable';
|
import autoTable from 'jspdf-autotable';
|
||||||
|
|
||||||
@ -19,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 printTable = () => {
|
const generatePDF = (shouldPrint = false) => {
|
||||||
const doc = new jsPDF();
|
const doc = new jsPDF();
|
||||||
|
|
||||||
// Headers
|
// Headers
|
||||||
@ -55,7 +56,12 @@ 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`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function submit(e: FormEvent) {
|
async function submit(e: FormEvent) {
|
||||||
@ -209,8 +215,13 @@ export function DailySalesReportPage() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-4 pt-2 flex justify-center print:hidden">
|
<div className="p-4 pt-4 pb-6 flex flex-col gap-4 print:hidden">
|
||||||
<Button type="button" onClick={printTable} full>Print / Save PDF</Button>
|
<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>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user