Total Recurring Fees (over term): ${wobl_formatCurrency(totalRecurringFeesOverTerm)}
Total Estimated Cost of Loan (Interest + Fees): ${wobl_formatCurrency(totalLoanCost)}
`;
const amortTableBody = document.querySelector('#wobl-amortization-table tbody');
amortTableBody.innerHTML = ''; // Clear previous
amortizationSchedule.forEach(row => {
const tr = amortTableBody.insertRow();
tr.insertCell().textContent = row.month;
tr.insertCell().textContent = wobl_formatCurrency(row.payment);
tr.insertCell().textContent = wobl_formatCurrency(row.principal);
tr.insertCell().textContent = wobl_formatCurrency(row.interest);
tr.insertCell().textContent = wobl_formatCurrency(row.balance);
});
wobl_navigateToTab(2); // Show results tab
}
function wobl_generatePDF() {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
alert('PDF generation library (jsPDF) is not loaded.'); return;
}
const JSPDF_CONSTRUCTOR = window.jspdf.jsPDF;
const tempDoc = new JSPDF_CONSTRUCTOR();
if (typeof tempDoc.autoTable !== 'function') {
alert('jsPDF AutoTable plugin is not loaded.'); return;
}
if (Object.keys(wobl_loanDataForPdf).length === 0) {
alert('Please calculate loan costs first.'); return;
}
const doc = new JSPDF_CONSTRUCTOR();
const data = wobl_loanDataForPdf;
let yPos = 15;
const pageMargin = 15;
const pageWidth = doc.internal.pageSize.getWidth();
const usableWidth = pageWidth - (2 * pageMargin);
const purpleColor = [106, 75, 255]; // #6a4bff
function addHeader(text) {
doc.setFontSize(16);
doc.setTextColor(purpleColor[0], purpleColor[1], purpleColor[2]);
doc.text(text, pageWidth / 2, yPos, { align: 'center' });
yPos += 10;
}
function addSubHeader(text) {
doc.setFontSize(12);
doc.setFont(undefined, 'bold');
doc.setTextColor(89, 60, 207); // Darker purple text #593ccf
doc.text(text, pageMargin, yPos);
yPos += 7;
}
addHeader("Women-Owned Business Loan Cost Estimate");
// Inputs
addSubHeader("Loan Inputs:");
const inputData = [
["Loan Amount Requested:", wobl_formatCurrency(data.loanAmount)],
["Annual Interest Rate:", `${data.annualInterestRate.toFixed(2)}%`],
["Loan Term:", `${data.loanTermYears} years`],
["Origination Fee %:", `${data.originationFeePercent.toFixed(1)}%`],
["Other Upfront Fees:", wobl_formatCurrency(data.otherUpfrontFees)],
["Annual Recurring Fees:", wobl_formatCurrency(data.annualRecurringFees)],
];
doc.autoTable({
startY: yPos,
body: inputData,
theme: 'grid',
styles: { fontSize: 9, cellPadding: 2 },
headStyles: { fillColor: purpleColor }, // Not using head here
columnStyles: { 0: { fontStyle: 'bold' } },
didDrawPage: function() { yPos = pageMargin; }
});
yPos = doc.lastAutoTable.finalY + 10;
// Cost Summary
if (yPos > doc.internal.pageSize.getHeight() - 60) { doc.addPage(); yPos = pageMargin; }
addSubHeader("Estimated Costs Summary:");
const summaryData = [
["Estimated Monthly Payment (P&I):", wobl_formatCurrency(data.monthlyPayment)],
["Total Principal Paid:", wobl_formatCurrency(data.totalPrincipalPaid)],
["Total Interest Paid:", wobl_formatCurrency(data.totalInterestPaid)],
["Origination Fee Amount:", wobl_formatCurrency(data.originationFeeAmount)],
["Total Other Upfront Fees:", wobl_formatCurrency(data.otherUpfrontFees)],
["Total Recurring Fees (over term):", wobl_formatCurrency(data.totalRecurringFeesOverTerm)],
[{content: "Total Estimated Cost of Loan (Interest + Fees):", styles: {fontStyle:'bold', fillColor: [240,234,255]}}, // Light purple bg
{content: wobl_formatCurrency(data.totalLoanCost), styles:{fontStyle:'bold', fillColor: [240,234,255]}}],
];
doc.autoTable({
startY: yPos,
body: summaryData,
theme: 'grid',
styles: { fontSize: 9, cellPadding: 2 },
columnStyles: { 0: { fontStyle: 'bold' } },
didParseCell: function(hookData) {
if (hookData.row.index === summaryData.length - 1) { // Last row (Total Cost)
hookData.cell.styles.fontStyle = 'bold';
hookData.cell.styles.fillColor = [224, 212, 255]; // Slightly darker light purple
}
},
didDrawPage: function() { yPos = pageMargin; }
});
yPos = doc.lastAutoTable.finalY + 10;
// Amortization Schedule
if (data.amortizationSchedule && data.amortizationSchedule.length > 0) {
if (yPos > doc.internal.pageSize.getHeight() - 40) { doc.addPage(); yPos = pageMargin; }
addSubHeader("Amortization Schedule:");
const amortBody = data.amortizationSchedule.map(row => [
row.month,
wobl_formatCurrency(row.payment),
wobl_formatCurrency(row.principal),
wobl_formatCurrency(row.interest),
wobl_formatCurrency(row.balance)
]);
doc.autoTable({
startY: yPos,
head: [['Month', 'Payment', 'Principal', 'Interest', 'Balance']],
body: amortBody,
theme: 'striped',
headStyles: { fillColor: purpleColor, textColor: [255,255,255] },
styles: { fontSize: 8, cellPadding: 1.5, halign: 'right' },
columnStyles: { 0: { halign: 'center' } },
didDrawPage: function() { yPos = pageMargin; }
});
yPos = doc.lastAutoTable.finalY + 10;
}
// Resources section (simplified for PDF)
if (yPos > doc.internal.pageSize.getHeight() - 50) { doc.addPage(); yPos = pageMargin; }
addSubHeader("Resources for Women-Owned Businesses (USA - Abbreviated):");
doc.setFontSize(8);
doc.setTextColor(80,80,80);
let resourcesText = "Consider exploring: SBA Office of Women's Business Ownership (sba.gov/women), SBA Loans (7(a), 504, Microloans), Grants (e.g., Amber Grant, Grants.gov), Certified Development Companies (CDCs), Community Development Financial Institutions (CDFIs), NAWBO, AWBC. This list is not exhaustive.";
const resourceLines = doc.splitTextToSize(resourcesText, usableWidth);
doc.text(resourceLines, pageMargin, yPos);
doc.save("Women_Owned_Business_Loan_Cost_Estimate.pdf");
}