`;
// 2. Action Phases
const phases = [
{ key: 'stab', name: 'Phase I: Stabilization (0-3 Months)', color: '#e74c3c' },
{ key: 'rest', name: 'Phase II: Restructuring (3-9 Months)', color: '#f39c12' },
{ key: 'grow', name: 'Phase III: Sustainable Growth (9-18 Months)', color: '#2ecc71' }
];
phases.forEach(phase => {
const phaseActions = actions[phase.key];
html += `
`;
}
});
container.innerHTML = html;
}
function tmapSwitchTab(tabId) {
document.querySelectorAll('.tmap-tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.tmap-content').forEach(c => c.classList.remove('active'));
const idx = tabId === 'builder' ? 0 : 1;
document.querySelectorAll('.tmap-tab-btn')[idx].classList.add('active');
document.getElementById('tmap-' + tabId).classList.add('active');
if (tabId === 'preview') {
tmapRenderReport();
}
}
function tmapLoadExample() {
if(!confirm("Overwrite current data and load an example turnaround plan?")) return;
// Set metadata
document.getElementById('inp-company').value = "MegaRetail Inc.";
document.getElementById('inp-period').value = "Q3 2025 - Q2 2027";
document.getElementById('inp-issues').value = "Over-leveraged balance sheet; store footprint too large; declining foot traffic.";
// Clear all rows
document.getElementById('tmap-stab-rows').innerHTML = '';
document.getElementById('tmap-rest-rows').innerHTML = '';
document.getElementById('tmap-grow-rows').innerHTML = '';
// Stabilization
tmapAddActionRow('stab', "Immediate 20% headcount reduction in corporate offices", "CEO/HR", "30 Days");
tmapAddActionRow('stab', "Obtain DIP financing to manage working capital", "CFO/Legal", "60 Days");
tmapAddActionRow('stab', "Suspend dividend payments and share buybacks", "Board of Directors", "Immediate");
// Restructuring
tmapAddActionRow('rest', "Close 50 least profitable store locations", "COO/Real Estate", "9 Months");
tmapAddActionRow('rest', "Re-design supply chain logistics for efficiency", "Supply Chain", "6 Months");
tmapAddActionRow('rest', "Launch digital transformation of customer loyalty program", "CMO", "8 Months");
// Growth
tmapAddActionRow('grow', "Expand profitable e-commerce channel by 40%", "Product/CMO", "18 Months");
tmapAddActionRow('grow', "Introduce 3 new private label product lines", "Merchandising", "15 Months");
tmapAddActionRow('grow', "Establish debt-equity ratio target (2:1)", "CFO", "12 Months");
tmapRenderReport();
tmapSwitchTab('preview');
}
/* --- PDF Generation --- */
async function tmapGeneratePDF() {
tmapRenderReport(); // Ensure report is updated
const actions = tmapGetActionData();
const meta = {
company: document.getElementById('inp-company').value || "Company Name",
period: document.getElementById('inp-period').value || "Reporting Period",
issues: document.getElementById('inp-issues').value || "No critical issues defined."
};
const { jsPDF } = window.jspdf;
const doc = new jsPDF('l', 'mm', 'a4'); // Landscape for better table fit
// Styling
const red = [231, 76, 60];
const navy = [44, 62, 80];
let y = 20;
// Header
doc.setFillColor(...red);
doc.rect(0, 0, 297, 20, 'F');
doc.setTextColor(255, 255, 255);
doc.setFontSize(16);
doc.text(`Turnaround Action Plan: ${meta.company}`, 14, 13);
// Meta Data
doc.setTextColor(0, 0, 0);
doc.setFontSize(10);
doc.setFont(undefined, 'bold');
doc.text("REPORTING PERIOD:", 14, y + 10);
doc.text("CRITICAL ISSUES:", 100, y + 10);
doc.setFont(undefined, 'normal');
doc.text(meta.period, 14, y + 15);
const splitIssues = doc.splitTextToSize(meta.issues, 100);
doc.text(splitIssues, 100, y + 15);
y += 35;
// Action Phases
const phases = [
{ key: 'stab', name: 'Phase I: Stabilization (0-3 Months)', color: [231, 76, 60] },
{ key: 'rest', name: 'Phase II: Restructuring (3-9 Months)', color: [243, 156, 18] },
{ key: 'grow', name: 'Phase III: Sustainable Growth (9-18 Months)', color: [46, 204, 113] }
];
phases.forEach(phase => {
const phaseActions = actions[phase.key];
if (y > 180) { doc.addPage(); y = 20; }
doc.setFontSize(12);
doc.setFont("helvetica", "bold");
doc.setTextColor(...phase.color);
doc.text(phase.name, 14, y);
y += 5;
if (phaseActions.length === 0) {
doc.setFontSize(10);
doc.setTextColor(150, 150, 150);
doc.text("No actions defined for this phase.", 14, y + 5);
y += 10;
} else {
const tableBody = phaseActions.map(a => [a.desc, a.owner, a.deadline]);
doc.autoTable({
startY: y,
head: [['Action Description', 'Owner', 'Deadline']],
body: tableBody,
theme: 'grid',
headStyles: { fillColor: navy, fontSize: 9 },
styles: { fontSize: 8.5 },
columnStyles: {
0: { cellWidth: 150, overflow: 'linebreak' },
1: { cellWidth: 40, halign: 'center', fontStyle: 'bold' },
2: { cellWidth: 40, halign: 'center', textColor: red }
}
});
y = doc.lastAutoTable.finalY + 10;
}
});
// Signature Block
y += 10;
doc.setFontSize(10);
doc.text("Approved By (CEO): ___________________________", 14, y);
doc.text("Date of Approval: _______________", 150, y);
doc.save(`Turnaround_Plan_${meta.company.replace(/\s/g, '_')}.pdf`);
}
${phase.name}
`;
if (phaseActions.length === 0) {
html += `No actions defined for this phase.
`; } else { html += `| Action Description | Owner | Deadline |
|---|---|---|
| ${action.desc} | ${action.owner} | ${action.deadline} |
