# ListPurchaseReceiptEvidenceForMatching

## Overview

ListPurchaseReceiptEvidenceForMatching returns posted purchase goods-receipt evidence for supplier bill matching. It is the inventory-owned boundary query used by purchase matching logic so purchase does not query InventoryExecution or InventoryExecutionLine tables directly.

The query returns inbound InventoryExecutionLine evidence scoped to one purchase order and a set of purchase-order line IDs. Only posted goods-receipt executions are eligible. Each evidence row includes both the InventoryExecutionLine ID used for line-level quantity allocation and the InventoryExecution ID used for receipt header context.

## Business Rules

- Only InventoryExecution rows with `executionType=GOODS_RECEIPT` and `status=POSTED` are included
- Only InventoryExecutionLine rows with `direction=IN` are included
- The InventoryExecution must have `sourceDocumentType=PURCHASE_ORDER`
- The InventoryExecution `sourceDocumentId` must match the requested purchase order ID
- The InventoryExecutionLine `sourceLineId` must match one of the requested purchase-order line IDs
- Results are ordered by InventoryExecutionLine creation time for FIFO-style allocation by the caller
- Callers must use InventoryExecutionLine IDs, not only InventoryExecution IDs, when tracking consumed receipt quantity

## Process Flow

```mermaid
flowchart TD
    A[Receive purchase order ID and line IDs] --> B{Any line IDs?}
    B -->|No| C[Return empty evidence]
    B -->|Yes| D[Join InventoryExecutionLine to InventoryExecution]
    D --> E[Filter posted purchase goods receipt IN lines]
    E --> F[Return receipt evidence rows]
```

## External Dependencies

- None

## Error Scenarios

None. No matching receipt evidence returns an empty list.

## Test Cases

- lists posted purchase goods receipt evidence for matching
- returns empty evidence without querying when no purchase order lines are provided
