{
  "ursId": "URS-019",
  "title": "Bill-Only without PO for Approved Accounts",
  "timestamp": "2026-08-03T23:02:04.137Z",
  "durationMs": 103438,
  "config": {
    "inboxUrl": "http://localhost:36893",
    "dbHost": "localhost",
    "dbPort": 46683,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Login",
      "status": "pass",
      "description": "Step 1: Login",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-01-logged-in.png"
      ],
      "explanation": "Proves that Blair Bennett (Corveta Sales Rep) can authenticate and reach the application. Establishes the user context for all subsequent steps.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-08-03T23:02:15.313Z",
      "finishedAt": "2026-08-03T23:02:15.313Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/videos/step-01-login.webm"
    },
    {
      "name": "Step 2: Billing form",
      "status": "pass",
      "description": "Step 2: Billing form",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-02-account-selection-page.png"
      ],
      "explanation": "Confirms Blair can navigate to the new bill-only order creation form and reach the account selection step (Step 2). Verifies the billing feature is accessible to the sales rep role.",
      "startedAt": "2026-08-03T23:02:23.346Z",
      "finishedAt": "2026-08-03T23:02:23.346Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/videos/step-02-billing-form.webm"
    },
    {
      "name": "Step 3: Unapproved account hidden",
      "status": "pass",
      "description": "Step 3: Unapproved account hidden",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-03-account-dropdown-open.png",
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-03-search-cedar-no-results.png",
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-03-search-ross-found.png"
      ],
      "explanation": "The system enforces the approval gate at the UI level: the account selector only shows accounts with status=\"active\" (approved by Vantis). Cedar Crest Hospital Account Request, which is set to status=\"proposed\" (unapproved) by the test setup, does not appear as a selectable option. ROSS Surgical Account Request (active/approved) is visible, confirming the selector works correctly. This is the negative test — it proves the approval gate is enforced.",
      "startedAt": "2026-08-03T23:02:31.865Z",
      "finishedAt": "2026-08-03T23:02:36.432Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/videos/step-03-unapproved-account.webm"
    },
    {
      "name": "Step 4: Create order",
      "status": "pass",
      "description": "Step 4: Create order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-04-ross-account-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-04-devices-step.png",
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-04-products-added.png",
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-04-no-po-entered.png",
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-04-review-before-submit.png",
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-04-order-submitted.png"
      ],
      "explanation": "An approved account (ROSS Surgical Account Request, status=\"active\") can successfully complete the full bill-only order submission flow — including leaving the PO field empty. The order is accepted and a BO-XXXX order number is assigned. This is the positive test proving that approved accounts can submit Bill-Only without PO.",
      "expectedEmailTemplates": [
        "bill-only"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.inventory_items_decrement",
        "billing_order:status_change"
      ],
      "startedAt": "2026-08-03T23:02:47.507Z",
      "finishedAt": "2026-08-03T23:03:04.544Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/videos/step-04-create-order.webm"
    },
    {
      "name": "Step 5: Verify order",
      "status": "pass",
      "description": "Step 5: Verify order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-05-billing-list.png",
        "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/step-05-new-order-found.png"
      ],
      "explanation": "The newly created bill-only order appears on the billing list, confirming it was persisted correctly. The specific order number captured in Step 4 is visible, providing end-to-end traceability from form submission to database record.",
      "startedAt": "2026-08-03T23:03:45.192Z",
      "finishedAt": "2026-08-03T23:03:45.254Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/videos/step-05-verify-order.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Approved account has active status",
      "query": "SELECT id, name, status FROM sales_accounts WHERE id = ANY($1) ORDER BY name",
      "status": "pass",
      "rows": [
        {
          "id": "1fb8c9d0-e1f2-3456-1234-567890123456",
          "name": "Cedar Crest Hospital Account Request",
          "status": "proposed"
        },
        {
          "id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "name": "ROSS Surgical Account Request",
          "status": "active"
        }
      ],
      "assertion": "ROSS Hospital should have status='active' (approved)"
    },
    {
      "name": "Unapproved account has proposed status",
      "query": "SELECT id, name, status FROM sales_accounts WHERE id = ANY($1) ORDER BY name",
      "status": "pass",
      "rows": [
        {
          "id": "1fb8c9d0-e1f2-3456-1234-567890123456",
          "name": "Cedar Crest Hospital Account Request",
          "status": "proposed"
        },
        {
          "id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "name": "ROSS Surgical Account Request",
          "status": "active"
        }
      ],
      "assertion": "Cedar Healthcare should have status='proposed' (unapproved)"
    },
    {
      "name": "New billing order BO-1 exists for approved account",
      "query": "SELECT id, order_number, status, sales_account_id, created_at\n        FROM billing_orders\n        WHERE sales_account_id = 'fea7b8c9-d0e1-2345-0123-456789012345' AND order_number = 'BO-1'",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9dd-ccbb-73e1-ab4e-eeccb1ca1189",
          "order_number": "BO-1",
          "status": "submitted",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "created_at": "2026-08-03T23:03:04.063Z"
        }
      ],
      "assertion": "Order BO-1 should exist for ROSS Hospital (approved account)"
    },
    {
      "name": "No new billing orders for unapproved account",
      "query": "SELECT id, order_number, status, created_at\n      FROM billing_orders\n      WHERE sales_account_id = '1fb8c9d0-e1f2-3456-1234-567890123456' AND created_at > NOW() - INTERVAL '10 minutes'\n      ORDER BY created_at DESC",
      "status": "pass",
      "rows": [],
      "assertion": "No billing orders should have been created for Cedar Healthcare (unapproved account) during the test"
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z",
  "auditStartTime": "2026-08-03T23:02:02.288Z",
  "emailEvidence": [
    {
      "subject": "New Bill-Only Order - 8/3/2026 - Vantis BO-1",
      "template": "New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-019-bill-only-without-po/2026-08-03T23-02-04-137Z/screenshots/emails/2026-08-03T23-03-06-066Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-08-03T23:02:13.219Z",
      "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-08-03T23:02:19.368Z",
      "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-08-03T23:02:27.577Z",
      "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-08-03T23:02:40.296Z",
      "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-08-03T23:03:04.063Z",
      "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": "019fc9dd-ccbb-73e1-ab4e-eeccb1ca1189",
      "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-08-03T23:03:04.063Z",
      "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": "019fc9dd-ccbb-73e1-ab4e-eeccb1ca1189",
      "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-08-03T23:03:04.063Z",
      "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": "019fc9dd-ccbb-73e1-ab4e-eeccb1ca1189",
      "secondaryObjectId": null,
      "payload": {
        "reason": "inventory_items_decremented",
        "itemCount": 1,
        "performed": true,
        "entityType": "billing_order",
        "inventorySource": "inventory_items"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:03:04.063Z",
      "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": "019fc9dd-ccbb-73e1-ab4e-eeccb1ca1189",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:03:06.104Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019fc9dd-ccbb-73e1-ab4e-eeccb1ca1189",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/019fc9dd-d45c-7e57-9af9-c7aeacb48d03/",
        "subject": "New Bill-Only Order - 8/3/2026 - Vantis BO-1",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:03:39.085Z",
      "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"
    }
  ],
  "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: Login",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 4: Create order",
      "expectedAction": "decision:bill_only_order.inventory_items_decrement",
      "found": true
    },
    {
      "stepName": "Step 4: Create order",
      "expectedAction": "billing_order:status_change",
      "found": true
    }
  ],
  "emailAssertions": [
    {
      "stepName": "Step 4: Create order",
      "expectedTemplate": "bill-only",
      "found": true
    }
  ]
}