Error in biweekly calculation. Please check inputs or report issue.
";
mbcLastCalculationData = null;
return;
}
}
const totalPaymentsBiweekly = loanAmount + totalInterestBiweekly;
const payoffTimeBiweeklyYears = Math.floor(monthsBiweekly / 12);
const payoffTimeBiweeklyRemainderMonths = monthsBiweekly % 12;
// --- Savings ---
const interestSaved = totalInterestMonthly - totalInterestBiweekly;
const monthsSaved = (payoffTimeMonthlyMonthsTotal - monthsBiweekly);
const yearsSaved = Math.floor(monthsSaved / 12);
const remainderMonthsSaved = monthsSaved % 12;
mbcLastCalculationData = {
inputs: { loanAmount, annualRate, loanTermYears },
monthlyPlan: {
monthlyPayment: standardMonthlyPayment,
payoffTimeYears: payoffTimeMonthlyYears,
payoffTimeMonths: 0, // Standard term
totalInterest: totalInterestMonthly,
totalPaid: totalPaymentsMonthly
},
biweeklyPlan: {
biweeklyPayment: standardMonthlyPayment / 2,
payoffTimeYears: payoffTimeBiweeklyYears,
payoffTimeMonths: payoffTimeBiweeklyRemainderMonths,
totalInterest: totalInterestBiweekly,
totalPaid: totalPaymentsBiweekly
},
savings: {
interestSaved: interestSaved,
yearsSaved: yearsSaved,
monthsSaved: remainderMonthsSaved
}
};
let outputHTML = `
Standard Monthly Payment: $${standardMonthlyPayment.toFixed(2)}
Equivalent Biweekly Payment (paid every two weeks): $${(standardMonthlyPayment / 2).toFixed(2)}
| Metric |
Monthly Plan |
Biweekly Plan |
| Payoff Time |
${payoffTimeMonthlyYears} Years |
${payoffTimeBiweeklyYears} Years, ${payoffTimeBiweeklyRemainderMonths} Months |
| Total Principal Paid |
$${loanAmount.toFixed(2)} |
$${loanAmount.toFixed(2)} |
| Total Interest Paid |
$${totalInterestMonthly.toFixed(2)} |
$${totalInterestBiweekly.toFixed(2)} |
| Total Amount Paid |
$${totalPaymentsMonthly.toFixed(2)} |
$${totalPaymentsBiweekly.toFixed(2)} |
Potential Savings with Biweekly Payments:
You could save approximately $${interestSaved.toFixed(2)} in interest.
You could pay off your loan approximately ${yearsSaved} years and ${remainderMonthsSaved} months sooner.
`;
resultsOutput.innerHTML = outputHTML;
}
// --- PDF Download Functionality ---
function mbcDownloadPDF() {
if (!mbcLastCalculationData) {
alert("Please calculate the savings first before downloading the PDF.");
mbcNavigateTab('mbcComparisonTab');
mbcCalculateSavings();
if (!mbcLastCalculationData) return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const { inputs, monthlyPlan, biweeklyPlan, savings } = mbcLastCalculationData;
const primaryColor = [0, 121, 107]; // RGB for #00796b
let y = 15;
doc.setFontSize(16);
doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text("Monthly vs. Biweekly Loan Payment Comparison", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 8;
doc.setFontSize(8);
doc.setTextColor(100);
doc.text("Illustrative comparison. Assumes biweekly payments lead to one extra monthly payment per year.", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 10;
doc.setFontSize(10);
doc.setTextColor(51, 51, 51);
doc.text("Loan Inputs:", 14, y); y += 6;
doc.text(` Loan Amount: $${inputs.loanAmount.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}`, 14, y);
doc.text(`Annual Interest Rate: ${inputs.annualRate.toFixed(2)}%`, 100, y); y += 6;
doc.text(` Loan Term: ${inputs.loanTermYears} years`, 14, y); y+= 8;
doc.setFontSize(11);
doc.text(`Standard Monthly Payment: $${monthlyPlan.monthlyPayment.toFixed(2)}`, 14, y); y+=6;
doc.text(`Equivalent Biweekly Payment: $${biweeklyPlan.biweeklyPayment.toFixed(2)} (paid every two weeks)`, 14, y); y+= 10;
const head = [['Metric', 'Monthly Plan', 'Biweekly Plan']];
const body = [
['Payoff Time', `${monthlyPlan.payoffTimeYears} Years`, `${biweeklyPlan.payoffTimeYears} Yrs, ${biweeklyPlan.payoffTimeMonths} Mos`],
['Total Principal Paid', `$${inputs.loanAmount.toFixed(2)}`, `$${inputs.loanAmount.toFixed(2)}`],
['Total Interest Paid', `$${monthlyPlan.totalInterest.toFixed(2)}`, `$${biweeklyPlan.totalInterest.toFixed(2)}`],
['Total Amount Paid', `$${monthlyPlan.totalPaid.toFixed(2)}`, `$${biweeklyPlan.totalPaid.toFixed(2)}`]
];
doc.autoTable({
startY: y,
head: head,
body: body,
theme: 'grid',
headStyles: { fillColor: primaryColor, textColor: [255,255,255], halign: 'center' },
columnStyles: { 0: { halign: 'left'}, 1: {halign: 'center'}, 2: {halign: 'center'} }
});
y = doc.lastAutoTable.finalY + 10;
doc.setFontSize(12); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text("Potential Savings with Biweekly Payments:", 14, y); y+=7;
doc.setFontSize(11); doc.setTextColor(39, 174, 96); // Green
doc.text(` Interest Saved: $${savings.interestSaved.toFixed(2)}`, 14, y); y+=6;
doc.text(` Time Saved: ${savings.yearsSaved} years and ${savings.monthsSaved} months sooner`, 14, y); y+=10;
if (y > 250) { doc.addPage(); y = 20; } // Basic pagination
doc.setFontSize(9); doc.setTextColor(85, 85, 85);
const footerText = "Important: Biweekly payment plans effectively make one extra monthly payment per year. Always check with your lender regarding their biweekly payment policies, how extra payments are applied (ensure to principal), and if any fees are associated with such services. This calculator assumes no additional fees for the biweekly plan.";
const splitFooter = doc.splitTextToSize(footerText, doc.internal.pageSize.getWidth() - 28);
doc.text(splitFooter, 14, y);
doc.save("Monthly_vs_Biweekly_Loan_Savings.pdf");
}
// Initial setup
// No specific nav button disabling needed for this simple 2-tab setup.
// Make functions globally accessible
window.mbcSwitchTab = mbcSwitchTab;
window.mbcNavigateTab = mbcNavigateTab;
window.mbcCalculateSavings = mbcCalculateSavings;
window.mbcDownloadPDF = mbcDownloadPDF;