# ERD — HRIS Presensi & Payroll

**Sumber requirement:** [PRD.md](./PRD.md)  
**Versi:** 1.1  
**Tanggal:** 29 Agustus 2026  
**Status:** Logical data model untuk MVP dan fitur pasca-MVP yang sudah disebutkan di PRD

## 1. Ruang Lingkup

ERD ini menerjemahkan kebutuhan PRD menjadi model relasional. Entitas yang bersifat turunan seperti dashboard dan report tidak dibuat sebagai tabel khusus; datanya dihitung dari tabel transaksi dan dapat dioptimalkan kemudian melalui query, view, cache, atau materialized report.

Model menggunakan prinsip berikut:

- seluruh data operasional memiliki scope `company_id`; data organisasi di bawahnya mengikuti company melalui foreign key;
- setiap tabel domain yang diekspos melalui URL/API publik memiliki `public_id` UUID v7 yang unique; `id` numerik tidak pernah diekspos ke publik;
- `branch_id` pada employee, attendance, dan payroll dipertahankan sebagai snapshot/scope operasional agar histori tetap dapat dilaporkan ketika penempatan berubah;
- status domain penting menggunakan enum atau lookup terkontrol, bukan string bebas;
- nominal uang menggunakan `decimal`, bukan `float`;
- payroll menyimpan snapshot sumber per item agar perubahan master setelah kalkulasi tidak mengubah payroll lama;
- face template disimpan terenkripsi di private storage/database dan tidak pernah dikirim ke frontend;
- approval dibuat polymorphic agar leave, overtime, reimbursement, dan attendance correction memakai workflow yang sama;
- `created_at`, `updated_at`, dan bila relevan `deleted_at` ditambahkan oleh implementasi Laravel.

## 2. ERD Utama

Diagram berikut adalah logical ERD. Tabel `users`, `roles`, dan `permissions` mendukung authentication/RBAC. Relasi polymorphic ditandai dengan pasangan `*_type` dan `*_id`.

```mermaid
erDiagram
    companies ||--o{ branches : has
    companies ||--o{ departments : has
    companies ||--o{ divisions : has
    companies ||--o{ positions : has
    companies ||--o{ job_levels : has
    companies ||--o{ employees : employs
    companies ||--o{ users : scopes
    companies ||--o{ salary_components : owns
    companies ||--o{ salary_structures : owns
    companies ||--o{ payroll_periods : runs
    companies ||--o{ approval_workflows : configures
    companies ||--o{ announcements : publishes
    companies ||--o{ events : owns

    branches ||--o{ departments : contains
    branches ||--o{ divisions : contains
    branches ||--o{ positions : contains
    branches ||--o{ employees : assigns
    branches ||--o{ shifts : uses
    branches ||--o{ holidays : observes
    branches ||--o{ payrolls : pays

    divisions ||--o{ departments : contains
    departments ||--o{ positions : contains
    departments ||--o{ employees : groups
    divisions ||--o{ employees : groups
    positions ||--o{ employees : assigns
    job_levels ||--o{ employees : grades

    employees ||--o| users : has_account
    employees ||--o{ employee_documents : owns
    employees ||--o{ face_templates : enrolls
    employees ||--o{ face_verifications : verifies
    employees ||--o{ work_schedules : follows
    employees ||--o{ attendances : records
    employees ||--o{ leave_balances : receives
    employees ||--o{ leave_requests : submits
    employees ||--o{ permission_requests : submits
    employees ||--o{ overtime_requests : submits
    employees ||--o{ employee_salary_structures : assigned
    employees ||--o{ payrolls : receives
    employees ||--o{ loans : requests
    employees ||--o{ reimbursements : submits

    users }o--o{ roles : assigned
    roles }o--o{ permissions : grants

    shifts ||--o{ work_schedules : scheduled
    holidays ||--o{ work_schedules : overrides
    work_schedules ||--o{ attendances : determines
    branches ||--o{ attendance_locations : validates
    attendances ||--o{ attendance_locations : captures
    attendances ||--o{ attendance_logs : audits
    attendances ||--o{ attendance_corrections : corrected

    leave_types ||--o{ leave_balances : allocates
    leave_types ||--o{ leave_requests : selected
    events ||--o{ leave_balances : allocates
    leave_balances ||--o{ event_balance_histories : records

    salary_structures ||--o{ salary_structure_items : contains
    salary_components ||--o{ salary_structure_items : included
    salary_structures ||--o{ employee_salary_structures : assigned
    branches ||--o{ employee_salary_structures : scoped
    positions ||--o{ employee_salary_structures : scoped
    employee_salary_structures }o--o| employees : employee_override

    payroll_periods ||--o{ payrolls : contains
    payrolls ||--o{ payroll_items : contains
    payrolls ||--o{ payroll_adjustments : adjusts
    payrolls ||--o| payslips : generates
    salary_components ||--o{ payroll_items : snapshots
    employees ||--o{ payroll_items : itemized

    loans ||--o{ loan_installments : amortizes
    payrolls ||--o{ loan_installments : deducts

    approval_workflows ||--o{ approval_workflow_steps : defines
    approval_workflows ||--o{ approval_requests : uses
    users ||--o{ approval_requests : requests
    approval_requests ||--o{ approval_actions : records
    users ||--o{ approval_actions : decides

    users ||--o{ notifications : receives
    users ||--o{ audit_logs : acts
```

