# DATABASE SCHEMA – ERPdash

This document defines the core database structure used by the ERP system.
AI agents must follow these tables and relations and avoid inventing new tables unless explicitly requested.

---

# Core Tables

## branches
Fields:
- id
- code
- name (json, translatable)
- is_main
- is_active
- created_at
- updated_at

## settings
Fields:
- id
- key
- value
- group
- created_at
- updated_at

## number_sequences
Fields:
- id
- name
- prefix
- next_number
- padding
- branch_id
- created_at
- updated_at

---

# Finance Foundation

## fiscal_years
Fields:
- id
- name
- start_date
- end_date
- is_closed
- created_at
- updated_at

## fiscal_periods
Fields:
- id
- fiscal_year_id
- name
- start_date
- end_date
- is_closed

---

# Cost Centers

## cost_centers
Fields:
- id
- code
- name (json translatable)
- parent_id
- branch_id
- is_active
- created_by
- updated_by
- created_at
- updated_at

Relations:
- parent_id -> cost_centers.id
- branch_id -> branches.id

---

# Accounting

## accounts
Fields:
- id
- code
- name (json)
- parent_id
- account_type
- is_active

## journals
Fields:
- id
- code
- name
- branch_id

## journal_entries
Fields:
- id
- journal_id
- entry_number
- entry_date
- branch_id
- fiscal_year_id

## journal_entry_lines
Fields:
- id
- journal_entry_id
- account_id
- debit
- credit
- cost_center_id

---

# Important Rules

- All translatable fields must be JSON.
- Foreign keys must be indexed.
- Avoid nullable fields unless required.
- Use snake_case naming.

