Personal Loan EMI Calculator
Loan Summary
Monthly EMI:
$0.00
Total Interest Payable:
$0.00
Total Amount Payable (Principal + Interest):
$0.00
Error: Calculator components failed to load.
"; } }); function formatCurrencyPLE(value) { const num = Number(value); if (isNaN(num)) return "0.00"; return num.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); } function calculateEmiPLE() { if (!loanAmountInPLE || !annualInterestRateInPLE || !loanTenureMonthsInPLE) { alert("Initialization error. Please refresh."); return; } const principal = parseFloat(loanAmountInPLE.value); const annualRate = parseFloat(annualInterestRateInPLE.value); const tenureMonths = parseInt(loanTenureMonthsInPLE.value); if (isNaN(principal) || principal <= 0) { alert("Please enter a valid Loan Amount greater than 0."); return; } if (isNaN(annualRate) || annualRate < 0) { alert("Please enter a valid Annual Interest Rate (0 or positive)."); return; } if (isNaN(tenureMonths) || tenureMonths <= 0) { alert("Please enter a valid Loan Tenure in months (greater than 0)."); return; } let emi = 0; let totalInterest = 0; let totalAmount = 0; if (annualRate === 0) { emi = principal / tenureMonths; totalInterest = 0; totalAmount = principal; } else { const monthlyRate = annualRate / 12 / 100; const powerTerm = Math.pow(1 + monthlyRate, tenureMonths); if (powerTerm - 1 === 0) { emi = principal / tenureMonths; } else { emi = principal * monthlyRate * powerTerm / (powerTerm - 1); } if (isNaN(emi) || !isFinite(emi)) { alert("Could not calculate EMI. Please check your inputs."); emi = 0; totalInterest = 0; totalAmount = 0; } else { totalAmount = emi * tenureMonths; totalInterest = totalAmount - principal; if (totalInterest < 0) totalInterest = 0; } } monthlyEmiOutPLE.textContent = `$${formatCurrencyPLE(emi)}`; totalInterestOutPLE.textContent = `$${formatCurrencyPLE(totalInterest)}`; totalAmountOutPLE.textContent = `$${formatCurrencyPLE(totalAmount)}`; calculatedValuesPLE = { principal: principal, annualRate: annualRate, tenureMonths: tenureMonths, emi: emi, totalInterest: totalInterest, totalAmount: totalAmount }; resultsSectionPLE.style.display = "block"; } function generatePdfPLE() { if (Object.keys(calculatedValuesPLE).length === 0 || !resultsSectionPLE || resultsSectionPLE.style.display === 'none') { alert('Please calculate the EMI first to generate a PDF summary.'); return; } if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') { alert('PDF generation library (jsPDF) is not loaded.'); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); if (typeof doc.autoTable !== 'function') { alert('PDF generation plugin (jsPDF-AutoTable) is not loaded.'); return; } const data = calculatedValuesPLE; try { doc.setFontSize(18); doc.setTextColor(102, 0, 0); // #660000 Dark Maroon doc.text("Personal Loan EMI Calculation Summary", 14, 22); doc.setFontSize(10); doc.setTextColor(100); doc.text(`Report Generated: ${new Date().toLocaleDateString()}`, 14, 28); let startY = 38; const tableTheme = 'grid'; const headFillColor = [128, 0, 0]; // Maroon #800000 const headTextColor = [255, 255, 255]; // White doc.setFontSize(12); doc.setTextColor(115, 0, 0); // #730000 doc.text("Loan Inputs", 14, startY); startY += 7; doc.autoTable({ head: [['Parameter', 'Value']], body: [ ['Loan Amount (Principal)', `$${formatCurrencyPLE(data.principal)}`], ['Annual Interest Rate (APR)', `${(data.annualRate || 0).toFixed(2)}%`], ['Loan Tenure', `${data.tenureMonths} months`] ], startY: startY, theme: tableTheme, headStyles: { fillColor: headFillColor, textColor: headTextColor }, styles: { fontSize: 10 } }); startY = doc.lastAutoTable.finalY + 12; doc.setFontSize(12); doc.setTextColor(115, 0, 0); doc.text("Calculation Results", 14, startY); startY += 7; doc.autoTable({ head: [['Description', 'Amount']], body: [ ['Monthly EMI', `$${formatCurrencyPLE(data.emi)}`], ['Total Interest Payable', `$${formatCurrencyPLE(data.totalInterest)}`], ['Total Amount Payable (Principal + Interest)', `$${formatCurrencyPLE(data.totalAmount)}`] ], startY: startY, theme: tableTheme, headStyles: { fillColor: headFillColor, textColor: headTextColor }, styles: { fontSize: 10 }, columnStyles: { 1: { fontStyle: 'bold' } } }); doc.save("Personal_Loan_EMI_Summary.pdf"); } catch (error) { console.error("PLE PDF Error:", error); alert("An error occurred while generating the PDF: " + error.message); } }