# Validation Report: URS-016

**Title:** Auto-decrement Inventory After Order Submission
**Date:** 2026-08-03T23:02:02.369Z
**Duration:** 134.8s
**Overall Status:** ✅ PASS

## User Requirement

> The system shall automatically decrement inventory after a bill-only order is submitted.

*Source: `User_Requirement_Specifications_Vantis_DeviceFlow.xlsx` — the run below proves the system meets this requirement.*

## Environment

- **Inbox URL:** http://localhost:34059
- **Database:** localhost:40721/cc_repinbox_dev

## Setup

Status: ✅ PASS

## Test Steps

Each step below corresponds to one Playwright test that ran sequentially. Screenshots and video recordings provide visual evidence of the UI behaviour.

### 1. Step 1: Initial inventory — ✅ PASS

**What this step proves:**

Logs in as a sales rep (Blair Bennett) and navigates to TRUNK-36 to record the starting quantities for NovaPatch and LiraLock. This establishes the known baseline so subsequent steps can prove the correct delta was applied after each order.

**Audit events generated by this step:**

*(Evidence matched by declared name — step timing not available or no events fell in window)*

| Time | Type | Action | User | Org | Performed |
|------|------|--------|------|-----|-----------|
| 2026-08-03 23:02:09Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — |
| 2026-08-03 23:02:19Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — |
| 2026-08-03 23:02:55Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — |
| 2026-08-03 23:03:01Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — |
| 2026-08-03 23:03:39Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — |

**Screenshots:**

![step 01 logged in](screenshots/step-01-logged-in.png)

![step 01 initial inventory](screenshots/step-01-initial-inventory.png)

**Video recording:**

[▶ Watch step recording](videos/step-01-initial-inventory.webm)

---

### 2. Step 2: First order — ✅ PASS

**What this step proves:**

Creates and submits a bill-only order for 3 NovaPatch and 2 LiraLock devices from trunk inventory. This exercises the full order-submission flow that should trigger an automatic inventory decrement in the database.

**Audit events generated by this step:**

*(Evidence scoped to step execution window: 2026-08-03T23:02:29.442Z → 2026-08-03T23:02:52.107Z)*

| Time | Type | Action | User | Org | Performed |
|------|------|--------|------|-----|-----------|
| 2026-08-03 23:02:49Z | billing_order | status_change | blair.bennett@corvetasurgical.com | Vantis | — |
| 2026-08-03 23:02:49Z | decision | bill_only.link_purchase_order | blair.bennett@corvetasurgical.com | Corveta Surgical Group | no |
| 2026-08-03 23:02:49Z | decision | bill_only_order.inventory_items_decrement | blair.bennett@corvetasurgical.com | Vantis | yes |
| 2026-08-03 23:02:49Z | decision | bill_only_order.direct_po_import_on_create | blair.bennett@corvetasurgical.com | Vantis | no |
| 2026-08-03 23:02:50Z | transactional_email | new_bill_only | — | Corveta Surgical Group | — |

**Emails triggered by this step:**

*(Evidence matched by declared name — step timing not available or no events fell in window)*

**Email 1: New Bill-Only Order - 8/3/2026 - Vantis BO-1**

Template: `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1`

![New Bill-Only Order - 8/3/2026 - Vantis BO-1](screenshots/emails/2026-08-03T23-02-50-400Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1.png)

**Email 2: New Bill-Only Order - 8/3/2026 - Vantis BO-2**

Template: `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-2`

![New Bill-Only Order - 8/3/2026 - Vantis BO-2](screenshots/emails/2026-08-03T23-03-33-584Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-2.png)

**Email 3: New Bill-Only Order - 8/3/2026 - Vantis BO-3**

Template: `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-3`

![New Bill-Only Order - 8/3/2026 - Vantis BO-3](screenshots/emails/2026-08-03T23-04-08-712Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-3.png)

**Screenshots:**

![step 02 account selected](screenshots/step-02-account-selected.png)

![step 02 devices selected](screenshots/step-02-devices-selected.png)

