Loan Cost Analyzer (Comparing Interest Rates & Fees)

Common Loan Details

${summaryMsg}

`; resultsSummaryDiv.style.display = 'block'; } if(downloadPdfButton) downloadPdfButton.style.display = 'block'; } if(downloadPdfButton) { downloadPdfButton.onclick = function() { if (!comparisonDataForPdf) { alert("Please calculate comparison first."); return; } console.log("APRC Tool: Generating PDF..."); if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') { alert('Error: jsPDF library not loaded.'); console.error("APRC Tool: jsPDF not loaded."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); if (typeof doc.autoTable !== 'function') { alert('Error: jsPDF-AutoTable plugin not loaded.'); console.error("APRC Tool: jsPDF-AutoTable not loaded."); return; } const { inputs, option1, option2 } = comparisonDataForPdf; doc.setFontSize(18); doc.text("Loan Cost Comparison Report (Interest & Fees)", 14, 22); let yPos = 30; doc.setFontSize(12); doc.text("Common Loan Inputs:", 14, yPos); yPos += 7; doc.setFontSize(10); doc.text(` Desired Loan Amount: $${inputs.desiredAmount.toFixed(2)}`, 14, yPos); yPos += 5; doc.text(` Loan Term: ${inputs.termYrs} years`, 14, yPos); yPos += 7; doc.setFontSize(12); doc.text("Overall Comparison Summary:", 14, yPos); yPos +=7; doc.setFontSize(10); const summaryP = resultsSummaryDiv.querySelector('p'); if (summaryP) { const summaryLines = doc.splitTextToSize(summaryP.innerText, 180); doc.text(summaryLines, 14, yPos); yPos += (summaryLines.length * 5) + 2; } const head = [['Feature', option1.name, option2.name]]; const body = [ ['Nominal Interest Rate', `${option1.rate.toFixed(2)}%`, `${option2.rate.toFixed(2)}%`], ['Loan Fees (Financed)', `$${option1.fees.toFixed(2)}`, `$${option2.fees.toFixed(2)}`], ['Total Amount Financed', `$${option1.totalFinanced.toFixed(2)}`, `$${option2.totalFinanced.toFixed(2)}`], ['Monthly Payment', `$${option1.monthlyPmt.toFixed(2)}`, `$${option2.monthlyPmt.toFixed(2)}`], ['Total Interest Paid', `$${option1.totalInterest.toFixed(2)}`, `$${option2.totalInterest.toFixed(2)}`], [{content: 'Total Cost of Loan (Interest + Fees)', styles: {fontStyle: 'bold'}}, {content: `$${option1.totalCost.toFixed(2)}`, styles: {fontStyle: 'bold',textColor: option1.totalCost <= option2.totalCost ? [40,167,69] : [0,0,0]}}, {content: `$${option2.totalCost.toFixed(2)}`, styles: {fontStyle: 'bold', textColor: option2.totalCost < option1.totalCost ? [40,167,69] : [0,0,0]}}], ['Total Repayment', `$${option1.totalRepayment.toFixed(2)}`, `$${option2.totalRepayment.toFixed(2)}`], ]; doc.autoTable({ head: head, body: body, startY: yPos, headStyles: { fillColor: [0, 123, 255] }, styles: { font: "helvetica", fontSize: 9, cellPadding: 2 }, columnStyles: { 0: { halign: 'left', fontStyle: 'bold' }, 1: { halign: 'right' }, 2: { halign: 'right' } }, alternateRowStyles: { fillColor: [233, 236, 239] }, didDrawPage: function (data) { doc.setFontSize(9); doc.text('Page ' + doc.internal.getNumberOfPages(), data.settings.margin.left, doc.internal.pageSize.height - 10); } }); yPos = doc.previousAutoTable.finalY + 10; doc.setFontSize(9); doc.setTextColor(100); const noteLines = doc.splitTextToSize("Note: This tool helps compare loan costs by showing the impact of interest rates and fees. The 'Total Cost of Loan' reflects these combined expenses. An Annual Percentage Rate (APR), if quoted by a lender, also aims to represent this true cost. Always verify all terms with your lender.", 180); doc.text(noteLines, 14, yPos); const toolName = "LoanCostComparison_InterestAndFees"; const date = new Date(); const filename = `${toolName}_${date.getFullYear()}${String(date.getMonth() + 1).padStart(2, '0')}${String(date.getDate()).padStart(2, '0')}.pdf`; doc.save(filename); console.log("APRC Tool: PDF generated: " + filename); }; } // Initial setup aprc_openTab(null, 'aprcTab1'); console.log("APRC Tool: Initialized. Tab 1 displayed."); // Final critical elements check const allElements = { desiredLoanAmountEl, loanTermYearsEl, opt1LenderNameEl, opt1InterestRateEl, opt1FeesEl, opt2LenderNameEl, opt2InterestRateEl, opt2FeesEl, ...tabLinks, ...tabContents, ...errorDivs, resultsSummaryDiv, comparisonTable, comparisonBody, downloadPdfButton, opt1NameHeaderEl, opt2NameHeaderEl }; let allCriticalFound = true; for (const key in allElements) { if (!allElements[key]) { console.error(`APRC Tool: CRITICAL - Element for '${key}' was NOT FOUND in the DOM.`); allCriticalFound = false; } } if (!allCriticalFound) { const toolContainer = document.getElementById("aprcLoanCostAnalyzerTool"); if (toolContainer) toolContainer.innerHTML = "

Tool initialization failed: Critical HTML element missing. Check console.

"; return; } console.log("APRC Tool: All critical DOM elements located."); });
Scroll to Top