## 3. Tabel dan Kolom Utama

Kolom `id` pada seluruh tabel adalah primary key internal bertipe `BIGINT`. Tabel domain yang dapat dirujuk dari URL/API publik juga memiliki kolom `public_id` bertipe UUID v7 dengan unique constraint. Foreign key internal tetap menggunakan `*_id` bertipe `BIGINT`; `public_id` hanya digunakan sebagai identifier eksternal yang aman dan tidak berurutan.

### 3.1 Foundation dan Organisasi

#### `companies`

Menyimpan tenant/perusahaan.

| Kolom        | Keterangan                          |
| ------------ | ----------------------------------- |
| `id`         | PK internal, `BIGINT`               |
| `public_id`  | UUID v7 unique untuk URL/API publik |
| `code`       | Kode unik perusahaan                |
| `name`       | Nama perusahaan                     |
| `legal_name` | Nama legal, nullable                |
| `timezone`   | Timezone default perusahaan         |
| `status`     | `ACTIVE`, `INACTIVE`                |

#### `branches`

Lokasi kerja dan geofence.

| Kolom                     | Keterangan                                     |
| ------------------------- | ---------------------------------------------- |
| `id`                      | PK internal, `BIGINT`                          |
| `public_id`               | UUID v7 unique untuk URL/API publik            |
| `company_id`              | FK ke `companies`                              |
| `code`                    | Unik dalam company                             |
| `name`                    | Nama cabang                                    |
| `address`                 | Alamat                                         |
| `latitude`, `longitude`   | Koordinat geofence, wajib                      |
| `radius_meters`           | Radius presensi yang diizinkan                 |
| `max_gps_accuracy_meters` | Batas akurasi GPS, wajib                       |
| `timezone`                | Timezone cabang, nullable; fallback ke company |
| `status`                  | `ACTIVE`, `INACTIVE`                           |

#### `departments`, `divisions`, `positions`, `job_levels`

Masing-masing memiliki `id` BIGINT, `public_id` UUID v7 unique bila diekspos ke URL/API publik, `company_id`, `code`, `name`, `status`, dan `sort_order` bila dibutuhkan. `divisions` dapat memiliki `branch_id` nullable untuk master lintas cabang. `departments` memiliki `division_id` sebagai parent wajib secara bisnis dan `branch_id` nullable. `positions` memiliki `department_id` sebagai parent wajib secara bisnis, sedangkan `job_level_id` tetap nullable.

#### `users`, `roles`, `permissions`

