Detailed License Audit
| Product Name |
Product ID |
Status |
${resultsTableRows}
`;
downloadSection.classList.remove('hidden');
showTab(1);
};
runCheckBtn.addEventListener('click', runComplianceCheck);
// --- PDF DOWNLOAD ---
const downloadPDF = () => {
if (!currentData) return;
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const btnText = getElem('pdf-btn-text');
const btnSpinner = getElem('pdf-btn-spinner');
btnText.classList.add('hidden');
btnSpinner.classList.remove('hidden');
downloadPdfBtn.disabled = true;
try {
const pageWidth = pdf.internal.pageSize.getWidth();
const margin = 40;
let y = margin;
pdf.setFont('helvetica', 'bold');
pdf.setFontSize(22);
pdf.text("Reseller Compliance Report", pageWidth / 2, y, { align: 'center' });
y += 20;
pdf.setFont('helvetica', 'normal');
pdf.setFontSize(10);
pdf.text(`Generated on: ${today.toLocaleDateString('en-US')}`, pageWidth / 2, y, { align: 'center' });
y += 35;
pdf.autoTable({
startY: y,
theme: 'plain',
body: [
[{ content: 'Reseller Name:', styles: { fontStyle: 'bold' } }, currentData.name],
[{ content: 'Reseller ID:', styles: { fontStyle: 'bold' } }, currentData.id],
[{ content: 'Overall Status:', styles: { fontStyle: 'bold' } }, { content: currentData.overallStatus, styles: { fontStyle: 'bold' } }],
],
didDrawPage: (data) => { y = data.cursor.y; }
});
y += 20;
pdf.setFont('helvetica', 'bold');
pdf.text("Executive Summary", margin, y);
y += 15;
pdf.setFont('helvetica', 'normal');
const summaryLines = pdf.splitTextToSize(currentData.summary, pageWidth - margin * 2);
pdf.text(summaryLines, margin, y);
y += summaryLines.length * 12 + 25;
const tableData = currentData.results.map(item => [item.name, item.id, item.status]);
pdf.autoTable({
startY: y,
head: [['Product Name', 'Product ID', 'Status']],
body: tableData,
theme: 'striped',
headStyles: { fillColor: [29, 78, 216] }, // blue-700
didParseCell: function (data) {
if (data.section === 'body' && data.column.index === 2) {
if (data.cell.raw === 'Unauthorized') data.cell.styles.textColor = '#DC2626';
if (data.cell.raw === 'Authorized') data.cell.styles.textColor = '#16A34A';
}
},
});
pdf.save(`Compliance-Report-${currentData.id}.pdf`);
} catch(e) { console.error("PDF Generation failed:", e); }
finally {
btnText.classList.remove('hidden');
btnSpinner.classList.add('hidden');
downloadPdfBtn.disabled = false;
}
};
downloadPdfBtn.addEventListener('click', downloadPDF);
// --- Initialize the component ---
initialize();
});