# Schema Database (Mermaid ERD)

```mermaid
---
id: af83e0c4-b407-4fe2-843d-c0e310cb1db8
---
erDiagram
    USERS {
        bigint id PK
        string name
        string email UK
        timestamp email_verified_at
        string password
        string role "super_admin|operator|teacher|student"
        boolean is_active
        string remember_token
        timestamp created_at
        timestamp updated_at
    }

    TEACHERS {
        bigint id PK
        bigint user_id FK
        string employee_number UK
        string full_name
        string photo
        string gender "male|female"
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    CLASSROOMS {
        bigint id PK
        string name
        string grade_level "X|XI|XII"
        bigint homeroom_teacher_id FK
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    STUDENTS {
        bigint id PK
        bigint user_id FK
        string student_number UK
        string full_name
        bigint classroom_id FK
        string photo
        string gender "male|female"
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    SUBJECTS {
        bigint id PK
        string code UK
        string name
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    ACADEMIC_YEARS {
        bigint id PK
        string name
        date start_date
        date end_date
        timestamp created_at
        timestamp updated_at
    }

    SEMESTERS {
        bigint id PK
        bigint academic_year_id FK
        string name
        date start_date
        date end_date
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    SCHEDULES {
        bigint id PK
        bigint semester_id FK
        string day_of_week "monday|tuesday|wednesday|thursday|friday|saturday"
        int session_order
        time start_time
        time end_time
        bigint subject_id FK
        bigint classroom_id FK
        bigint teacher_id FK
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    TEACHER_QR_TOKENS {
        bigint id PK
        bigint teacher_id FK
        string token UK
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    STUDENT_QR_TOKENS {
        bigint id PK
        bigint student_id FK
        string token UK
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }

    SETTINGS {
        bigint id PK
        string key UK
        string value
        string type "string|integer|boolean|json"
        string group "attendance|alert|system"
        string description
        timestamp created_at
        timestamp updated_at
    }

    KIOSK_TOKENS {
        bigint id PK
        string token UK
        string kiosk_name
        string device_identifier UK
        boolean is_active
        timestamp expires_at
        bigint created_by FK
        timestamp created_at
        timestamp updated_at
    }

    TEACHER_DAILY_ATTENDANCES {
        bigint id PK
        bigint teacher_id FK
        date date
        string status "present|late|absent|permission|sick|out_of_office"
        time check_in_time
        time check_out_time
        boolean is_auto
        text notes
        timestamp created_at
        timestamp updated_at
    }

    STUDENT_DAILY_ATTENDANCES {
        bigint id PK
        bigint student_id FK
        date date
        string status "present|late|absent|permission|sick"
        time check_in_time
        time check_out_time
        boolean is_auto
        text notes
        timestamp created_at
        timestamp updated_at
    }

    TEACHING_ATTENDANCES {
        bigint id PK
        bigint schedule_id FK
        date date
        bigint teacher_id FK
        string status "teaching|not_teaching"
        text notes
        bigint submitted_by FK
        timestamp submitted_at
        timestamp created_at
        timestamp updated_at
    }

    STUDENT_SUBJECT_ATTENDANCES {
        bigint id PK
        bigint schedule_id FK
        date date
        bigint student_id FK
        string status "present|absent|permission|sick|late"
        text notes
        bigint submitted_by FK
        timestamp submitted_at
        timestamp created_at
        timestamp updated_at
    }

    SUBSTITUTE_TEACHERS {
        bigint id PK
        bigint schedule_id FK
        date date
        bigint original_teacher_id FK
        bigint substitute_teacher_id FK
        bigint appointed_by FK
        timestamp created_at
    }

    HOLIDAYS {
        bigint id PK
        date start_date
        date end_date
        string description
        string type "holiday|school_event"
        string scope "whole_school|per_class"
        boolean is_daily_attendance_active
        bigint created_by FK
        timestamp created_at
        timestamp updated_at
    }

    CLASSROOM_HOLIDAYS {
        bigint id PK
        bigint holiday_id FK
        bigint classroom_id FK
    }

    TEACHER_LEAVE_REQUESTS {
        bigint id PK
        bigint teacher_id FK
        date start_date
        date end_date
        string type "permission|sick"
        text reason
        string attachment
        string status "pending|approved|rejected|canceled"
        bigint reviewed_by FK
        timestamp reviewed_at
        text reviewer_notes
        boolean is_admin_input
        timestamp created_at
        timestamp updated_at
    }

    STUDENT_LEAVE_REQUESTS {
        bigint id PK
        bigint student_id FK
        date start_date
        date end_date
        string type "permission|sick"
        text reason
        string attachment
        string status "pending|approved|rejected|canceled"
        bigint reviewed_by FK
        timestamp reviewed_at
        text reviewer_notes
        boolean is_admin_input
        timestamp created_at
        timestamp updated_at
    }

    USERS ||--o| TEACHERS : has
    USERS ||--o| STUDENTS : has
    TEACHERS ||--o{ CLASSROOMS : homeroom_of
    CLASSROOMS ||--o{ STUDENTS : contains
    ACADEMIC_YEARS ||--o{ SEMESTERS : has
    SEMESTERS ||--o{ SCHEDULES : has
    SUBJECTS ||--o{ SCHEDULES : scheduled_for
    CLASSROOMS ||--o{ SCHEDULES : follows
    TEACHERS ||--o{ SCHEDULES : teaches

    TEACHERS ||--o{ TEACHER_QR_TOKENS : owns
    STUDENTS ||--o{ STUDENT_QR_TOKENS : owns
    USERS ||--o{ KIOSK_TOKENS : creates

    TEACHERS ||--o{ TEACHER_DAILY_ATTENDANCES : attends
    STUDENTS ||--o{ STUDENT_DAILY_ATTENDANCES : attends

    SCHEDULES ||--o{ TEACHING_ATTENDANCES : generates
    TEACHERS ||--o{ TEACHING_ATTENDANCES : attends
    USERS ||--o{ TEACHING_ATTENDANCES : submits

    SCHEDULES ||--o{ STUDENT_SUBJECT_ATTENDANCES : generates
    STUDENTS ||--o{ STUDENT_SUBJECT_ATTENDANCES : attends
    USERS ||--o{ STUDENT_SUBJECT_ATTENDANCES : submits

    SCHEDULES ||--o{ SUBSTITUTE_TEACHERS : assigned_in
    TEACHERS ||--o{ SUBSTITUTE_TEACHERS : original_teacher
    TEACHERS ||--o{ SUBSTITUTE_TEACHERS : substitute_teacher
    USERS ||--o{ SUBSTITUTE_TEACHERS : appoints

    USERS ||--o{ HOLIDAYS : creates
    HOLIDAYS ||--o{ CLASSROOM_HOLIDAYS : scoped_to
    CLASSROOMS ||--o{ CLASSROOM_HOLIDAYS : receives

    TEACHERS ||--o{ TEACHER_LEAVE_REQUESTS : requests
    STUDENTS ||--o{ STUDENT_LEAVE_REQUESTS : requests
    USERS ||--o{ TEACHER_LEAVE_REQUESTS : reviews
    USERS ||--o{ STUDENT_LEAVE_REQUESTS : reviews
```
