Dealer Financing vs. Bank Loan Cost Analyzer
Vehicle & General Loan Information
Dealer Financing Option
Bank/Credit Union Loan Option
Comparison Results
| Feature | Dealer Financing | Bank/CU Loan |
|---|
${summaryMsg}
`; resultsSummaryDiv.style.display = 'block'; downloadPdfButton.style.display = 'block'; } if(downloadPdfButton) { downloadPdfButton.onclick = function() { if (!comparisonResultsData) { alert("Please calculate comparison first."); return; } console.log("DFBL Calc: Generating PDF..."); if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') { alert('Error: jsPDF library not loaded.'); console.error("DFBL Calc: 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("DFBL Calc: jsPDF-AutoTable not loaded."); return; } const { inputs, dealer, bank } = comparisonResultsData; doc.setFontSize(18); doc.text("Dealer vs. Bank Loan Comparison Report", 14, 22); let yPos = 30; doc.setFontSize(12); doc.text("Common Loan Inputs:", 14, yPos); yPos += 7; doc.setFontSize(10); doc.text(` Vehicle Price: $${inputs.vPrice.toFixed(2)}`, 14, yPos); yPos += 5; doc.text(` Down Payment: $${inputs.downPmt.toFixed(2)}`, 14, yPos); yPos += 5; doc.text(` Trade-in Value: $${inputs.tradeIn.toFixed(2)}`, 14, yPos); yPos += 5; doc.text(` Sales Tax Rate: ${(inputs.salesTaxPercent * 100).toFixed(2)}%`, 14, yPos); yPos += 5; doc.text(` Loan Term: ${inputs.termYrs} years`, 14, yPos); yPos += 7; doc.setFontSize(12); doc.text("Overall Summary:", 14, yPos); yPos +=7; doc.setFontSize(10); const summaryP = resultsSummaryDiv.querySelector('p'); if (summaryP) { const summaryLines = doc.splitTextToSize(summaryP.innerText, 180); // Split text to fit width doc.text(summaryLines, 14, yPos); yPos += (summaryLines.length * 5) + 2; // Adjust yPos based on number of lines } const head = [['Feature', 'Dealer Financing', 'Bank/CU Loan']]; const body = [ ['Interest Rate (%)', dealer.rate.toFixed(2), bank.rate.toFixed(2)], ['Loan Fees (financed) ($)', dealer.fees.toFixed(2), bank.fees.toFixed(2)], ['Cash Rebate Applied ($)', dealer.rebate.toFixed(2), 'N/A'], ['Sales Tax Amount ($)', dealer.salesTax.toFixed(2), bank.salesTax.toFixed(2)], ['Net Amount Financed ($)', (dealer.principal > 0 ? dealer.principal : 0).toFixed(2), (bank.principal > 0 ? bank.principal : 0).toFixed(2)], ['Monthly Payment ($)', dealer.monthlyPmt.toFixed(2), bank.monthlyPmt.toFixed(2)], ['Total Interest Paid ($)', dealer.totalInterest.toFixed(2), bank.totalInterest.toFixed(2)], ['Total Payments (Loan Life) ($)', dealer.totalPmt.toFixed(2), bank.totalPmt.toFixed(2)], [{content: 'Overall Vehicle Cost ($)', styles: {fontStyle: 'bold'}}, {content: `$${dealer.overallCost.toFixed(2)}`, styles: {fontStyle: 'bold', textColor: dealer.overallCost <= bank.overallCost ? [40,167,69] : [0,0,0]}}, {content: `$${bank.overallCost.toFixed(2)}`, styles: {fontStyle: 'bold', textColor: bank.overallCost <= dealer.overallCost ? [40,167,69] : [0,0,0]}} ], ]; 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); } }); const toolName = "DealerVsBankLoanAnalyzer"; 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("DFBL Calc: PDF generated: " + filename); }; } // Initial setup dfbl_openTab(null, 'dfblTab1'); console.log("DFBL Calc: Initialized. Tab 1 displayed."); // Final critical elements check for developer const allElements = { vehiclePriceEl, downPaymentEl, tradeInValueEl, salesTaxRateEl, loanTermYearsEl, dealerRateEl, dealerRebateEl, dealerFeesEl, bankRateEl, bankFeesEl, ...tabLinks, ...tabContents, ...errorDivs, resultsSummaryDiv, comparisonTable, comparisonBody, downloadPdfButton }; for (const key in allElements) { if (!allElements[key]) { console.error(`DFBL Calc: CRITICAL - Element for '${key}' was NOT FOUND in the DOM.`); const toolContainer = document.getElementById("dfblLoanAnalyzerTool"); if (toolContainer) toolContainer.innerHTML = "Tool initialization failed: Critical HTML element missing. Check console.
"; return; // Stop further script execution } } console.log("DFBL Calc: All critical DOM elements located."); });