# ClosePurchaseRequisition

## Permission Scope

purchaseRequisition

## Overview

ClosePurchaseRequisition sets `status` to `CLOSED` on an approved purchase requisition that will not be converted to a purchase order, typically because the need was fulfilled through existing stock or an alternative channel.

## Business Rules

- Target purchase requisition must exist
- Only requisitions with `status` = `APPROVED` can be closed
- Closing preserves the original requisition for audit
- Close reason is optional but recommended for traceability

## Process Flow

```mermaid
flowchart TD
    A[Receive close request] --> B{Purchase requisition exists?}
    B -->|No| C[Return PURCHASE_REQUISITION_NOT_FOUND]
    B -->|Yes| D{Status is APPROVED?}
    D -->|No| E[Return PURCHASE_REQUISITION_NOT_CLOSABLE]
    D -->|Yes| F["Set status to CLOSED"]
    F --> G[Return closed requisition]
```

## External Dependencies

- None

## Error Scenarios

- **PURCHASE_REQUISITION_NOT_FOUND**: Referenced purchase requisition does not exist
- **PURCHASE_REQUISITION_NOT_CLOSABLE**: Purchase requisition status does not allow closure

## Test Cases

- closes an approved purchase requisition
- closes an approved requisition with a close reason
- closes an approved requisition without a close reason
- returns error when purchase requisition does not exist
- returns error when purchase requisition is not in approved status
- returns error when purchase requisition is already converted
- returns error when purchase requisition is in draft status
- returns error when purchase requisition is in submitted status
