Hypothetical Rate Lock Expiry Calculator

Error: Tool components failed to load.

"; } }); function formatDateRLPT(dateObj) { if (!dateObj || isNaN(dateObj.getTime())) return "--/--/----"; const day = String(dateObj.getDate()).padStart(2, '0'); const month = String(dateObj.getMonth() + 1).padStart(2, '0'); // Month is 0-indexed const year = dateObj.getFullYear(); return `${month}/${day}/${year}`; } function calculateLockExpiryRLPT() { if (!lockStartDateInRLPT || !lockDurationDaysInRLPT || !resultsSectionRLPT) { alert("Initialization error. Please refresh."); return; } const startDateStr = lockStartDateInRLPT.value; const durationDays = parseInt(lockDurationDaysInRLPT.value); const lockedApr = parseFloat(lockedAprInRLPT.value); // For PDF record if (!startDateStr) { alert("Please select a Start Date for the hypothetical lock."); return; } if (isNaN(durationDays) || durationDays <= 0) { alert("Please enter a valid positive number for Lock Duration in days."); return; } if (isNaN(lockedApr) && lockedAprInRLPT.value.trim() !== "") { // APR is optional for calculation but validate if entered alert("Please enter a valid number for the hypothetically locked APR, or leave it blank."); return; } const startDate = new Date(startDateStr + "T00:00:00"); // Ensure it's parsed as local date, not UTC midnight then converted if (isNaN(startDate.getTime())) { alert("Invalid Start Date selected."); return; } const expiryDate = new Date(startDate); expiryDate.setDate(startDate.getDate() + durationDays); const today = new Date(); today.setHours(0, 0, 0, 0); // Normalize today to midnight for day comparison // Calculate difference in milliseconds then convert to days const diffTime = expiryDate.getTime() - today.getTime(); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); let status = ""; let statusClass = ""; if (diffDays > 0) { status = `Active (${diffDays} day${diffDays !== 1 ? 's' : ''} remaining)`; statusClass = "status-active"; } else if (diffDays === 0) { status = "Expires Today"; statusClass = "status-expires-today"; } else { // diffDays < 0 status = `Expired (${Math.abs(diffDays)} day${Math.abs(diffDays) !== 1 ? 's' : ''} ago)`; statusClass = "status-expired"; } lockExpiryDateOutRLPT.textContent = formatDateRLPT(expiryDate); daysRemainingOutRLPT.textContent = (diffDays >= 0) ? diffDays : 0; // Don't show negative days remaining lockStatusOutRLPT.textContent = status; lockStatusOutRLPT.className = ''; // Clear existing classes lockStatusOutRLPT.classList.add(statusClass); calculatedValuesRLPT = { inputs: { apr: isNaN(lockedApr) ? "N/A" : lockedApr, startDate: startDateStr, duration: durationDays }, outputs: { expiryDate: formatDateRLPT(expiryDate), daysRemaining: (diffDays >= 0) ? diffDays : `Expired ${Math.abs(diffDays)} day(s) ago`, status: status } }; resultsSectionRLPT.style.display = "block"; } function generatePdfRLPT() { if (Object.keys(calculatedValuesRLPT).length === 0 || !resultsSectionRLPT || resultsSectionRLPT.style.display === 'none') { alert('Please calculate the expiry details 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 = calculatedValuesRLPT; try { doc.setFontSize(16); doc.setTextColor(52, 58, 64); // #343A40 Dark Gray doc.text("Hypothetical Rate Lock Expiry Calculation", 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 = [108, 117, 125]; // #6C757D Gray const headTextColor = [255, 255, 255]; doc.setFontSize(12); doc.setTextColor(73, 80, 87); // #495057 doc.text("User-Provided Hypothetical Lock Details", 14, startY); startY += 7; doc.autoTable({ body: [ ['Hypothetically Locked APR:', data.inputs.apr === "N/A" ? "N/A" : `${data.inputs.apr.toFixed(3)}%`], ['Hypothetical Lock Start Date:', data.inputs.startDate ? formatDateRLPT(new Date(data.inputs.startDate + "T00:00:00")) : "N/A"], ['Hypothetical Lock Duration:', `${data.inputs.duration} days`] ], 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(73, 80, 87); doc.text("Calculated Expiry Information", 14, startY); startY += 7; doc.autoTable({ body: [ ['Calculated Expiration Date:', data.outputs.expiryDate], ['Status / Days Remaining (as of today):', data.outputs.status] ], startY: startY, theme: 'plain', styles: { fontSize: 10, cellPadding: 1.5, fontStyle: 'bold' }, columnStyles: { 0: { cellWidth: 70 } } }); startY = doc.lastAutoTable.finalY + 10; doc.setFontSize(9); doc.setTextColor(120); const noteText = "Note: This tool calculates dates based on the hypothetical information you provided. It does not offer, secure, or guarantee any interest rate lock, nor does it verify information with any financial institution. Rate locks are agreements made directly with lenders and are subject to their terms and conditions."; const splitNote = doc.splitTextToSize(noteText, doc.internal.pageSize.getWidth() - 28); doc.text(splitNote, 14, startY); doc.save("Hypothetical_Rate_Lock_Expiry.pdf"); } catch (error) { console.error("RLPT PDF Error:", error); alert("An error occurred while generating the PDF: " + error.message); } }
Scroll to Top