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

# Calculate sale totals

> Computes line and sale totals exactly as creating the sale would, plus an equal monthly installment plan when `installment_count` is given. Line figures are rounded for display; `total` is summed from the unrounded lines and rounded once, the same figure POST /sales checks an installment plan against. Nothing is saved.



## OpenAPI

````yaml /api-referansi/openapi.json post /v1/sales/calculate
openapi: 3.1.0
info:
  title: Flextell API
  version: 0.0.1
  description: >-
    Flextell REST API referansı. Kimlik doğrulama, scope ve istek kuralları için
    API sekmesindeki rehberlere bakın.
servers:
  - url: https://app.flextell.ai/api
    description: Üretim
security:
  - oauth2: []
  - bearer: []
paths:
  /v1/sales/calculate:
    post:
      tags:
        - Sales
      summary: Calculate sale totals
      description: >-
        Computes line and sale totals exactly as creating the sale would, plus
        an equal monthly installment plan when `installment_count` is given.
        Line figures are rounded for display; `total` is summed from the
        unrounded lines and rounded once, the same figure POST /sales checks an
        installment plan against. Nothing is saved.
      operationId: sales.calculate
      parameters:
        - name: X-Tenant
          in: header
          required: true
          description: >-
            Tenant identifier. Send the Tenant ID in the `X-Tenant` header to
            scope API requests to a specific tenant.
          schema:
            type: number
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SaleCalculateRequest'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: string
                  data:
                    type: object
                    properties:
                      items:
                        type: array
                        items: {}
                      sub_total:
                        type: number
                      total_discount:
                        type: number
                      total_tax:
                        type: number
                      total:
                        type: number
                      installments:
                        type: array
                        items:
                          type: object
                          properties:
                            installment_number:
                              type: string
                            amount:
                              type: number
                            due_date:
                              type: string
                          required:
                            - installment_number
                            - amount
                            - due_date
                    required:
                      - items
                      - sub_total
                      - total_discount
                      - total_tax
                      - total
                      - installments
                required:
                  - success
                  - data
        '401':
          $ref: '#/components/responses/AuthenticationException'
        '403':
          $ref: '#/components/responses/AuthorizationException'
        '422':
          $ref: '#/components/responses/ValidationException'
        '428':
          description: >-
            Mandatory setup is incomplete. Finish the setup wizard first;
            `data.next_step` names the step to continue with.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    examples:
                      - false
                  error_code:
                    type: string
                    enum:
                      - SETUP_REQUIRED
                    examples:
                      - SETUP_REQUIRED
                  message:
                    type: string
                    examples:
                      - Complete the required setup steps to continue.
                  data:
                    type: object
                    properties:
                      next_step:
                        type:
                          - string
                          - 'null'
                        examples:
                          - clinic_info
                    required:
                      - next_step
                required:
                  - success
                  - error_code
                  - message
                  - data
components:
  schemas:
    SaleCalculateRequest:
      type: object
      description: >-
        Nothing is stored, so anyone who may fill in the sale form may ask for
        its figures.
      properties:
        items:
          type: array
          description: Sale line items, as they would be sent to create the sale.
          items:
            type: object
            properties:
              quantity:
                type: number
                description: Quantity.
                minimum: 0.0001
              unit_price:
                type: number
                description: Unit price.
                minimum: 0
              tax_rate:
                type: integer
                description: Tax rate (0, 1, 10, or 20).
                enum:
                  - '0'
                  - '1'
                  - '10'
                  - '20'
              discount_amount:
                type: number
                description: Discount amount.
                minimum: 0
              discount_percentage:
                type: number
                description: Discount percentage (0-100).
                minimum: 0
                maximum: 100
              total_price:
                type:
                  - number
                  - 'null'
                description: >-
                  Total price for this item. Server-calculated unless the tenant
                  enabled the accounting setting preserve_item_total_price, in
                  which case this value is kept and total_tax absorbs the
                  rounding difference.
                minimum: 0
            required:
              - quantity
              - unit_price
              - tax_rate
              - discount_amount
              - discount_percentage
          minItems: 1
          maxItems: 500
        installment_count:
          type:
            - integer
            - 'null'
          description: Number of installments to suggest a plan for (optional).
          minimum: 2
          maximum: 120
        first_due_date:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            Due date of the first installment (YYYY-MM-DD); the others follow
            monthly. Required with installment_count.
      required:
        - items
      title: SaleCalculateRequest
  responses:
    AuthenticationException:
      description: Unauthenticated
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    AuthorizationException:
      description: Authorization error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    ValidationException:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Errors overview.
              errors:
                type: object
                description: A detailed description of each field that failed validation.
                additionalProperties:
                  type: array
                  items:
                    type: string
            required:
              - message
              - errors
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://app.flextell.ai/oauth/authorize
          tokenUrl: https://app.flextell.ai/oauth/token
          scopes:
            '*': all
    bearer:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.