9. Implementation Plan
${data['src-implementation'] || 'Not provided.'}
10. Performance Management (KPIs)
${data['src-kpis'] || 'Not provided.'}
`;
}
function downloadPDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const data = getFormData();
const pageHeight = doc.internal.pageSize.height;
const pageWidth = doc.internal.pageSize.width;
const margin = 20;
const maxWidth = pageWidth - (margin * 2);
let currentY = margin;
const checkPageBreak = (spaceNeeded) => {
if (currentY + spaceNeeded > pageHeight - margin) {
doc.addPage();
currentY = margin;
}
};
const addSection = (title, text) => {
checkPageBreak(20); // Space for title
doc.setFontSize(14);
doc.setFont(undefined, 'bold');
doc.text(title, margin, currentY);
currentY += 8;
doc.setLineWidth(0.5);
doc.line(margin, currentY, maxWidth + margin, currentY);
currentY += 8;
doc.setFontSize(11);
doc.setFont(undefined, 'normal');
const lines = doc.splitTextToSize(text || 'Not provided.', maxWidth);
checkPageBreak(lines.length * 5 + 10); // Space for text + padding
doc.text(lines, margin, currentY);
currentY += (lines.length * 5) + 10; // Add padding after section
};
// --- PDF Content ---
doc.setFontSize(20);
doc.setFont(undefined, 'bold');
doc.text("Strategic Sourcing Plan", pageWidth / 2, currentY, { align: 'center' });
currentY += 15;
addSection('1. Executive Summary', data['src-exec-summary']);
addSection('2. Project Scope & Objectives', `Scope:\n${data['src-scope']}\n\nObjectives:\n${data['src-objectives']}`);
addSection('3. Sourcing Team', data['src-team']);
addSection('4. Category Profile & Spend Analysis', data['src-spend']);
addSection('5. Market Analysis', data['src-market']);
addSection('6. Sourcing Strategy', data['src-strategy']);
addSection('7. Sourcing Event Plan', data['src-event-plan']);
addSection('8. Negotiation & Selection', data['src-negotiation']);
addSection('9. Implementation Plan', data['src-implementation']);
addSection('10. Performance Management (KPIs)', data['src-kpis']);
doc.save('strategic-sourcing-plan.pdf');
}
// --- Tab Navigation ---
function switchTab(tabIndex) {
tabs.forEach((tab, index) => {
tab.classList.toggle('active', index === tabIndex);
contents[index].classList.toggle('active', index === tabIndex);
});
currentTab = tabIndex;
updateNavButtons();
}
function updateNavButtons() {
prevBtn.disabled = currentTab === 0;
nextBtn.disabled = currentTab === tabs.length - 1;
}
tabs.forEach((tab, index) => {
tab.addEventListener('click', () => switchTab(index));
});
nextBtn.addEventListener('click', () => { if (currentTab < tabs.length - 1) switchTab(currentTab + 1); });
prevBtn.addEventListener('click', () => { if (currentTab > 0) switchTab(currentTab - 1); });
// --- Event Listeners ---
generateBtn.addEventListener('click', () => {
// IV.D.1: This is type="button"
renderReviewSheet();
switchTab(1); // Switch to review tab
});
pdfDownloadBtn.addEventListener('click', downloadPDF);
// --- Initial Setup ---
updateNavButtons();
// Pre-fill review sheet with default data for first load
renderReviewSheet();
});