> ## 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.

# Export a generic accounting file (journal entries / configurable CSV)

> Returns balanced double-entry journal entries (écritures comptables) for a date period over the per-ticket sales read model, serialised to a CONFIGURABLE, tool-agnostic ledger CSV importable into the common French accounting tools (Sage, Cegid, EBP, Quadra) WITHOUT a vendor-specific connector. Each ticket books a debit on the encaissement account of its settlement method (PCG 531/512/511/419…) and per-VAT-rate credits on revenue (707) + collected TVA (44571), so Σ débit = Σ crédit. The account mapping is FR-PCG-defaulted but OVERRIDABLE (`revenueAccount`, `vatAccount`, `roundingAccount`, `cashAccount`, `bankAccount`) and the CSV `delimiter` + `decimalSeparator` are configurable. REQUIRES `from` and `to` as `YYYY-MM-DD` with `from <= to`; a missing, malformed or inverted period returns 400. `format` defaults to `json` (the structured payload); `format=csv` streams the raw ledger CSV as a `text/csv` attachment (`ecritures_<from>_<to>.csv`). Optionally narrow to a single `store`.



## OpenAPI

````yaml /openapi.json get /v1/finance/accounting-export
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/finance/accounting-export:
    get:
      tags:
        - Finance
      summary: Export a generic accounting file (journal entries / configurable CSV)
      description: >-
        Returns balanced double-entry journal entries (écritures comptables) for
        a date period over the per-ticket sales read model, serialised to a
        CONFIGURABLE, tool-agnostic ledger CSV importable into the common French
        accounting tools (Sage, Cegid, EBP, Quadra) WITHOUT a vendor-specific
        connector. Each ticket books a debit on the encaissement account of its
        settlement method (PCG 531/512/511/419…) and per-VAT-rate credits on
        revenue (707) + collected TVA (44571), so Σ débit = Σ crédit. The
        account mapping is FR-PCG-defaulted but OVERRIDABLE (`revenueAccount`,
        `vatAccount`, `roundingAccount`, `cashAccount`, `bankAccount`) and the
        CSV `delimiter` + `decimalSeparator` are configurable. REQUIRES `from`
        and `to` as `YYYY-MM-DD` with `from <= to`; a missing, malformed or
        inverted period returns 400. `format` defaults to `json` (the structured
        payload); `format=csv` streams the raw ledger CSV as a `text/csv`
        attachment (`ecritures_<from>_<to>.csv`). Optionally narrow to a single
        `store`.
      operationId: exportAccounting
      parameters:
        - schema:
            type: string
          in: query
          name: from
          required: false
          description: >-
            REQUIRED — inclusive period start (`YYYY-MM-DD`, `from <= to`).
            Missing/inverted → 400.
        - schema:
            type: string
          in: query
          name: to
          required: false
          description: >-
            REQUIRED — inclusive period end (`YYYY-MM-DD`, `from <= to`).
            Missing/inverted → 400.
        - schema:
            type: string
          in: query
          name: store
          required: false
          description: Optional — narrow the écritures to one store by its canonical id.
        - schema:
            type: string
          in: query
          name: format
          required: false
          description: >-
            `json` (default) returns the structured payload; `csv` streams the
            raw ledger CSV as a `text/csv; charset=utf-8` attachment
            (`ecritures_<from>_<to>.csv`). Any other value 400s.
        - schema:
            type: string
          in: query
          name: delimiter
          required: false
          description: CSV field delimiter (default `;`). One character.
        - schema:
            type: string
          in: query
          name: decimalSeparator
          required: false
          description: Euro amount decimal separator, `,` (default) or `.`.
        - schema:
            type: string
          in: query
          name: revenueAccount
          required: false
          description: Override the revenue (707) account. 3–20 digits.
        - schema:
            type: string
          in: query
          name: vatAccount
          required: false
          description: Override the collected-VAT (44571) account. 3–20 digits.
        - schema:
            type: string
          in: query
          name: roundingAccount
          required: false
          description: Override the rounding/suspense (471) account. 3–20 digits.
        - schema:
            type: string
          in: query
          name: cashAccount
          required: false
          description: Override the cash encaissement (531) account. 3–20 digits.
        - schema:
            type: string
          in: query
          name: bankAccount
          required: false
          description: >-
            Override the bank encaissement (512) account for card + split
            payments. 3–20 digits.
      responses:
        '200':
          description: >-
            For `format=json` (default): the structured export — balanced
            entries, totals and the CSV text. For `format=csv`: this JSON
            envelope is REPLACED by the raw ledger CSV streamed as a `text/csv;
            charset=utf-8` attachment (`Content-Disposition: attachment;
            filename="ecritures_<from>_<to>.csv"`) — the `content` field below
            is exactly that file body.
          content:
            application/json:
              schema:
                type: object
                properties:
                  from:
                    type: string
                  to:
                    type: string
                  entryCount:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  totalDebitCents:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  totalCreditCents:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  balanced:
                    type: boolean
                  fileName:
                    type: string
                  content:
                    type: string
                  entries:
                    type: array
                    items:
                      type: object
                      properties:
                        journalCode:
                          type: string
                        journalLabel:
                          type: string
                        entryNumber:
                          type: string
                        entryDate:
                          type: string
                        accountNumber:
                          type: string
                        accountLabel:
                          type: string
                        entryLabel:
                          type: string
                        documentRef:
                          type: string
                        debitCents:
                          type: integer
                          minimum: -9007199254740991
                          maximum: 9007199254740991
                        creditCents:
                          type: integer
                          minimum: -9007199254740991
                          maximum: 9007199254740991
                      required:
                        - journalCode
                        - journalLabel
                        - entryNumber
                        - entryDate
                        - accountNumber
                        - accountLabel
                        - entryLabel
                        - documentRef
                        - debitCents
                        - creditCents
                      additionalProperties: false
                required:
                  - from
                  - to
                  - entryCount
                  - totalDebitCents
                  - totalCreditCents
                  - balanced
                  - fileName
                  - content
                  - entries
                additionalProperties: false
                description: >-
                  For `format=json` (default): the structured export — balanced
                  entries, totals and the CSV text. For `format=csv`: this JSON
                  envelope is REPLACED by the raw ledger CSV streamed as a
                  `text/csv; charset=utf-8` attachment (`Content-Disposition:
                  attachment; filename="ecritures_<from>_<to>.csv"`) — the
                  `content` field below is exactly that file body.
                example:
                  from: '2026-07-28'
                  to: '2026-07-28'
                  entryCount: 3
                  totalDebitCents: 3600
                  totalCreditCents: 3600
                  balanced: true
                  fileName: ecritures_20260728_20260728.csv
                  content: "Date;Journal;Compte;LibelleCompte;Piece;Libelle;Debit;Credit\r\n2026-07-28;VE;531000;Encaissement espèces;T-1;T-1;36,00;0,00\r\n2026-07-28;VE;707000;Ventes de marchandises;T-1;T-1;0,00;30,00\r\n2026-07-28;VE;445710;TVA collectée;T-1;T-1;0,00;6,00"
                  entries:
                    - journalCode: VE
                      journalLabel: Journal des ventes
                      entryNumber: T-1
                      entryDate: '2026-07-28T10:00:00.000Z'
                      accountNumber: '531000'
                      accountLabel: Encaissement espèces
                      entryLabel: T-1
                      documentRef: T-1
                      debitCents: 3600
                      creditCents: 0
                    - journalCode: VE
                      journalLabel: Journal des ventes
                      entryNumber: T-1
                      entryDate: '2026-07-28T10:00:00.000Z'
                      accountNumber: '707000'
                      accountLabel: Ventes de marchandises
                      entryLabel: T-1
                      documentRef: T-1
                      debitCents: 0
                      creditCents: 3000
                    - journalCode: VE
                      journalLabel: Journal des ventes
                      entryNumber: T-1
                      entryDate: '2026-07-28T10:00:00.000Z'
                      accountNumber: '445710'
                      accountLabel: TVA collectée
                      entryLabel: T-1
                      documentRef: T-1
                      debitCents: 0
                      creditCents: 600
        '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'
        '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.

````