Carryforward Calculation Details:
'; html += '| ${header} | `; } html += '
|---|
| ${cell} | `; } html += '
Final Remaining NOL Carryforward: ${lastRow[4]}
`; } else if (lastRow[3] === 'NOL Fully Utilized') { html += `Final Remaining NOL Carryforward: ${formatCurrency(0)} (NOL Fully Utilized)
`; } else { html += `Final Remaining NOL Carryforward: ${lastRow[4]}
`; } calculationResultsDiv.innerHTML = html; } function downloadPdf() { // Ensure jsPDF and AutoTable are loaded if (typeof window.jspdf === 'undefined' || typeof window.jspdf.API.autoTable === 'undefined') { console.error('jsPDF or AutoTable library not loaded.'); alert('PDF generation library not loaded. Please try again.'); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'landscape' // Use landscape for wider table }); let yPos = 15; // Starting Y position // Title doc.setFontSize(18); doc.setTextColor(0, 86, 179); // RGB for #0056b3 (Accent color) doc.text('US Federal Net Operating Loss (NOL) Carryforward Calculation', 15, yPos); yPos += 20; // Check if calculation results are available if (calculationResultsData.length < 5 || calculationResultsData[3][0] !== 'Carryforward Year') { // If no calculation results (e.g., error or info message is displayed) doc.setFontSize(12); doc.setTextColor(51, 51, 51); // Text color // Get the current text content from the results div const textContent = calculationResultsDiv.textContent.trim(); const splitText = doc.splitTextToSize(textContent, 250); // Wider width for landscape doc.text(splitText, 15, yPos); yPos += (splitText.length * 7) + 10; const lossYr = lossYearInput.value.trim() || 'Info'; doc.save(`us_nol_info_${lossYr}.pdf`); return; } // Add Summary Details from calculationResultsData doc.setFontSize(12); doc.setTextColor(51, 51, 51); // Text color doc.text(`${calculationResultsData[0][0]} ${calculationResultsData[0][1]}`, 15, yPos); yPos += 8; doc.text(`${calculationResultsData[1][0]} ${calculationResultsData[1][1]}`, 15, yPos); yPos += 15; // Space after summary // Prepare table data for AutoTable from calculationResultsData const tableHead = calculationResultsData[3]; const tableBody = calculationResultsData.slice(4); // Data rows start from index 4 // Add table to PDF using AutoTable doc.autoTable({ startY: yPos, head: [tableHead], body: tableBody, theme: 'striped', // Use striped theme for alternating rows headStyles: { fillColor: [0, 86, 179], textColor: 255, fontStyle: 'bold' }, // Header matches primary-accent bodyStyles: { textColor: [51, 51, 51], fontSize: 9 }, // Body matches text-color, slightly smaller font alternateRowStyles: { fillColor: [248, 249, 250] }, // Matches secondary-bg styles: { cellPadding: 3, rowPageBreak: 'avoid' }, margin: { left: 15, right: 15 }, didDrawPage: function(data) { // Optional: Footer - Add page numbers // let pageCount = doc.internal.getNumberOfPages(); // doc.setFontSize(8); // doc.setTextColor(150); // doc.text('Page ' + data.pageNumber + ' of ' + pageCount, data.settings.margin.left, doc.internal.pageSize.height - 10); } }); yPos = doc.autoTable.previous.finalY + 15; // Position after the table // Add the Note below the table doc.setFontSize(9); doc.setTextColor(85, 85, 85); // RGB for #555 (Note text color) // Get the note content from the HTML const noteElement = document.querySelector('#results-tab .note'); if (noteElement) { const noteText = noteElement.textContent.trim(); const splitNote = doc.splitTextToSize(noteText, 250); // Wider width for landscape doc.text(splitNote, 15, yPos); } // Save the PDF const lossYr = nolLossYear || 'NOL'; doc.save(`us_nol_carryforward_${lossYr}.pdf`); } // Initial state setup downloadPdfBtn.style.display = 'none'; // Hide PDF button initially renderCarryforwardYearList(); // Render empty list initially // Set initial results area content calculationResultsDiv.innerHTML = 'Enter NOL details and carryforward years in the other tabs, then click "Calculate Carryforward".
'; });