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

# Gider pusulası ön hesaplama

> Gider pusulası oluşturulmadan önce kalemi (miktar, birim fiyat, mahiyet) ve müşteri bilgisini hesaplar. **Hiçbir yan etkisi yoktur:** kayıt oluşmaz, seri-sıra numarası tüketilmez. `source: "bankTransaction"` kullanıldığında hareketin bağlı olduğu banka hesabı aktif olmalıdır; pasif hesap `409 BANK_ACCOUNT_INACTIVE` döndürür. Gövde `POST /v1/expenses` ile aynıdır; yalnız `isDraft` ve `allowDuplicate` kullanılamaz.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/expenses/preview
openapi: 3.0.3
info:
  title: SarrafPro API v1
  version: 1.0.0
  description: >-
    SarrafPro sürümlü dış API yüzeyi. Cari hesaplar, uyum kayıtları, banka
    hesapları ve hareketleri okunabilir; fatura ve gider pusulası oluşturulup
    gönderilebilir; KMTS etiket/işaret kodları sorgulanabilir. Kimlik doğrulama
    HTTP Basic'tir: base64(apiUserId:secretKey). Tüm yanıtlar sabit zarf
    formatındadır: başarılı yanıtta success/data/meta, hatalı yanıtta
    success/error{code,message,details}/traceId. Her yanıtta x-request-id
    başlığı döner ve traceId ile aynıdır.
servers:
  - url: https://api.sarraf.pro
    description: Canlı ortam
security:
  - BasicAuth: []
tags:
  - name: Customers
    description: >-
      Cari hesaplar ve uyum — listeleme, detay, müşteri tanı oluşturma,
      kayıt/sicil sorgusu, tanı formları, kimlik belgeleri, yaptırım sorguları
      ve sicil geçmişi
    x-group: Müşteriler
  - name: Bank accounts
    description: Banka hesapları, bakiyeler ve sorgu tetikleme
    x-group: Banka
  - name: Bank transactions
    description: Gelen/giden banka hareketleri — detayda gömülü MASAK özeti
    x-group: Banka
  - name: Invoices
    description: Fatura oluşturma ve gönderimi, kesilen faturalar ve kalem şablonları
    x-group: Faturalar
  - name: Expenses
    description: Gider pusulası oluşturma, kesinleştirme ve kayıtlar
    x-group: Giderler
  - name: KMTS
    description: KMTS güvenlikli etiket/işaret doğrulaması ve firma sorgu geçmişi
    x-group: KMTS
