openapi: 3.0.0
info:
  version: 1.0.0
  title: ows-ledger API Specifications
servers:
  - url: https://qa-ows-ledger.theorchard.io
    description: QA server

paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK

  /ledger/bulk/:
    post:
      summary: Bulk create ledger entries
      requestBody:
        description: Array of parameters for any one of ledger_account or ledger_deposit
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                anyOf:
                  - $ref: '#/components/schemas/LedgerAccountPost'
                  - $ref: '#/components/schemas/LedgerDepositPost'
      responses:
        '201':
          description: POST success

  /ledger-contract-flowthrough/bulk:
    post:
      summary: Bulk create ledger-contract-flowthrough entries
      requestBody:
        description: Array of parameters for any one of ledger_contract_flowthrough or ledger_deposit
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                anyOf:
                  - $ref: '#/components/schemas/LedgerContractFlowthroughPost'
                  - $ref: '#/components/schemas/LedgerDepositPost'
      responses:
        '201':
          description: POST success
        '400':
          description: Bad request - invalid syntax or unrecognized currency code
        '409':
          description: Conflict - a database constraint was violated
        '422':
          description: Unprocessable Entity - a value is out of range or too long

  /bulk/accounts-balance/:
    get:
      summary: Get balances for a list of account_ids
      parameters:
        - description: comma separated list of account_ids
          name: account_ids
          in: query
          required: false
          schema:
            type: string
        - description: minimum value for account's balance to filter
          name: balance_min
          in: query
          required: false
          schema:
            type: number
        - description: maximum value for account's balance to filter
          name: balance_max
          in: query
          required: false
          schema:
            type: number
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/LedgerAccountCurrentBalanceBulk'

  /bulk/contracts/closed-balance/:
    get:
      summary: Get balances for a list of contract_ids
      parameters:
        - description: comma separated list of contract_ids
          name: contract_ids
          in: query
          required: false
          schema:
            type: string
        - description: comma separated list of account_ids
          name: account_ids
          in: query
          required: false
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/LedgerAccountContractCurrentBalanceBulk'

  /ledger-account/account/{account_id}/:
    get:
      deprecated: true
      summary: Get all of an account's ledger information, not paginated
      parameters:
      - description: id of the account
        name: account_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LedgerAccountList'

  /ledger-accounts/account/{account_id}/:
    get:
      summary: Get a paginated list of an account's ledger information
      parameters:
      - description: id of the account
        name: account_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    $ref: '#/components/schemas/LedgerAccountList'
                  total_count:
                    type: integer
                    example: 1

  /ledger-account/account/{account_id}/current-balance/:
    get:
      summary: Get an account's current balance
      parameters:
      - description: The id of the account
        name: account_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LedgerAccountCurrentBalance'

  /ledger-account/accounting-period/{accounting_period_id}/accounts/:
    get:
      deprecated: true
      summary: Get ledger_account records by accounting period id
      parameters:
        - description: id of an accounting period
          name: accounting_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: limit query parameter
          name: limit
          in: query
          required: false
          schema:
            type: integer
        - description: offset query parameter
          name: offset
          in: query
          required: false
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    type: integer
                    example: 1
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/LedgerAccountDetail'

  /ledger-account-contract/account/{account_id}/payable-balance/:
    get:
      summary: Get an account's payable balance
      description: An account's payable balance is the sum of all its positive contract balances
      parameters:
        - description: id of an account
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  account_id:
                    description: id of the specified account
                    example: 123
                    type: integer
                  currency_code:
                    description: ISO-3 currency code of balance
                    example: 'EUR'
                    type: string
                  payable_balance:
                    description: the account's payable balance, determined by summing up the child contracts' positive balances
                    example: '3000.00'
                    type: string

  /ledger-accounting-run-balance/{accounting_run_id}/bulk/:
    post:
      summary: Create an accounting run's summary
      description: Bulk create ledger_accounting_run_balance entries
      parameters:
        - description: id of an accounting run
          name: accounting_run_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Array of ledger_accounting_run_balance objects
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/LedgerAccountingRunBalancePost'
      responses:
        '201':
          description: POST success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/LedgerAccountingRunBalanceDetail'

  /ledger-accounting-run-balance/{accounting_run_id}/:
    get:
      summary: An accounting run's summary of royalty transactions
      description: Get ledger_accounting_run_balance records by accounting run id
      parameters:
        - description: id of an accounting run
          name: accounting_run_id
          in: path
          required: true
          schema:
            type: integer
        - description: limit query parameter
          name: limit
          in: query
          required: false
          schema:
            type: integer
        - description: offset query parameter
          name: offset
          in: query
          required: false
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    type: integer
                    example: 1
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/LedgerAccountingRunBalanceDetail'

  /ledger-accounting-run-balance/contract-count/dataloader:
    post:
      summary: Get contract count for multiple accounting runs (dataloader)
      description: >
        Retrieve the number of unique contracts per accounting run from ledger_accounting_run_balance.
        Requires a JSON body containing a list of accounting_run_ids.
      requestBody:
        description: List of accounting_run_id values to query
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    accounting_run_id:
                      type: integer
                      description: ID of the accounting run
                      example: 123
                    contract_count:
                      type: integer
                      description: Number of contracts linked to the accounting run
                      example: 5
        '403':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    example: ERROR_CODE_AUTHORIZATION
                  message:
                    type: string
                    example: Unauthorized

  /ledger-accounting-run-balance/accounting-period/{accounting_period_id}/vat-category/{vat_category}/:
    get:
      summary: An accounting run's summary of royalty transactions
      description: Get ledger_accounting_run_balance records by accounting period id and vat category
      parameters:
        - description: id of an accounting period
          name: accounting_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: category of VAT
          name: vat_category
          in: path
          required: true
          schema:
            type: string
        - description: limit query parameter
          name: limit
          in: query
          required: false
          schema:
            type: integer
        - description: offset query parameter
          name: offset
          in: query
          required: false
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    type: integer
                    example: 1
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/LedgerAccountingRunBalanceVatDetail'

  /ledger-accounting-run-vat/accounting-period/{accounting_period_id}/vat-category/{vat_category}/:
    get:
      summary: A list of leger accounting run vat for a specified accounting_period
      description: Get ledger_accounting_run_vat records by accounting period id and vat category
      parameters:
        - description: id of an accounting period
          name: accounting_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: category of VAT
          name: vat_category
          in: path
          required: true
          schema:
            type: string
        - description: country code query parameter
          name: country_code
          in: query
          required: false
          schema:
            type: string
        - description: limit query parameter
          name: limit
          in: query
          required: false
          schema:
            type: integer
        - description: offset query parameter
          name: offset
          in: query
          required: false
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    type: integer
                    example: 1
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/LedgerAccountingRunVatDetail'

  /ledger-accounting-run-vat/bulk/:
    post:
      summary: Bulk create ledger_accounting_run_vat entries
      requestBody:
        description: Array of ledger_accounting_run_vat objects
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/LedgerAccountingRunVatPost'
      responses:
        '201':
          description: POST success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/LedgerAccountingRunVatDetail'

  /ledger-accounting-run-vat/accounting-period/{accounting_period_id}/overview/:
    get:
      summary: Get overview for Ledger Accounting Run Vat
      description: Get count of ledger_accounting_run_vat records for a specific accounting_period grouped by VAT category and country of tax residence
      parameters:
        - description: The id of the accounting_period
          name: accounting_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/LedgerAccountingRunVatOverview'

  /ledger-adjustment/statement-period/{statement_period_id}/pending:
    get:
      description: Get a list of pending ledger_adjustment records by statement period id
      parameters:
        - description: id of an statement period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: limit query parameter
          name: limit
          in: query
          required: false
          schema:
            type: integer
        - description: offset query parameter
          name: offset
          in: query
          required: false
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    type: integer
                    example: 1
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/LedgerAdjustmentExtendedSchema'

  /ledger-adjustment-applied/bulk:
    post:
      summary: Bulk create ledger_adjustment_applied entries
      requestBody:
        description: List of ledger_adjustment_applied objects
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/LedgerAdjustmentAppliedPostSchema'
      responses:
        '201':
          description: POST success

  /ledger-adjustments/:
    get:
      description: Get a list of applied/pending adjustments.
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LedgerAdjustmentListSchema'

  /ledger-contract-advance-applied/{ledger_contract_advance_applied_id}/:
    get:
      description: GET a ledger_contract_advance_applied record by ID
      parameters:
        - description: ID of the ledger_contract_advance_applied record
          name: ledger_contract_advance_applied_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LedgerContractAdvanceAppliedDetail'

  /ledger-contract-advance-applied/contract-advance/{contract_advance_id}/:
    get:
      description: GET a ledger_contract_advance_applied record by parent contract_advance
      parameters:
        - description: ID of the parent contract_advance
          name: contract_advance_id
          in: path
          required: true
          schema:
              type: integer
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LedgerContractAdvanceAppliedDetail'
        404:
          description: does not exist
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: type of response
                    example: 'error'
                  message:
                    type: string
                    description: error message
                    example: Specified ledger_contract_advance_applied record does not exist

  /ledger-contract-advance-applied/contract-advance/{contract_advance_id}/paid:
    post:
      description: Create the ledger entries for a contract advance
      parameters:
        - description: id of the contract advance
          name: contract_advance_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: contract advance ledger details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LedgerContractAdvancePost'
      responses:
        '201':
          description: 201 Created

  /ledger-contract-advance-applied/worksheet/{worksheet_payment_contract_advance_id}/{entry_type}:
    get:
      summary: Endpoint to get ledger data by worksheet id
      parameters:
        - in: path
          name: worksheet_payment_contract_advance_id
          schema:
            type: integer
          required: true
          description: The ID of the worksheet payment contract advance
        - in: path
          name: entry_type
          schema:
            type: string
            enum: [debit, credit]
          required: true
          description: The type of the entry (debit or credit)
      responses:
        '200':
          description: success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LedgerContractAdvanceAppliedDetail'
        '400':
          description: Bad request
        '404':
          description: Not found

  /ledger-correction/bulk/:
      post:
        summary: Bulk create ledger_correction entries
        requestBody:
          description: List of ledger_correction objects
          required: true
          content:
            application/json:
              schema:
                type: array
                items:
                    $ref: '#/components/schemas/LedgerCorrectionPost'
        responses:
          '201':
            description: POST success
            content:
              application/json:
                schema:
                  type: array
                  items:
                    $ref: '#/components/schemas/LedgerCorrectionDetail'

  /ledger-reserve-release/bulk/:
      post:
        summary: Bulk create ledger_reserve_release entries
        requestBody:
          description: List of ledger_reserve_release objects
          required: true
          content:
            application/json:
              schema:
                type: array
                items:
                    $ref: '#/components/schemas/LedgerReserveReleasePost'
        responses:
          '201':
            description: POST success
            content:
              application/json:
                schema:
                  type: array
                  items:
                    $ref: '#/components/schemas/LedgerReserveReleaseDetail'

  /ledger-reserve-release-schedule/bulk/:
    post:
      description: Bulk create ledger_reserve_release_schedule entries
      requestBody:
        description: List of ledger_reserve_release_schedule objects
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/LedgerReserveReleaseSchedulePost'
      responses:
        '201':
          description: POST success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/LedgerReserveReleaseScheduleDetail'

  /ledger-reserve-release-schedule/statement-period/{statement_period_id}/release/:
    get:
      description: Get a list of ledger_reserve_release_schedule records by statement period id
      parameters:
        - description: id of an statement period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/LedgerReserveReleaseScheduleExtended'

  /ledger-reserve-taken/accounting-run/{accounting_run_id}/:
    get:
      description: Get a list of ledger_reserve_taken records by accounting run id
      parameters:
        - description: id of an accounting run
          name: accounting_run_id
          in: path
          required: true
          schema:
            type: integer
        - description: limit query parameter
          name: limit
          in: query
          required: false
          schema:
            type: integer
        - description: offset query parameter
          name: offset
          in: query
          required: false
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    type: integer
                    example: 1
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/LedgerReserveTakenDetailAccountContract'
    post:
      summary: Debit reserves from ledger_account for ledger_reserve_taken entries in the specified accounting_run.
      parameters:
        - description: id of an accounting run
          name: accounting_run_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '201':
          description: POST success

  /ledger-reserve-taken/bulk/:
    post:
      summary: Bulk create ledger_reserve_taken entries
      requestBody:
        description: List of ledger_reserve_taken objects
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/LedgerReserveTakenPost'
      responses:
        '201':
          description: POST success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/LedgerReserveTakenDetail'

  /reference-vat-rate/:
    get:
      summary: Get the reference list of vat rates
      description: Get all reference_vat_rates records without any limitations
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/ReferenceVatRateList'
                  total_count:
                    type: integer

  /reference-adjustment-types:
    get:
      description: Get a list of reference_adjustment_type records sorted by type_name
      parameters:
        - description: limit query parameter
          name: limit
          in: query
          required: false
          schema:
            type: integer
        - description: offset query parameter
          name: offset
          in: query
          required: false
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    type: integer
                    example: 1
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/ReferenceAdjustmentTypeDetailSchema'

  /reference-adjustment-types/{reference_adjustment_type_id}:
    get:
      description: Get a reference_adjustment_type record by id
      parameters:
        - description: id of an reference adjustment type
          name: reference_adjustment_type_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReferenceAdjustmentTypeDetailSchema'
  /ledger-vat-summary/statement-period/{statement_period_id}/event/{event_id}/bulk:
    post:
      summary: Create ledger vat summary
      description: Bulk create ledger_vat_summary entries
      parameters:
        - description: id of a statement period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: id of an event
          name: event_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Array of ledger_vat_summary objects
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/LedgerVatSummary'
      responses:
        '201':
          description: POST success

  /ledger-account-contracts/account/{account_id}/:
    get:
      summary: Get a paginated list of an account's ledger information
      parameters:
      - description: id of the account
        name: account_id
        in: path
        required: true
        schema:
          type: integer
      - description: string of contract IDs, separated by commas
        name: contract_ids
        in: query
        required: true
        schema:
          type: string
      - description: string of abacus event name, separated by commas
        name: event_names
        in: query
        required: true
        schema:
          type: string
      - description: string of statement period IDs, separated by commas
        name: statement_period_ids
        in: query
        required: true
        schema:
          type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    $ref: '#/components/schemas/LedgerContractAccountList'
                  total_count:
                    type: integer
                    example: 1

