diff --git a/backend/main.py b/backend/main.py index 960ef63..ed11b55 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1291,7 +1291,38 @@ async def update_attendance_record( return {"message": "ok", "id": record_id} -# ============ Holidays CRUD ============ +# ============ Employees List (combined source) ============ +@app.get("/api/employees/list") +async def list_employees( + source: Optional[str] = "all", # "all" / "attendance" / "leave" / "accident" + db: Session = Depends(get_db), + current_user: User = Depends(get_current_user), +): + """List distinct employee names from attendance + leave + accident records. + + Used by frontend dropdowns to show ALL staff, even those who haven't taken leave yet. + + source: + - all (default): UNION of attendance + leave + accident + - attendance: only attendance_records.employee_name + - leave: only leave_records.employee_name + - accident: only Accident.employee_name + """ + names = set() + if source in ("all", "attendance"): + for n in db.query(AttendanceRecord.employee_name).distinct().all(): + if n[0]: names.add(n[0]) + if source in ("all", "leave"): + for n in db.query(LeaveRecord.employee_name).distinct().all(): + if n[0]: names.add(n[0]) + if source in ("all", "accident"): + for n in db.query(Accident.employee_name).distinct().all(): + if n[0]: names.add(n[0]) + sorted_names = sorted(names, key=lambda x: x.lower()) + return {"employees": sorted_names, "count": len(sorted_names), "source": source} + + +# ============ Holidays CRUD ============# ============ Holidays CRUD ============ @app.get("/api/holidays", response_model=List[HolidayOut]) async def list_holidays( year: Optional[int] = None, diff --git a/frontend/src/pages/holidays/Holidays.jsx b/frontend/src/pages/holidays/Holidays.jsx index 8b47f60..e2cd085 100644 --- a/frontend/src/pages/holidays/Holidays.jsx +++ b/frontend/src/pages/holidays/Holidays.jsx @@ -284,7 +284,13 @@ function LeavesTab() { URL.revokeObjectURL(url) } - const uniqueEmps = [...new Set(leaves.map(l => l.employee_name))].sort() + // Fetch employee list from /api/employees/list (UNION of attendance + leave + accident) + const [employees, setEmployees] = useState([]) + useEffect(() => { + api.get('/api/employees/list') + .then(({ data }) => setEmployees(data.employees || [])) + .catch(() => setEmployees([])) + }, []) return (