# CreateInventoryCount

## Permission Scope

inventoryControl

## Overview

createInventoryCount creates a new inventory count document in PLANNED status. Inventory counts are used to verify physical stock against system records. Counts can be full (entire warehouse) or cycle (specific storage locations).

## Business Rules

- countType is required and must be one of: FULL, CYCLE
- Location scope is required — either warehouseId or storageLocationId must be specified
- plannedDate is required
- Count is created in PLANNED status

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B{Valid countType?}
    B -->|No| C[Return error: INVALID_COUNT_TYPE]
    B -->|Yes| D{warehouseId provided?}
    D -->|Yes| E{Warehouse exists?}
    E -->|No| F[Return error: WAREHOUSE_NOT_FOUND]
    E -->|Yes| G[Create count in PLANNED status]
    D -->|No| H{storageLocationId provided?}
    H -->|Yes| I{Location exists?}
    I -->|No| J[Return error: STORAGE_LOCATION_NOT_FOUND]
    I -->|Yes| G
    H -->|No| K[Return error: location scope required]
    G --> L[Return created count]
```

## External Dependencies

- None (internal models: [Warehouse](../models/Warehouse.md), [StorageLocation](../models/StorageLocation.md))

## Error Scenarios

- **WAREHOUSE_NOT_FOUND**: Referenced warehouse does not exist
- **STORAGE_LOCATION_NOT_FOUND**: Referenced storage location does not exist
- **INVALID_COUNT_TYPE**: countType is not FULL or CYCLE

## Test Cases

- returns error when warehouse not found
- returns error when invalid count type
- returns error when no location scope provided
- returns error when storage location not found
- creates full count
- creates cycle count for specific location
