`;
// Charts
html += `
`;
html += `
`;
outputDiv.innerHTML = html;
// Render Charts
renderChart('dtiChart', 'Debt-to-Income (DTI)', data.dti, 43);
renderChart('ltvChart', 'Loan-to-Value (LTV)', data.ltv, 80);
}
function renderChart(canvasId, label, value, threshold) {
const ctx = document.getElementById(canvasId).getContext('2d');
new Chart(ctx, {
type: 'doughnut',
data: {
labels: [label, ''],
datasets: [{
data: [value, 100 - value],
backgroundColor: [value <= threshold ? '#22C55E' : '#EF4444', '#E5E7EB'],
borderWidth: 0
}]
},
options: {
responsive: true,
cutout: '70%',
plugins: {
legend: { display: false },
title: { display: true, text: `${label}: ${value.toFixed(2)}%` }
}
}
});
}
// --- PDF Download ---
function downloadPDF() {
const { jsPDF } = window.jspdf;
const loader = document.getElementById('loader');
loader.style.display = 'block';
const content = document.getElementById('pdf-content');
html2canvas(content, { scale: 2 }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgWidth = pdfWidth - 20;
const imgHeight = canvas.height * imgWidth / canvas.width;
let heightLeft = imgHeight;
let position = 10;
pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight);
heightLeft -= (pdf.internal.pageSize.getHeight() - 20);
while (heightLeft > 0) {
position = heightLeft - imgHeight + 10;
pdf.addPage();
pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight);
heightLeft -= (pdf.internal.pageSize.getHeight() - 20);
}
pdf.save('Pre-Approval_Status.pdf');
loader.style.display = 'none';
});
}