- `users`: `id` BIGINT, `public_id` UUID v7 unique bila dirujuk publik, `employee_id` nullable/unique, `company_id` nullable untuk akun super admin, `name`, `email` unique, `password_hash`, `status`, `last_login_at`.
- `roles`: `company_id` nullable, `code`, `name`, dan scope role seperti super admin, company admin/HR, manager, finance, employee. Role `GLOBAL` wajib memiliki `company_id` null; role `COMPANY` dan `BRANCH` wajib memiliki company owner.
- `permissions`: `code`, `name`, `module`.
- Tabel pivot `role_user` menyimpan `role_id`, `user_id`, dan bila diperlukan `company_id`/`branch_id` sebagai scope akses.
- Tabel pivot `permission_role` menyimpan `permission_id` dan `role_id`.

#### `employees`

Profil dan penempatan karyawan.

| Kolom                             | Keterangan                                                                               |
| --------------------------------- | ---------------------------------------------------------------------------------------- |
| `id`                              | PK                                                                                       |
| `company_id`, `branch_id`         | Scope organisasi                                                                         |
| `department_id`, `division_id`    | Unit organisasi, nullable                                                                |
| `position_id`, `job_level_id`     | Jabatan dan grade, nullable                                                              |
| `manager_id`                      | Self-FK ke `employees`, nullable                                                         |
| `employee_no`                     | Employee ID, unik dalam company                                                          |
| `nik`                             | NIK, unique sesuai kebijakan                                                             |
| `full_name`                       | Nama karyawan                                                                            |
| `photo_path`                      | Path foto profil, nullable; bukan face template                                          |
| `email`, `phone`                  | Kontak                                                                                   |
| `gender`, `birth_date`, `address` | Data personal                                                                            |
| `joined_at`, `ended_at`           | Tanggal masuk/keluar                                                                     |
| `employment_status`               | `PROBATION`, `CONTRACT`, `PERMANENT`, `FREELANCE`, `PART_TIME`, `RESIGNED`, `TERMINATED` |

`employee_documents` menyimpan metadata dokumen: `employee_id`, `document_type`, `document_number` nullable, `file_path` private, `issued_at`, `expires_at`, dan `status`. File tidak disimpan langsung di database.

### 3.2 Face, Shift, dan Jadwal

#### `face_templates`

Menyimpan hasil enrollment, bukan raw image.

| Kolom                       | Keterangan                     |
| --------------------------- | ------------------------------ |
| `employee_id`               | FK ke employee                 |
| `encrypted_template`        | Embedding/template terenkripsi |
| `template_version`          | Versi model/provider           |
| `provider`                  | Provider face/liveness         |
| `quality_score`             | Hasil quality check            |
| `status`                    | `ACTIVE`, `REVOKED`, `EXPIRED` |
| `enrolled_at`, `revoked_at` | Lifecycle dan retention        |

`face_verifications` mencatat hasil verifikasi tanpa menyimpan payload biometrik mentah: `employee_id`, `face_template_id` nullable, `attendance_id` nullable, `provider`, `liveness_result`, `face_detected`, `one_face_only`, `confidence_score`, `similarity_score`, `result`, `failure_reason`, `verified_at`.

#### `shifts`

Kolom utama: `company_id`, `branch_id` nullable, `code`, `name`, `start_time`, `end_time`, `break_start`, `break_end`, `late_after_minutes`, `early_leave_after_minutes`, `is_overnight`, `status`.

`is_overnight` wajib true untuk shift seperti 22:00–07:00. Waktu disimpan bersama timezone operasional yang jelas.

#### `work_schedules`

Penugasan shift per employee dan tanggal.

| Kolom                            | Keterangan                               |
| -------------------------------- | ---------------------------------------- |
| `employee_id`                    | FK                                       |
| `shift_id`                       | FK nullable untuk `OFF`                  |
| `holiday_id`                     | FK nullable bila ada override hari libur |
| `schedule_date`                  | Tanggal jadwal                           |
| `day_type`                       | `WORKDAY`, `DAY_OFF`, `HOLIDAY`          |
| `effective_from`, `effective_to` | Untuk pola jadwal efektif                |

