`;
taskListContainer.appendChild(taskElement);
});
}
// --- INITIALIZATION ---
loadSampleData();
renderTasks();
updateUI();
function loadSampleData() {
const today = new Date();
const getFutureDate = (days) => new Date(today.getTime() + days * 24 * 60 * 60 * 1000).toISOString().split('T')[0];
tasks = [
{ id: 1, name: 'File Q3 Estimated Taxes', dueDate: getFutureDate(10), category: 'Tax', notes: 'IRS Form 1040-ES' },
{ id: 2, name: 'Renew Business License', dueDate: getFutureDate(45), category: 'Licensing', notes: 'City of Springfield License #12345' },
{ id: 3, name: 'Submit Annual Corporate Report', dueDate: getFutureDate(-5), category: 'Corporate', notes: 'For Delaware Division of Corporations' },
{ id: 4, name: 'Employee Harassment Training', dueDate: getFutureDate(90), category: 'HR', notes: 'Required for all managers.' },
{ id: 5, name: 'Pay Property Tax Bill', dueDate: getFutureDate(0), category: 'Tax', notes: 'County tax assessment office.' },
];
}
// --- CRUD OPERATIONS ---
taskForm.addEventListener('submit', (e) => {
e.preventDefault();
const id = parseInt(taskIdInput.value);
const taskData = {
name: taskNameInput.value,
dueDate: taskDueDateInput.value,
category: taskCategoryInput.value,
notes: taskNotesInput.value,
};
if (id) { // Editing existing task
const taskIndex = tasks.findIndex(t => t.id === id);
if (taskIndex > -1) {
tasks[taskIndex] = { ...tasks[taskIndex], ...taskData };
}
} else { // Adding new task
taskData.id = Date.now();
tasks.push(taskData);
}
renderTasks();
changeTab(1);
taskForm.reset();
taskIdInput.value = '';
});
window.editTask = (id) => {
const task = tasks.find(t => t.id === id);
if (!task) return;
taskIdInput.value = task.id;
taskNameInput.value = task.name;
taskDueDateInput.value = task.dueDate;
taskCategoryInput.value = task.category;
taskNotesInput.value = task.notes;
saveTaskBtn.textContent = 'Update Task';
changeTab(2);
};
window.cancelEdit = () => {
taskForm.reset();
taskIdInput.value = '';
saveTaskBtn.textContent = 'Save Task';
if (currentTab !== 1) {
changeTab(1);
}
};
window.deleteTask = (id) => {
tasks = tasks.filter(t => t.id !== id);
renderTasks();
};
// --- PDF DOWNLOAD ---
window.downloadPDF = () => {
if (typeof jspdf === 'undefined' || !jspdf.jsPDF.API.autoTable) {
console.error("Could not generate PDF. A required library is missing.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const sortedTasks = [...tasks].sort((a, b) => new Date(a.dueDate) - new Date(b.dueDate));
const head = [['Task', 'Category', 'Due Date', 'Status']];
const body = sortedTasks.map(task => {
const status = getStatus(task.dueDate);
return [
task.name,
task.category,
new Date(task.dueDate + 'T00:00:00').toLocaleDateString(),
status.text
];
});
const title = "Compliance Deadline Report";
const generatedDate = `Generated on: ${new Date().toLocaleDateString()}`;
doc.setFontSize(18);
doc.text(title, doc.internal.pageSize.getWidth() / 2, 40, { align: 'center' });
doc.setFontSize(10);
doc.text(generatedDate, doc.internal.pageSize.getWidth() / 2, 55, { align: 'center' });
doc.autoTable({
head: head,
body: body,
startY: 70,
theme: 'grid',
headStyles: { fillColor: [243, 244, 246], textColor: [75, 85, 99], fontStyle: 'bold' },
didDrawPage: function (data) {
// Footer with disclaimer
const disclaimer = "Disclaimer: This report is for informational purposes only and does not constitute legal advice. Verify all deadlines with the appropriate authorities.";
doc.setFontSize(8);
const disclaimerY = doc.internal.pageSize.height - 30;
doc.text(disclaimer, data.settings.margin.left, disclaimerY, { maxWidth: doc.internal.pageSize.width - data.settings.margin.left - data.settings.margin.right });
}
});
doc.save("Compliance-Report.pdf");
};
});