(Feat-Fix): Fixed employee swapping not showing up in the Daily Attendance dashboard.
This commit is contained in:
@@ -245,16 +245,6 @@ export const DashboardPage: React.FC = () => {
|
|||||||
return currentContractorId;
|
return currentContractorId;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function to get the effective department ID for an employee
|
|
||||||
// If employee has an active swap, return the original department ID
|
|
||||||
const getEffectiveDepartmentId = (employeeId: number, currentDepartmentId?: number) => {
|
|
||||||
const swap = activeSwaps.find((s) => s.employee_id === employeeId);
|
|
||||||
if (swap) {
|
|
||||||
return swap.original_department_id;
|
|
||||||
}
|
|
||||||
return currentDepartmentId;
|
|
||||||
};
|
|
||||||
|
|
||||||
return supervisors.map((supervisor) => {
|
return supervisors.map((supervisor) => {
|
||||||
const deptContractors = employees.filter(
|
const deptContractors = employees.filter(
|
||||||
(e) =>
|
(e) =>
|
||||||
@@ -373,14 +363,14 @@ export const DashboardPage: React.FC = () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add unassigned employees node if there are any
|
// Add "Swapped In" node for employees swapped into this department without a specific contractor
|
||||||
if (unassignedEmployees.length > 0) {
|
if (swappedIntoThisDept.length > 0) {
|
||||||
contractorNodes.push({
|
contractorNodes.push({
|
||||||
id: -supervisor.department_id!, // Negative ID to avoid conflicts
|
id: -supervisor.department_id!, // Negative ID to avoid conflicts
|
||||||
name: "Unassigned (Swapped)",
|
name: "Swapped In",
|
||||||
role: "Contractor",
|
role: "Contractor",
|
||||||
department: supervisor.department_name || "",
|
department: supervisor.department_name || "",
|
||||||
children: unassignedEmployees.map((emp) => {
|
children: swappedIntoThisDept.map(({ emp, originalContractor }) => {
|
||||||
const empAttendance = attendance.find((a) =>
|
const empAttendance = attendance.find((a) =>
|
||||||
a.employee_id === emp.id
|
a.employee_id === emp.id
|
||||||
);
|
);
|
||||||
@@ -390,12 +380,11 @@ export const DashboardPage: React.FC = () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
id: emp.id,
|
id: emp.id,
|
||||||
name: emp.name,
|
name: `${emp.name} (from ${originalContractor?.name || "other"})`,
|
||||||
role: "Employee",
|
role: "Employee",
|
||||||
department: emp.department_name || "",
|
department: emp.department_name || "",
|
||||||
subDepartment: empAllocation?.sub_department_name || "-",
|
subDepartment: empAllocation?.sub_department_name || "-",
|
||||||
activity: empAllocation?.description || empAllocation?.activity ||
|
activity: empAllocation?.description || empAllocation?.activity || "-",
|
||||||
"Swapped",
|
|
||||||
status: empAttendance
|
status: empAttendance
|
||||||
? (empAttendance.status === "CheckedIn" ||
|
? (empAttendance.status === "CheckedIn" ||
|
||||||
empAttendance.status === "CheckedOut"
|
empAttendance.status === "CheckedOut"
|
||||||
|
|||||||
Reference in New Issue
Block a user