![step 02 documents](screenshots/step-02-documents.png)

![step 02 review](screenshots/step-02-review.png)

![step 02 order submitted](screenshots/step-02-order-submitted.png)

**Video recording:**

[▶ Watch step recording](videos/step-02-first-order.webm)

---

### 3. Step 3: Verify first decrement — ✅ PASS

**What this step proves:**

Navigates to TRUNK-36 immediately after the first order and confirms that NovaPatch and LiraLock quantities have each decreased by the ordered amount. This proves the inventory auto-decrement fires on order submission.

**Screenshots:**

![step 03 inventory after first order](screenshots/step-03-inventory-after-first-order.png)

**Video recording:**

[▶ Watch step recording](videos/step-03-verify-decrement.webm)

---

### 4. Step 4: Second order — ✅ PASS

**What this step proves:**

Submits a second bill-only order and then re-checks the inventory to verify that quantities reflect both orders cumulatively. This proves the decrement is applied consistently across multiple successive submissions.

**Audit events generated by this step:**

*(Evidence scoped to step execution window: 2026-08-03T23:03:33.604Z → 2026-08-03T23:03:36.475Z)*

| Time | Type | Action | User | Org | Performed |
|------|------|--------|------|-----|-----------|
| 2026-08-03 23:03:33Z | transactional_email | new_bill_only | — | Corveta Surgical Group | — |

**Emails triggered by this step:**

*(Evidence matched by declared name — step timing not available or no events fell in window)*

**Email 1: New Bill-Only Order - 8/3/2026 - Vantis BO-1**

Template: `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1`

![New Bill-Only Order - 8/3/2026 - Vantis BO-1](screenshots/emails/2026-08-03T23-02-50-400Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1.png)

**Email 2: New Bill-Only Order - 8/3/2026 - Vantis BO-2**

Template: `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-2`

![New Bill-Only Order - 8/3/2026 - Vantis BO-2](screenshots/emails/2026-08-03T23-03-33-584Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-2.png)

**Email 3: New Bill-Only Order - 8/3/2026 - Vantis BO-3**

Template: `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-3`

![New Bill-Only Order - 8/3/2026 - Vantis BO-3](screenshots/emails/2026-08-03T23-04-08-712Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-3.png)

**Screenshots:**

![step 04 second order submitted](screenshots/step-04-second-order-submitted.png)

![step 04 inventory after second order](screenshots/step-04-inventory-after-second-order.png)

**Video recording:**

[▶ Watch step recording](videos/step-04-second-order.webm)

---

### 5. Step 5: Shortage edge case — ✅ PASS

**What this step proves:**

Orders more NovaPatch units than are available in trunk stock. The system permits submission in best-effort mode and consumes all remaining units, bringing the count to zero. This proves the system handles inventory shortages without blocking the order while still tracking the discrepancy.

**Audit events generated by this step:**

*(Evidence scoped to step execution window: 2026-08-03T23:04:02.400Z → 2026-08-03T23:04:13.507Z)*

| Time | Type | Action | User | Org | Performed |
|------|------|--------|------|-----|-----------|
| 2026-08-03 23:04:07Z | decision | bill_only_order.direct_po_import_on_create | blair.bennett@corvetasurgical.com | Vantis | no |
| 2026-08-03 23:04:07Z | billing_order | status_change | blair.bennett@corvetasurgical.com | Vantis | — |
| 2026-08-03 23:04:07Z | decision | bill_only_order.inventory_items_decrement | blair.bennett@corvetasurgical.com | Vantis | yes |
| 2026-08-03 23:04:07Z | decision | bill_only.link_purchase_order | blair.bennett@corvetasurgical.com | Corveta Surgical Group | no |
| 2026-08-03 23:04:08Z | transactional_email | new_bill_only | — | Corveta Surgical Group | — |

**Emails triggered by this step:**

*(Evidence matched by declared name — step timing not available or no events fell in window)*

