# Phase 25 : Transferts Multi-dépôts

**Priorité :** P4
**Complexité :** HAUTE (refactoring stock)
**Routes :** ~10
**Entités :** 3

---

## Objectif

Gérer plusieurs dépôts/entrepôts par company avec transferts de stock entre eux. Chaque produit a un stock par dépôt.

---

## Entités

### `Warehouse` (Dépôt)
Table : `pos_warehouse`

| Champ | Type | Description |
|-------|------|-------------|
| id | int PK | |
| company | FK Company CASCADE | |
| name | string 100, NotBlank | |
| code | string 20 | Unique par company |
| address | string 255 nullable | |
| city | string 100 nullable | |
| phone | string 20 nullable | |
| isActive | bool default true | |
| isDefault | bool default false | Un seul par company |
| managedBy | FK User SET NULL nullable | |
| TimestampableEntity, SoftDeleteableEntity | | |

### `WarehouseStock` (Stock par dépôt)
Table : `pos_warehouse_stock`

| Champ | Type | Description |
|-------|------|-------------|
| id | int PK | |
| warehouse | FK Warehouse CASCADE | |
| product | FK Product CASCADE | |
| currentStock | int default 0 | |
| minStock | int default 0 | |

**Unique :** (warehouse_id, product_id)

### `StockTransfer`
Table : `pos_stock_transfer`

| Champ | Type | Description |
|-------|------|-------------|
| id | int PK | |
| company | FK Company CASCADE | |
| reference | string 30 | Auto : `TRF-{PREFIX}-{YEAR}-{SEQ}` |
| sourceWarehouse | FK Warehouse | |
| destinationWarehouse | FK Warehouse | |
| status | string 20 | `draft`, `in_transit`, `received`, `cancelled` |
| requestedBy | FK User CASCADE | |
| shippedBy | FK User SET NULL nullable | |
| shippedAt | datetime nullable | |
| receivedBy | FK User SET NULL nullable | |
| receivedAt | datetime nullable | |
| notes | text nullable | |
| TimestampableEntity | | |

### `StockTransferLine`
Table : `pos_stock_transfer_line`

| Champ | Type | Description |
|-------|------|-------------|
| id | int PK | |
| transfer | FK StockTransfer CASCADE | |
| product | FK Product | |
| requestedQuantity | int | |
| shippedQuantity | int default 0 | |
| receivedQuantity | int default 0 | |

---

## Impact sur le modèle existant

**Approche recommandée :** table pivot `WarehouseStock`
- `Product.currentStock` reste le stock TOTAL (somme de tous les dépôts)
- `WarehouseStock` contient le détail par dépôt
- Les ventes déduisent du dépôt de la caisse (`Register.warehouse` — nouveau champ)
- Rétro-compatible : si pas de warehouse configuré, tout fonctionne comme avant

**Modifications :**
- `Register.php` : ajouter `warehouse` FK Warehouse SET NULL nullable
- `StockMovement.php` : ajouter `warehouse` FK SET NULL nullable
- `StockService` : adapter pour prise en compte du dépôt si multi-dépôts activé

---

## Routes Manager (~10)

CRUD Warehouse (5) + CRUD StockTransfer workflow (5)

---

## Complexité
Cette phase est un refactoring important. À ne faire que quand le besoin multi-dépôts est réel.