Tambahkan unique constraint yang mencegah dua jadwal aktif untuk employee dan tanggal yang sama.

`holidays` menyimpan `company_id`, `branch_id` nullable, `holiday_date`, `name`, `is_paid`, dan `status`.

### 3.3 Attendance dan Koreksi

#### `attendances`

Satu record ringkasan presensi per employee per tanggal kerja.

| Kolom                                          | Keterangan                                                                                               |
| ---------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| `employee_id`, `company_id`, `branch_id`       | Scope dan snapshot penempatan                                                                            |
| `work_schedule_id`                             | Jadwal yang dipakai                                                                                      |
| `attendance_date`                              | Tanggal operasional                                                                                      |
| `status`                                       | `PRESENT`, `LATE`, `ABSENT`, `LEAVE`, `SICK`, `PERMISSION`, `HOLIDAY`, `DAY_OFF`, `BUSINESS_TRIP`, `WFH` |
| `clock_in_at`, `clock_out_at`                  | Timestamp presensi                                                                                       |
| `working_duration_seconds`                     | Durasi kerja terhitung                                                                                   |
| `late_duration_seconds`, `early_leave_seconds` | Durasi pelanggaran                                                                                       |
| `overtime_duration_seconds`                    | Kandidat lembur/hasil kalkulasi                                                                          |
| `source`                                       | `WEB`, `MOBILE`, `DEVICE`, atau sumber lain                                                              |
| `finalized_at`                                 | Penguncian untuk payroll, nullable                                                                       |

Unique key yang disarankan: `employee_id + attendance_date`. Jika bisnis mengizinkan split shift, gunakan key berbasis `work_schedule_id` dan dokumentasikan aturan agregasinya.

#### `attendance_locations`

Bukti lokasi untuk clock in/out: `attendance_id`, `event_type` (`CLOCK_IN`, `CLOCK_OUT`), `latitude`, `longitude`, `accuracy_meters`, `distance_meters`, `branch_latitude`, `branch_longitude`, `validation_result`, `failure_reason`, `captured_at`.

Distance harus dihitung server-side dari koordinat branch; `validation_result` dari client tidak dipercaya.

#### `attendance_logs`

Audit event presensi: `attendance_id`, `event_type`, `actor_user_id` nullable, `event_at`, `status_before`, `status_after`, `metadata_json` terbatas, `ip_address`, `user_agent`. Jangan masukkan face template atau raw provider payload.

#### `attendance_corrections`

Permintaan koreksi: `attendance_id`, `requested_by_user_id`, `reason`, `before_snapshot_json`, `after_snapshot_json`, `status`, `approved_at`, `applied_at`. Keputusan approval dicatat melalui `approval_requests` dan `approval_actions`.

### 3.4 Leave, Permission, dan Overtime

#### `leave_types`

`company_id`, `code`, `name`, `description`, `default_days`, `requires_attachment`, `is_paid`, `status`.

#### `leave_balances`

Saldo per employee dan tahun/periode. Untuk saldo cuti, `leave_type_id` terisi;
untuk saldo event, `event_id` terisi dan `leave_type_id` kosong. Kolom utama:
`employee_id`, `leave_type_id` nullable, `event_id` nullable, `year`,
`opening_balance`, `accrued_days`, `used_days`, `adjusted_days`,
`remaining_days`, `balance_amount`, `used_amount`, `remaining_amount`.
Field nominal hanya digunakan untuk saldo event. Unique key cuti adalah
`employee_id + leave_type_id + year`; saldo event harus unik untuk employee,
event, dan tahun yang sama.

#### `events`

Master event perusahaan/cabang tanpa saldo dan transaksi keuangan:
`company_id`, `branch_id` nullable, `public_id`, `title`, `description`
nullable, `event_date`, `end_date` nullable, dan `status` (`ACTIVE`,
`INACTIVE`).

