Employee dropdown list all staff from attendance + leave + accident
This commit is contained in:
+32
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user