
- FastAPI application with JWT authentication and role-based access control - Complete employee management with CRUD operations - Department management with manager assignments - Leave management system with approval workflow - Payroll processing with overtime and deductions calculation - Attendance tracking with clock in/out functionality - SQLite database with proper migrations using Alembic - Role-based permissions (Admin, HR Manager, Manager, Employee) - Comprehensive API documentation and health checks - CORS enabled for cross-origin requests Environment Variables Required: - SECRET_KEY: JWT secret key for token signing Features implemented: - User registration and authentication - Employee profile management - Department hierarchy management - Leave request creation and approval - Payroll record processing - Daily attendance tracking - Hours calculation for attendance - Proper error handling and validation
36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Date, Numeric, Enum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from app.db.base import Base
|
|
import enum
|
|
|
|
class EmploymentStatus(enum.Enum):
|
|
ACTIVE = "active"
|
|
INACTIVE = "inactive"
|
|
TERMINATED = "terminated"
|
|
|
|
class Employee(Base):
|
|
__tablename__ = "employees"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id"), unique=True, nullable=False)
|
|
employee_id = Column(String, unique=True, index=True, nullable=False)
|
|
department_id = Column(Integer, ForeignKey("departments.id"))
|
|
position = Column(String, nullable=False)
|
|
salary = Column(Numeric(10, 2))
|
|
hire_date = Column(Date, nullable=False)
|
|
status = Column(Enum(EmploymentStatus), default=EmploymentStatus.ACTIVE)
|
|
phone = Column(String)
|
|
address = Column(String)
|
|
emergency_contact = Column(String)
|
|
emergency_phone = Column(String)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relationships
|
|
user = relationship("User")
|
|
department = relationship("Department", foreign_keys=[department_id], back_populates="employees")
|
|
managed_departments = relationship("Department", foreign_keys="Department.manager_id", back_populates="manager")
|
|
leave_requests = relationship("LeaveRequest", back_populates="employee")
|
|
payroll_records = relationship("PayrollRecord", back_populates="employee")
|
|
attendance_records = relationship("AttendanceRecord", back_populates="employee") |