{
  "ursId": "URS-050",
  "title": "Select Another Rep's Trunk Stock for Bill-Only Orders",
  "timestamp": "2026-04-23T03:43:21.310Z",
  "durationMs": 71606,
  "config": {
    "inboxUrl": "http://localhost:64931",
    "dbHost": "localhost",
    "dbPort": 64932,
    "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": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/screenshots/step-01-logged-in.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/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-04-23T03:43:26.097Z",
      "finishedAt": "2026-04-23T03:43:29.464Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/videos/step-01-own-trunk.webm"
    },
    {
      "name": "Step 2: Bill-only form start",
      "status": "pass",
      "description": "Step 2: Bill-only form start",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/screenshots/step-02-bill-only-form.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/screenshots/step-02-account-selected.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/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-04-23T03:43:44.442Z",
      "finishedAt": "2026-04-23T03:43:46.306Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/videos/step-02-bill-only-start.webm"
    },
    {
      "name": "Step 3: Other rep trunk selection",
      "status": "pass",
      "description": "Step 3: Other rep trunk selection",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/screenshots/step-03-other-button-clicked.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/screenshots/step-03-rep-trunk-dropdown.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/screenshots/step-03-ryan-trunk-selected.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/screenshots/step-03-product-from-ryan.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/screenshots/step-03-review-other-rep-source.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/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.enqueue_upload_classification"
      ],
      "startedAt": "2026-04-23T03:43:59.897Z",
      "finishedAt": "2026-04-23T03:44:23.150Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/videos/step-03-other-rep-trunk.webm"
    },
    {
      "name": "Step 4: Database verification",
      "status": "pass",
      "description": "Step 4: Database verification",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/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-04-23T03:44:29.619Z",
      "finishedAt": "2026-04-23T03:44:29.619Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/videos/step-04-db-verification.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Bill-only order created by Bob",
      "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": "019db870-44f4-7496-a32e-e56d5f34dad2",
          "order_number": "BO-1",
          "status": "submitted",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "created_at": "2026-04-23T03:44:18.654Z",
          "created_by_user_id": "17b8c9d0-e1f2-3456-1234-567890123456"
        }
      ],
      "assertion": "At least one billing order should have been created by Bob Kauffman 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": "019db870-44f2-7c67-ade0-33faa1e7b3d4",
          "billing_order_id": "019db870-44f4-7496-a32e-e56d5f34dad2",
          "location_id": "b7f8a9b0-c1d2-3456-1234-567890123456",
          "lot_number": "URS050-SP-001",
          "product_id": "01989ca1-f2f8-7ab7-8269-7179342797cc",
          "product_name": "FiberLocker® Instrument SN",
          "location_name": "TRUNK-26",
          "location_type": "trunk_stock"
        }
      ],
      "assertion": "At least one billing order item should have location_id = b7f8a9b0-c1d2-3456-1234-567890123456 (Ryan'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": "019db870-44f4-7496-a32e-e56d5f34dad2",
          "sales_account_id": "fea7b8c9-d0e1-2345-0123-456789012345",
          "account_name": "BOSS Surgical Account Request"
        }
      ],
      "assertion": "The billing order should be linked to BOSS 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": "019db870-44fb-7db8-9438-86f6fc04fa09",
          "item_id": "019db870-44fb-7db8-9438-86f55bc9d50b",
          "quantity": 1,
          "status": "ready",
          "info": {
            "action": "removed",
            "reason": "bill_only_order",
            "bestEffort": true,
            "billingOrderId": "019db870-44f4-7496-a32e-e56d5f34dad2",
            "shortageQuantity": 1,
            "requestedQuantity": 1
          },
          "created_at": "2026-04-23T03:44:18.654Z",
          "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 (Ryan)"
    },
    {
      "name": "Bob'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": "Bob's trunk (TRUNK-36) should not have any bill_only_order removals for the test lot"
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z",
  "auditStartTime": "2026-04-23T03:43:19.403Z",
  "emailEvidence": [
    {
      "subject": "New Bill-Only Order - 4/22/2026 - ZuriMED BO-1",
      "template": "New_Bill-Only_Order_-_4_22_2026_-_ZuriMED_BO-1",
      "screenshotPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-050-other-rep-trunk-stock/2026-04-23T03-43-21-308Z/screenshots/emails/2026-04-23T03-44-19-116Z-New_Bill-Only_Order_-_4_22_2026_-_ZuriMED_BO-1.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-04-23T03:43:23.483Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:43:32.892Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:43:47.513Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:44:18.654Z",
      "eventType": "decision",
      "action": "bill_only_order.enqueue_upload_classification",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019db870-44f4-7496-a32e-e56d5f34dad2",
      "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-04-23T03:44:19.130Z",
      "eventType": "transactional_email",
      "action": "new_bill_only",
      "userEmail": null,
      "userId": null,
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019db870-44f4-7496-a32e-e56d5f34dad2",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "bob.kauffman@stellartech.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/019db870-46b0-7e84-bfa8-16f2cb31a79d/",
        "subject": "New Bill-Only Order - 4/22/2026 - ZuriMED BO-1",
        "messageId": "dev-console-log",
        "relatedEntityType": "billing_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-04-23T03:44:24.305Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.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.enqueue_upload_classification",
      "found": true
    }
  ],
  "emailAssertions": [
    {
      "stepName": "Step 3: Other rep trunk selection",
      "expectedTemplate": "New Bill-Only Order",
      "found": true
    }
  ]
}