**Email 1: New Bill-Only Order - 8/3/2026 - Vantis BO-1**

Template: `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1`

![New Bill-Only Order - 8/3/2026 - Vantis BO-1](screenshots/emails/2026-08-03T23-02-50-400Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1.png)

**Email 2: New Bill-Only Order - 8/3/2026 - Vantis BO-2**

Template: `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-2`

![New Bill-Only Order - 8/3/2026 - Vantis BO-2](screenshots/emails/2026-08-03T23-03-33-584Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-2.png)

**Email 3: New Bill-Only Order - 8/3/2026 - Vantis BO-3**

Template: `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-3`

![New Bill-Only Order - 8/3/2026 - Vantis BO-3](screenshots/emails/2026-08-03T23-04-08-712Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-3.png)

**Screenshots:**

![step 05 shortage warning](screenshots/step-05-shortage-warning.png)

![step 05 review with shortage](screenshots/step-05-review-with-shortage.png)

![step 05 shortage result](screenshots/step-05-shortage-result.png)

![step 05 final inventory](screenshots/step-05-final-inventory.png)

**Video recording:**

[▶ Watch step recording](videos/step-05-shortage-edge-case.webm)

---

## Database Validations

The following SQL queries ran against the application database after the Playwright scenarios completed. Each query asserts a specific condition that proves the feature under test persisted its data correctly.

### Inventory items exist at trunk — ✅ PASS

**Assertion:** Both test inventory items (NovaPatch and LiraLock) should exist at TRUNK-36

```sql
SELECT ii.id, ii.di, ii.lot, ii.quantity_ready, ii.quantity_backordered, ii.quantity_in_transit
      FROM inventory_items ii
      WHERE ii.real_world_location_id = $1
        AND ii.lot IN ($2, $3)
      ORDER BY ii.lot
```

| id | di | lot | quantity_ready | quantity_backordered | quantity_in_transit |
| --- | --- | --- | --- | --- | --- |
| b2ac20b4-7847-451a-ab44-8df797fe697e | 07649988202247 | URS016-FL-001 | 12 | 0 | 0 |
| 66a853cb-377b-4851-a3a9-32e9cac716c9 | 07649988202230 | URS016-SP-001 | 0 | 0 | 0 |

### Inventory quantities decremented — ✅ PASS

**Assertion:** Both inventory items should have quantity_ready less than their initial values

```sql
SELECT ii.lot, ii.quantity_ready,
        CASE
          WHEN ii.lot = $2 THEN 20
          WHEN ii.lot = $3 THEN 15
        END as initial_quantity,
        CASE
          WHEN ii.lot = $2 THEN 20 - ii.quantity_ready
          WHEN ii.lot = $3 THEN 15 - ii.quantity_ready
        END as total_decremented
      FROM inventory_items ii
      WHERE ii.real_world_location_id = $1
        AND ii.lot IN ($2, $3)
      ORDER BY ii.lot
```

| lot | quantity_ready | initial_quantity | total_decremented |
| --- | --- | --- | --- |
| URS016-FL-001 | 12 | 15 | 3 |
| URS016-SP-001 | 0 | 20 | 20 |

### Recent billing orders created — ✅ PASS

**Assertion:** At least one billing order should have been created by Blair Bennett in the last 30 minutes

```sql
SELECT bo.id, bo.order_number, bo.status, bo.procedure_date,
        bo.created_at, bo.created_by_user_id
      FROM billing_orders bo
      WHERE bo.created_by_user_id = $1
        AND bo.created_at > NOW() - INTERVAL '30 minutes'
      ORDER BY bo.created_at DESC
      LIMIT 5
```

