# CancelPurchaseRequisition

## Permission Scope

purchaseRequisition

## Overview

CancelPurchaseRequisition stops a purchase requisition before it is approved or converted and moves `status` to `CANCELLED`.

## Business Rules

- Target purchase requisition must exist
- Only requisitions with `status` in `DRAFT` or `SUBMITTED` can be cancelled
- Cancelling an `APPROVED`, `CONVERTED`, or `CLOSED` requisition is forbidden
- Cancelling preserves the original requisition for audit and traceability

## Process Flow

```mermaid
flowchart TD
    A[Receive cancel request] --> B{Purchase requisition exists?}
    B -->|No| C[Return PURCHASE_REQUISITION_NOT_FOUND]
    B -->|Yes| D{Status cancellable?}
    D -->|No| E[Return PURCHASE_REQUISITION_NOT_CANCELLABLE]
    D -->|Yes| F["Set status to CANCELLED"]
    F --> G[Return cancelled requisition]
```

## External Dependencies

- None

## Error Scenarios

- **PURCHASE_REQUISITION_NOT_FOUND**: Referenced purchase requisition does not exist
- **PURCHASE_REQUISITION_NOT_CANCELLABLE**: Purchase requisition status does not allow cancellation

## Test Cases

- cancels a draft purchase requisition
- cancels a submitted purchase requisition
- returns error when purchase requisition does not exist
- returns error when purchase requisition is approved
- returns error when purchase requisition is already converted
- returns error when purchase requisition is closed
- returns error when purchase requisition is already cancelled