#### `event_balance_histories`

Ledger pengeluaran saldo event: `leave_balance_id`, `transaction_date`,
`amount`, `balance_before`, `balance_after`, dan `description`. Insert, update,
dan delete menghitung ulang saldo berdasarkan urutan tanggal dan ID transaksi
dalam satu database transaction. Saldo tidak boleh menjadi negatif.

#### `leave_requests`

`employee_id`, `leave_type_id`, `start_date`, `end_date`, `total_days`, `reason`, `attachment_path` nullable, `status`, `submitted_at`, `approved_at`, `rejected_at`. Status minimal: `DRAFT`, `SUBMITTED`, `APPROVED`, `REJECTED`, `CANCELLED`.

#### `permission_requests`

Untuk telat, pulang cepat, tidak masuk, pribadi, WFH, atau dinas luar. Kolom: `employee_id`, `permission_type`, `start_at`, `end_at`, `reason`, `attachment_path` nullable, `status`, `submitted_at`.

#### `overtime_requests`

`employee_id`, `attendance_id` nullable, `overtime_date`, `start_at`, `end_at`, `duration_seconds`, `reason`, `status`, `submitted_at`, `approved_at`. Durasi final yang masuk payroll harus berasal dari request/status yang disetujui atau aturan bisnis yang ditetapkan.

### 3.5 Salary Master dan Payroll

#### `salary_components`

`company_id`, `code`, `name`, `component_type` (`EARNING`, `DEDUCTION`), `calculation_type`, `taxable`, `affects_overtime`, `status`.

Komponen PRD seperti basic salary, allowance, overtime, bonus, commission, BPJS, PPh 21, loan/kasbon, late penalty, absence deduction, dan other deduction dibuat sebagai data master.

#### `salary_structures` dan `salary_structure_items`

- `salary_structures`: `company_id`, `code`, `name`, `description`, `status`.
- `salary_structure_items`: `salary_structure_id`, `salary_component_id`, `amount` nullable, `percentage` nullable, `calculation_rule` nullable, `sort_order`.

Validasi harus memastikan item memiliki aturan nominal atau formula yang valid dan tidak menduplikasi komponen dalam satu structure.

#### `employee_salary_structures`

Assignment effective-dated: `employee_id` nullable, `salary_structure_id`, `company_id`, `branch_id` nullable, `position_id` nullable, `job_level_id` nullable, `effective_from`, `effective_to` nullable, `reason`, `status`.

Assignment dapat berscope employee, position, job level, atau branch. Untuk satu employee, tidak boleh ada dua assignment efektif yang overlap setelah resolusi prioritas.

#### `payroll_periods`

`company_id`, `code`, `name`, `start_date`, `end_date`, `payment_date`, `status`, `locked_at`, `closed_at`. Lifecycle: `DRAFT` → `CALCULATED` → `REVIEW` → `APPROVED` → `PAID` → `CLOSED`.

#### `payrolls`

Header hasil payroll per employee: `payroll_period_id`, `employee_id`, `company_id`, `branch_id`, `employee_snapshot_json`, `salary_snapshot_json`, `gross_amount`, `total_deduction`, `net_amount`, `status`, `calculated_at`, `approved_at`, `paid_at`, `closed_at`.

Unique key: `payroll_period_id + employee_id`.

#### `payroll_items`

Detail earning/deduction: `payroll_id`, `salary_component_id` nullable, `code_snapshot`, `name_snapshot`, `component_type`, `quantity`, `rate`, `amount`, `source_type`, `source_id` nullable, `calculation_snapshot_json`.

`name_snapshot`, `code_snapshot`, dan nilai perhitungan wajib disimpan agar histori payroll immutable terhadap perubahan salary master.

#### `payroll_adjustments`

Adjustment manual/otomatis: `payroll_id`, `component_type`, `description`, `amount`, `reason`, `requested_by_user_id`, `approved_by_user_id` nullable, `status`.

#### `payslips`

