# RejectPurchaseRequisition

## Permission Scope

purchaseRequisition

## Overview

RejectPurchaseRequisition returns a submitted purchase requisition's `status` to `DRAFT` and records the rejection reason so the requester can revise the document.

## Business Rules

- Target purchase requisition must exist
- Only requisitions with `status` = `SUBMITTED` can be rejected
- Rejection reason is required and preserved for audit
- Rejection does not alter line content; it only changes `status` back to `DRAFT`

## Process Flow

```mermaid
flowchart TD
    A[Receive reject request] --> B{Purchase requisition exists?}
    B -->|No| C[Return PURCHASE_REQUISITION_NOT_FOUND]
    B -->|Yes| D{Status is SUBMITTED?}
    D -->|No| E[Return PURCHASE_REQUISITION_NOT_SUBMITTED]
    D -->|Yes| F{Reason provided?}
    F -->|No| G[Return REJECTION_REASON_REQUIRED]
    F -->|Yes| H["Store rejection reason and set status to DRAFT"]
    H --> I[Return rejected requisition]
```

## External Dependencies

- None

## Error Scenarios

- **PURCHASE_REQUISITION_NOT_FOUND**: Referenced purchase requisition does not exist
- **PURCHASE_REQUISITION_NOT_SUBMITTED**: Purchase requisition is not in `SUBMITTED` status
- **REJECTION_REASON_REQUIRED**: No rejection reason was provided

## Test Cases

- rejects a submitted purchase requisition back to draft
- records the rejection reason for audit
- returns error when purchase requisition does not exist
- returns error when purchase requisition is not submitted
- returns error when rejection reason is missing
