> ## Documentation Index
> Fetch the complete documentation index at: https://docs-pos.solya.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Get a purchase order's received-vs-ordered variance (écart de réception)

> Returns the received-vs-ordered variance (écart de réception) of one purchase order: a per-line signed gap valued in integer cents (varianceQuantity = received − ordered; negative is a shortfall still outstanding, positive an over-receipt), plus the outstanding/over-received line counts and the shortfall/over-receipt valued totals. Every ordered line appears (an un-received line reads received = 0). The procurement twin of the transfer receipt-discrepancy report. 404s for an unknown order id.



## OpenAPI

````yaml /openapi.json get /v1/purchase-orders/{orderId}/variance
openapi: 3.0.3
info:
  title: Solya POS API
  version: 1.0.0
  description: >-
    The Solya POS backend HTTP surface. Every documented operation is
    agent-ready: it carries an `operationId`, an agent-facing `description`, the
    `pos.*` scopes it enforces (`x-required-permissions`) and an `x-agent-tier`.
    Success responses return the payload as raw JSON; failures return the
    `ErrorResponse` envelope (`{ error: { code, message, statusCode } }`).
servers:
  - url: /
    description: The backend, relative to its deployed origin.
security: []
paths:
  /v1/purchase-orders/{orderId}/variance:
    get:
      tags:
        - Procurement
      summary: Get a purchase order's received-vs-ordered variance (écart de réception)
      description: >-
        Returns the received-vs-ordered variance (écart de réception) of one
        purchase order: a per-line signed gap valued in integer cents
        (varianceQuantity = received − ordered; negative is a shortfall still
        outstanding, positive an over-receipt), plus the
        outstanding/over-received line counts and the shortfall/over-receipt
        valued totals. Every ordered line appears (an un-received line reads
        received = 0). The procurement twin of the transfer receipt-discrepancy
        report. 404s for an unknown order id.
      operationId: getPurchaseOrderVariance
      parameters:
        - schema:
            type: string
            minLength: 1
          in: path
          name: orderId
          required: true
          description: The purchase order (bon de commande) id.
      responses:
        '200':
          description: >-
            The per-line received-vs-ordered variance with the valued
            shortfall/over-receipt totals.
          content:
            application/json:
              schema:
                type: object
                properties:
                  lines:
                    type: array
                    items:
                      type: object
                      properties:
                        skuId:
                          type: string
                          pattern: ^[0-9a-f]{64}$
                          description: SKU digest (64-hex) of the line.
                        orderedQuantity:
                          type: integer
                          minimum: 0
                          maximum: 9007199254740991
                          description: Units originally ordered.
                        receivedQuantity:
                          type: integer
                          minimum: 0
                          maximum: 9007199254740991
                          description: Units received so far.
                        varianceQuantity:
                          type: integer
                          minimum: -9007199254740991
                          maximum: 9007199254740991
                          description: >-
                            received − ordered: negative is a shortfall,
                            positive an over-receipt.
                        unitCostCents:
                          type: integer
                          minimum: 0
                          maximum: 9007199254740991
                          description: Unit cost in cents valuing the line.
                        valuedVarianceCents:
                          type: integer
                          minimum: -9007199254740991
                          maximum: 9007199254740991
                          description: >-
                            varianceQuantity × unitCostCents; signed, in integer
                            cents.
                      required:
                        - skuId
                        - orderedQuantity
                        - receivedQuantity
                        - varianceQuantity
                        - unitCostCents
                        - valuedVarianceCents
                      additionalProperties: false
                    description: >-
                      Per-SKU received-vs-ordered variance (every ordered line
                      appears).
                  totalOrderedQuantity:
                    type: integer
                    minimum: 0
                    maximum: 9007199254740991
                    description: Total units ordered across lines.
                  totalReceivedQuantity:
                    type: integer
                    minimum: 0
                    maximum: 9007199254740991
                    description: Total units received across lines.
                  outstandingLineCount:
                    type: integer
                    minimum: 0
                    maximum: 9007199254740991
                    description: >-
                      Lines still short of their ordered quantity (received <
                      ordered).
                  overReceivedLineCount:
                    type: integer
                    minimum: 0
                    maximum: 9007199254740991
                    description: >-
                      Lines that received strictly more than ordered (received >
                      ordered).
                  totalValuedVarianceCents:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                    description: Net valued variance across all lines, in cents.
                  shortfallValueCents:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                    description: Sum of the negative (shortfall) variances, in cents.
                  overReceiptValueCents:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                    description: Sum of the positive (over-receipt) variances, in cents.
                required:
                  - lines
                  - totalOrderedQuantity
                  - totalReceivedQuantity
                  - outstandingLineCount
                  - overReceivedLineCount
                  - totalValuedVarianceCents
                  - shortfallValueCents
                  - overReceiptValueCents
                additionalProperties: false
                description: >-
                  The per-line received-vs-ordered variance with the valued
                  shortfall/over-receipt totals.
                example:
                  lines:
                    - skuId: >-
                        e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
                      orderedQuantity: 24
                      receivedQuantity: 20
                      varianceQuantity: -4
                      unitCostCents: 4500
                      valuedVarianceCents: -18000
                  totalOrderedQuantity: 24
                  totalReceivedQuantity: 20
                  outstandingLineCount: 1
                  overReceivedLineCount: 0
                  totalValuedVarianceCents: -18000
                  shortfallValueCents: -18000
                  overReceiptValueCents: 0
        '400':
          description: >-
            The request failed schema validation; `error.fieldErrors` lists the
            fields.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorResponse'
        '401':
          description: No valid credential was presented — send a bearer token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: The actor is authenticated but lacks the required `pos.*` scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: No resource matches the addressed identifier.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: An unexpected server error — safe to retry idempotent requests.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
components:
  schemas:
    ValidationErrorResponse:
      type: object
      required:
        - error
      additionalProperties: false
      description: >-
        A `VALIDATION_FAILED` envelope carrying the offending fields in
        `fieldErrors`.
      properties:
        error:
          type: object
          required:
            - code
            - message
            - statusCode
          additionalProperties: false
          properties:
            code:
              type: string
              enum:
                - VALIDATION_FAILED
            message:
              type: string
            statusCode:
              type: integer
            fieldErrors:
              type: array
              description: >-
                One entry per rejected field: the field path and why it was
                rejected.
              items:
                type: object
                required:
                  - field
                  - message
                additionalProperties: false
                properties:
                  field:
                    type: string
                    description: Dot-path of the offending field.
                  message:
                    type: string
                    description: Why the field was rejected.
    ErrorResponse:
      type: object
      required:
        - error
      additionalProperties: false
      description: The uniform failure envelope every non-2xx response returns.
      properties:
        error:
          type: object
          required:
            - code
            - message
            - statusCode
          additionalProperties: false
          properties:
            code:
              type: string
              enum:
                - VALIDATION_FAILED
                - UNAUTHORIZED
                - FORBIDDEN
                - NOT_FOUND
                - CONFLICT
                - BUSINESS_RULE_VIOLATION
                - INTERNAL_ERROR
              description: >-
                Machine-readable kernel `ResultCode` — branch on this, not on
                `message`.
            message:
              type: string
              description: >-
                Human-readable explanation. Safe to surface; never leaks server
                internals.
            statusCode:
              type: integer
              description: >-
                The HTTP status, mirrored into the body so a client need not
                read headers.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        `Authorization: Bearer <token>`. Accepts EITHER a Keycloak access token
        (scopes-in-token) OR an opaque POS session token; both resolve to the
        same `pos.*` scope vocabulary the route guards enforce.

````