// Sample employee data let employees = [ { id: 1, name: 'John Doe', position: 'Software Engineer', department: 'IT', avatar: 'http://static.photos/technology/200x200/1' }, { id: 2, name: 'Jane Smith', position: 'HR Manager', department: 'Human Resources', avatar: 'http://static.photos/office/200x200/2' }, { id: 3, name: 'Robert Johnson', position: 'Accountant', department: 'Finance', avatar: 'http://static.photos/finance/200x200/3' }, { id: 4, name: 'Emily Davis', position: 'Marketing Specialist', department: 'Marketing', avatar: 'http://static.photos/retail/200x200/4' }, { id: 5, name: 'Michael Brown', position: 'Operations Manager', department: 'Operations', avatar: 'http://static.photos/industry/200x200/5' }, ]; let selectedEmployees = []; let currentPayPeriod = 'January 1-15, 2023'; let currentDepartment = 'All Departments'; // Sample DTR data with Philippine format const dtrData = [ { date: '2023-01-01', day: 'Sunday', amIn: '--', amOut: '--', pmIn: '--', pmOut: '--', tardiness: '0.00', undertime: '0.00', overtime: '0.00', totalHours: '0.0', status: 'Rest Day' }, { date: '2023-01-02', day: 'Monday', amIn: '08:15 AM', amOut: '12:00 PM', pmIn: '01:00 PM', pmOut: '05:15 PM', tardiness: '0.25', undertime: '0.00', overtime: '0.00', totalHours: '8.0', status: 'Present' }, { date: '2023-01-03', day: 'Tuesday', amIn: '08:00 AM', amOut: '12:00 PM', pmIn: '01:00 PM', pmOut: '06:30 PM', tardiness: '0.00', undertime: '0.00', overtime: '1.50', totalHours: '9.5', status: 'Present' }, { date: '2023-01-04', day: 'Wednesday', amIn: '08:45 AM', amOut: '12:00 PM', pmIn: '01:00 PM', pmOut: '04:30 PM', tardiness: '0.75', undertime: '0.50', overtime: '0.00', totalHours: '7.0', status: 'Present' }, { date: '2023-01-05', day: 'Thursday', amIn: '--', amOut: '--', pmIn: '--', pmOut: '--', tardiness: '0.00', undertime: '0.00', overtime: '0.00', totalHours: '0.0', status: 'Absent' }, ]; // Load employees into the list with search and filter function loadEmployees() { const employeeList = document.querySelector('.w-full.md\\:w-1\\/3 .space-y-3'); employeeList.innerHTML = ''; const searchInput = document.querySelector('input[type="text"]'); const searchTerm = searchInput.value.toLowerCase(); const filteredEmployees = employees.filter(employee => { const matchesSearch = employee.name.toLowerCase().includes(searchTerm) || employee.position.toLowerCase().includes(searchTerm) || employee.department.toLowerCase().includes(searchTerm); const matchesDepartment = currentDepartment === 'All Departments' || employee.department === currentDepartment; return matchesSearch && matchesDepartment; }); filteredEmployees.forEach(employee => { const isSelected = selectedEmployees.some(e => e.id === employee.id); const employeeCard = document.createElement('div'); employeeCard.className = `employee-card bg-white p-4 rounded-lg border ${isSelected ? 'border-blue-500 bg-blue-50' : 'border-gray-200'} hover:border-blue-300 hover:shadow-sm transition-all cursor-pointer`; employeeCard.dataset.id = employee.id; employeeCard.innerHTML = `
${employee.name}

${employee.name}

${employee.position} • ${employee.department}

`; employeeList.appendChild(employeeCard); }); updateSelectedEmployeesList(); feather.replace(); } // Update selected employees list function updateSelectedEmployeesList() { const selectedContainer = document.querySelector('.bg-gray-100.rounded-lg.p-4 .flex'); selectedContainer.innerHTML = ''; selectedEmployees.forEach(employee => { const chip = document.createElement('div'); chip.className = 'bg-blue-100 text-blue-800 px-3 py-1 rounded-full text-sm flex items-center gap-1'; chip.innerHTML = ` ${employee.name} `; selectedContainer.appendChild(chip); }); feather.replace(); } // Load DTR data into the table function loadDTRData() { const dtrTableBody = document.querySelector('table tbody'); dtrTableBody.innerHTML = ''; // Only show data if employees are selected if (selectedEmployees.length === 0) { const row = document.createElement('tr'); row.innerHTML = `Select employees to view their DTR`; dtrTableBody.appendChild(row); return; } dtrData.forEach(record => { const row = document.createElement('tr'); row.className = 'hover:bg-gray-50'; row.innerHTML = ` ${record.date} ${record.day} ${record.amIn} ${record.amOut} ${record.pmIn} ${record.pmOut} ${record.tardiness} ${record.undertime} ${record.overtime} ${record.totalHours} ${record.status} `; dtrTableBody.appendChild(row); }); } // Event listeners for interactive elements document.addEventListener('DOMContentLoaded', () => { // Search functionality document.querySelector('input[type="text"]').addEventListener('input', loadEmployees); // Pay period dropdown document.querySelector('select:nth-of-type(1)').addEventListener('change', function() { currentPayPeriod = this.value; loadDTRData(); }); // Department dropdown document.querySelector('select:nth-of-type(2)').addEventListener('change', function() { currentDepartment = this.value; loadEmployees(); }); // Add employee button document.querySelector('.bg-blue-500').addEventListener('click', function() { // In a real app, this would open a modal for adding a new employee alert('Add employee functionality would go here'); }); // Generate DTR button document.querySelector('.mt-6 .bg-blue-500').addEventListener('click', function() { if (selectedEmployees.length === 0) { alert('Please select at least one employee'); return; } // In a real app, this would generate and download the DTR alert(`Generating DTR for ${selectedEmployees.length} employees for ${currentPayPeriod}`); }); // Cancel button document.querySelector('.mt-6 .border-gray-300').addEventListener('click', function() { selectedEmployees = []; loadEmployees(); loadDTRData(); }); // Employee selection document.addEventListener('click', function(e) { // Employee card click if (e.target.closest('.employee-card')) { const card = e.target.closest('.employee-card'); const employeeId = parseInt(card.dataset.id); const employee = employees.find(e => e.id === employeeId); const index = selectedEmployees.findIndex(e => e.id === employeeId); if (index === -1) { selectedEmployees.push(employee); } else { selectedEmployees.splice(index, 1); } loadEmployees(); loadDTRData(); } // Remove selected employee chip if (e.target.closest('.bg-blue-100 button')) { const button = e.target.closest('button'); const employeeId = parseInt(button.dataset.id); selectedEmployees = selectedEmployees.filter(e => e.id !== employeeId); loadEmployees(); loadDTRData(); } }); });