{
  "ursId": "URS-050",
  "title": "Select Another Rep's Trunk Stock for Bill-Only Orders",
  "timestamp": "2026-08-03T23:04:20.746Z",
  "durationMs": 69662,
  "config": {
    "inboxUrl": "http://localhost:37227",
    "dbHost": "localhost",
    "dbPort": 45725,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Login and own trunk",
      "status": "pass",
      "description": "Step 1: Login and own trunk",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-01-logged-in.png",
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-01-own-trunk-inventory.png"
      ],
      "explanation": "A sales rep logs in and navigates to their trunk stock. This establishes the baseline inventory context and confirms that a rep can view their own trunk before attempting to use another rep's trunk.",
      "startedAt": "2026-08-03T23:04:25.836Z",
      "finishedAt": "2026-08-03T23:04:29.004Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/videos/step-01-own-trunk.webm"
    },
    {
      "name": "Step 2: Bill-only form start",
      "status": "pass",
      "description": "Step 2: Bill-only form start",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-02-bill-only-form.png",
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-02-account-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-02-devices-step.png"
      ],
      "explanation": "The sales rep begins a new bill-only order by selecting the manufacturer and a sales account. This step navigates through the first two stages of the bill-only form to reach the inventory source selection screen.",
      "startedAt": "2026-08-03T23:04:43.938Z",
      "finishedAt": "2026-08-03T23:04:45.403Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/videos/step-02-bill-only-start.webm"
    },
    {
      "name": "Step 3: Other rep trunk selection",
      "status": "pass",
      "description": "Step 3: Other rep trunk selection",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-03-other-button-clicked.png",
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-03-rep-trunk-dropdown.png",
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-03-ryan-trunk-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-03-product-from-ryan.png",
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-03-review-other-rep-source.png",
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-03-order-submitted.png"
      ],
      "explanation": "The rep selects \"Other Rep Trunk\" as the inventory source and chooses a specific colleague's trunk from the dropdown. The order is completed and submitted, demonstrating that the system correctly allows a rep to draw from another rep's trunk stock when creating a bill-only order.",
      "expectedEmailTemplates": [
        "New Bill-Only Order"
      ],
      "expectedAuditActions": [
        "decision:bill_only_order.inventory_items_decrement"
      ],
      "startedAt": "2026-08-03T23:05:00.099Z",
      "finishedAt": "2026-08-03T23:05:20.830Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/videos/step-03-other-rep-trunk.webm"
    },
    {
      "name": "Step 4: Database verification",
      "status": "pass",
      "description": "Step 4: Database verification",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/step-04-billing-list.png"
      ],
      "explanation": "The billing list is opened to confirm the submitted order appears. This step provides screenshot evidence that the bill-only order is visible in the system after submission using another rep's trunk.",
      "startedAt": "2026-08-03T23:05:28.080Z",
      "finishedAt": "2026-08-03T23:05:28.080Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/videos/step-04-db-verification.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Bill-only order created by Blair",
      "query": "SELECT bo.id, bo.order_number, bo.status, bo.sales_account_id,\n        bo.created_at, bo.created_by_user_id\n      FROM billing_orders bo\n      WHERE bo.created_by_user_id = $1\n        AND bo.created_at > NOW() - INTERVAL '30 minutes'\n      ORDER BY bo.created_at DESC\n      LIMIT 5",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9df-d431-75d3-b678-4ae17a616fde",
          "order_number": "BO-1",
          "status": "submitted",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "created_at": "2026-08-03T23:05:17.024Z",
          "created_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456"
        }
      ],
      "assertion": "At least one billing order should have been created by Blair Bennett in the last 30 minutes"
    },
    {
      "name": "Order items reference other rep's trunk",
      "query": "SELECT boi.id, boi.billing_order_id, boi.location_id,\n        boi.lot_number, boi.product_id, op.title as product_name,\n        rwl.name as location_name, rwl.type as location_type\n      FROM billing_order_items boi\n      JOIN billing_orders bo ON boi.billing_order_id = bo.id\n      LEFT JOIN org_products op ON boi.product_id = op.id\n      LEFT JOIN real_world_locations rwl ON boi.location_id = rwl.id\n      WHERE bo.created_by_user_id = $1\n        AND bo.created_at > NOW() - INTERVAL '30 minutes'\n      ORDER BY bo.created_at DESC\n      LIMIT 10",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9df-d42d-79fd-8746-907d1906db65",
          "billing_order_id": "019fc9df-d431-75d3-b678-4ae17a616fde",
          "location_id": "b7f8a9b0-c1d2-3456-1234-567890123456",
          "lot_number": "URS050-SP-001",
          "product_id": "01989ca2-6a54-7834-8376-06a0251bacd8",
          "product_name": "NovaPatch® PET",
          "location_name": "TRUNK-26",
          "location_type": "trunk_stock"
        }
      ],
      "assertion": "At least one billing order item should have location_id = b7f8a9b0-c1d2-3456-1234-567890123456 (Rana's TRUNK-26)"
    },
    {
      "name": "Lot number matches test data",
      "query": "SELECT boi.lot_number, boi.location_id, rwl.name as location_name\n      FROM billing_order_items boi\n      JOIN billing_orders bo ON boi.billing_order_id = bo.id\n      LEFT JOIN real_world_locations rwl ON boi.location_id = rwl.id\n      WHERE bo.created_by_user_id = $1\n        AND bo.created_at > NOW() - INTERVAL '30 minutes'\n        AND boi.lot_number = $2\n      LIMIT 5",
      "status": "pass",
      "rows": [
        {
          "lot_number": "URS050-SP-001",
          "location_id": "b7f8a9b0-c1d2-3456-1234-567890123456",
          "location_name": "TRUNK-26"
        }
      ],
      "assertion": "Billing order item should have lot_number = URS050-SP-001"
    },
    {
      "name": "Order linked to correct sales account",
      "query": "SELECT bo.id, bo.sales_account_id, sa.name as account_name\n      FROM billing_orders bo\n      JOIN sales_accounts sa ON bo.sales_account_id = sa.id\n      WHERE bo.created_by_user_id = $1\n        AND bo.created_at > NOW() - INTERVAL '30 minutes'\n        AND bo.sales_account_id = $2\n      ORDER BY bo.created_at DESC\n      LIMIT 5",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9df-d431-75d3-b678-4ae17a616fde",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "account_name": "ROSS Surgical Account Request"
        }
      ],
      "assertion": "The billing order should be linked to ROSS Surgical Account"
    },
    {
      "name": "Inventory history records removal from other rep's trunk",
      "query": "SELECT ih.id, ih.item_id, ih.quantity, ih.status, ih.info,\n        ih.created_at, ii.lot, ii.real_world_location_id, rwl.name as location_name\n      FROM inventory_history ih\n      JOIN inventory_items ii ON ih.item_id = ii.id\n      LEFT JOIN real_world_locations rwl ON ii.real_world_location_id = rwl.id\n      WHERE ii.lot = $1\n        AND ii.organization_id = $2\n        AND ih.created_at > NOW() - INTERVAL '30 minutes'\n        AND ih.info->>'action' = 'removed'\n        AND ih.info->>'reason' = 'bill_only_order'\n      ORDER BY ih.created_at DESC\n      LIMIT 10",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9df-d443-7f83-80a1-42975f9e2408",
          "item_id": "fbcd85d6-d571-4857-86ed-0eb1ed7cd1fa",
          "quantity": 1,
          "status": "ready",
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "019fc9df-d431-75d3-b678-4ae17a616fde",
            "shortageQuantity": 0,
            "requestedQuantity": 1
          },
          "created_at": "2026-08-03T23:05:17.024Z",
          "lot": "URS050-SP-001",
          "real_world_location_id": "b7f8a9b0-c1d2-3456-1234-567890123456",
          "location_name": "TRUNK-26"
        }
      ],
      "assertion": "Inventory history should show a removal with reason=bill_only_order from TRUNK-26 (Rana)"
    },
    {
      "name": "Blair's own trunk was NOT decremented",
      "query": "SELECT ih.id, ih.item_id, ih.info, ih.created_at, ii.lot\n      FROM inventory_history ih\n      JOIN inventory_items ii ON ih.item_id = ii.id\n      WHERE ii.lot = $1\n        AND ii.organization_id = $2\n        AND ih.created_at > NOW() - INTERVAL '30 minutes'\n        AND ih.info->>'action' = 'removed'\n        AND ih.info->>'reason' = 'bill_only_order'\n      LIMIT 5",
      "status": "pass",
      "rows": [],
      "assertion": "Blair's trunk (TRUNK-36) should not have any bill_only_order removals for the test lot"
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z",
  "auditStartTime": "2026-08-03T23:04:18.867Z",
  "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-050-other-rep-trunk-stock/2026-08-03T23-04-20-745Z/screenshots/emails/2026-08-03T23-05-18-022Z-New_Bill-Only_Order_-_8_3_2026_-_Vantis_BO-1.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-08-03T23:04:19.361Z",
      "eventType": "checklist",
      "action": "checklists.create",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019fc9de-f2a3-7870-a862-af3c9b5f88bf",
      "secondaryObjectId": null,
      "payload": {
        "title": "Lot expiration review (1 location need attention)",
        "source": {
          "type": "lot_expiration",
          "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
        }
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:04:19.425Z",
      "eventType": "decision",
      "action": "ensure_lot_expiration_checklist",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "secondaryObjectId": null,
      "payload": {
        "reason": "created_1_reopened_0_already_open_1",
        "performed": true,
        "entityType": "organization"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:04:24.156Z",
      "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:04:32.025Z",
      "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:04:47.456Z",
      "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:05:17.024Z",
      "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": "019fc9df-d431-75d3-b678-4ae17a616fde",
      "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:05:17.024Z",
      "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": "019fc9df-d431-75d3-b678-4ae17a616fde",
      "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:05:17.024Z",
      "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": "019fc9df-d431-75d3-b678-4ae17a616fde",
      "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:05:17.024Z",
      "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": "019fc9df-d431-75d3-b678-4ae17a616fde",
      "secondaryObjectId": null,
      "payload": {
        "reason": null,
        "toStatus": "submitted",
        "fromStatus": null,
        "automatedAction": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:05:18.065Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019fc9df-d431-75d3-b678-4ae17a616fde",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/019fc9df-d7d2-7ee3-9596-6c2772a29ea5/",
        "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:05:23.031Z",
      "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 3: Other rep trunk selection",
      "expectedAction": "decision:bill_only_order.inventory_items_decrement",
      "found": true
    }
  ],
  "emailAssertions": [
    {
      "stepName": "Step 3: Other rep trunk selection",
      "expectedTemplate": "New Bill-Only Order",
      "found": true
    }
  ]
}