Satu payslip per payroll: `payroll_id` unique, `employee_id`, `period_label`, `file_path` private nullable, `generated_at`, `published_at`, `downloaded_at` nullable, `status`. Access control harus memastikan employee hanya dapat melihat payslip miliknya.

### 3.6 Kasbon dan Reimbursement (Pasca-MVP)

#### `loans` dan `loan_installments`

- `loans`: `employee_id`, `company_id`, `loan_no`, `amount`, `tenor_months`, `installment_amount`, `remaining_balance`, `start_date`, `reason`, `status`.
- `loan_installments`: `loan_id`, `payroll_id` nullable, `installment_no`, `due_date`, `amount`, `paid_amount`, `status`, `paid_at`.

#### `reimbursements`

`employee_id`, `company_id`, `category` (`TRANSPORT`, `MEDICAL`, `INTERNET`, `BUSINESS`, `OPERATIONAL`), `amount`, `expense_date`, `description`, `receipt_path` private, `status`, `paid_at`, `paid_by_user_id` nullable. Flow approval: employee → manager → finance.

### 3.7 Approval, Notification, dan Audit

#### `approval_workflows` dan `approval_workflow_steps`

- `approval_workflows`: `company_id`, `module`, `name`, `status`.
- `approval_workflow_steps`: `approval_workflow_id`, `step_order`, `approver_type`, `role_id` nullable, `minimum_scope`, `is_required`.

`approver_type` dapat berupa `ROLE`, `MANAGER`, atau `USER`. Konfigurasi harus mendukung leave/overtime employee → manager → HR dan reimbursement employee → manager → finance.

#### `approval_requests` dan `approval_actions`

- `approval_requests`: `approval_workflow_id`, `requester_user_id`, `approvable_type`, `approvable_id`, `current_step`, `status`, `submitted_at`, `completed_at`.
- `approval_actions`: `approval_request_id`, `step_order`, `approver_user_id`, `decision` (`APPROVED`, `REJECTED`, `RETURNED`), `comment`, `acted_at`.

Tambahkan unique constraint agar satu approver tidak dapat memutuskan step yang sama dua kali. Semua perubahan status harus transactional dan idempotent.

#### `notifications`

In-app notification: `user_id`, `type`, `title`, `body`, `notifiable_type`, `notifiable_id` nullable, `action_url` nullable, `read_at`, `created_at`. Push notification berada di luar scope MVP.

#### `announcements`

Pengumuman perusahaan: `company_id`, `public_id`, `title`, `content`, `status`,
`published_at` nullable, dan `expires_at` nullable. Dashboard hanya mengambil
announcement aktif dalam periode publish/expiry dan sesuai tenant.

#### `audit_logs`

Append-only audit: `company_id` nullable, `actor_user_id` nullable, `action`, `auditable_type`, `auditable_id`, `before_snapshot_json` nullable, `after_snapshot_json` nullable, `reason` nullable, `ip_address`, `user_agent`, `created_at`.

Audit wajib mencakup employee, salary, attendance, attendance correction, approval, payroll, face registration, dan perubahan lokasi/geofence. Jangan menyimpan password, secret, raw face image, embedding plaintext, atau payload provider lengkap.

## 4. Relasi Penting dan Aturan Integritas

