# Task 13 — Warehouses

## Goal
Build the Warehouses module to manage physical storage locations for inventory operations.
This module is the foundation for stock movements, stock balances, and future inventory reports.

---

## Database

Table: `warehouses`

Fields:
- id
- code (string, unique)
- name (json, translatable)
- 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 branch_id
- index is_active

---

## Relations

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

Future relations:
- stockMovements() -> hasMany StockMovement

---

## Business Rules

1. Warehouse code must be unique.
2. Warehouse name must use HasTranslations.
3. Warehouse may belong to a branch.
4. Only active warehouses should be selectable in stock movement screens.

---

## Files

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

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

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

### Requests
- app/Http/Requests/Admin/Inventory/StoreWarehouseRequest.php
- app/Http/Requests/Admin/Inventory/UpdateWarehouseRequest.php

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

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

---

## Permissions

- inventory.warehouses.view
- inventory.warehouses.create
- inventory.warehouses.update
- inventory.warehouses.delete

---

## Validation Rules

- code: required, unique:warehouses,code
- name.ar: required, string
- name.en: nullable, string
- branch_id: nullable, exists:branches,id
- is_active: boolean

---

## UI

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

Fields in form:
- code
- name_ar
- name_en
- branch
- is_active

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

---

## Lang Keys

Suggested keys:
- warehouses
- warehouse
- create_warehouse
- edit_warehouse
- warehouse_code
- warehouse_name
- branch
- is_active
- status

---

## Seeder

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

---

## Steps

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

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

### Step 3
Create `WarehouseService`.

### Step 4
Create Form Requests.

### Step 5
Create `WarehouseController`.

### 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