| id | order_number | status | procedure_date | created_at | created_by_user_id |
| --- | --- | --- | --- | --- | --- |
| 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | BO-3 | submitted | 2026-08-03T00:00:00.000Z | 2026-08-03T23:04:07.275Z | 17b8c9d0-e1f2-3456-1234-567890123456 |
| 019fc9de-3688-7643-b07f-cf1cb081ad88 | BO-2 | submitted | 2026-08-03T00:00:00.000Z | 2026-08-03T23:03:31.146Z | 17b8c9d0-e1f2-3456-1234-567890123456 |
| 019fc9dd-93a6-7041-a007-6be6b642e70c | BO-1 | submitted | 2026-08-03T00:00:00.000Z | 2026-08-03T23:02:49.431Z | 17b8c9d0-e1f2-3456-1234-567890123456 |

### Billing order items reference correct products — ✅ PASS

**Assertion:** Billing order items should reference NovaPatch and/or LiraLock products

```sql
SELECT boi.id, boi.billing_order_id, op.title as product_name,
        boi.lot_number, boi.serial_number, boi.location_id,
        boi.inventory_discrepancy
      FROM billing_order_items boi
      JOIN org_products op ON boi.product_id = op.id
      JOIN billing_orders bo ON boi.billing_order_id = bo.id
      WHERE bo.created_by_user_id = $1
        AND bo.created_at > NOW() - INTERVAL '30 minutes'
      ORDER BY bo.created_at DESC, op.title
```

| id | billing_order_id | product_name | lot_number | serial_number | location_id | inventory_discrepancy |
| --- | --- | --- | --- | --- | --- | --- |
| 019fc9de-c3a0-7842-80d7-9b1ce21df8fa | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | true |
| 019fc9de-c3a0-7842-80d7-9b24b77ec17e | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b253d0dab98 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b26308dc49c | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b27419fc970 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b285b74d29f | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b291d0ca060 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b2a42533610 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b2ba05c37c9 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b18be441e90 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | true |
| 019fc9de-c3a0-7842-80d7-9b19389e8ccc | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | true |
| 019fc9de-c3a0-7842-80d7-9b1ad3f92fd1 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | true |
| 019fc9de-c3a0-7842-80d7-9b1b5554a0bf | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | true |
| 019fc9de-c3a0-7842-80d7-9b1dd886a5b4 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b1e7e837479 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b1f136c82fa | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b2091739c44 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b2144b67639 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b22ed88bc18 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-c3a0-7842-80d7-9b2381b0ff63 | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-3681-7d1d-9386-18fc9475dd53 | 019fc9de-3688-7643-b07f-cf1cb081ad88 | LiraLock® Instrument SN | URS016-FL-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-3684-71d9-bcff-6cb7601ebb19 | 019fc9de-3688-7643-b07f-cf1cb081ad88 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9de-3684-71d9-bcff-6cb6099092d3 | 019fc9de-3688-7643-b07f-cf1cb081ad88 | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9dd-939e-7c5c-99bf-7d64ce3b7d1f | 019fc9dd-93a6-7041-a007-6be6b642e70c | LiraLock® Instrument SN | URS016-FL-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9dd-939f-7c33-87de-85fe219416c0 | 019fc9dd-93a6-7041-a007-6be6b642e70c | LiraLock® Instrument SN | URS016-FL-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9dd-93a1-7e1a-a1b0-4d634be021bb | 019fc9dd-93a6-7041-a007-6be6b642e70c | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9dd-93a1-7e1a-a1b0-4d62a72ecd8f | 019fc9dd-93a6-7041-a007-6be6b642e70c | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |
| 019fc9dd-93a1-7e1a-a1b0-4d64775ad23b | 019fc9dd-93a6-7041-a007-6be6b642e70c | NovaPatch® PET | URS016-SP-001 | NULL | a6e7f8a9-b0c1-2345-0123-456789012345 | false |

### Inventory history records bill_only_order removals — ✅ PASS

**Assertion:** Inventory history should contain records with action=removed and reason=bill_only_order

```sql
SELECT ih.id, ih.item_id, ih.quantity, ih.status, ih.info,
        ih.created_at, ih.inventory_id
      FROM inventory_history ih
      WHERE ih.item_id IN (
        SELECT id FROM inventory_items
        WHERE real_world_location_id = $1
          AND lot IN ($2, $3)
      )
      AND ih.created_at > NOW() - INTERVAL '30 minutes'
      AND ih.info->>'action' = 'removed'
      AND ih.info->>'reason' = 'bill_only_order'
      ORDER BY ih.created_at DESC
      LIMIT 20
```