paths:
  /v1/expenses/preview:
    post:
      tags:
        - Expenses
      summary: Gider pusulası ön hesaplama
      description: >-
        Gider pusulası oluşturulmadan önce kalemi (miktar, birim fiyat, mahiyet)
        ve müşteri bilgisini hesaplar. **Hiçbir yan etkisi yoktur:** kayıt
        oluşmaz, seri-sıra numarası tüketilmez. `source: "bankTransaction"`
        kullanıldığında hareketin bağlı olduğu banka hesabı aktif olmalıdır;
        pasif hesap `409 BANK_ACCOUNT_INACTIVE` döndürür. Gövde `POST
        /v1/expenses` ile aynıdır; yalnız `isDraft` ve `allowDuplicate`
        kullanılamaz.
      operationId: previewExpense
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExpensePreviewRequest'
      responses:
        '200':
          description: Hesaplama sonucu.
          headers:
            x-request-id:
              description: İstek kimliği; yanıt gövdesindeki meta.requestId ile aynıdır.
              schema:
                type: string
                format: uuid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExpensePreviewResponse'
        '400':
          $ref: '#/components/responses/ValidationFailed'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: >-
            Banka hareketi pasif hesaba bağlı (`BANK_ACCOUNT_INACTIVE`) veya
            resmileştirilmiş.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: >-
            İş kuralı hatası (ayar eksik/pasif, TCKN/VKN doğrulanamadı, e-fatura
            mükellefi, kalem hesaplanamadı).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    ExpensePreviewRequest:
      type: object
      description: 'Yazma uçlarında gövde zarfı: data zorunludur.'
      properties:
        data:
          type: object
          properties:
            source:
              type: string
              enum:
                - bankTransaction
                - manual
              description: Gider pusulası kaynağı.
            bankTransactionId:
              type: string
              description: >-
                Resmileştirilecek **giden** banka hareketi (yalnız `source:
                bankTransaction`).
            amount:
              type: number
              description: >-
                Pusula tutarı (yalnız `source: manual`; banka kaynağında
                hareketin tutarı kullanılır).
            idNo:
              type: string
              description: Satıcı TCKN/VKN. **Zorunlu.**
            nameSurname:
              type: string
              description: Satıcı ad soyad / ünvan.
            templateKey:
              type: string
              description: >-
                Kalem şablonu anahtarı. Verilmezse firmanın gider pusulası
                varsayılan şablonu kullanılır.
            exchanges:
              type: number
              description: Has/kur değeri. Verilmezse güncel fiyat listesinden alınır.
            attribute:
              type: string
              description: Mahiyet. Verilmezse şablonun kalem adı kullanılır.
            description:
              type: string
              description: Açıklama.
            transactionDate:
              type: string
              format: date-time
              description: >-
                Pusula tarihi. Banka kaynağında hareketin tarihi, serbest
                kaynakta şimdi.
            customerInfo:
              $ref: '#/components/schemas/InvoiceCustomerInfoInput'
            currentCode:
              type: string
              description: Muhasebe cari kodu.
            serial:
              type: string
              description: >-
                Seri (yalnız `source: manual`). Verilmezse firma ayarından
                üretilir.
            number:
              type: string
              description: >-
                Sıra numarası (yalnız `source: manual`). Verilmezse firma
                ayarından üretilir.
            bankName:
              type: string
              description: 'Ödemenin geçtiği banka (yalnız `source: manual`).'
            invoiceNo:
              type: array
              items:
                type: string
              description: 'Takas ise ilgili fatura numaraları (yalnız `source: manual`).'
            isSwap:
              type: boolean
              description: 'Takas mı (yalnız `source: manual`).'
          required:
            - source
            - idNo
      required:
        - data
    ExpensePreviewResponse:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - true
        data:
          $ref: '#/components/schemas/ExpensePreviewResult'
        meta:
          $ref: '#/components/schemas/MetaBase'
      required:
        - success
        - data
        - meta
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          $ref: '#/components/schemas/ErrorBody'
        traceId:
          type: string
          format: uuid
          description: x-request-id başlığı ile aynı değer.
      required:
        - success
        - error
        - traceId
    InvoiceCustomerInfoInput:
      type: object
      description: >-
        Faturada kullanılacak müşteri bilgisi (yalnız `source: manual`). Verilen
        alanlar cari kaydından gelen bilgiyi geçersiz kılar.
      properties:
        nameSurname:
          type: string
        taxOffice:
          type: string
        address:
          type: string
        cities:
          type: string
          description: İlçe.
        states:
          type: string
          description: İl.
        phone:
          type: string
        email:
          type: string
    ExpensePreviewResult:
      type: object
      properties:
        source:
          type: string
          enum:
            - bankTransaction
            - manual
        sourceId:
          type: string
          nullable: true
          description: Banka kaynağında hareket kimliği.
        amount:
          type: number
        exchanges:
          type: number
          description: Hesapta kullanılan has/kur değeri.
        serial:
          type: string
          description: Pusulanın alacağı seri.
        expectedNumber:
          type: number
          description: >-
            Beklenen sıra numarası. Ön hesaplamada numara tüketilmez; kesin
            numara oluşturma cevabında döner.
        attribute:
          type: string
          nullable: true
          description: Mahiyet.
        quantity:
          type: number
        price:
          type: number
          description: Birim fiyat.
        unitName:
          type: string
          description: Birim (GRM/C62).
        template:
          $ref: '#/components/schemas/InvoiceTemplateSummary'
        customer:
          $ref: '#/components/schemas/InvoicePreviewCustomer'
    MetaBase:
      type: object
      properties:
        requestId:
          type: string
          format: uuid
        timestamp:
          type: string
          format: date-time
      required:
        - requestId
        - timestamp
    ErrorBody:
      type: object
      properties:
        code:
          type: string
          enum:
            - VALIDATION_FAILED
            - AUTH_INVALID_CREDENTIALS
            - AUTH_FORBIDDEN
            - RESOURCE_NOT_FOUND
            - BANK_ACCOUNT_INACTIVE
            - CONFLICT
            - UPSTREAM_ERROR
            - UPSTREAM_RESULT_UNCERTAIN
            - KMTS_RATE_LIMITED
            - KMTS_RATE_LIMIT_UNAVAILABLE
            - KMTS_PROVIDER_TIMEOUT
            - KMTS_PROVIDER_UNAVAILABLE
            - KMTS_PROVIDER_RATE_LIMITED
            - KMTS_PROVIDER_RESPONSE_INVALID
            - KMTS_HISTORY_WRITE_FAILED
            - INTERNAL_ERROR
        message:
          type: string
        details:
          type: array
          items:
            $ref: '#/components/schemas/ErrorDetail'
      required:
        - code
        - message
        - details
    InvoiceTemplateSummary:
      type: object
      properties:
        key:
          type: string
          nullable: true
        title:
          type: string
          nullable: true
        lineName:
          type: string
          nullable: true
        material:
          type: string
          nullable: true
    InvoicePreviewCustomer:
      type: object
      description: >-
        Faturada kullanılması beklenen müşteri bilgisi; cari kaydı, müşteri
        kaydı ve istekteki değerlerden çözümlenir.
      properties:
        taxNumber:
          type: string
          nullable: true
        name:
          type: string
          nullable: true
        taxOffice:
          type: string
          nullable: true
        address:
          type: string
          nullable: true
        district:
          type: string
          nullable: true
        city:
          type: string
          nullable: true
        phone:
          type: string
          nullable: true
        mail:
          type: string
          nullable: true
        country:
          type: string
          nullable: true
    ErrorDetail:
      type: object
      properties:
        field:
          type: string
        rule:
          type: string
        state:
          type: string
          nullable: true
        attemptId:
          type: string
          format: uuid
          nullable: true
        verificationId:
          type: string
          nullable: true
        retryAfter:
          type: integer
          nullable: true
        retryable:
          type: boolean
        errorCode:
          type: string
  responses:
    ValidationFailed:
      description: Doğrulama hatası (geçersiz parametre).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Kimlik doğrulama başarısız.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Kayıt bulunamadı.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalError:
      description: Beklenmeyen sunucu hatası.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
      description: >-
        Kullanıcı adı apiUserId, parola secretKey. Authorization: Basic
        base64(apiUserId:secretKey)

````