Vehicle Depreciation & Loan Balance Analyzer
Vehicle & Depreciation Details
Loan Details
Analysis & Results
Enter details and click "Analyze" to see results.
| Year | Start Loan Balance | Vehicle Value | Annual Payments | Interest Paid | Principal Paid | End Loan Balance | Equity |
|---|---|---|---|---|---|---|---|
| No data yet. | |||||||
Total Interest Paid (over actual payments): $${totalInterestPaidOverLoanLife.toFixed(2)}
`; vdlaLastAnalysisData = { inputs: { initialPrice, depRateYear1: depRateYear1*100, depRateSubsequent: depRateSubsequent*100, loanAmount, annualInterestRate: annualInterestRate*100, loanTermYears, projectionYears }, monthlyPayment, totalInterestPaidOverLoanLife, table: analysisResults }; } function vdlaDownloadPDF() { if (!vdlaLastAnalysisData || !vdlaLastAnalysisData.table || vdlaLastAnalysisData.table.length === 0) { alert("Please analyze the data first before downloading the PDF."); vdlaNavigateTab('vdlaResultsTab'); // Ensure results tab is active vdlaAnalyze(); // Try to analyze if (!vdlaLastAnalysisData || !vdlaLastAnalysisData.table || vdlaLastAnalysisData.table.length === 0) return; // Still no data } const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'landscape' }); // Landscape for wider table const { inputs, monthlyPayment, totalInterestPaidOverLoanLife, table } = vdlaLastAnalysisData; const primaryColor = [0, 121, 107]; // RGB for #00796b let y = 15; doc.setFontSize(16); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]); doc.text("Vehicle Depreciation & Loan Balance Analysis", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' }); y += 10; doc.setFontSize(10); doc.setTextColor(51, 51, 51); doc.text(`Initial Vehicle Price: $${inputs.initialPrice.toFixed(2)}`, 14, y); doc.text(`Dep. Rate Year 1: ${inputs.depRateYear1.toFixed(1)}%`, 80, y); doc.text(`Subsequent Dep. Rate: ${inputs.depRateSubsequent.toFixed(1)}%`, 140, y); y += 6; doc.text(`Loan Amount: $${inputs.loanAmount.toFixed(2)}`, 14, y); doc.text(`Interest Rate: ${inputs.annualInterestRate.toFixed(2)}%`, 80, y); doc.text(`Loan Term: ${inputs.loanTermYears} years`, 140, y); y += 6; doc.text(`Projection Period: ${inputs.projectionYears} years`, 14, y); doc.text(`Monthly Payment: $${monthlyPayment.toFixed(2)}`, 80, y); doc.text(`Total Interest Paid: $${totalInterestPaidOverLoanLife.toFixed(2)}`, 140, y); y += 10; const tableColumnStyles = { 0: { halign: 'center' }, // Year 1: { halign: 'right' }, // Start Loan Balance 2: { halign: 'right' }, // Vehicle Value 3: { halign: 'right' }, // Annual Payments 4: { halign: 'right' }, // Interest Paid 5: { halign: 'right' }, // Principal Paid 6: { halign: 'right' }, // End Loan Balance 7: { halign: 'right' } // Equity }; const head = [['Year', 'Start Loan Bal.', 'Vehicle Value', 'Annual Pymts', 'Interest Paid', 'Principal Paid', 'End Loan Bal.', 'Equity ($)']]; const body = table.map(row => [ row.year, `$${row.beginningLoanBalance.toFixed(2)}`, `$${row.vehicleValue.toFixed(2)}`, `$${row.annualPayments.toFixed(2)}`, `$${row.interestPaid.toFixed(2)}`, `$${row.principalPaid.toFixed(2)}`, `$${row.endingLoanBalance.toFixed(2)}`, `$${row.equity.toFixed(2)}` ]); doc.autoTable({ startY: y, head: head, body: body, theme: 'grid', headStyles: { fillColor: primaryColor, textColor: [255,255,255] }, columnStyles: tableColumnStyles, didDrawCell: (data) => { // Color equity cell if (data.column.index === 7 && data.cell.section === 'body') { const equityValue = parseFloat(data.cell.raw.toString().replace('$', '')); if (equityValue < 0) { doc.setTextColor(192, 57, 43); // Red } else { doc.setTextColor(39, 174, 96); // Green } } } }); doc.save("Vehicle_Depreciation_Loan_Analysis.pdf"); } // Initial setup vdlaUpdateNavButtons(); // Make functions globally accessible window.vdlaSwitchTab = vdlaSwitchTab; window.vdlaNavigateTab = vdlaNavigateTab; window.vdlaAnalyze = vdlaAnalyze; window.vdlaDownloadPDF = vdlaDownloadPDF;