| id | item_id | quantity | status | info | created_at | inventory_id |
| --- | --- | --- | --- | --- | --- | --- |
| 019fc9de-c3b0-7003-be17-e7f4a1609abb | 66a853cb-377b-4851-a3a9-32e9cac716c9 | 15 | ready | `{"action":"removed","reason":"bill_only_order","bestEffort":true,"billingOrderId":"019fc9de-c3a3-790b-b8e9-2ca0e500b424","shortageQuantity":0,"requestedQuantity":15}` | 2026-08-03T23:04:07.275Z | fa000001-0000-4000-8000-000000000001 |
| 019fc9de-c3b1-74da-8372-26d54305e815 | 66a853cb-377b-4851-a3a9-32e9cac716c9 | 5 | ready | `{"action":"removed","reason":"bill_only_order","bestEffort":true,"billingOrderId":"019fc9de-c3a3-790b-b8e9-2ca0e500b424","shortageQuantity":5,"requestedQuantity":20}` | 2026-08-03T23:04:07.275Z | fa000001-0000-4000-8000-000000000001 |
| 019fc9de-3698-754b-b6b9-b75ae66a3304 | b2ac20b4-7847-451a-ab44-8df797fe697e | 1 | ready | `{"action":"removed","reason":"bill_only_order","bestEffort":true,"billingOrderId":"019fc9de-3688-7643-b07f-cf1cb081ad88","shortageQuantity":0,"requestedQuantity":1}` | 2026-08-03T23:03:31.146Z | fa000001-0000-4000-8000-000000000001 |
| 019fc9de-3698-754b-b6b9-b75b7b89746e | 66a853cb-377b-4851-a3a9-32e9cac716c9 | 2 | ready | `{"action":"removed","reason":"bill_only_order","bestEffort":true,"billingOrderId":"019fc9de-3688-7643-b07f-cf1cb081ad88","shortageQuantity":0,"requestedQuantity":2}` | 2026-08-03T23:03:31.146Z | fa000001-0000-4000-8000-000000000001 |
| 019fc9dd-93d0-7c48-bcf3-12ec93f8e63d | b2ac20b4-7847-451a-ab44-8df797fe697e | 2 | ready | `{"action":"removed","reason":"bill_only_order","bestEffort":true,"billingOrderId":"019fc9dd-93a6-7041-a007-6be6b642e70c","shortageQuantity":0,"requestedQuantity":2}` | 2026-08-03T23:02:49.431Z | fa000001-0000-4000-8000-000000000001 |
| 019fc9dd-93d0-7c48-bcf3-12ed2ef96ea1 | 66a853cb-377b-4851-a3a9-32e9cac716c9 | 3 | ready | `{"action":"removed","reason":"bill_only_order","bestEffort":true,"billingOrderId":"019fc9dd-93a6-7041-a007-6be6b642e70c","shortageQuantity":0,"requestedQuantity":3}` | 2026-08-03T23:02:49.431Z | fa000001-0000-4000-8000-000000000001 |

### Inventory transactions created — ✅ PASS

**Assertion:** Inventory transactions should exist with source_type = bill_only_order

```sql
SELECT it.id, it.source_type, it.source_id, it.created_at,
        it.distributor_organization_id, it.manufacturer_organization_id
      FROM inventory_transactions it
      WHERE it.source_type = 'bill_only_order'
        AND it.created_at > NOW() - INTERVAL '30 minutes'
        AND (it.distributor_organization_id = $1 OR it.manufacturer_organization_id = $1)
      ORDER BY it.created_at DESC
      LIMIT 10
```

