# Task 14 — Items

## Goal
Build the Items module to manage inventory products or stock items used in warehouses, stock movements, and later sales operations.
This module supports bilingual item names and inventory-ready product structure.

---

## Database

Table: `items`

Fields:
- id
- code (string, unique)
- name (json, translatable)
- description (json, nullable, translatable)
- type (string, default `stock`)
  - stock
  - service
- unit (string)
- branch_id (nullable, FK to branches.id)
- is_active (boolean, default true)
- created_by (nullable, FK to admins.id)
- updated_by (nullable, FK to admins.id)
- created_at
- updated_at

Indexes:
- unique code
- index type
- index branch_id
- index is_active

---

## Relations

Item model relations:
- branch() -> belongsTo Branch
- creator() -> belongsTo Admin
- updater() -> belongsTo Admin

Future relations:
- stockMovements() -> hasMany StockMovement
- salesLines() -> hasMany invoice/order lines later

---

## Business Rules

1. Item code must be unique.
2. Item name and description must use HasTranslations.
3. Type can be `stock` or `service`.
4. Only `stock` items should appear in stock movements.
5. Only active items should be selectable in operational screens.

---

## Files

### Model
- app/Models/Inventory/Item.php

### Service
- app/Services/Inventory/ItemService.php

### Controller
- app/Http/Controllers/Admin/Inventory/ItemController.php

### Requests
- app/Http/Requests/Admin/Inventory/StoreItemRequest.php
- app/Http/Requests/Admin/Inventory/UpdateItemRequest.php

### Views
- resources/views/dashboard/inventory/items/index.blade.php
- resources/views/dashboard/inventory/items/create.blade.php
- resources/views/dashboard/inventory/items/edit.blade.php

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

---

## Permissions

- inventory.items.view
- inventory.items.create
- inventory.items.update
- inventory.items.delete

---

## Validation Rules

- code: required, unique:items,code
- name.ar: required, string
- name.en: nullable, string
- description.ar: nullable, string
- description.en: nullable, string
- type: required, in:stock,service
- unit: required, string
- branch_id: nullable, exists:branches,id
- is_active: boolean

---

## UI

Views path:
`resources/views/dashboard/inventory/items/`

Fields in form:
- code
- name_ar
- name_en
- description_ar
- description_en
- type
- unit
- branch
- is_active

Index columns:
- code
- name
- type
- unit
- branch
- status
- actions

---

## Lang Keys

Suggested keys:
- items
- item
- create_item
- edit_item
- item_code
- item_name
- description
- item_type
- unit
- branch
- is_active
- status
- stock
- service

---

## Seeder

Update RolePermissionSeeder with:
- inventory.items.view
- inventory.items.create
- inventory.items.update
- inventory.items.delete

---

## Steps

### Step 1
Create migration for `items` table.

### Step 2
Create `Item` model with HasTranslations.

### Step 3
Create `ItemService`.

### Step 4
Create Form Requests.

### Step 5
Create `ItemController`.

### Step 6
Create routes.

### Step 7
Create views.

### Step 8
Create lang files.

### Step 9
Update `RolePermissionSeeder`.

---

## Notes for AI

- Follow docs/ai/AI_MASTER_PROJECT.md
- Follow docs/ai/ARCHITECTURE_RULES.md
- Follow docs/ai/DATABASE_SCHEMA.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

