`;
resultsDiv.classList.remove('hidden');
};
function updateReportTab() {
const summaryDiv = document.getElementById('report-summary');
if(invoices.length > 0) {
document.getElementById('pdfDownloadBtn').disabled = false;
summaryDiv.innerHTML = `
Your report is ready to be downloaded. It will contain a summary of your financial overview and a detailed list of all ${invoices.length} invoices.
`; } else { document.getElementById('pdfDownloadBtn').disabled = true; summaryDiv.innerHTML = `Please add and manage invoices to generate a report.
`; } } window.changeTab = (tabNumber) => { currentTab = tabNumber; document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active')); document.querySelectorAll('.tab-button').forEach(b => b.classList.remove('active')); document.getElementById(`tab-content-${tabNumber}`)?.classList.add('active'); document.getElementById(`tab-btn-${tabNumber}`)?.classList.add('active'); updateNavButtons(); }; window.navigateTab = (direction) => { const newTab = currentTab + direction; if (newTab >= 1 && newTab <= totalTabs) { changeTab(newTab); } }; function updateNavButtons() { document.getElementById('prevBtn').disabled = (currentTab === 1); document.getElementById('nextBtn').disabled = (currentTab === totalTabs); } window.downloadPDF = () => { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); doc.setFontSize(22); doc.setFont('helvetica', 'bold'); doc.text('Invoice Management Report', 105, 20, { align: 'center' }); const tableBody = [ ['Total Outstanding', document.getElementById('total-outstanding').textContent], ['Total Factored', document.getElementById('total-factored').textContent], ['Invoices Overdue', document.getElementById('overdue-count').textContent], ]; doc.autoTable({ startY: 30, head: [['Metric', 'Value']], body: tableBody, theme: 'grid' }); doc.autoTable({ startY: doc.lastAutoTable.finalY + 15, head: [['Client Name', 'Amount ($)', 'Due Date', 'Status']], body: invoices.map(i => [i.client, i.amount.toLocaleString(), i.dueDate, i.status]), theme: 'striped', headStyles: { fillColor: [45, 55, 72] } }); doc.save('Invoice_Factoring_Report.pdf'); }; // Initial setup changeTab(1); loadSampleInvoices(); });