| id | source_type | source_id | created_at | distributor_organization_id | manufacturer_organization_id |
| --- | --- | --- | --- | --- | --- |
| 019fc9de-c3ad-751b-9472-129573618d8c | bill_only_order | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | 2026-08-03T23:04:07.275Z | b2c3d4e5-f6a7-8901-bcde-f12345678901 | NULL |
| 019fc9de-3694-7735-aebc-196855c07bc5 | bill_only_order | 019fc9de-3688-7643-b07f-cf1cb081ad88 | 2026-08-03T23:03:31.146Z | b2c3d4e5-f6a7-8901-bcde-f12345678901 | NULL |
| 019fc9dd-93b2-7126-9b1c-9ea1db1140df | bill_only_order | 019fc9dd-93a6-7041-a007-6be6b642e70c | 2026-08-03T23:02:49.431Z | b2c3d4e5-f6a7-8901-bcde-f12345678901 | NULL |

### No negative inventory quantities — ✅ PASS

**Assertion:** Inventory quantities should never go below zero (CHECK constraint enforced)

```sql
SELECT ii.id, ii.lot, ii.quantity_ready
      FROM inventory_items ii
      WHERE ii.real_world_location_id = $1
        AND ii.lot IN ($2, $3)
        AND ii.quantity_ready < 0
```

*No rows returned*

## Audit & Email Assertion Ledger

Per-declaration outcome of every `expectedAuditActions` and `expectedEmailTemplates` entry written into the orchestrator. Missing evidence here is a real test failure, not a soft warning.

### Audit Action Assertions

Each row asserts that a declared `expectedAuditActions` entry produced a matching row in `audit_events`. A ❌ flips overall status to FAIL — the declaration is real proof, not just an annotation.

| Step | Expected Audit Action | Found |
|------|-----------------------|-------|
| Step 1: Initial inventory | `user_log:user:login` | ✅ |
| Step 2: First order | `decision:bill_only_order.inventory_items_decrement` | ✅ |
| Step 4: Second order | `decision:bill_only_order.inventory_items_decrement` | ✅ |

### Email Template Assertions

Each row asserts that a declared `expectedEmailTemplates` entry was matched (case-insensitive substring) by a captured email subject or template. A ❌ flips overall status to FAIL.

| Step | Expected Template | Found |
|------|-------------------|-------|
| Step 2: First order | `New Bill-Only Order` | ✅ |
| Step 4: Second order | `New Bill-Only Order` | ✅ |
| Step 5: Shortage edge case | `New Bill-Only Order` | ✅ |

## Audit Log Events

Every row written to `audit_events` while this test was running (scoped to the demo organizations). Provides compliance evidence that user actions are traced end-to-end (URS-003).

**Capture window start:** 2026-08-03T23:02:00.689Z

<details><summary>Query used to capture events</summary>

```sql
SELECT
    ae.created_at,
    ae.event_type,
    ae.action,
    ae.user_id,
    u.email AS user_email,
    ae.organization_id,
    o.name AS organization_name,
    ae.object_id,
    ae.secondary_object_id,
    ae.payload,
    ae.route,
    ae.trace_id
  FROM audit_events ae
  LEFT JOIN users u ON u.id = ae.user_id
  LEFT JOIN organizations o ON o.id = ae.organization_id
  WHERE ae.created_at >= $1
    AND ae.organization_id = ANY($2::uuid[])
  ORDER BY ae.created_at ASC
```
</details>

20 event(s) captured:

