Personal Loan Origination Fee Estimator


Error: Calculator components failed to load.

"; } // Initial state for fee input display toggleFeeInputOFE(); }); function toggleFeeInputOFE() { if (feeTypePercentageRadioOFE && feeTypePercentageRadioOFE.checked) { if(feePercentageGroupOFE) feePercentageGroupOFE.style.display = "block"; if(feeFlatGroupOFE) feeFlatGroupOFE.style.display = "none"; } else if (feeTypeFlatRadioOFE && feeTypeFlatRadioOFE.checked) { if(feePercentageGroupOFE) feePercentageGroupOFE.style.display = "none"; if(feeFlatGroupOFE) feeFlatGroupOFE.style.display = "block"; } } function formatCurrencyOFE(value) { const num = Number(value); if (isNaN(num) || !isFinite(num)) return "0.00"; return num.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); } function calculateOriginationFeeOFE() { const loanAmount = parseFloat(loanAmountInOFE.value); const isPercentageFee = feeTypePercentageRadioOFE.checked; let feeValue; let feeTypeString = ""; if (isNaN(loanAmount) || loanAmount <= 0) { alert("Please enter a valid Loan Amount greater than 0."); return; } let originationFee = 0; if (isPercentageFee) { feeValue = parseFloat(feePercentageValueInOFE.value); if (isNaN(feeValue) || feeValue < 0 || feeValue > 100) { alert("Please enter a valid Fee Percentage (0-100)."); return; } originationFee = loanAmount * (feeValue / 100); feeTypeString = `${feeValue}% of Loan Amount`; } else { // Flat Fee feeValue = parseFloat(feeFlatValueInOFE.value); if (isNaN(feeValue) || feeValue < 0) { alert("Please enter a valid Flat Fee Amount (0 or positive)."); return; } originationFee = feeValue; feeTypeString = `Flat Fee`; } const netDisbursed = loanAmount - originationFee; calculatedFeeOutOFE.textContent = `$${formatCurrencyOFE(originationFee)}`; netDisbursedOutOFE.textContent = `$${formatCurrencyOFE(netDisbursed < 0 ? 0 : netDisbursed)}`; // Net disbursed shouldn't be negative if (netDisbursed < 0) { feeNoteOutOFE.textContent = "Note: The calculated origination fee exceeds the loan amount, resulting in a negative net disbursed amount. Please review your inputs."; } else { feeNoteOutOFE.textContent = `The Origination Fee is an upfront cost of borrowing. Your loan principal (the amount on which interest and repayments are typically calculated) is the requested Loan Amount of $${formatCurrencyOFE(loanAmount)}. The Net Amount Disbursed is what you would typically receive after the fee is deducted.`; } calculatedValuesOFE = { inputs: { loanAmount, feeType: isPercentageFee ? "percentage" : "flat", feeInputValue: feeValue, feeTypeString: feeTypeString }, outputs: { originationFee, netDisbursed, note: feeNoteOutOFE.textContent } }; resultsSectionOFE.style.display = "block"; } function generatePdfOFE() { if (Object.keys(calculatedValuesOFE).length === 0 || !resultsSectionOFE || resultsSectionOFE.style.display === 'none') { alert('Please calculate the fee 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 = calculatedValuesOFE; try { doc.setFontSize(16); doc.setTextColor(74, 93, 35); // #4A5D23 Darker Olive Green doc.text("Personal Loan Origination Fee Estimation", 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 = [85, 107, 47]; // #556B2F Dark Olive Green const headTextColor = [255, 255, 255]; doc.setFontSize(12); doc.setTextColor(74, 93, 35); doc.text("Loan & Fee Inputs", 14, startY); startY += 7; let feeInputDisplay = ""; if (data.inputs.feeType === "percentage") { feeInputDisplay = `${(data.inputs.feeInputValue || 0).toFixed(2)}%`; } else { feeInputDisplay = `$${formatCurrencyOFE(data.inputs.feeInputValue)}`; } doc.autoTable({ body: [ ['Requested Loan Amount:', `$${formatCurrencyOFE(data.inputs.loanAmount)}`], ['Origination Fee Type:', data.inputs.feeTypeString], ['Specified Fee Value:', feeInputDisplay] ], startY: startY, theme: 'plain', styles: { fontSize: 10, cellPadding: 1.5 }, columnStyles: { 0: { fontStyle: 'bold', cellWidth: 70 } } }); startY = doc.lastAutoTable.finalY + 10; doc.setFontSize(12); doc.setTextColor(74, 93, 35); doc.text("Fee Estimation Results", 14, startY); startY += 7; doc.autoTable({ body: [ ['Calculated Origination Fee:', `$${formatCurrencyOFE(data.outputs.originationFee)}`], ['Net Amount Disbursed (Loan Amount - Fee):', `$${formatCurrencyOFE(data.outputs.netDisbursed < 0 ? 0 : data.outputs.netDisbursed)}`] ], startY: startY, theme: 'plain', styles: { fontSize: 10, cellPadding: 1.5, fontStyle: 'bold' }, columnStyles: { 0: { cellWidth: 70 } } }); startY = doc.lastAutoTable.finalY + 8; doc.setFontSize(9); doc.setTextColor(88, 76, 62); // #584c3e Brownish const splitNote = doc.splitTextToSize(data.outputs.note, doc.internal.pageSize.getWidth() - 28); doc.text(splitNote, 14, startY); doc.save("Personal_Loan_Origination_Fee_Summary.pdf"); } catch (error) { console.error("OFE PDF Error:", error); alert("An error occurred while generating the PDF: " + error.message); } }
Scroll to Top