Business Loan Bridge Financing Calculator
Associated Costs
Summary & Results
Please complete the previous tabs to see the summary.
Please correct errors in Tab 2: Associated Costs.
';
if(blbfc_domElements.pdfDownloadBtn) blbfc_domElements.pdfDownloadBtn.classList.add('blbfc-hidden');
return;
}
const loanAmount = parseFloat(blbfc_domElements.loanAmount.value);
const loanTermMonths = parseInt(blbfc_domElements.loanTerm.value);
const annualInterestRate = parseFloat(blbfc_domElements.interestRate.value);
const feeTypeRadio = document.querySelector('input[name="blbfc-originationFeeType"]:checked');
if (!feeTypeRadio) {
console.error("Fee type radio not checked during calculation.");
return;
}
const feeType = feeTypeRadio.value;
let originationFeeCost = 0;
if (feeType === 'percentage') {
const feePercent = parseFloat(blbfc_domElements.originationFeePercent.value || 0); // Default to 0 if empty
originationFeeCost = loanAmount * (feePercent / 100);
} else {
originationFeeCost = parseFloat(blbfc_domElements.originationFeeFixed.value || 0); // Default to 0 if empty
}
const otherFees = parseFloat(blbfc_domElements.otherFees.value || 0); // Default to 0 if empty
const totalUpfrontCosts = originationFeeCost + otherFees;
const totalInterest = loanAmount * (annualInterestRate / 100 / 12) * loanTermMonths;
const monthlyInterest = loanTermMonths > 0 ? totalInterest / loanTermMonths : 0;
const totalRepaymentPrincipalAndInterest = loanAmount + totalInterest;
const grandTotalCostOfLoan = totalInterest + totalUpfrontCosts;
if(blbfc_domElements.resultsContainer){
blbfc_domElements.resultsContainer.innerHTML = `
Inputs Summary
Bridge Loan Amount Requested: ${blbfc_formatCurrency(loanAmount)}
Loan Term: ${loanTermMonths} months
Annual Interest Rate: ${annualInterestRate.toFixed(2)}%
Calculated Fees
Loan Origination Fee: ${blbfc_formatCurrency(originationFeeCost)}
Other Estimated Fees: ${blbfc_formatCurrency(otherFees)}
Total One-Time Fees: ${blbfc_formatCurrency(totalUpfrontCosts)}
Interest Calculation
Total Interest Accrued over Term: ${blbfc_formatCurrency(totalInterest)}
Effective Monthly Interest Payment: ${blbfc_formatCurrency(monthlyInterest)}
Total Repayment (End of Term)
Principal Repayment: ${blbfc_formatCurrency(loanAmount)}
Total Interest Repayment: ${blbfc_formatCurrency(totalInterest)}
Total Loan Repayment (Principal + Interest): ${blbfc_formatCurrency(totalRepaymentPrincipalAndInterest)}
Overall Cost Summary
Total Cost of Bridge Loan (Interest + Fees): ${blbfc_formatCurrency(grandTotalCostOfLoan)}
`;
}
if(blbfc_domElements.pdfDownloadBtn) blbfc_domElements.pdfDownloadBtn.classList.remove('blbfc-hidden');
}
function blbfc_generatePdf() {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
console.error("jsPDF library (window.jspdf.jsPDF) is not loaded!");
alert("Sorry, PDF generation is currently unavailable. The jsPDF library didn't load correctly.");
return;
}
if (typeof window.jspdf.jsPDF.API === 'undefined' || typeof window.jspdf.jsPDF.API.autoTable === 'undefined') {
console.error("jsPDF-AutoTable plugin (on jsPDF.API.autoTable) is not loaded!");
alert("Sorry, PDF generation is currently unavailable. The AutoTable plugin didn't load correctly.");
return;
}
const ActualJsPDF = window.jspdf.jsPDF;
if (!blbfc_validateTab1() || !blbfc_validateTab2()) {
alert("Please ensure all inputs are correctly filled before generating PDF.");
if (!blbfc_validateTab1()) {
const tab1Button = document.querySelector(`.blbfc-tab-link[data-tab="blbfc-tab1"]`);
if (tab1Button) tab1Button.click();
} else if (!blbfc_validateTab2()) {
const tab2Button = document.querySelector(`.blbfc-tab-link[data-tab="blbfc-tab2"]`);
if (tab2Button) tab2Button.click();
}
return;
}
const doc = new ActualJsPDF();
const loanAmount = parseFloat(blbfc_domElements.loanAmount.value);
const loanTermMonths = parseInt(blbfc_domElements.loanTerm.value);
const annualInterestRate = parseFloat(blbfc_domElements.interestRate.value);
const feeTypeRadio = document.querySelector('input[name="blbfc-originationFeeType"]:checked');
if (!feeTypeRadio) { console.error("Fee type radio not found for PDF."); return; }
const feeType = feeTypeRadio.value;
let originationFeePercentVal = "N/A";
let originationFeeFixedVal = "N/A";
let originationFeeCost = 0;
if (feeType === 'percentage') {
const feePercentInput = blbfc_domElements.originationFeePercent;
if (feePercentInput && feePercentInput.value.trim() !== "") { // Check not empty
originationFeePercentVal = parseFloat(feePercentInput.value);
originationFeeCost = loanAmount * (originationFeePercentVal / 100);
originationFeePercentVal += "%";
} else { originationFeePercentVal = "0.00%"; originationFeeCost = 0;}
} else {
const feeFixedInput = blbfc_domElements.originationFeeFixed;
if (feeFixedInput && feeFixedInput.value.trim() !== "") { // Check not empty
originationFeeFixedVal = parseFloat(feeFixedInput.value);
originationFeeCost = originationFeeFixedVal;
originationFeeFixedVal = blbfc_formatCurrency(originationFeeFixedVal);
} else { originationFeeFixedVal = blbfc_formatCurrency(0); originationFeeCost = 0;}
}
const otherFeesInput = blbfc_domElements.otherFees;
const otherFees = (otherFeesInput && otherFeesInput.value.trim() !== "") ? parseFloat(otherFeesInput.value) : 0;
const totalUpfrontCosts = originationFeeCost + otherFees;
const totalInterest = loanAmount * (annualInterestRate / 100 / 12) * loanTermMonths;
const monthlyInterest = loanTermMonths > 0 ? totalInterest / loanTermMonths : 0;
const totalRepaymentPrincipalAndInterest = loanAmount + totalInterest;
const grandTotalCostOfLoan = totalInterest + totalUpfrontCosts;
doc.setFontSize(18);
const primaryColorRGB = blbfc_hexToRgb(getComputedStyle(document.documentElement).getPropertyValue('--blbfc-primary-color').trim());
const secondaryColorRGB = blbfc_hexToRgb(getComputedStyle(document.documentElement).getPropertyValue('--blbfc-secondary-color').trim());
if (primaryColorRGB) doc.setTextColor(primaryColorRGB.r, primaryColorRGB.g, primaryColorRGB.b);
else doc.setTextColor(0, 90, 156); // Fallback primary
doc.text("Business Loan Bridge Financing Summary", 105, 20, null, null, "center");
doc.setFontSize(12);
doc.setTextColor(51, 51, 51);
let startY = 35;
const tableHeadFillColor = secondaryColorRGB ? [secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b] : [0, 51, 102]; // Fallback secondary
doc.setFontSize(14);
if (secondaryColorRGB) doc.setTextColor(secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b);
else doc.setTextColor(0, 51, 102); // Fallback secondary
doc.text("Inputs Summary", 14, startY);
startY += 7;
doc.autoTable({
startY: startY,
theme: 'grid',
headStyles: { fillColor: tableHeadFillColor },
body: [
["Bridge Loan Amount Requested:", blbfc_formatCurrency(loanAmount)],
["Loan Term:", `${loanTermMonths} months`],
["Annual Interest Rate:", `${annualInterestRate.toFixed(2)}%`],
],
margin: { left: 14, right: 14 }
});
startY = doc.autoTable.previous.finalY + 10;
doc.setFontSize(14);
if (secondaryColorRGB) doc.setTextColor(secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b); else doc.setTextColor(0, 51, 102);
doc.text("Calculated Fees", 14, startY);
startY += 7;
let feeBody = [
["Loan Origination Fee Type:", feeType === 'percentage' ? "Percentage" : "Fixed Amount"]
];
if(feeType === 'percentage') {
feeBody.push(["Origination Fee Percentage:", originationFeePercentVal]);
} else {
feeBody.push(["Origination Fee Fixed Amount:", originationFeeFixedVal]);
}
feeBody.push(["Calculated Origination Fee Cost:", blbfc_formatCurrency(originationFeeCost)]);
feeBody.push(["Other Estimated Fees:", blbfc_formatCurrency(otherFees)]);
feeBody.push(["Total One-Time Fees:", blbfc_formatCurrency(totalUpfrontCosts)]);
doc.autoTable({
startY: startY,
theme: 'grid',
headStyles: { fillColor: tableHeadFillColor },
body: feeBody,
margin: { left: 14, right: 14 }
});
startY = doc.autoTable.previous.finalY + 10;
doc.setFontSize(14);
if (secondaryColorRGB) doc.setTextColor(secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b); else doc.setTextColor(0, 51, 102);
doc.text("Interest Calculation", 14, startY);
startY += 7;
doc.autoTable({
startY: startY,
theme: 'grid',
headStyles: { fillColor: tableHeadFillColor },
body: [
["Total Interest Accrued over Term:", blbfc_formatCurrency(totalInterest)],
["Effective Monthly Interest Payment:", blbfc_formatCurrency(monthlyInterest)],
],
margin: { left: 14, right: 14 }
});
startY = doc.autoTable.previous.finalY + 10;
doc.setFontSize(14);
if (secondaryColorRGB) doc.setTextColor(secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b); else doc.setTextColor(0, 51, 102);
doc.text("Total Repayment (End of Term)", 14, startY);
startY += 7;
doc.autoTable({
startY: startY,
theme: 'grid',
headStyles: { fillColor: tableHeadFillColor },
body: [
["Principal Repayment:", blbfc_formatCurrency(loanAmount)],
["Total Interest Repayment:", blbfc_formatCurrency(totalInterest)],
["Total Loan Repayment (Principal + Interest):", blbfc_formatCurrency(totalRepaymentPrincipalAndInterest)],
],
margin: { left: 14, right: 14 }
});
startY = doc.autoTable.previous.finalY + 10;
doc.setFontSize(14);
if (secondaryColorRGB) doc.setTextColor(secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b); else doc.setTextColor(0, 51, 102);
doc.text("Overall Cost Summary", 14, startY);
startY += 7;
doc.autoTable({
startY: startY,
theme: 'grid',
headStyles: { fillColor: tableHeadFillColor },
body: [
[{ content: "Total Cost of Bridge Loan (Interest + Fees):", styles: { fontStyle: 'bold'} },
{ content: blbfc_formatCurrency(grandTotalCostOfLoan), styles: { fontStyle: 'bold'} }],
],
margin: { left: 14, right: 14 }
});
doc.setFontSize(10);
doc.setTextColor(150);
doc.text(`Report generated on: ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`, 14, doc.internal.pageSize.height - 10);
doc.save("Bridge_Loan_Financing_Summary.pdf");
}
function blbfc_hexToRgb(hex) {
if (!hex || typeof hex !== 'string') return null;
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
return r + r + g + g + b + b;
});
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
window.blbfc_switchTab = blbfc_switchTab;
window.blbfc_navigateToTab = blbfc_navigateToTab;
window.blbfc_toggleOriginationFeeInput = blbfc_toggleOriginationFeeInput;
window.blbfc_generatePdf = blbfc_generatePdf;