# Task 24 — Notifications

## Goal
Build the Notifications module to provide in-system alerts for key ERP events such as approvals, posting, payroll actions, and operational updates.
This task focuses on database-backed notifications and dashboard display.

---

## Scope

This task covers:
- notification storage and listing
- unread/read status
- dashboard notification UI
- basic notification service

This task does NOT cover:
- email notifications
- SMS notifications
- push notifications
- real-time websockets

---

## Database

Preferred approach:
- use Laravel database notifications table

If custom implementation is needed, table: `notifications`

Fields:
- id
- type
- notifiable_type
- notifiable_id
- data (json)
- read_at (nullable timestamp)
- created_at
- updated_at

Indexes:
- index notifiable_type
- index notifiable_id
- index read_at

---

## Relations

Notification should belong to a notifiable model (Admin initially).

Initial target:
- Admin dashboard users

---

## Business Rules

1. Notifications must be storable in database.
2. Notifications can be marked as read.
3. Dashboard should show unread count.
4. Notifications should support generic payload in JSON.
5. Notification service should be reusable by Finance, Sales, Inventory, and HR later.

---

## Files

### Service
- app/Services/System/NotificationService.php

### Controller
- app/Http/Controllers/Admin/System/NotificationController.php

### Views
- resources/views/dashboard/system/notifications/index.blade.php
- partials or dropdown view if needed in layout

### Lang files
- lang/ar/system.php
- lang/en/system.php

---

## Permissions

- system.notifications.view
- system.notifications.update

---

## UI

Views path:
`resources/views/dashboard/system/notifications/`

### UI requirements
- unread count in dashboard header/dropdown
- notifications list page
- mark as read action

---

## Lang Keys

Suggested keys:
- notifications
- notification
- mark_as_read
- unread_notifications
- all_notifications
- no_notifications

---

## Seeder

Update RolePermissionSeeder with:
- system.notifications.view
- system.notifications.update

---

## Steps

### Step 1
Create or confirm notifications table strategy.

### Step 2
Create `NotificationService`.

### Step 3
Create `NotificationController`.

### Step 4
Add routes in `routes/admin.php`.

### Step 5
Create notifications list/dropdown view.

### Step 6
Create lang files.

### Step 7
Update `RolePermissionSeeder`.

---

## Notes for AI

- Follow docs/ai/AI_MASTER_PROJECT.md
- Follow docs/ai/ARCHITECTURE_RULES.md
- Follow docs/ai/MODULE_STRUCTURE.md
- Execute one step at a time
- Do not modify unrelated files
- Do not generate tests in this task
- Wait for confirmation after each step