| Time | Type | Action | User | Org | Object ID | Performed | Reason |
|------|------|--------|------|-----|-----------|-----------|--------|
| 2026-08-03 23:02:09Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — | — |  |
| 2026-08-03 23:02:19Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — | — |  |
| 2026-08-03 23:02:49Z | billing_order | status_change | blair.bennett@corvetasurgical.com | Vantis | 019fc9dd-93a6-7041-a007-6be6b642e70c | — |  |
| 2026-08-03 23:02:49Z | decision | bill_only.link_purchase_order | blair.bennett@corvetasurgical.com | Corveta Surgical Group | 019fc9dd-93a6-7041-a007-6be6b642e70c | no | no_purchase_order_selected |
| 2026-08-03 23:02:49Z | decision | bill_only_order.inventory_items_decrement | blair.bennett@corvetasurgical.com | Vantis | 019fc9dd-93a6-7041-a007-6be6b642e70c | yes | inventory_items_decremented |
| 2026-08-03 23:02:49Z | decision | bill_only_order.direct_po_import_on_create | blair.bennett@corvetasurgical.com | Vantis | 019fc9dd-93a6-7041-a007-6be6b642e70c | no | No uploaded PO documents |
| 2026-08-03 23:02:50Z | transactional_email | new_bill_only | — | Corveta Surgical Group | 019fc9dd-93a6-7041-a007-6be6b642e70c | — |  |
| 2026-08-03 23:02:55Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — | — |  |
| 2026-08-03 23:03:01Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — | — |  |
| 2026-08-03 23:03:31Z | decision | bill_only.link_purchase_order | blair.bennett@corvetasurgical.com | Corveta Surgical Group | 019fc9de-3688-7643-b07f-cf1cb081ad88 | no | no_purchase_order_selected |
| 2026-08-03 23:03:31Z | decision | bill_only_order.inventory_items_decrement | blair.bennett@corvetasurgical.com | Vantis | 019fc9de-3688-7643-b07f-cf1cb081ad88 | yes | inventory_items_decremented |
| 2026-08-03 23:03:31Z | decision | bill_only_order.direct_po_import_on_create | blair.bennett@corvetasurgical.com | Vantis | 019fc9de-3688-7643-b07f-cf1cb081ad88 | no | No uploaded PO documents |
| 2026-08-03 23:03:31Z | billing_order | status_change | blair.bennett@corvetasurgical.com | Vantis | 019fc9de-3688-7643-b07f-cf1cb081ad88 | — |  |
| 2026-08-03 23:03:33Z | transactional_email | new_bill_only | — | Corveta Surgical Group | 019fc9de-3688-7643-b07f-cf1cb081ad88 | — |  |
| 2026-08-03 23:03:39Z | user_log | user:login | blair.bennett@corvetasurgical.com | Corveta Surgical Group | — | — |  |
| 2026-08-03 23:04:07Z | decision | bill_only_order.direct_po_import_on_create | blair.bennett@corvetasurgical.com | Vantis | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | no | No uploaded PO documents |
| 2026-08-03 23:04:07Z | billing_order | status_change | blair.bennett@corvetasurgical.com | Vantis | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | — |  |
| 2026-08-03 23:04:07Z | decision | bill_only_order.inventory_items_decrement | blair.bennett@corvetasurgical.com | Vantis | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | yes | inventory_items_decremented |
| 2026-08-03 23:04:07Z | decision | bill_only.link_purchase_order | blair.bennett@corvetasurgical.com | Corveta Surgical Group | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | no | no_purchase_order_selected |
| 2026-08-03 23:04:08Z | transactional_email | new_bill_only | — | Corveta Surgical Group | 019fc9de-c3a3-790b-b8e9-2ca0e500b424 | — |  |

## Email Evidence

3 notification email(s) were captured during this test run. Each email is rendered as a screenshot for compliance review.

### 1. New Bill-Only Order - 8/3/2026 - Vantis BO-1

**Template:** `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1`

![New Bill-Only Order - 8/3/2026 - Vantis BO-1](screenshots/emails/2026-08-03T23-02-50-400Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1.png)

### 2. New Bill-Only Order - 8/3/2026 - Vantis BO-2

**Template:** `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-2`

![New Bill-Only Order - 8/3/2026 - Vantis BO-2](screenshots/emails/2026-08-03T23-03-33-584Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-2.png)

### 3. New Bill-Only Order - 8/3/2026 - Vantis BO-3

**Template:** `New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-3`

![New Bill-Only Order - 8/3/2026 - Vantis BO-3](screenshots/emails/2026-08-03T23-04-08-712Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-3.png)
