`;
// Project Progress Chart
const projectWidget = document.createElement('div');
projectWidget.className = 'as-widget';
projectWidget.innerHTML = `
${task.name}
${task.project}
${employee ? employee.name : 'Unassigned'}
${task.hours}
${task.status}
`;
tableBody.innerHTML += row;
});
employeeSelect.innerHTML = '';
appData.employees.forEach(emp => {
employeeSelect.innerHTML += ``;
});
};
// --- EVENT HANDLERS --- //
const switchTab = (tabId) => {
activeTab = tabId;
tabContents.forEach(content => content.classList.toggle('active', content.id === tabId));
tabButtons.forEach(button => button.classList.toggle('active', button.dataset.tab === tabId));
if (tabId === 'dashboard') renderDashboard();
if (tabId === 'task-management') renderTaskManagement();
};
tabButtons.forEach(button => {
button.addEventListener('click', () => switchTab(button.dataset.tab));
});
// Task Management Form
$('#tm-task-form').addEventListener('submit', (e) => {
e.preventDefault();
const newTask = {
id: nextTaskId++,
name: $('#tm-task-name').value,
project: $('#tm-project-name').value,
employeeId: parseInt($('#tm-assigned-to').value),
hours: parseInt($('#tm-hours-allocated').value),
status: $('#tm-status').value
};
appData.tasks.push(newTask);
renderTaskManagement();
e.target.reset();
});
// Team Config Form
$('#tc-team-form').addEventListener('submit', (e) => {
e.preventDefault();
const newEmployee = {
id: nextEmployeeId++,
name: $('#tc-employee-name').value,
capacity: parseInt($('#tc-weekly-capacity').value)
};
appData.employees.push(newEmployee);
alert(`Employee "${newEmployee.name}" added successfully!`);
e.target.reset();
});
// PDF Download
$('#download-pdf-btn').addEventListener('click', () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const metrics = calculateMetrics();
doc.setFontSize(22);
doc.text("Time & Work Allocation Summary", 105, 20, null, null, "center");
doc.setFontSize(16);
doc.text("Project Progress (Hours)", 14, 35);
const projectData = Object.entries(metrics.projectStats).map(([name, data]) => [name, data.completed, data.total]);
doc.autoTable({
startY: 40,
head: [['Project', 'Completed Hours', 'Total Hours']],
body: projectData
});
doc.text("Employee Workload (Active Hours)", 14, doc.lastAutoTable.finalY + 15);
const workloadData = metrics.employeeWorkload.map(emp => [emp.name, emp.assigned, emp.capacity]);
doc.autoTable({
startY: doc.lastAutoTable.finalY + 20,
head: [['Employee', 'Assigned Hours', 'Weekly Capacity']],
body: workloadData
});
doc.save('work-allocation-summary.pdf');
});
// Navigation Buttons
const tabOrder = ['dashboard', 'task-management', 'team-config'];
$('#next-btn').addEventListener('click', () => {
const currentIndex = tabOrder.indexOf(activeTab);
const nextIndex = (currentIndex + 1) % tabOrder.length;
switchTab(tabOrder[nextIndex]);
});
$('#prev-btn').addEventListener('click', () => {
const currentIndex = tabOrder.indexOf(activeTab);
const prevIndex = (currentIndex - 1 + tabOrder.length) % tabOrder.length;
switchTab(tabOrder[prevIndex]);
});
// --- INITIALIZATION --- //
switchTab('dashboard');
});
