{
  "ursId": "URS-080",
  "title": "Par-level replenishment",
  "timestamp": "2026-09-29T02:31:00.388Z",
  "durationMs": 98201,
  "config": {
    "inboxUrl": "http://localhost:45893",
    "dbHost": "localhost",
    "dbPort": 43735,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Admin sets par levels at the location",
      "status": "pass",
      "description": "Step 1: Admin sets par levels at the location",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-01-par-editor-empty.png",
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-01-par-levels-set.png"
      ],
      "explanation": "Alex Admin (Vantis manufacturer) opens the seeded consignment location's settings page and, in the Par Agreements editor, adds a par level of 20 for URS080-PLATE and URS080-SCREW by picking each SKU and clicking Add. Each save shows the \"Par agreement saved\" toast and the row renders the par level next to the SKU's org-wide minimum shipment size (5 for the plate, none for the screw), which the editor exposes read-only. This establishes the par configuration the rest of the chain is driven by and proves par levels are set per (location, SKU) with an audit event per save.",
      "expectedAuditActions": [
        "par_agreement_set:set_par_agreement"
      ],
      "startedAt": "2026-09-29T02:31:10.600Z",
      "finishedAt": "2026-09-29T02:31:18.202Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/videos/step-01-set-par.webm"
    },
    {
      "name": "Step 2: Org-wide par agreements page lists the location",
      "status": "pass",
      "description": "Step 2: Org-wide par agreements page lists the location",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-02-par-agreements-page.png"
      ],
      "explanation": "The cross-location par agreements page (/inventory/par-agreements) groups every agreement in the organization by location. The run deep-links to the location's anchor and verifies the location heading, its \"2 SKUs\" count, and both SKUs at par 20. This proves the agreements set on the location page are the same org-wide records, not a per-page copy.",
      "startedAt": "2026-09-29T02:31:24.320Z",
      "finishedAt": "2026-09-29T02:31:24.320Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/videos/step-02-par-page.webm"
    },
    {
      "name": "Step 3: Account profile shows par levels",
      "status": "pass",
      "description": "Step 3: Account profile shows par levels",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-03-account-par-levels.png"
      ],
      "explanation": "The sales account that ships to the location renders a read-only \"Par levels\" section listing the agreements at its shipping location, with a \"View par agreements\" link that lands on the location's group on the org-wide page. This proves par levels are visible from the account context where replenishment is discussed with the customer.",
      "startedAt": "2026-09-29T02:31:31.248Z",
      "finishedAt": "2026-09-29T02:31:31.248Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/videos/step-03-account-widget.webm"
    },
    {
      "name": "Step 4: Replenishment forecast dashboard shows SKUs below par",
      "status": "pass",
      "description": "Step 4: Replenishment forecast dashboard shows SKUs below par",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-04-forecast-dashboard.png"
      ],
      "explanation": "The par replenishment forecast dashboard recomputes the live forecast for the location: with 12 plates and 6 screws on hand against par 20, no scheduled demand, and nothing inbound, both SKUs are projected below par at the 3-day arrival. The \"SKUs below par\" KPI reads 2 of 2 and each SKU bar shows its projected-at-arrival count and recommended order (10 for the plate — the deficit of 8 rounded up to the minimum shipment of 5 — and 14 for the screw). This proves the deterministic forecast math and the minimum-shipment rounding.",
      "startedAt": "2026-09-29T02:31:37.550Z",
      "finishedAt": "2026-09-29T02:31:37.550Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/videos/step-04-forecast.webm"
    },
    {
      "name": "Step 5: Inbox surfaces the replenishment task with a live forecast",
      "status": "pass",
      "description": "Step 5: Inbox surfaces the replenishment task with a live forecast",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-05-task-detail.png",
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-05-go-to-task.png"
      ],
      "explanation": "The \"Replenish URS080 Lakeside Surgical Center\" task is waiting in Alex's inbox. Its detail panel renders the forecast card, which recomputes the forecast live against current inventory (the same numbers as the dashboard: par 20, projected 12 and 6, recommended 10 and 14), and its \"Go to Task\" action is a deep link into the new-order form carrying prefillReplenishment=1, the location id, and the explicit supplying manufacturer id. This proves the replenishment work reaches the responsible person with the live recommendation attached. The task itself is seeded by setup because the daily replenishment scan is not scheduled in production; its generation is covered by the module integration tests.",
      "startedAt": "2026-09-29T02:31:44.222Z",
      "finishedAt": "2026-09-29T02:31:44.327Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/videos/step-05-inbox-task.webm"
    },
    {
      "name": "Step 6: Prefilled replenishment order form",
      "status": "pass",
      "description": "Step 6: Prefilled replenishment order form",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-06-prefilled-quantities.png"
      ],
      "explanation": "Clicking \"Go to Task\" opens the new-order form on the products step. The load recomputes the forecast for the location, selects the location and Vantis as its own supplier, and seeds each below-par SKU with its recommended quantity, showing the \"Prefilled from par forecast for URS080 Lakeside Surgical Center\" banner. The plate reads 10 and the screw 14, both still editable. This proves the handoff from task to order is prefilled end to end from the same forecast.",
      "startedAt": "2026-09-29T02:31:51.076Z",
      "finishedAt": "2026-09-29T02:31:51.076Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/videos/step-06-prefill.webm"
    },
    {
      "name": "Step 7: Admin submits the replenishment order",
      "status": "pass",
      "description": "Step 7: Admin submits the replenishment order",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-07-products-with-notes.png",
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-07-review.png",
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-07-submitted.png"
      ],
      "explanation": "Alex re-enters through the task, keeps the prefilled quantities, tags the notes with the URS-080 marker, advances to the review step (which lists both SKUs at 10 and 14 units), and submits. Because Vantis is both the requesting and the fulfilling organization, the order is self-fulfilled: it skips the submission grace window and auto-approval resolves inline at creation, writing the order_request_created and auto_approve_order decisions. This closes the chain: a par shortfall becomes a traceable, approved replenishment order.",
      "expectedAuditActions": [
        "decision:order_request_created",
        "decision:auto_approve_order"
      ],
      "startedAt": "2026-09-29T02:31:57.434Z",
      "finishedAt": "2026-09-29T02:32:00.504Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/videos/step-07-submit.webm"
    },
    {
      "name": "Step 8: Admin removes a par agreement",
      "status": "pass",
      "description": "Step 8: Admin removes a par agreement",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-08-confirm-remove.png",
        "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/step-08-plate-remains.png"
      ],
      "explanation": "Back on the location's settings page, Alex clicks the trash icon on the URS080-SCREW row and confirms Remove. The \"Par agreement removed\" toast appears and only the URS080-PLATE row remains. This proves par agreements can be withdrawn per (location, SKU) with an audit event that preserves the removed par level.",
      "expectedAuditActions": [
        "par_agreement_deleted:delete_par_agreement"
      ],
      "startedAt": "2026-09-29T02:32:36.550Z",
      "finishedAt": "2026-09-29T02:32:37.589Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/videos/step-08-remove-par.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Plate par agreement persisted at par 20",
      "query": "SELECT id, org_product_id, par_level, created_at, updated_at\n    FROM par_agreements\n    WHERE organization_id = $1 AND location_id = $2 AND org_product_id = $3",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb00-81b6-72a4-894f-d1fa81dd9699",
          "org_product_id": "08000000-0000-4000-8000-000000000011",
          "par_level": 20,
          "created_at": "2026-09-29T02:31:13.890Z",
          "updated_at": "2026-09-29T02:31:13.890Z"
        }
      ],
      "assertion": "A par_agreements row for URS080-PLATE at the location should exist with par_level=20, created during the run."
    },
    {
      "name": "Screw par agreement removed",
      "query": "SELECT id, par_level FROM par_agreements\n    WHERE organization_id = $1 AND location_id = $2 AND org_product_id = $3",
      "status": "pass",
      "rows": [],
      "assertion": "No par_agreements row should remain for URS080-SCREW at the location after Step 8."
    },
    {
      "name": "Minimum shipment sizes unchanged on the products",
      "query": "SELECT id, sku, min_shipment_quantity FROM org_products\n    WHERE organization_id = $1 AND id IN ($2, $3)\n    ORDER BY sku",
      "status": "pass",
      "rows": [
        {
          "id": "08000000-0000-4000-8000-000000000011",
          "sku": "URS080-PLATE",
          "min_shipment_quantity": 5
        },
        {
          "id": "08000000-0000-4000-8000-000000000012",
          "sku": "URS080-SCREW",
          "min_shipment_quantity": null
        }
      ],
      "assertion": "org_products.min_shipment_quantity should still be 5 for URS080-PLATE and NULL for URS080-SCREW."
    },
    {
      "name": "Par agreement set audit events recorded",
      "query": "SELECT id, action, user_id, secondary_object_id, payload, created_at\n    FROM audit_events\n    WHERE organization_id = $1\n      AND created_at >= $2\n      AND event_type = 'par_agreement_set'\n      AND action = 'set_par_agreement'\n      AND user_id = $3\n      AND payload->>'locationId' = $4\n    ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb00-81b8-7dbd-8c25-a02155f665a4",
          "action": "set_par_agreement",
          "user_id": "f6a7b8c9-d0e1-2345-f123-456789012345",
          "secondary_object_id": "08000000-0000-4000-8000-000000000011",
          "payload": "{\"parLevel\":20,\"locationId\":\"08000000-0000-4000-8000-000000000001\",\"orgProductId\":\"08000000-0000-4000-8000-000000000011\"}",
          "created_at": "2026-09-29T02:31:13.890Z"
        },
        {
          "id": "01a0eb00-8ff4-72a8-a012-ee2346f3703e",
          "action": "set_par_agreement",
          "user_id": "f6a7b8c9-d0e1-2345-f123-456789012345",
          "secondary_object_id": "08000000-0000-4000-8000-000000000012",
          "payload": "{\"parLevel\":20,\"locationId\":\"08000000-0000-4000-8000-000000000001\",\"orgProductId\":\"08000000-0000-4000-8000-000000000012\"}",
          "created_at": "2026-09-29T02:31:17.743Z"
        }
      ],
      "assertion": "Setting each par level should write an audit_events row (event_type=par_agreement_set, action=set_par_agreement) by Alex whose payload names the location and whose secondary_object_id is the product."
    },
    {
      "name": "Par agreement deleted audit event recorded",
      "query": "SELECT id, action, user_id, secondary_object_id, payload, created_at\n    FROM audit_events\n    WHERE organization_id = $1\n      AND created_at >= $2\n      AND event_type = 'par_agreement_deleted'\n      AND action = 'delete_par_agreement'\n      AND user_id = $3\n      AND secondary_object_id = $4\n      AND payload->>'locationId' = $5\n    ORDER BY created_at DESC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-c610-740c-99c6-42df9b1970c0",
          "action": "delete_par_agreement",
          "user_id": "f6a7b8c9-d0e1-2345-f123-456789012345",
          "secondary_object_id": "08000000-0000-4000-8000-000000000012",
          "payload": "{\"parLevel\":20,\"locationId\":\"08000000-0000-4000-8000-000000000001\",\"orgProductId\":\"08000000-0000-4000-8000-000000000012\"}",
          "created_at": "2026-09-29T02:32:37.132Z"
        }
      ],
      "assertion": "Removing the screw agreement should write an audit_events row (event_type=par_agreement_deleted, action=delete_par_agreement) by Alex naming the screw product, the location, and the removed par level 20."
    },
    {
      "name": "Replenishment task linked to the location and supplying manufacturer",
      "query": "SELECT id, status, criteria_type, criteria_config, linked_object_id, route, item_key, metadata\n    FROM checklist_items\n    WHERE organization_id = $1 AND id = $2",
      "status": "pass",
      "rows": [
        {
          "id": "08000000-0000-4000-8000-000000000042",
          "status": "ready",
          "criteria_type": "inventory.par_replenishment",
          "criteria_config": {
            "type": "inventory.par_replenishment",
            "raisedFor": "2026-09-29",
            "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
          },
          "linked_object_id": "08000000-0000-4000-8000-000000000001",
          "route": "/orders/requests/new?prefillReplenishment=1&locationId=08000000-0000-4000-8000-000000000001&manufacturerId=a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "item_key": "par-replenishment-a1b2c3d4-e5f6-7890-abcd-ef1234567890-08000000-0000-4000-8000-000000000001",
          "metadata": {
            "type": "par_replenishment_item",
            "products": [
              {
                "sku": "URS080-PLATE",
                "title": "URS080 Fixation Plate",
                "parLevel": 20,
                "demandSource": "none",
                "orgProductId": "08000000-0000-4000-8000-000000000011",
                "projectedOnHandAtArrival": 12,
                "recommendedOrderQuantity": 10
              },
              {
                "sku": "URS080-SCREW",
                "title": "URS080 Bone Screw",
                "parLevel": 20,
                "demandSource": "none",
                "orgProductId": "08000000-0000-4000-8000-000000000012",
                "projectedOnHandAtArrival": 6,
                "recommendedOrderQuantity": 14
              }
            ],
            "raisedFor": "2026-09-29",
            "locationId": "08000000-0000-4000-8000-000000000001",
            "arrivalDate": "2026-10-02",
            "locationName": "URS080 Lakeside Surgical Center",
            "totalRecommendedUnits": 24,
            "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
          }
        }
      ],
      "assertion": "The checklist item should have criteria_type=inventory.par_replenishment, manufacturerOrganizationId=<supplying manufacturer> in criteria_config and metadata, linked_object_id=<location>, item_key=par-replenishment-<manufacturer>-<location>, and route /orders/requests/new?prefillReplenishment=1&locationId=<location>&manufacturerId=<manufacturer>."
    },
    {
      "name": "Replenishment order request created for the location",
      "query": "SELECT id, request_number, status, order_type, requesting_organization_id,\n      fulfilling_organization_id, requested_by_user_id, location_id, sales_account_id,\n      submission_grace_until, notes, created_at\n    FROM order_requests\n    WHERE requesting_organization_id = $1\n      AND notes LIKE '%' || $2 || '%'\n      AND created_at >= $3\n    ORDER BY created_at DESC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-35f2-7235-ae9d-8f03d617fca1",
          "request_number": "OR-1",
          "status": "approved",
          "order_type": "dropship",
          "requesting_organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "fulfilling_organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "requested_by_user_id": "f6a7b8c9-d0e1-2345-f123-456789012345",
          "location_id": "08000000-0000-4000-8000-000000000001",
          "sales_account_id": "08000000-0000-4000-8000-000000000002",
          "submission_grace_until": null,
          "notes": "URS-080 validation run — submitted at 2026-09-29T02:31:56.835Z",
          "created_at": "2026-09-29T02:32:00.204Z"
        }
      ],
      "assertion": "A URS-080 order request should exist with Vantis as both requesting and fulfilling org, placed by Alex, at the seeded location and sales account, with the account order type the prefill selects (dropship) and no submission grace window (self-fulfilled orders resolve inline)."
    },
    {
      "name": "Order items carry the forecast-recommended quantities",
      "query": "SELECT oi.id, oi.product_id, p.sku, oi.requested_quantity, oi.approved_quantity,\n      oi.pending_quantity, oi.rejected_quantity\n    FROM order_request_items oi\n    JOIN org_products p ON p.id = oi.product_id\n    WHERE oi.order_request_id = $1\n    ORDER BY p.sku",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-35f9-7104-8ece-b193c121c18a",
          "product_id": "08000000-0000-4000-8000-000000000011",
          "sku": "URS080-PLATE",
          "requested_quantity": 10,
          "approved_quantity": 10,
          "pending_quantity": 0,
          "rejected_quantity": 0
        },
        {
          "id": "01a0eb01-35f9-7104-8ece-b192eedc6441",
          "product_id": "08000000-0000-4000-8000-000000000012",
          "sku": "URS080-SCREW",
          "requested_quantity": 14,
          "approved_quantity": 14,
          "pending_quantity": 0,
          "rejected_quantity": 0
        }
      ],
      "assertion": "The order should have exactly two items: URS080-PLATE × 10 and URS080-SCREW × 14."
    },
    {
      "name": "Self-fulfilled order auto-approved inline",
      "query": "-- status from the order row and approved_quantity from the item rows above",
      "status": "pass",
      "rows": [
        {
          "status": "approved",
          "items": [
            "URS080-PLATE: 10/10",
            "URS080-SCREW: 14/14"
          ]
        }
      ],
      "assertion": "With Vantis fulfilling its own request and no approval threshold on the catalog rows, the order should be status=approved with approved_quantity equal to requested_quantity on every item."
    },
    {
      "name": "Order creation and auto-approval decisions recorded",
      "query": "SELECT id, action, payload->>'performed' AS performed, payload->>'reason' AS reason, created_at\n    FROM audit_events\n    WHERE organization_id = $1\n      AND created_at >= $2\n      AND event_type = 'decision'\n      AND action IN ('order_request_created', 'auto_approve_order')\n      AND object_id = $3\n    ORDER BY created_at ASC",
      "status": "pass",
      "rows": [
        {
          "id": "01a0eb01-3645-765c-aea2-7a3258a1652a",
          "action": "auto_approve_order",
          "performed": "true",
          "reason": "Auto-approved 2 of 2 items",
          "created_at": "2026-09-29T02:32:00.204Z"
        },
        {
          "id": "01a0eb01-35f4-7983-b2cb-c4765132fd65",
          "action": "order_request_created",
          "performed": "true",
          "reason": "Order request OR-1 created (importSource=manual)",
          "created_at": "2026-09-29T02:32:00.204Z"
        }
      ],
      "assertion": "Submitting should log decision audit rows for the order: action='order_request_created' (performed=true) and action='auto_approve_order' (performed=true)."
    },
    {
      "name": "Multi-tenant isolation: Corveta sees no URS-080 rows",
      "query": "SELECT\n      (SELECT COUNT(*)::int FROM par_agreements\n        WHERE organization_id = $1 AND location_id = $2) AS corveta_par_agreements,\n      (SELECT COUNT(*)::int FROM org_products\n        WHERE organization_id = $1 AND sku LIKE 'URS080-%') AS corveta_products,\n      (SELECT COUNT(*)::int FROM checklist_items\n        WHERE organization_id = $1 AND linked_object_id = $2) AS corveta_checklist_items,\n      (SELECT COUNT(*)::int FROM order_requests\n        WHERE (requesting_organization_id = $1 OR fulfilling_organization_id = $1)\n          AND location_id = $2) AS corveta_order_requests",
      "status": "pass",
      "rows": [
        {
          "corveta_par_agreements": 0,
          "corveta_products": 0,
          "corveta_checklist_items": 0,
          "corveta_order_requests": 0
        }
      ],
      "assertion": "Corveta (the other demo org) should own zero par agreements, products, checklist items, or order requests tied to the URS-080 location or SKUs."
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z",
  "auditStartTime": "2026-09-29T02:30:58.660Z",
  "emailEvidence": [
    {
      "subject": "Drop-Ship Order Created - OR-1-FO-1",
      "template": "Drop-Ship_Order_Created_-_OR-1-FO-1",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-080-par-level-replenishment/2026-09-29T02-31-00-387Z/screenshots/emails/2026-09-29T02-32-02-203Z-Drop-Ship_Order_Created_-_OR-1-FO-1.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-09-29T02:31:05.983Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:31:13.890Z",
      "eventType": "par_agreement_set",
      "action": "set_par_agreement",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-81b6-72a4-894f-d1fa81dd9699",
      "secondaryObjectId": "08000000-0000-4000-8000-000000000011",
      "payload": {
        "parLevel": 20,
        "locationId": "08000000-0000-4000-8000-000000000001",
        "orgProductId": "08000000-0000-4000-8000-000000000011"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:17.743Z",
      "eventType": "par_agreement_set",
      "action": "set_par_agreement",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-8ff2-78ed-a7b6-cc702f124dc8",
      "secondaryObjectId": "08000000-0000-4000-8000-000000000012",
      "payload": {
        "parLevel": 20,
        "locationId": "08000000-0000-4000-8000-000000000001",
        "orgProductId": "08000000-0000-4000-8000-000000000012"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:31:20.794Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:31:27.389Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:31:33.833Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:31:39.955Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:31:46.655Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:31:52.854Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:32:00.204Z",
      "eventType": "decision",
      "action": "representatives.gate_rep_action",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "secondaryObjectId": null,
      "payload": {
        "reason": "no_blocking_relationship",
        "orderType": "dropship",
        "performed": false,
        "entityType": "organization",
        "gatedAction": "order_request",
        "isOwnTrunkDestination": false,
        "requestingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:00.204Z",
      "eventType": "decision",
      "action": "order_request_created",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-35f2-7235-ae9d-8f03d617fca1",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Order request OR-1 created (importSource=manual)",
        "priority": "normal",
        "itemCount": 2,
        "orderType": "dropship",
        "performed": true,
        "entityType": "order_request",
        "importSource": "manual",
        "requestNumber": "OR-1",
        "selfFulfilled": true,
        "resolvedLocationId": "08000000-0000-4000-8000-000000000001",
        "resolvedSalesAccountId": "08000000-0000-4000-8000-000000000002",
        "fulfillingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "requestingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:00.204Z",
      "eventType": "fulfillment_order",
      "action": "status_change",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3611-789b-84ea-5ec6a41d42ca",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Fulfillment order created from approved items",
        "toStatus": "created",
        "fromStatus": null,
        "automatedAction": true,
        "requestingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:00.204Z",
      "eventType": "fulfillment_order",
      "action": "status_change",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3611-789b-84ea-5ec6a41d42ca",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Order automatically submitted for fulfillment",
        "toStatus": "submitted",
        "fromStatus": "created",
        "automatedAction": true,
        "requestingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:00.204Z",
      "eventType": "decision",
      "action": "basicErp.deriveSalesOrder",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-35f2-7235-ae9d-8f03d617fca1",
      "secondaryObjectId": null,
      "payload": {
        "reason": "flag_disabled",
        "performed": false,
        "entityType": "order_request"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:00.204Z",
      "eventType": "decision",
      "action": "auto_approve_order",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-35f2-7235-ae9d-8f03d617fca1",
      "secondaryObjectId": null,
      "payload": {
        "items": [
          {
            "itemId": "01a0eb01-35f9-7104-8ece-b192eedc6441",
            "approvedQuantity": 14,
            "rejectedQuantity": 0,
            "requestedQuantity": 14
          },
          {
            "itemId": "01a0eb01-35f9-7104-8ece-b193c121c18a",
            "approvedQuantity": 10,
            "rejectedQuantity": 0,
            "requestedQuantity": 10
          }
        ],
        "reason": "Auto-approved 2 of 2 items",
        "performed": true,
        "entityType": "order_request",
        "totalItems": 2,
        "importSource": "manual",
        "selfFulfilled": true,
        "allFullyApproved": true,
        "hasBlockingIssues": false,
        "hasMissingPoIssue": false,
        "hasDuplicateIssues": false,
        "resolvedLocationId": "08000000-0000-4000-8000-000000000001",
        "preventAutoApproval": false,
        "needsAutoApproveGate": false,
        "fulfillingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "requestingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "allowAutoApproveImportedOrders": false,
        "partialOrderAutoApprovalEnabled": false
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:00.204Z",
      "eventType": "decision",
      "action": "extensiv_order_push.skipped",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3611-789b-84ea-5ec6a41d42ca",
      "secondaryObjectId": "01a0eb01-35f2-7235-ae9d-8f03d617fca1",
      "payload": {
        "flags": {
          "wms_integrations": false,
          "extensiv_wms_integration": false
        },
        "reason": "wms_feature_flag_disabled",
        "orderType": "dropship",
        "performed": false,
        "entityType": "FulfillmentOrder",
        "triggerReason": "fulfillment_order_submitted"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:02.238Z",
      "eventType": "transactional_email",
      "action": "order_created",
      "userEmail": null,
      "userId": null,
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb01-3611-789b-84ea-5ec6a41d42ca",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "alex.admin@vantismedical.com"
        ],
        "s3Path": "email-audit/a1b2c3d4-e5f6-7890-abcd-ef1234567890/01a0eb01-3da5-7624-beb2-d22f314ac8d0/",
        "subject": "Drop-Ship Order Created - OR-1-FO-1",
        "messageId": "dev-console-log",
        "relatedEntityType": "fulfillment_order"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-09-29T02:32:32.906Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "alex.admin@vantismedical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-09-29T02:32:37.132Z",
      "eventType": "par_agreement_deleted",
      "action": "delete_par_agreement",
      "userEmail": "alex.admin@vantismedical.com",
      "userId": "f6a7b8c9-d0e1-2345-f123-456789012345",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "01a0eb00-8ff2-78ed-a7b6-cc702f124dc8",
      "secondaryObjectId": "08000000-0000-4000-8000-000000000012",
      "payload": {
        "parLevel": 20,
        "locationId": "08000000-0000-4000-8000-000000000001",
        "orgProductId": "08000000-0000-4000-8000-000000000012"
      },
      "route": null,
      "traceId": null
    }
  ],
  "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: Admin sets par levels at the location",
      "expectedAction": "par_agreement_set:set_par_agreement",
      "found": true
    },
    {
      "stepName": "Step 7: Admin submits the replenishment order",
      "expectedAction": "decision:order_request_created",
      "found": true
    },
    {
      "stepName": "Step 7: Admin submits the replenishment order",
      "expectedAction": "decision:auto_approve_order",
      "found": true
    },
    {
      "stepName": "Step 8: Admin removes a par agreement",
      "expectedAction": "par_agreement_deleted:delete_par_agreement",
      "found": true
    }
  ],
  "emailAssertions": []
}