# RecordCountLine

## Permission Scope

inventoryControl

## Overview

recordCountLine records the physically counted quantity for a specific count line during an inventory count. The variance between the system snapshot and the counted quantity is automatically calculated. Count lines in RECOUNT status (after a previous rejection) or REJECTED status (re-counted after rejection) can also be recorded.

## Business Rules

- Inventory count must be in IN_PROGRESS status
- Count line must be in PENDING, RECOUNT, or REJECTED status
- countedQuantity is required
- Variance is automatically calculated as countedQuantity minus system snapshot quantity

## Process Flow

```mermaid
flowchart TD
    A[Receive record request] --> B{Count exists?}
    B -->|No| C[Return error: COUNT_NOT_FOUND]
    B -->|Yes| D{Count IN_PROGRESS?}
    D -->|No| E[Return error: COUNT_NOT_IN_PROGRESS]
    D -->|Yes| F{Count line exists?}
    F -->|No| G[Return error: COUNT_LINE_NOT_FOUND]
    F -->|Yes| H{Line status PENDING, RECOUNT, or REJECTED?}
    H -->|No| I[Return error: COUNT_LINE_INVALID_STATUS]
    H -->|Yes| J[Record countedQuantity]
    J --> K[Calculate variance]
    K --> L[Update count line]
    L --> M[Return updated count line]
```

## External Dependencies

- None

## Error Scenarios

- **COUNT_NOT_FOUND**: Referenced count does not exist
- **COUNT_NOT_IN_PROGRESS**: Count is not in IN_PROGRESS status
- **COUNT_LINE_NOT_FOUND**: Referenced count line does not exist
- **COUNT_LINE_INVALID_STATUS**: Count line is not in PENDING, RECOUNT, or REJECTED status

## Test Cases

- returns error when count not found
- returns error when count not in progress
- returns error when count line not found
- returns error when line not pending
- records counted quantity
- calculates variance correctly
- allows recording for RECOUNT status lines
- allows recording for REJECTED status lines