components:
  schemas:
    LedgerAccountList:
      type: object
      properties:
        ledger_account_id:
          type: number
          description: id of the ledger_account
        account_id:
          type: number
          description: id of the account
        accounting_period_id:
          type: string
          description: id of the accounting period
        amount:
          type: number
          description: amount to be credited/debited to the ledger
        contract_id:
          type: number
          description: id of the contract
        currency_code:
          type: string
          description: currency code
        currency_name:
          type: string
          description: name of the currency
        date:
          type: string
          description: start date of accounting run
        ending_balance:
          type: number
          description: current balance of a account (opening_balance + amount)
        opening_balance:
          type: number
          description: previous balance of the ledger account
        statement_period_id:
          type: integer
          description: ID of the statement period associated to the ledger entry's event
        transaction_type:
          type: string
          description: type of transaction
      example:
        ledger_account_id: 123
        account_id: 1
        accounting_period_id: 1100
        amount: '100.00'
        contract_id: 44
        currency_code: 'USD'
        currency_name: 'US Dollar'
        date: '2020-01-01'
        ending_balance: '100.00'
        opening_balance: '0.00'
        statement_period_id: 265
        transaction_type: 'accounting run'

    LedgerAccountCurrentBalance:
      type: object
      properties:
        currency_code:
          type: string
          description: code of the currency
        currency_name:
          type: string
          description: name of the currency
        current_balance:
          type: number
          description: current balance of an account
      example:
        currency_code: 'USD'
        currency_name: 'US Dollar'
        current_balance: '100.00'

    LedgerAccountContractCurrentBalance:
      type: object
      properties:
        currency_code:
          type: string
          description: code of the currency
        current_balance:
          type: number
          description: current balance of an account
      example:
        currency_code: 'USD'
        current_balance: '100.00'

    LedgerAccountCurrentBalanceBulk:
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerAccountCurrentBalance'
      properties:
        account_id:
          type: integer
          description: account's identifier
      example:
        account_id: 1

    LedgerAccountContractCurrentBalanceBulk:
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerAccountContractCurrentBalance'
      properties:
        ledger_account_contract_id:
          type: integer
          description: ledger's identifier
        account_id:
          type: integer
          description: account's identifier
        contract_id:
          type: integer
          description: contract's identifier
      example:
        ledger_account_contract_id: 1
        account_id: 1
        contract_id: 1

    LedgerAccountDetail:
      type: object
      properties:
        ledger_account_id:
          type: integer
          description: ledger account identifier
        abacus_event_id:
          type: integer
          description: abacus_event's identifier
        account_id:
          type: integer
          description: account's identifier
        contract_id:
          type: integer
          description: contract's identifier
        currency_amount:
          type: number
          description: amount applied to account's ledger -- can be positive or negative
        currency_code:
          type: string
          description: iso-standard currency code of currency_amount
        current_balance:
          type: number
          description: account's current balance (currency_amount + previous_balance)
        note:
          type: string
          description: a short note about the ledger
        previous_balance:
          type: number
          description: account's previous balance
      required:
        - ledger_account_id
        - abacus_event_id
        - account_id
        - currency_amount
        - currency_code
        - current_balance
        - previous_balance
      example:
        ledger_account_id: 1
        abacus_event_id: 10
        account_id: 123
        contract_id: 44
        currency_amount: '100.00'
        currency_code: 'USD'
        current_balance: '500.00'
        previous_balance: '400.00'

    LedgerAccountingRunBalancePost:
      type: object
      properties:
        abacus_event_id:
          type: integer
          description: id of the related abacus event
        adjusted_net_revenue:
          type: number
          description: total royalties for the contract after fees
            (total_net - total_adjustment - mech_deduction - mech_deduction_fees)
        contract_id:
          type: integer
          description: id of the related contract
        currency_code:
          type: string
          description: iso-standard currency code
        distribution_fee:
          type: number
          description: fee charged to account for distribution
            (total_gross_revenue_amount - total_net_revenue_amount)
        mechanical_deduction_admin_fee_total:
          type: number
          description: total amount of mechanical deduction admin fees for contract
        mechanical_deduction_total:
          type: number
          description: total amount of mechanical deductions for contract
        total_gross_revenue_amount:
          type: number
          description: total royalty amount before adjustments, deductions, and fees
        total_net_revenue_amount:
          type: number
          description: total royalty amount after adjustments, deductions, and fees
      required:
        - abacus_event_id
        - adjusted_net_revenue
        - contract_id
        - currency_code
        - distribution_fee
        - total_gross_revenue_amount
        - total_net_revenue_amount
      example:
        abacus_event_id: 1
        adjusted_net_revenue: '20.00'
        contract_id: 44
        currency_code: 'USD'
        distribution_fee: '130.00'
        mechanical_deduction_admin_fee_total: '10.00'
        mechanical_deduction_total: '40.00'
        total_gross_revenue_amount: '200.00'
        total_net_revenue_amount: '70.00'

    LedgerAccountingRunBalanceDetail:
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerAccountingRunBalancePost'
      properties:
        ledger_accounting_run_balance_id:
          type: integer
          description: id of the object
        account_id:
          type: integer
          description: id of the account for which the contract royalties were calculated
        account_name:
          type: string
          description: name of the account for which the contract royalties were calculated
        accounting_run_id:
          type: integer
          description: id of the related accounting_run
        contract_name:
          type: integer
          description: name of the contract for which royalties were calculated
      required:
        - ledger_accounting_run_balance_id
        - accounting_run_id
      example:
        ledger_accounting_run_balance_id: 1
        abacus_event_id: 1
        account_id: 123
        account_name: 'Account 123'
        accounting_run_id: 1
        adjusted_net_revenue: '-30.00'
        contract_id: 44
        contract_name: 'Contract 44'
        currency_code: 'USD'
        distribution_fee: '130.00'
        mechanical_deduction_admin_fee_total: '10.00'
        mechanical_deduction_total: '40.00'
        total_gross_revenue_amount: '200.00'
        total_net_revenue_amount: '70.00'

    LedgerAccountPost:
      type: object
      properties:
        abacus_event_id:
          type: integer
          description: id of the related abacus event
        account_id:
          type: integer
          description: an account id
        contract_id:
          type: integer
          description: a contract id (belonging to the account_id)
        currency_amount:
          type: number
          description: amount credited or debited from ledger
        currency_code:
          type: string
          description: iso-standard currency code of currency_amount
        model_type:
          type: string
          description: Must be 'account'
      required:
        - abacus_event_id
        - account_id
        - currency_amount
        - currency_code
        - model_type
      example:
        abacus_event_id: 1
        account_id: 123
        contract_id: 44
        currency_amount: 100.50
        currency_code: 'CAD'
        model_type: 'account'

    LedgerDepositPost:
      type: object
      properties:
        abacus_event_id:
          type: integer
          description: id of the related abacus event -- should have a corresponding record in ledger_account
        account_id:
          type: integer
          description: an account id
        contract_id:
          type: integer
          description: a contract id (belonging to the account_id)
        currency_code:
          type: string
          description: iso-standard currency code of currency_amount
        model_type:
          type: string
          description: Must be 'deposit'
        remaining_amount:
          type: number
          description: remainder of the a ledger_account's currency_amount after rounding
        rounded_amount:
          type: number
          description: rounded ledger_account's currency_amount to two decimal places
      required:
        - abacus_event_id
        - account_id
        - contract_id
        - currency_code
        - model_type
        - remaining_amount
        - rounded_amount
      example:
        abacus_event_id: 1
        account_id: 123
        contract_id: 44
        currency_code: 'CAD'
        model_type: 'deposit'
        remaining_amount: 0.003456
        rounded_amount: 100.12

    LedgerAccountingRunVatOverview:
      type: object
      properties:
        vat_category:
          type: string
          description: shows the VAT category - VAT applied or VAT exempt
        country_of_tax_residence:
          type: string
          description: country code defining the tax residence. Null if vat_category is "VAT exempt"
        contract_count:
          type: integer
          description: count of contracts
      example:
        vat_category: 'vat_applied'
        country_of_tax_residence: 'GBR'
        contract_count: 123

    LedgerAccountingRunVatPost:
      type: object
      properties:
        accounting_run_id:
          type: integer
          description: id of the related accounting run
        abacus_event_id:
          type: integer
          description: id of the related abacus event
        contract_id:
          type: integer
          description: id of the related contract
        currency_code:
          type: string
          description: iso-standard currency code
        country_of_tax_residence:
          type: string
          description: country code defining the tax residence
        gross_revenue:
          type: number
          description: gross revenue for the ledger accounting run vat
        net_revenue:
          type: number
          description: net revenue for the ledger accounting run vat
        distribution_fee:
          type: number
          description: The difference between gross and net revenue
        gross_vat_rate:
          type: number
          description: gross vat rate
        distribution_vat_rate:
          type: number
          description: distribution vat rate
        gross_vat:
          type: number
          description: gross revenue * tax rate
        distribution_vat:
          type: number
          description: distribution fee * tax rate
        adjusted_net_revenue:
          type: number
          description: adjusted net revenue for the ledger accounting run vat
        exempt_reason:
          type: number
          description: vat exempt reason
      required:
        - accounting_run_id
        - abacus_event_id
        - contract_id
        - currency_code
        - country_of_tax_residence
      example:
        accounting_run_id: 1
        abacus_event_id: 1
        contract_id: 44
        currency_code: 'GBP'
        country_of_tax_residence: 'GBR'
        gross_revenue: '200.00'
        net_revenue: '100.00'
        distribution_fee: '50.00'
        gross_vat_rate: '20.00'
        distribution_vat_rate: '20.00'
        gross_vat: '40.00'
        distribution_vat: '10.00'
        adjusted_net_revenue: '10.00'

    LedgerAccountingRunVatDetail:
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerAccountingRunVatPost'
      properties:
        ledger_accounting_run_vat_id:
          type: integer
          description: id of the ledger accounting run vat
      example:
        ledger_accounting_run_vat_id: 1

    LedgerAccountingRunBalanceVatDetail:
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerAccountingRunBalanceDetail'
      properties:
        country_of_tax_residence:
          type: string
          description: country code defining the tax residence
        payment_entity_id:
          type: integer
          description: ID of the reference_payment_entity
        is_vat_exempt:
          type: boolean
          description: confirms whether VAT is exempted or not
      required:
        - country_of_tax_residence
        - payment_entity_id
        - is_vat_exempt
      example:
        country_of_tax_residence: 'USA'
        payment_entity_id: 1
        is_vat_exempt: 1

    LedgerAdjustmentAppliedPostSchema:
      type: object
      properties:
        abacus_event_id:
          type: integer
          description: id (fk) of the corresponding abacus event
        account_id:
          type: integer
          description: id (fk) of the corresponding abacus account
        contract_id:
          type: integer
          description: id (fk) of the corresponding abacus contract
        statement_period_id:
          type: integer
          description: id (fk) of the corresponding statement period
        ledger_adjustment_id:
          type: integer
          description: id (fk) of the corresponding ledger adjustment
        worksheet_adjustment_id:
          type: integer
          description: id (fk) of the corresponding worksheet adjustment
        adjustment_amount:
          type: number
          description: total amount of adjustments
        adjustment_currency_code:
          type: string
          description: iso-standard of adjustment's currency code
        adjustment_amount_payee_currency:
          type: number
          description: total amount of adjustments in payee's currency
        adjustment_payee_currency_code:
          type: string
          description: iso-standard of payee's currency code
      example:
        abacus_event_id: 1
        account_id: 1
        contract_id: 1
        statement_period_id: 1
        ledger_adjustment_id: 1
        worksheet_adjustment_id: 1
        adjustment_amount: '1500.00'
        adjustment_currency_code: 'USD'
        adjustment_amount_payee_currency: '1362.20'
        adjustment_payee_currency_code: 'GBP'

    LedgerAdjustmentExtendedSchema:
      title: LedgerAdjustmentDetail
      type: object
      properties:
        ledger_adjustment_id:
          type: integer
          description: id (pk) of the ledger adjustment
        abacus_event_id:
          type: integer
          description: id (fk) of the corresponding abacus event
        account_id:
          type: integer
          description: id (fk) of the corresponding abacus account
        contract_id:
          type: integer
          description: id (fk) of the corresponding abacus contract
        activity_statement_period_id:
          type: integer
          description: id (fk) of the statement period, when adjustment took place
        apply_to_statement_period_id:
          type: integer
          description: id (fk) of the statement period to apply adjustment to
        reference_adjustment_type_id:
          type: integer
          description: id (fk) of the corresponding reference adjustment type
        adjustment_amount:
          type: number
          description: total amount of adjustments
        adjustment_currency_code:
          type: string
          description: iso-standard of adjustment's currency code
        account_currency_code:
          type: string
          description: iso-standard of the associated account's currency code
        note:
          type: string
          description: optional text note
        details:
          type: array
          items:
            $ref: '#/components/schemas/LedgerAdjustmentDetailSchema'
      example:
        ledger_adjustment_id: 1
        abacus_event_id: 1
        account_id: 1
        contract_id: 1
        activity_statement_period_id: 1
        apply_to_statement_period_id: 2
        reference_adjustment_type_id: 1
        adjustment_amount: '125.42'
        adjustment_currency_code: 'USD'
        note: 'informative message'
        details: []

    LedgerAdjustmentDetailSchema:
      title: LedgerAdjustmentDetail
      type: object
      properties:
        ledger_adjustment_detail_id:
          type: integer
          description: id (pk) of the ledger adjustment detail
        account_id:
          type: integer
          description: id (fk) of the corresponding abacus account
        contract_id:
          type: integer
          description: id (fk) of the corresponding abacus contract
        activity_statement_period_id:
          type: integer
          description: id (fk) of the statement period, when adjustment took place
        apply_to_statement_period_id:
          type: integer
          description: id (fk) of the statement period to apply adjustment to
        reference_adjustment_type_id:
          type: integer
          description: id (fk) of the corresponding reference adjustment type
        currency_code:
          type: string
          description: iso-standard of adjustment's currency code
        amount:
          type: number
          description: amount of adjustment
        upc:
          type: string
          description: upc
        distribution_type:
          type: string
          description: distribution_type
        note:
          type: string
          description: optional text note
      example:
        ledger_adjustment_detail_id: 1
        account_id: 1
        contract_id: 1
        activity_statement_period_id: 1
        apply_to_statement_period_id: 2
        reference_adjustment_type_id: 1
        currency_code: 'USD'
        amount: '125.42'
        upc: '555444333222111'
        distribution_type: 'digital'
        note: 'informative message'

    LedgerAdjustmentListSchema:
        type: object
        properties:
          ledger_adjustment_id:
            type: integer
            description: id of the ledger adjustment
          adjustment_ledger_status:
            type: string
            description: either "Applied" or "Pending"
          account_id:
            type: integer
            description: id of the corresponding abacus account
          contract_id:
            type: integer
            description: id of the corresponding abacus contract
          activity_statement_period_id:
            type: integer
            description: id of the statement period, when adjustment took place
          apply_to_statement_period_id:
            type: integer
            description: id  of the statement period to apply adjustment to
          adjustment_type:
            type: string
            description: type of adjustment
          adjustment_amount:
            type: number
            description: total amount of adjustments
          adjustment_currency_code:
            type: string
            description: iso-standard of adjustment's currency code
          note:
            type: string
            description: optional text note
        example:
          ledger_adjustment_id: 1
          adjustment_ledger_status: 'Pending'
          account_id: 1
          contract_id: 1
          activity_statement_period_id: 1
          apply_to_statement_period_id: 2
          adjustment_type: 'Admin Fees'
          adjustment_amount: '125.42'
          adjustment_currency_code: 'USD'
          note: 'informative message'

    LedgerContractAdvanceAppliedDetail:
        title: LedgerContractAdvanceApplied detail fields
        type: object
        properties:
          ledger_contract_advance_applied_id:
              type: number
              description: ID of the ledger_contract_advance_applied record
          abacus_event_id:
              type: number
              description: ID of the related abacus_event
          account_id:
              type: number
              description: ID of the related account
          contract_id:
              type: number
              description: ID of the related contract
          contract_advance_id:
              type: number
              description: ID of the contract_advance
          statement_period_id:
              type: number
              description: ID of the related statement_period_id in which the advance is being applied
          worksheet_payment_contract_advance_id:
            type: number
            description: worksheet ID
          advance_amount:
              type: number
              description: amount of the advance
          advance_currency_code:
              type: string
              description: Alpha-3 iso currency code of the advance_amount
          advance_amount_payee_currency:
              type: number
              description: amount of the advance converted into the account's payment currency
          advance_payee_currency_code:
              type: string
              description: Alpha-3 iso currency code of the account's payment currency
          vat_amount:
              type: number
              description: amount of VAT applied to the advance_amount in the advance_currency
          vat_amount_payee_currency:
              type: number
              description: amount of VAT applied converted into the account's payment currency
          withholding_tax_amount:
              type: number
              description: amount of withholding tax applied to the advance_amount in the advance_currency
          withholding_tax_amount_payee_currency:
              type: number
              description: amount of withholding tax converted into the account's payment currency
          amount_after_withholding_and_vat:
              type: number
              description: the advance_amount after applying VAT and withholding tax
          amount_after_withholding_and_vat_payee_currency:
              type: number
              description: the advance_amount after applying VAT and withholding tax, all in the account's payment currency
          us_source_income_rate:
              type: number
              description: exists for audit purposes; unrelated to the calculation of applying an advance
          exchange_rate:
            type: string
            description: rate to convert an advance amount from one currency to another
        required:
            - ledger_contract_advance_applied_id
            - abacus_event_id
            - account_id
            - contract_id
            - contract_advance_id
            - statement_period_id
            - advance_amount
            - advance_currency_code
            - advance_amount_payee_currency
            - advance_payee_currency_code
        example:
            ledger_contract_advance_applied_id: 1
            abacus_event_id: 1
            account_id: 1
            contract_id: 1
            contract_advance_id: 1
            statement_period_id: 300
            advance_amount: -100.90
            advance_currency_code: 'AUD'
            advance_amount_payee_currency: -100.90
            account_payment_currency_code: 'AUD'
            vat_amount: -10.00
            vat_amount_payee_currency: -10.00
            withholding_tax_amount: 10.00
            withholding_tax_amount_payee_currency: 10.00
            amount_after_withholding_and_vat: -100.90
            amount_after_withholding_and_vat_payee_currency: -100.90
            us_source_income_rate: 99.00
            worksheet_payment_contract_advance_id: 1
            exchange_rate: 1.0001

    LedgerContractAdvancePost:
        title:  LedgerContractAdvance POST request fields
        type: object
        properties:
          abacus_event_id:
            type: number
            description: id of the related abacus_event
          account_id:
            type: number
            description: id of the related account
          contract_id:
            type: number
            description: id of the related contract
          statement_period_id:
            type: number
            description: id of the related statement period for the Date Paid
          advance_amount:
            type: number
            description:  currency amount of the advance
          advance_currency_code:
            type: string
            description: Alpha-3 iso currency code
          account_payment_currency_code:
            type: string
            description: Alpha-3 iso currency code. account's payment currency
          exchange_rate:
            type: string
            description: rate to convert an advance amount from one currency to another
          vat_amount:
            type: number
            description: VAT amount
          withholding_tax_amount:
            type: number
            description: withholding tax amount
          amount_after_withholding_and_vat:
            type: number
            description: amount after withholding and VAT
          us_source_income_rate:
            type: number
            description: US source income rate
          worksheet_payment_contract_advance_id:
            type: number
            description: worksheet ID
          advance_amount_payee_currency:
            type: number
            description: amount of the advance in payee currency
          amount_after_withholding_and_vat_payee_currency:
            type: number
            description: amount after withholding and VAT in payee currency
          withholding_tax_amount_payee_currency:
            type: number
            description: withholding tax amount in payee currency
          vat_amount_payee_currency:
            type: number
            description: VAT amount in payee currency
        required:
          - abacus_event_id
          - account_id
          - contract_id
          - statement_period_id
          - advance_amount
          - advance_currency_code
          - account_payment_currency_code
        example:
          abacus_event_id: 1
          account_id: 1
          contract_id: 1
          statement_period_id: 1
          advance_amount: -100.90
          advance_currency_code : 'AUD'
          account_payment_currency_code: 'AUD'
          vat_amount: -10.00
          withholding_tax_amount: 10.00
          amount_after_withholding_and_vat: -100.90
          us_source_income_rate: 99.00

    LedgerCorrectionPost:
      title: ledger_correction POST request body
      type: object
      properties:
        abacus_event_id:
          type: integer
          description: id (fk) of the corresponding abacus event
        worksheet_correction_id:
          type: integer
          description: id (pk) of the corresponding worksheet correction
        account_id:
          type: integer
          description: id (fk) of the corresponding abacus account
        contract_id:
          type: integer
          description: id (fk) of the corresponding abacus contract
        statement_period_id:
          type: integer
          description: id (fk) of the statement period
        correction_statement_period_id:
          type: integer
          description: id (fk) of the statement period
        correction_type:
          type: string
          description: either royalty_reversal or royalty_correction
        currency_code:
          type: string
          description: iso-standard currency code
        gross_revenue:
          type: number
          description: the gross revenue of the correction
        distribution_fee:
          type: number
          description: the fee to be applied to the gross revenue of the correction
        mechanical_deduction_admin_fee_total:
          type: number
          description: total amount of mechanical deduction admin fees for contract
        mechanical_deduction_total:
          type: number
          description: total amount of mechanical deductions for contract
        net_revenue:
          type: number
          description: the net amount of the correction after fees
        note:
          type: string
          description: optional text note
      example:
        abacus_event_id: 1
        worksheet_correction_id: 1
        account_id: 1
        contract_id: 1
        statement_period_id: 1
        correction_statement_period_id: 2
        correction_type: 'royalty_reversal'
        currency_code: 'USD'
        gross_revenue: '150.42'
        mechanical_deduction_admin_fee_total: '10.00'
        mechanical_deduction_total: '40.00'
        distribution_fee: '-25.00'
        net_revenue: '125.42'
        note: 'informative message'

    LedgerCorrectionDetail:
      title: ledger_correction detail
      allOf:
        - $ref: '#/components/schemas/LedgerCorrectionPost'
      properties:
        ledger_correction_id:
          type: integer
          description: ID of the ledger_correction record
      example:
        ledger_correction_id: 1
        abacus_event_id: 1
        worksheet_correction_id: 1
        account_id: 1
        contract_id: 1
        statement_period_id: 1
        correction_statement_period_id: 2
        correction_type: 'royalty_reversal'
        currency_code: 'USD'
        gross_revenue: '150.42'
        distribution_fee: '-25.00'
        mechanical_deduction_admin_fee_total: '10.00'
        mechanical_deduction_total: '40.00'
        net_revenue: '125.42'
        note: 'informative message'

    LedgerVatSummary:
      title: LedgerVatSummary
      description: Used to bulk create ledger_vat_summary records
      type: object
      properties:
        account_id:
          type: integer
          description: id of the related account
        contract_id:
          type: integer
          description: id of the related contract
        vat_category:
          type: string
          description: category name (closing_balance, commission, distribution_fee or gross_revenue)
        payee_currency_code:
          type: string
          description: iso-standard payoneer currency code
        vat_currency_code:
          type: string
          description: iso-standard vat currency code
        base_amount_payee_currency:
          type: number
          description: base amount of the payee currency
        vat_rate:
          type: number
          description: amount of the vat rate
        vat_amount_payee_currency:
          type: number
          description: vat amount payee currency
        vat_amount_vat_currency:
          type: number
          description: vat amount vat currency
        wht_rate:
          type: number
          description: wht rate
        wht_amount_payee_currency:
          type: number
          description: wht amount payee currency
        wht_amount_vat_currency:
          type: number
          description: wht amount vat currency
        net_amount_payee_currency:
          type: number
          description: net amount vat currency
        abacus_exempt_reason:
          type: string
          description: reason text
        description:
          type: string
          description: description of entry
      required:
        - account_id
        - contract_id
        - vat_category
        - payee_currency_code
        - vat_currency_code
        - base_amount_payee_currency
        - vat_rate
        - vat_amount_payee_currency
        - vat_amount_vat_currency
        - net_amount_payee_currency
      example:
          account_id: 1
          contract_id: 1
          vat_category: 'closing_balances'
          payee_currency_code: 'USD'
          vat_currency_code: 'GBP'
          base_amount_payee_currency: '100.00'
          vat_rate: '20.00'
          vat_amount_payee_currency: '80.00'
          vat_amount_vat_currency: '63.71'
          net_amount_payee_currency: '180.00'
          abacus_exempt_reason: None
          description: None

    LedgerReserveReleasePost:
      title: LedgerReserveReleasePost
      description: Used to bulk create ledger_reserve_release records
      type: object
      properties:
        abacus_event_id:
          type: integer
          description: id of the related abacus event
        statement_period_id:
          type: integer
          description: id of the statement period within which reserves are released
        ledger_reserve_release_schedule_id:
          type: integer
          description: id of the parent ledger_reserve_release_schedule record
        installment_amount:
          type: number
          description: amount of reserve to release -- should be positive and match the installment_amount of the parent ledger_reserve_release_schedule record
      required:
        - abacus_event_id
        - statement_period_id
        - ledger_reserve_release_schedule_id
        - installment_amount
      example:
        abacus_event_id: 2
        ledger_reserve_release_schedule_id: 1
        statement_period_id: 2
        installment_amount: '1500.11'

    LedgerReserveReleaseDetail:
      title: LedgerReserveReleaseDetail
      allOf:
        - $ref: '#/components/schemas/LedgerReserveReleasePost'
      properties:
        ledger_reserve_release_id:
          type: integer
          description: ID of the ledger_reserve_release record
      example:
        ledger_reserve_release_id: 1
        abacus_event_id: 2
        ledger_reserve_release_schedule_id: 1
        statement_period_id: 2
        installment_amount: '1500.11'

    LedgerReserveReleaseSchedulePost:
      title: LedgerReserveReleaseSchedulePost
      description: Used to bulk create ledger_reserve_release_schedule records
      type: object
      properties:
        abacus_event_id:
          type: integer
          description: id of the related abacus event
        account_id:
          type: integer
          description: id of the related account
        taken_statement_period_id:
          type: integer
          description: id of the taken statement period
        release_statement_period_id:
          type: integer
          description: id of the related release statement period
        ledger_reserve_taken_id:
          type: integer
          description: id of the related ledger_reserve_taken entry
        currency_code:
          type: string
          description: iso-standard currency code
        installment_amount:
          type: number
          description: total amount for the release, expected to be negative
        outstanding_amount_after_installment:
          type: number
          description: outstanding amount after installment deduction, expected to be negative
        early_release_date:
          type: string
          description: if not null, indicates that reserves were released early on the specified date
      required:
        - abacus_event_id
        - account_id
        - taken_statement_period_id
        - release_statement_period_id
        - ledger_reserve_taken_id
        - currency_code
        - installment_amount
        - outstanding_amount_after_installment
      example:
        abacus_event_id: 1
        account_id: 1
        taken_statement_period_id: 1
        release_statement_period_id: 2
        ledger_reserve_taken_id: 1
        currency_code: 'USD'
        installment_amount: '-1500.11'
        outstanding_amount_after_installment: '-2100.01'
        early_release_date: null

    LedgerReserveReleaseScheduleDetail:
      title: LedgerReserveReleaseScheduleDetail
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerReserveReleaseSchedulePost'
      properties:
        ledger_reserve_release_schedule_id:
          type: integer
          description: id (pk) of the ledger reserve release schedule
      required:
        - ledger_reserve_release_schedule_id
        - abacus_event_id
        - account_id
        - taken_statement_period_id
        - release_statement_period_id
        - ledger_reserve_taken_id
        - currency_code
        - installment_amount
        - outstanding_amount_after_installment
      example:
        ledger_reserve_release_schedule_id: 1
        abacus_event_id: 1
        account_id: 1
        taken_statement_period_id: 1
        release_statement_period_id: 2
        ledger_reserve_taken_id: 1
        currency_code: 'USD'
        installment_amount: '-1500.11'
        outstanding_amount_after_installment: '-2100.01'
        early_release_date: null

    LedgerReserveReleaseScheduleExtended:
      title: LedgerReserveReleaseScheduleExtended
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerReserveReleaseScheduleDetail'
        - type: object
          properties:
            contract_id:
              type: integer
              description: id of the related contract
      example:
        ledger_reserve_release_schedule_id: 1
        abacus_event_id: 1
        account_id: 1
        taken_statement_period_id: 1
        release_statement_period_id: 2
        ledger_reserve_taken_id: 1
        currency_code: 'USD'
        installment_amount: '-1500.11'
        outstanding_amount_after_installment: '-2100.01'
        contract_id: 1
        early_release_date: null

    LedgerReserveTakenPost:
      title: LedgerReserveTakenPost
      description: Used to bulk create ledger_reserve_taken records
      type: object
      properties:
        abacus_event_id:
          type: integer
          description: id of the related abacus event
        contract_reserve_id:
          type: integer
          description: id of the related contract reserve
        accounting_run_id:
          type: integer
          description: id of the related accounting run
        statement_period_id:
          type: integer
          description: id of the related statement period
        currency_code:
          type: string
          description: iso-standard currency code
        gross_sales:
          type: number
          description: total amount of sales without any deduction
        gross_returns:
          type: number
          description: total amount of returns without any deduction -- the value expected to be negative.
        net_revenue:
          type: number
          description: sum of gross_sales and gross_returns
        reserve_amount:
          type: number
          description: amount reserve before they are paid out to label/artist -- the value expected to be negative.
        net_revenue_after_reserve:
          type: number
          description: difference between net_revenue and reserve_amount
      required:
        - abacus_event_id
        - contract_reserve_id
        - accounting_run_id
        - statement_period_id
        - currency_code
        - gross_sales
        - gross_returns
        - net_revenue
        - reserve_amount
        - net_revenue_after_reserve
      example:
        abacus_event_id: 1
        contract_reserve_id: 1
        accounting_run_id: 1
        statement_period_id: 1
        currency_code: 'USD'
        gross_sales: '100.00'
        gross_returns: '-50.00'
        net_revenue: '150.00'
        reserve_amount: '-60.00'
        net_revenue_after_reserve: '90.00'

    LedgerReserveTakenDetail:
      title: LedgerReserveTakenDetail
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerReserveTakenPost'
      properties:
        ledger_reserve_taken_id:
          type: integer
          description: id of the ledger_reserve_taken record
      example:
        ledger_reserve_taken_id: 1
        abacus_event_id: 1
        contract_reserve_id: 1
        accounting_run_id: 1
        statement_period_id: 1
        currency_code: 'USD'
        gross_sales: '100.00'
        gross_returns: '-50.00'
        net_revenue: '150.00'
        reserve_amount: '-60.00'
        net_revenue_after_reserve: '90.00'

    LedgerReserveTakenDetailAccountContract:
      title: LedgerReserveTakenDetailAccountContract
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerReserveTakenDetail'
        - type: object
          properties:
            contract_id:
              type: integer
              description: id of the related contract
            account_id:
              type: integer
              description: id of the related account
      example:
        ledger_reserve_taken_id: 1
        abacus_event_id: 1
        contract_reserve_id: 1
        accounting_run_id: 1
        statement_period_id: 1
        currency_code: 'USD'
        gross_sales: '100.00'
        gross_returns: '-50.00'
        net_revenue: '150.00'
        reserve_amount: '-60.00'
        net_revenue_after_reserve: '90.00'
        contract_id: 1
        account_id: 1

    ReferenceAdjustmentTypeDetailSchema:
      title: ReferenceAdjustmentTypeDetail
      description: This table is a copy of the manual_adjustment_category table in art_relations.
      type: object
      properties:
        reference_adjustment_type_id:
          type: integer
          description: id (pk) of the reference adjustment type id
        type_name:
          type: string
          description: adjustment type name
        oa_category_name:
          type: string
          description: corresponding adjustment type name in legacy system
      example:
        reference_adjustment_type_id: 1
        type_name: 'Account Expense'
        oa_category_name: 'Vendor Expense'

    ReferenceVatRateList:
      type: object
      properties:
        reference_vat_rate_id:
          type: integer
          description: id of reference vat rate
        country_of_tax_residence:
          type: string
          description: country code defining the tax residence
        country_of_tax_policy:
          type: string
          description: country code defining the country of tax policy
        effective_date:
          type: string
          description: effective date
        tax_rate:
          type: number
          description: an amount of tax value
        is_sba_signed:
          type: boolean
          description: confirms whether VAT Self-Billing Agreement was signed or not
        is_tax_applicable:
          type: boolean
          description: confirms whether tax is applicable relating to country
        is_vat_registered_in_country_of_tax_policy:
          type: boolean
          description: is vat registered in country of tax policy
        transaction_type:
          type: string
          description: a comma separated list of transactions where VAT should be calculated
        vat_type:
          type: string
          description: shows the VAT role - supplier or client
      example:
        reference_vat_rate_id: 2
        effective_date: '2002-05-10'
        tax_rate: '19.00'
        country_of_tax_residence: 'GBR'
        country_of_tax_policy: 'GBR'
        is_tax_applicable: true
        vat_type: 'supplier'
        is_sba_signed: true
        is_vat_registered_in_country_of_tax_policy: true
        transaction_type: ['SP', 'RF']

    LedgerContractAccountList:
      title: ledger contract account detail
      type: object
      properties:
        ledger_account_contract_id:
          type: number
          description: id of the ledger_account
        account_id:
          type: number
          description: id of the account
        accounting_period_id:
          type: string
          description: id of the accounting period
        amount:
          type: number
          description: amount to be credited/debited to the ledger
        contract_id:
          type: number
          description: id of the contract
        currency_code:
          type: string
          description: currency code
        date:
          type: string
          description: start date of accounting run
        ending_balance:
          type: number
          description: current balance of a account (opening_balance + amount)
        opening_balance:
          type: number
          description: previous balance of the ledger account
        statement_period_id:
          type: integer
          description: ID of the statement period associated to the ledger entry's event
        transaction_type:
          type: string
          description: type of transaction
      example:
        ledger_account_contract_id: 123
        account_id: 1
        accounting_period_id: 1100
        amount: '100.00'
        contract_id: 44
        currency_code: 'USD'
        date: '2020-01-01'
        ending_balance: '100.00'
        opening_balance: '0.00'
        statement_period_id: 265
        transaction_type: 'accounting run'

    LedgerContractFlowthroughPost:
      type: object
      allOf:
        - $ref: '#/components/schemas/LedgerAccountPost'
      required:
        - abacus_event_id
        - account_id
        - currency_amount
        - currency_code
        - model_type
      example:
        abacus_event_id: 1
        account_id: 123
        contract_id: 44
        currency_amount: 100.50
        currency_code: 'USD'
        model_type: 'contract'
