# Equipment Maintenance System - Database Models

## Core Models & Relationships

### 1. `Ticket`
The heart of the application. It represents a request, complaint, or repair order.
- **Key Columns**: `case_no` (e.g., IT-00001), `status`, `cost`, `estimated_cost`, `explanation`, `resolved_at`, and timestamps for digital signatures (e.g., `branch_director_signed_at`).
- **Relationships**:
  - `employee()`: The employee the ticket belongs to.
  - `creator()`: The clerk/user who created the ticket.
  - `asset()`: The specific IT asset (if applicable).
  - `ticketCategory()`: e.g., Repair, Complaint, Service.
  - `technician()`: The assigned `Technician` (User).
  - `approvals()`: HasMany `TicketApproval` models linking to the workflow signatures.

### 2. `User` (and `Technician` / `Employee` extensions)
Handles authentication, roles, and profiles.
- **Key Columns**: `name`, `email`, `password`, `role_id`, `branch_id`.
- **Extensions**: 
  - `Technician`: A global scope is applied to only retrieve users where `role` is "Technician". It tracks `assigned_count` and `resolved_count` via relations.
  - `Employee`: Represents non-system users (staff) who own assets or raise complaints.

### 3. `Asset` & `AssetCategory`
Manages the hardware inventory.
- **Key Columns**: `asset_tag`, `serial_number`, `purchase_date`, `status`, `warranty_expiry`.
- **Relationships**: Belongs to `AssetCategory`, `Brand`, `BrandModel`, and `Directorate`. Can have an active `AssetAssignment` tying it to an Employee or a Location.

### 4. `Role` & `ApprovalSequence`
Dynamic workflow management.
- **`Role`**: Defines system access levels (e.g., Clerk, Director, IT Admin, Secy).
- **`ApprovalSequence`**: Maps a `TicketCategory` to an ordered list of `Role` IDs. It dynamically dictates the path a ticket takes. For example, a Repair ticket might go: Clerk -> Director -> IT Admin -> Addl Dir IT.

### 5. `TicketApproval`
Tracks the individual digital signatures (approvals/rejections) on a `Ticket`.
- **Columns**: `status` (Approved/Rejected), `comments`, `user_id` (the approver).

### 6. Organizational Models (`Directorate`, `Branch`)
- **`Directorate`**: Top-level departments.
- **`Branch`**: Sub-departments within a Directorate. Users and Employees are typically attached to Branches.

## Data Persistence & Tracking
- **`ActivityLog`**: Uses the `LogsActivity` trait on key models (like Ticket) to track state changes, who made them, and when. Useful for reverting changes or tracking the lifecycle of an edit.