| Area            | Aturan                                                                                                                               |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| Tenant          | `branch.company_id` harus sama dengan `company_id` pada parent. Scope harus diterapkan pada query dan policy, bukan hanya filter UI. |
| Employee        | `manager_id` hanya boleh menunjuk employee dalam scope organisasi yang diizinkan. `employee_no` unik per company.                    |
| Geofence        | Clock in/out diterima hanya bila distance dan accuracy memenuhi konfigurasi branch; hitung distance di server.                       |
| Attendance      | Cegah clock in/out ganda dengan validasi state, unique business key, dan idempotency key pada request.                               |
| Overnight shift | `end_time` pada hari berikutnya bila `is_overnight = true`; jangan menghitung durasi hanya dari tanggal yang sama.                   |
| Leave           | Approval mengubah saldo secara transactional dan tidak boleh mengurangi saldo dua kali ketika request diproses ulang.                |
| Overtime        | Hanya overtime yang disetujui yang menjadi input payroll, kecuali aturan bisnis menetapkan sumber lain.                              |
| Salary          | Assignment effective date tidak boleh overlap untuk employee yang sama setelah prioritas assignment diterapkan.                      |
| Payroll         | Satu employee hanya memiliki satu payroll dalam satu period. Recalculate tidak boleh menggandakan item.                              |
| Closed payroll  | Record `CLOSED` bersifat immutable melalui alur normal; perubahan membutuhkan reopen yang terotorisasi dan diaudit.                  |
| Payslip         | Akses dibatasi berdasarkan employee pemilik dan scope role. File disimpan private.                                                   |
| Sensitive data  | Face template, dokumen, receipt, dan payslip wajib memiliki access control, encryption/retention policy, dan audit yang sesuai.      |

## 5. Index dan Constraint Minimum

- Unique: `public_id` UUID v7 pada setiap tabel domain yang diekspos melalui URL/API publik.
- Unique: `companies.code`, `branches(company_id, code)`, `employees(company_id, employee_no)`, `users.email`, `payrolls(payroll_period_id, employee_id)`, `payslips.payroll_id`.
- Unique: `attendances(employee_id, attendance_date)` untuk pola satu record per hari.
- Unique: `leave_balances(employee_id, leave_type_id, year)` dan `work_schedules(employee_id, schedule_date)`.
- Index: seluruh foreign key; `employees(company_id, branch_id, employment_status)`; `attendances(company_id, attendance_date, status)`; `leave_requests(company_id, status, start_date)`; `overtime_requests(company_id, status, overtime_date)`; `payroll_periods(company_id, status, start_date)`; `audit_logs(company_id, created_at)`.
- Index polymorphic: `(approvable_type, approvable_id)`, `(auditable_type, auditable_id)`, dan `(notifiable_type, notifiable_id)`.
- Foreign key transaksi finansial dan audit tidak boleh dihapus secara cascade yang menghilangkan histori. Gunakan restrict atau strategi archival yang terdokumentasi.

## 6. Batas MVP dan Pasca-MVP

### MVP

Implementasikan bertahap sesuai PRD: authentication/RBAC, company, branch, department/division/position/job level, employee, shift, work schedule, holiday, face enrollment/verification, geolocation attendance, attendance correction, leave, permission, overtime, generic approval, salary component, salary structure, payroll period/calculation, payslip, notification in-app, audit log, dan report berbasis query.

### Pasca-MVP

`loans`, `loan_installments`, dan `reimbursements` sudah dimodelkan karena tercantum dalam PRD, tetapi dapat ditunda setelah alur MVP stabil. Integrasi bank, accounting, mobile/biometric device, push notification, KPI/performance, recruitment, training, dan fitur future hold tidak memerlukan tabel inti tambahan dalam ERD ini sampai requirement detailnya ditetapkan.

## 7. Keputusan yang Masih Perlu Dikunci Sebelum Migration Final

1. Konvensi `public_id`: tabel domain mana saja yang diekspos melalui URL/API publik.
2. Database final: MySQL atau PostgreSQL.
3. Timezone storage dan aturan tanggal payroll untuk branch berbeda timezone.
4. Apakah attendance hanya satu record per hari atau mendukung beberapa sesi/split shift.
5. Provider face/liveness, threshold confidence/similarity, retention, dan key management encryption.
6. Formula payroll, prorata, pembulatan, BPJS, PPh 21, overtime, penalty, dan cut-off.
7. Scope role lintas company/branch dan aturan resolusi manager pada approval.
8. Retention dan legal deletion policy untuk face template, dokumen, lokasi, audit, dan payslip.

Keputusan ini tidak boleh di-hardcode sebagai formula final sebelum disepakati karena dapat mengubah migration, service payroll, dan histori perhitungan.
