{
  "ursId": "URS-031",
  "title": "Record all transactions with timestamps and user IDs",
  "timestamp": "2026-09-29T02:30:47.546Z",
  "durationMs": 107296,
  "config": {
    "inboxUrl": "http://localhost:37077",
    "dbHost": "localhost",
    "dbPort": 37139,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Logged in as Blair Bennett",
      "status": "pass",
      "description": "Step 1: Logged in as Blair Bennett",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-01-logged-in.png"
      ],
      "explanation": "Authenticates as Blair Bennett (Corveta sales rep), establishing the user identity that will be recorded against subsequent transactions.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-09-29T02:30:55.092Z",
      "finishedAt": "2026-09-29T02:30:55.092Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/videos/step-01-login-bob.webm"
    },
    {
      "name": "Step 2: First order",
      "status": "pass",
      "description": "Step 2: First order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-02-account-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-02-devices-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-02-documents.png",
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-02-review.png",
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-02-order-submitted.png"
      ],
      "explanation": "Submits the first bill-only order as Blair Bennett. The system records the order in billing_orders with created_by_user_id and a server-side created_at timestamp.",
      "expectedEmailTemplates": [
        "New Bill-Only Order"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.inventory_items_decrement",
        "billing_order:status_change"
      ],
      "startedAt": "2026-09-29T02:31:07.969Z",
      "finishedAt": "2026-09-29T02:31:30.392Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/videos/step-02-first-order.webm"
    },
    {
      "name": "Step 3: Second order",
      "status": "pass",
      "description": "Step 3: Second order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-03-second-order-submitted.png"
      ],
      "explanation": "Submits a second bill-only order, demonstrating that each transaction is recorded independently with its own user ID and a distinct timestamp.",
      "expectedEmailTemplates": [
        "New Bill-Only Order"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.inventory_items_decrement",
        "billing_order:status_change"
      ],
      "startedAt": "2026-09-29T02:32:03.857Z",
      "finishedAt": "2026-09-29T02:32:03.857Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/videos/step-03-second-order.webm"
    },
    {
      "name": "Step 4: Billing list with recorded transactions",
      "status": "pass",
      "description": "Step 4: Billing list with recorded transactions",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-04-billing-list.png"
      ],
      "explanation": "Views the billing list as Blair, confirming that the Submitter and Created columns expose the recorded user and timestamp for each transaction in the UI.",
      "startedAt": "2026-09-29T02:32:11.343Z",
      "finishedAt": "2026-09-29T02:32:11.343Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/videos/step-04-billing-list.webm"
    },
    {
      "name": "Step 5: Returns list",
      "status": "pass",
      "description": "Step 5: Returns list",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-05-returns-list.png"
      ],
      "explanation": "Views the returns list, confirming that the Created By and Created columns expose user and timestamp attribution for return transactions.",
      "startedAt": "2026-09-29T02:32:18.693Z",
      "finishedAt": "2026-09-29T02:32:18.693Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/videos/step-05-returns-list.webm"
    },
    {
      "name": "Step 6: Cross-user billing view",
      "status": "pass",
      "description": "Step 6: Cross-user billing view",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-06-cross-user-billing.png"
      ],
      "explanation": "Logs in as Mark Manufacturer to verify that Blair's order transactions are visible to a different authorized user with the original user attribution intact.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-09-29T02:32:25.974Z",
      "finishedAt": "2026-09-29T02:32:25.974Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/videos/step-06-cross-user.webm"
    },
    {
      "name": "Step 6: Cross-user returns view",
      "status": "pass",
      "description": "Step 6: Cross-user returns view",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-06-cross-user-returns.png"
      ],
      "explanation": "As Mark Manufacturer, verifies that return transactions are also visible cross-user with Created By and Created columns showing the original submitter.",
      "startedAt": "2026-09-29T02:32:28.760Z",
      "finishedAt": "2026-09-29T02:32:28.760Z"
    },
    {
      "name": "Step 7: Combined transaction log",
      "status": "pass",
      "description": "Step 7: Combined transaction log",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/step-07-transaction-log.png"
      ],
      "explanation": "Renders a live query from billing_orders, inventory_transactions, audit_events, and returns tables, proving every recorded transaction has a user and timestamp.",
      "startedAt": "2026-09-29T02:32:31.862Z",
      "finishedAt": "2026-09-29T02:32:31.862Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/videos/step-07-transaction-log.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Bill-only orders recorded with user ID + timestamp",
      "query": "\n      SELECT id, order_number, status, created_by_user_id, created_at\n        FROM billing_orders\n       WHERE created_by_user_id = $1\n         AND created_at > NOW() - INTERVAL '30 minutes'\n       ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb00-b65f-75e7-a132-d7f361809099",
          "order_number": "BO-1",
          "status": "submitted",
          "created_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
          "order_number": "BO-2",
          "status": "submitted",
          "created_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "created_at": "2026-09-29T02:32:01.379Z"
        }
      ],
      "assertion": "At least two billing_orders created by Blair in the test window, each with created_by_user_id and created_at populated"
    },
    {
      "name": "Inventory transactions recorded with timestamp",
      "query": "\n      SELECT id, source_type, source_id, created_at,\n             distributor_organization_id, manufacturer_organization_id\n        FROM inventory_transactions\n       WHERE source_type = 'bill_only_order'\n         AND created_at > NOW() - INTERVAL '30 minutes'\n         AND (distributor_organization_id = $1 OR manufacturer_organization_id = $1)\n       ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb00-b66f-76f5-ac1f-3294e85410ea",
          "source_type": "bill_only_order",
          "source_id": "01a0eb00-b65f-75e7-a132-d7f361809099",
          "created_at": "2026-09-29T02:31:27.240Z",
          "distributor_organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "manufacturer_organization_id": null
        },
        {
          "id": "01a0eb01-3aa9-74ef-b451-62b78b735e54",
          "source_type": "bill_only_order",
          "source_id": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
          "created_at": "2026-09-29T02:32:01.379Z",
          "distributor_organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "manufacturer_organization_id": null
        }
      ],
      "assertion": "inventory_transactions rows exist for the bill-only orders, each with a non-null created_at"
    },
    {
      "name": "Inventory history records each change with a timestamp",
      "query": "\n      SELECT ih.id, ih.item_id, ih.quantity, ih.info, ih.created_at\n        FROM inventory_history ih\n       WHERE ih.created_at > NOW() - INTERVAL '30 minutes'\n         AND ih.info->>'reason' = 'bill_only_order'\n       ORDER BY ih.created_at ASC\n       LIMIT 20",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb00-b684-75a7-8c7a-ce9e97e853cd",
          "item_id": "2cc1ac87-b8a3-49b0-9224-e39f6fbdf3f5",
          "quantity": 2,
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eb00-b65f-75e7-a132-d7f361809099",
            "shortageQuantity": 0,
            "requestedQuantity": 2
          },
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b684-75a7-8c7a-ce9feff0471e",
          "item_id": "d8d3261f-e222-4f23-bd6c-ac6f3682363b",
          "quantity": 3,
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eb00-b65f-75e7-a132-d7f361809099",
            "shortageQuantity": 0,
            "requestedQuantity": 3
          },
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb01-3aae-730e-94ca-31cbd51e36de",
          "item_id": "2cc1ac87-b8a3-49b0-9224-e39f6fbdf3f5",
          "quantity": 1,
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
            "shortageQuantity": 0,
            "requestedQuantity": 1
          },
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3aae-730e-94ca-31cca8307548",
          "item_id": "d8d3261f-e222-4f23-bd6c-ac6f3682363b",
          "quantity": 1,
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
            "shortageQuantity": 0,
            "requestedQuantity": 1
          },
          "created_at": "2026-09-29T02:32:01.379Z"
        }
      ],
      "assertion": "inventory_history contains bill_only_order rows in the test window, each with created_at populated"
    },
    {
      "name": "Audit events recorded with user ID + timestamp",
      "query": "\n      SELECT id, organization_id, user_id, event_type, action,\n             object_id, created_at\n        FROM audit_events\n       WHERE created_at > NOW() - INTERVAL '30 minutes'\n         AND organization_id IN ($1, $2)\n       ORDER BY created_at ASC\n       LIMIT 50",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eaff-dad7-744a-b3ef-01b0d6fd2975",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": null,
          "event_type": "decision",
          "action": "return_overdue_sweep",
          "object_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "created_at": "2026-09-29T02:30:31.383Z"
        },
        {
          "id": "01a0eaff-dba4-736c-80f1-0924770b8e94",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": null,
          "event_type": "decision",
          "action": "ensure_lot_expiration_cycle_counter_assignment",
          "object_id": "a6e7f8a9-b0c1-2345-0123-456789012345",
          "created_at": "2026-09-29T02:30:31.589Z"
        },
        {
          "id": "01a0eaff-dbd1-7c9e-98d5-0ee4bce51a76",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": null,
          "event_type": "decision",
          "action": "ensure_lot_expiration_cycle_counter_assignment",
          "object_id": "b7f8a9b0-c1d2-3456-1234-567890123456",
          "created_at": "2026-09-29T02:30:31.647Z"
        },
        {
          "id": "01a0eaff-dc6d-7167-87b1-e578dd2b2d93",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": null,
          "event_type": "checklist",
          "action": "checklists.create",
          "object_id": "01a0eaff-dc0f-7e8a-98b4-12fca27f5802",
          "created_at": "2026-09-29T02:30:31.694Z"
        },
        {
          "id": "01a0eaff-de99-7ee7-b7df-48c31471e26a",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": null,
          "event_type": "decision",
          "action": "upgrade_lot_expiration_checklist_priority",
          "object_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "created_at": "2026-09-29T02:30:32.362Z"
        },
        {
          "id": "01a0eaff-df5d-7a56-850c-b66b7410ea3f",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": null,
          "event_type": "decision",
          "action": "ensure_lot_expiration_checklist",
          "object_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "created_at": "2026-09-29T02:30:32.549Z"
        },
        {
          "id": "01a0eb00-2f30-78b1-a147-881747c2cfcd",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "user_log",
          "action": "user:login",
          "object_id": null,
          "created_at": "2026-09-29T02:30:53.046Z"
        },
        {
          "id": "01a0eb00-408f-7b44-ba25-29b7bd5e2203",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "user_log",
          "action": "user:login",
          "object_id": null,
          "created_at": "2026-09-29T02:30:57.460Z"
        },
        {
          "id": "01a0eb00-7149-71b7-89f3-d4c1b5a2e220",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only_order.duplicate_submission_block",
          "object_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "created_at": "2026-09-29T02:31:09.658Z"
        },
        {
          "id": "01a0eb00-b54b-7e87-a49c-d40cab34977a",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only_order.duplicate_submission_block",
          "object_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b601-75a5-9e9a-a3b92b5f5a4b",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "representatives.gate_rep_action",
          "object_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b657-77c2-a4d7-bce8a391c1df",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "representatives.gate_rep_action",
          "object_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b666-7d8b-88fc-99ddd4722fc1",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only_order.inventory_items_decrement",
          "object_id": "01a0eb00-b65f-75e7-a132-d7f361809099",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b698-74a0-97da-b8ce4138994a",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only_order.direct_po_import_on_create",
          "object_id": "01a0eb00-b65f-75e7-a132-d7f361809099",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b6a1-7ce8-a60d-a91b21a9f2cf",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "billing_order",
          "action": "status_change",
          "object_id": "01a0eb00-b65f-75e7-a132-d7f361809099",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b6ae-709e-a290-74b7737e898d",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "basicErp.deriveSalesOrder",
          "object_id": "01a0eb00-b65f-75e7-a132-d7f361809099",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b6bc-757d-9608-05aae6ab9fd3",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "scheduled_task",
          "action": "scheduled_task.scheduled",
          "object_id": "01a0eb00-b6b6-7f70-9fb5-780d94a6b04f",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b6c5-79fe-98de-1f3f3baa35f5",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "scheduled_task",
          "action": "scheduled_task.scheduled",
          "object_id": "01a0eb00-b6c3-7c5a-8d6a-cedbd19b38ad",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b6d2-7bfd-aa73-3730d451d4a8",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "scheduled_task",
          "action": "scheduled_task.scheduled",
          "object_id": "01a0eb00-b6cc-7b50-915e-c5ba342b0df1",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-b6d8-721c-a455-c602332c42d0",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only.link_purchase_order",
          "object_id": "01a0eb00-b65f-75e7-a132-d7f361809099",
          "created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "id": "01a0eb00-bd61-7c5e-9df0-bfd978684962",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": null,
          "event_type": "decision",
          "action": "bill_only.notifications.cc_incident_recipients",
          "object_id": "01a0eb00-b65f-75e7-a132-d7f361809099",
          "created_at": "2026-09-29T02:31:29.378Z"
        },
        {
          "id": "01a0eb00-bf55-7663-b9c1-94eb6ae2874b",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": null,
          "event_type": "transactional_email",
          "action": "new_bill_only",
          "object_id": "01a0eb00-b65f-75e7-a132-d7f361809099",
          "created_at": "2026-09-29T02:31:29.923Z"
        },
        {
          "id": "01a0eb00-d0bb-7fbd-a8ec-e5bbdbe9019b",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "user_log",
          "action": "user:login",
          "object_id": null,
          "created_at": "2026-09-29T02:31:34.367Z"
        },
        {
          "id": "01a0eb00-fe54-7fb1-9548-7ae19f5bdaf7",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only_order.duplicate_submission_block",
          "object_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "created_at": "2026-09-29T02:31:45.986Z"
        },
        {
          "id": "01a0eb01-3a6c-7045-8f84-e054646bd3a6",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only_order.duplicate_submission_block",
          "object_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3a85-78c6-8bcd-4361d8ce448a",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "representatives.gate_rep_action",
          "object_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3a9c-71a7-9484-b249692aca32",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "representatives.gate_rep_action",
          "object_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3aa4-78c9-b52d-f4e834e3a9e3",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only_order.inventory_items_decrement",
          "object_id": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3ab3-7113-a1c8-8487f4a4f59c",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only_order.direct_po_import_on_create",
          "object_id": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3ab6-76f0-82f8-9f6267391293",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "billing_order",
          "action": "status_change",
          "object_id": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3ab9-7579-b3fe-bb5e2495ff14",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "basicErp.deriveSalesOrder",
          "object_id": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3abf-7a0e-9b74-495a69f995e9",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "scheduled_task",
          "action": "scheduled_task.scheduled",
          "object_id": "01a0eb01-3abe-7ccb-98de-c2355e1b35a3",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3ac4-702f-bbc0-40d066859c33",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "scheduled_task",
          "action": "scheduled_task.scheduled",
          "object_id": "01a0eb01-3ac2-7a85-9e81-3237861c1be4",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3ac8-7add-a5e9-481f16cb226d",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "scheduled_task",
          "action": "scheduled_task.scheduled",
          "object_id": "01a0eb01-3ac6-7ebf-b546-f3436391ce6a",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3acb-7708-ad14-add5d90f615e",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "decision",
          "action": "bill_only.link_purchase_order",
          "object_id": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
          "created_at": "2026-09-29T02:32:01.379Z"
        },
        {
          "id": "01a0eb01-3f51-7a4e-9aa0-f8d7d29fbfbb",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": null,
          "event_type": "decision",
          "action": "bill_only.notifications.cc_incident_recipients",
          "object_id": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
          "created_at": "2026-09-29T02:32:02.642Z"
        },
        {
          "id": "01a0eb01-413c-7f71-9443-e81a76443f3b",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": null,
          "event_type": "transactional_email",
          "action": "new_bill_only",
          "object_id": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
          "created_at": "2026-09-29T02:32:03.148Z"
        },
        {
          "id": "01a0eb01-4feb-717a-b0a3-f7f8467970c0",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "user_log",
          "action": "user:login",
          "object_id": null,
          "created_at": "2026-09-29T02:32:06.898Z"
        },
        {
          "id": "01a0eb01-6cc3-731d-a4b6-3020fee17f66",
          "organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "event_type": "user_log",
          "action": "user:login",
          "object_id": null,
          "created_at": "2026-09-29T02:32:14.285Z"
        },
        {
          "id": "01a0eb01-8982-77f1-a1d9-579fbbf7e5db",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "user_id": "d4e5f6a7-b8c9-0123-def1-234567890123",
          "event_type": "user_log",
          "action": "user:login",
          "object_id": null,
          "created_at": "2026-09-29T02:32:21.640Z"
        }
      ],
      "assertion": "At least one audit_events row in the test window has both user_id and created_at populated, and no row is missing created_at"
    },
    {
      "name": "Returns have created_by_user_id + created_at populated",
      "query": "\n      SELECT r.id, r.return_number, r.status, r.created_by_user_id,\n             r.created_at, u.email AS created_by_email\n        FROM returns r\n        LEFT JOIN users u ON u.id = r.created_by_user_id\n       WHERE r.return_number = ANY($1)\n          OR r.created_at > NOW() - INTERVAL '30 minutes'\n       ORDER BY r.created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "ca000003-0000-4000-8000-000000000003",
          "return_number": "VRI-RET-2025-003",
          "status": "submitted",
          "created_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "created_at": "2026-08-30T02:23:23.225Z",
          "created_by_email": "blair.bennett@corvetasurgical.com"
        },
        {
          "id": "ca000002-0000-4000-8000-000000000002",
          "return_number": "VRI-RET-2025-002",
          "status": "submitted",
          "created_by_user_id": "28c9d0e1-f2a3-4567-2345-678901234567",
          "created_at": "2026-09-15T02:23:23.225Z",
          "created_by_email": "rana.reyes@corvetasurgical.com"
        },
        {
          "id": "ca000001-0000-4000-8000-000000000001",
          "return_number": "VRI-RET-2025-001",
          "status": "submitted",
          "created_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456",
          "created_at": "2026-09-26T02:23:23.225Z",
          "created_by_email": "blair.bennett@corvetasurgical.com"
        }
      ],
      "assertion": "All pre-seeded returns (and any created during the test) have non-null created_by_user_id and created_at"
    },
    {
      "name": "Inventory transactions timestamped at or after their triggering order",
      "query": "\n      SELECT bo.order_number,\n             bo.created_at             AS order_created_at,\n             MIN(it.created_at)        AS first_txn_created_at\n        FROM billing_orders bo\n        JOIN inventory_transactions it\n          ON it.source_type = 'bill_only_order'\n         AND it.source_id = bo.id\n       WHERE bo.created_by_user_id = $1\n         AND bo.created_at > NOW() - INTERVAL '30 minutes'\n       GROUP BY bo.id, bo.order_number, bo.created_at",
      "status": "pass",
      "rows": [
        {
          "order_number": "BO-1",
          "order_created_at": "2026-09-29T02:31:27.240Z",
          "first_txn_created_at": "2026-09-29T02:31:27.240Z"
        },
        {
          "order_number": "BO-2",
          "order_created_at": "2026-09-29T02:32:01.379Z",
          "first_txn_created_at": "2026-09-29T02:32:01.379Z"
        }
      ],
      "assertion": "For every bill-only order in the test window, the earliest inventory_transaction linked to it has created_at >= billing_order.created_at"
    },
    {
      "name": "Multiple distinct users represented across transactions",
      "query": "\n      SELECT DISTINCT user_id FROM (\n        SELECT created_by_user_id AS user_id FROM billing_orders\n         WHERE created_at > NOW() - INTERVAL '30 minutes'\n           AND created_by_user_id IS NOT NULL\n        UNION\n        SELECT created_by_user_id AS user_id FROM returns\n         WHERE return_number = ANY($1)\n        UNION\n        SELECT user_id FROM audit_events\n         WHERE created_at > NOW() - INTERVAL '30 minutes'\n           AND user_id IS NOT NULL\n      ) u\n       ORDER BY user_id",
      "status": "pass",
      "rows": [
        {
          "user_id": "17b8c9d0-e1f2-3456-1234-567890123456"
        },
        {
          "user_id": "28c9d0e1-f2a3-4567-2345-678901234567"
        },
        {
          "user_id": "d4e5f6a7-b8c9-0123-def1-234567890123"
        }
      ],
      "assertion": "The combined transaction set (orders, returns, audit events) contains at least two distinct user IDs"
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z",
  "auditStartTime": "2026-09-29T02:30:46.444Z",
  "emailEvidence": [
    {
      "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-1",
      "template": "New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-1",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/emails/2026-09-29T02-31-29-846Z-New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-1.png"
    },
    {
      "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-2",
      "template": "New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-2",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-031-record-transactions-timestamps-userids/2026-09-29T02-30-47-314Z/screenshots/emails/2026-09-29T02-32-03-122Z-New_Bill-Only_Order_-_9_29_2026_-_Vantis_BO-2.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-09-29T02:30:53.046Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:30:57.460Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:31:09.658Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "surgery",
        "reason": "no_same_day_candidates",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 0,
        "flaggedCount": 0,
        "candidateCount": 0,
        "matchedSignals": {
          "patientId": false,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "review",
        "reason": "no_same_day_candidates",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 0,
        "flaggedCount": 0,
        "candidateCount": 0,
        "matchedSignals": {
          "patientId": false,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "decision",
      "action": "bill_only.link_purchase_order",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb00-b65f-75e7-a132-d7f361809099",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_purchase_order_selected",
        "performed": false,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "decision",
      "action": "basicErp.deriveSalesOrder",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-b65f-75e7-a132-d7f361809099",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-b6c3-7c5a-8d6a-cedbd19b38ad",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb00-b65f-75e7-a132-d7f361809099",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-13T02:31:27.667Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-b6cc-7b50-915e-c5ba342b0df1",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb00-b65f-75e7-a132-d7f361809099",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-20T02:31:27.667Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "decision",
      "action": "bill_only_order.inventory_items_decrement",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-b65f-75e7-a132-d7f361809099",
      "secondaryObjectId": null,
      "payload": {
        "reason": "inventory_items_decremented",
        "itemCount": 5,
        "performed": true,
        "entityType": "billing_order",
        "hasCaseToteItems": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "decision",
      "action": "bill_only_order.direct_po_import_on_create",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-b65f-75e7-a132-d7f361809099",
      "secondaryObjectId": null,
      "payload": {
        "reason": "No uploaded PO documents",
        "performed": false,
        "entityType": "billing_order",
        "fileSourceOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "hasSelectedPurchaseOrderId": false,
        "purchaseOrderDocumentCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "billing_order",
      "action": "status_change",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-b65f-75e7-a132-d7f361809099",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-b6b6-7f70-9fb5-780d94a6b04f",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb00-b65f-75e7-a132-d7f361809099",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-06T02:31:27.667Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:27.240Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:29.378Z",
      "eventType": "decision",
      "action": "bill_only.notifications.cc_incident_recipients",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-b65f-75e7-a132-d7f361809099",
      "secondaryObjectId": null,
      "payload": {
        "reason": "order has no no-charge item with an incident reason",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:29.923Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb00-b65f-75e7-a132-d7f361809099",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eb00-bf55-7663-b9c1-94eb6ae2874b/",
        "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-1",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:34.367Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:31:45.986Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "surgery",
        "reason": "all_candidates_vetoed",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 1,
        "flaggedCount": 0,
        "candidateCount": 1,
        "matchedSignals": {
          "patientId": false,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3ac2-7a85-9e81-3237861c1be4",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-13T02:32:01.469Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "decision",
      "action": "bill_only_order.duplicate_submission_block",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "fea7b8c9-d0e1-2345-0123-456789012345",
      "secondaryObjectId": null,
      "payload": {
        "step": "review",
        "reason": "all_candidates_vetoed",
        "performed": false,
        "entityType": "sales_account",
        "vetoedCount": 1,
        "flaggedCount": 0,
        "candidateCount": 1,
        "matchedSignals": {
          "patientId": false,
          "surgeonName": false,
          "patientLastName": false
        },
        "unmatchedCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "decision",
      "action": "bill_only.link_purchase_order",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_purchase_order_selected",
        "performed": false,
        "entityType": "billing_order",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": null,
        "performed": false,
        "entityType": "organization",
        "gatedAction": "bill_only",
        "isOwnTrunkDestination": null,
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "decision",
      "action": "bill_only_order.inventory_items_decrement",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
      "secondaryObjectId": null,
      "payload": {
        "reason": "inventory_items_decremented",
        "itemCount": 2,
        "performed": true,
        "entityType": "billing_order",
        "hasCaseToteItems": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "decision",
      "action": "bill_only_order.direct_po_import_on_create",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
      "secondaryObjectId": null,
      "payload": {
        "reason": "No uploaded PO documents",
        "performed": false,
        "entityType": "billing_order",
        "fileSourceOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "hasSelectedPurchaseOrderId": false,
        "purchaseOrderDocumentCount": 0
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "billing_order",
      "action": "status_change",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "decision",
      "action": "basicErp.deriveSalesOrder",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3abe-7ccb-98de-c2355e1b35a3",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-06T02:32:01.469Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:01.379Z",
      "eventType": "scheduled_task",
      "action": "scheduled_task.scheduled",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3ac6-7ebf-b546-f3436391ce6a",
      "secondaryObjectId": null,
      "payload": {
        "entityId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
        "revision": 0,
        "taskKind": "bill_only_po_missing_followup",
        "entityType": "billing_order",
        "scheduledAt": "2026-10-20T02:32:01.469Z"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:02.642Z",
      "eventType": "decision",
      "action": "bill_only.notifications.cc_incident_recipients",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
      "secondaryObjectId": null,
      "payload": {
        "reason": "order has no no-charge item with an incident reason",
        "performed": false,
        "entityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:03.148Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "01a0eb01-3aa1-7080-a70b-3e8175be48aa",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/01a0eb01-413c-7f71-9443-e81a76443f3b/",
        "subject": "New Bill-Only Order - 9/29/2026 - Vantis BO-2",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:06.898Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:32:14.285Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:32:21.640Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "mark.manufacturer@vantismedical.com",
      "userId": "d4e5f6a7-b8c9-0123-def1-234567890123",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "mark.manufacturer@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    }
  ],
  "auditQuery": "SELECT\n    ae.created_at,\n    ae.event_type,\n    ae.action,\n    ae.user_id,\n    u.email AS user_email,\n    ae.organization_id,\n    o.name AS organization_name,\n    ae.object_id,\n    ae.secondary_object_id,\n    ae.payload,\n    ae.route,\n    ae.trace_id\n  FROM audit_events ae\n  LEFT JOIN users u ON u.id = ae.user_id\n  LEFT JOIN organizations o ON o.id = ae.organization_id\n  WHERE ae.created_at >= $1\n    AND ae.organization_id = ANY($2::uuid[])\n  ORDER BY ae.created_at ASC",
  "auditAssertions": [
    {
      "stepName": "Step 1: Logged in as Blair Bennett",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 2: First order",
      "expectedAction": "decision:bill_only_order.inventory_items_decrement",
      "found": true
    },
    {
      "stepName": "Step 2: First order",
      "expectedAction": "billing_order:status_change",
      "found": true
    },
    {
      "stepName": "Step 3: Second order",
      "expectedAction": "decision:bill_only_order.inventory_items_decrement",
      "found": true
    },
    {
      "stepName": "Step 3: Second order",
      "expectedAction": "billing_order:status_change",
      "found": true
    },
    {
      "stepName": "Step 6: Cross-user billing view",
      "expectedAction": "user_log:user:login",
      "found": true
    }
  ],
  "emailAssertions": [
    {
      "stepName": "Step 2: First order",
      "expectedTemplate": "New Bill-Only Order",
      "found": true
    },
    {
      "stepName": "Step 3: Second order",
      "expectedTemplate": "New Bill-Only Order",
      "found": true
    }
  ]
}