-
Admin Dashboard
-
-
-
-
+ const [logsRes, usersRes, requestsRes] = await Promise.all([apiCall('/admin/logs'), apiCall('/admin/users'), apiCall('/admin/time-off-requests/pending')]);
+ if (!logsRes.success || !usersRes.success || !requestsRes.success) return;
+
+ allTimeEntries = logsRes.data;
+ allUsers = usersRes.data;
+ const pendingRequests = requestsRes.data;
+
+ const employeeTotals = allTimeEntries.reduce((acc, entry) => {
+ const dur = entry.punch_out_time ? (new Date(entry.punch_out_time) - new Date(entry.punch_in_time)) : (Date.now() - new Date(entry.punch_in_time));
+ acc[entry.username] = (acc[entry.username] || 0) + dur;
+ return acc;
+ }, {});
+
+ const punchedInEntries = allTimeEntries.filter(e => e.status === 'in');
+
+ mainViews.admin.innerHTML = `
+
+
+
+
Admin Dashboard
+
+
+
+
+
+
+
-
-
Currently Punched In
-
-
-
-
-
Pending Time Off Requests
-
-
-
| Employee | Dates | Reason | Actions |
${pendingRequests.map(r => `| ${r.username} | ${formatDate(r.start_date)} - ${formatDate(r.end_date)} | ${r.reason||''} | |
`).join('') || '| No pending requests. |
'}
-
-
-
Hours by Employee
-
| Employee | Total Hours |
${Object.entries(employeeTotals).map(([username, totalMs]) => `| ${username} | ${formatDecimal(totalMs)} |
`).join('') || '| No data. |
'}
-
-
-
Detailed Logs
-
| Employee | In | Out | Duration | Actions |
${allTimeEntries.map(e => `| ${e.username||'N/A'} | ${formatDateTime(e.punch_in_time)} | ${formatDateTime(e.punch_out_time)} | ${e.punch_out_time ? formatDecimal(new Date(e.punch_out_time) - new Date(e.punch_in_time)) : 'Running'} | |
`).join('')}
-
-
-
User & Payroll Management
-
-
-
-
-
Manage Users
| Username | Role | Actions |
${allUsers.map(u => `| ${u.username} | ${u.role} | ${u.isPrimary ? `Primary Admin` : `${u.username !== user.username ? `` : ''}`} |
`).join('')}
-
-
`;
- document.getElementById('archive-btn').addEventListener('click', handleArchive);
- document.getElementById('view-archives-btn').addEventListener('click', renderArchiveView);
- document.getElementById('view-time-off-history-btn').addEventListener('click', renderTimeOffHistoryView);
- document.getElementById('create-user-form').addEventListener('submit', handleCreateUser);
- document.getElementById('add-punch-form').addEventListener('submit', handleAddPunch);
- document.getElementById('admin-dashboard').addEventListener('click', handleAdminDashboardClick);
+ `).join('') || '
None'}
+
+