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

# Fatura ön hesaplama

> Fatura kesilmeden önce kalemleri, fatura türünü ve toplamları hesaplar. **Hiçbir yan etkisi yoktur:** entegratöre gönderim yapılmaz, veritabanına kayıt yazılmaz. Gövde, `POST /v1/invoices` ile aynıdır; yalnız `isDraft` ve `allowDuplicate` alanları kullanılamaz. Dönen `lines` ve `totals`, fatura kesildiğinde `GET /v1/invoices/{id}` içinde görünecek değerlerle aynı hesaba dayanır.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/invoices/preview
openapi: 3.0.3
info:
  title: Sarraf API v1
  version: 1.0.0
  description: >-
    Sarraf sürümlü dış API yüzeyi. Bu sürüm salt okunurdur; e-ticaret siteleri
    ve muhasebe programları için mevcut kayıtların okunmasını sağlar. Kimlik
    doğrulama mevcut dış API ile aynıdır: HTTP Basic,
    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ı kayıtları
    x-group: Giderler
paths:
  /v1/invoices/preview:
    post:
      tags:
        - Invoices
      summary: Fatura ön hesaplama
      description: >-
        Fatura kesilmeden önce kalemleri, fatura türünü ve toplamları hesaplar.
        **Hiçbir yan etkisi yoktur:** entegratöre gönderim yapılmaz,
        veritabanına kayıt yazılmaz. Gövde, `POST /v1/invoices` ile aynıdır;
        yalnız `isDraft` ve `allowDuplicate` alanları kullanılamaz. Dönen
        `lines` ve `totals`, fatura kesildiğinde `GET /v1/invoices/{id}` içinde
        görünecek değerlerle aynı hesaba dayanır.
      operationId: previewInvoice
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InvoicePreviewRequest'
      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/InvoicePreviewResponse'
        '400':
          $ref: '#/components/responses/ValidationFailed'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: >-
            Banka hareketi faturalandırılmış veya faturalandırma için
            planlanmış.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: >-
            İş kuralı hatası (kalem hesaplanamadı, tutar çok düşük, güncel kur
            bulunamadı vb.).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    InvoicePreviewRequest:
      type: object
      description: 'Yazma uçlarında gövde zarfı: data zorunludur.'
      properties:
        data:
          type: object
          properties:
            source:
              type: string
              enum:
                - bankTransaction
                - manual
              description: Fatura kaynağı.
            bankTransactionId:
              type: string
              description: >-
                Faturalandırılacak gelen banka hareketi (yalnız `source:
                bankTransaction`).
            amount:
              type: number
              description: >-
                Fatura tutarı (yalnız `source: manual`; banka kaynağında
                hareketin tutarı kullanılır).
            templateKey:
              type: string
              description: >-
                Kalem şablonu anahtarı. Verilmezse firmanın varsayılan şablonu
                kullanılır.
            exchanges:
              type: number
              description: Has/kur değeri. Verilmezse güncel fiyat listesinden alınır.
            idNo:
              type: string
              description: >-
                Müşteri TCKN/VKN. `source: manual` için zorunludur; banka
                kaynağında boş bırakılırsa hareketin kimlik bilgisi kullanılır.
            nameSurname:
              type: string
              description: Müşteri ad soyad / ünvan.
            transactionDate:
              type: string
              format: date-time
              description: 'Fatura tarihi (yalnız `source: manual`; varsayılan: şimdi).'
            paymentDate:
              type: string
              format: date-time
              description: >-
                Ödeme tarihi (yalnız `source: manual`; varsayılan: fatura
                tarihi).
            paymentType:
              type: string
              enum:
                - bank
                - pos
                - expense
                - other
              description: 'Ödeme şekli (`source: manual` için zorunlu).'
            bankName:
              type: string
              description: 'Ödemenin geçtiği banka (yalnız `source: manual`).'
            approvalCode:
              type: string
              description: 'POS onay kodu (yalnız `source: manual`, `paymentType: pos`).'
            iban:
              type: string
              description: 'Karşı IBAN (yalnız `source: manual`, `paymentType: bank`).'
            expenseNumber:
              type: string
              description: >-
                Mahsuplaşılan gider pusulası numarası (yalnız `source: manual`,
                `paymentType: expense`).
            paymentNote:
              type: string
              description: 'Ödeme notu (yalnız `source: manual`, `paymentType: other`).'
            description:
              type: string
              description: >-
                Fatura notu; satır satır fatura açıklamasına eklenir (yalnız
                `source: manual`).
            currentCode:
              type: string
              description: 'Muhasebe cari kodu (yalnız `source: manual`).'
            invoiceType:
              type: string
              enum:
                - OTOMATIK
                - ISTISNA
                - OZELMATRAH
                - SATIS
              description: >-
                Fatura türü (yalnız `source: manual`). Verilmezse veya
                `OTOMATIK` gönderilirse tür kalem şablonundan türetilir.
            customerInfo:
              $ref: '#/components/schemas/InvoiceCustomerInfoInput'
          required:
            - source
      required:
        - data
    InvoicePreviewResponse:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - true
        data:
          $ref: '#/components/schemas/InvoicePreviewResult'
        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
    InvoicePreviewResult:
      type: object
      properties:
        source:
          type: string
          enum:
            - bankTransaction
            - manual
        sourceId:
          type: string
          nullable: true
          description: Banka kaynağında hareket kimliği; serbest faturada null.
        amount:
          type: number
        exchanges:
          type: number
          description: Hesapta kullanılan has/kur değeri.
        invoiceType:
          type: string
          nullable: true
          description: Hesaplanan fatura türü (ISTISNA / OZELMATRAH / SATIS).
        channel:
          type: string
          enum:
            - earchive
            - einvoice
          description: >-
            Faturanın kesileceği kanal; alıcının e-fatura mükellefiyetine göre
            belirlenir.
        template:
          $ref: '#/components/schemas/InvoiceTemplateSummary'
        customer:
          $ref: '#/components/schemas/InvoicePreviewCustomer'
        totals:
          $ref: '#/components/schemas/InvoiceTotals'
        lines:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceLine'
    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
            - CONFLICT
            - UPSTREAM_ERROR
            - 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
    InvoiceTotals:
      type: object
      properties:
        linesTotal:
          type: number
          description: Kalem net toplamı (KDV hariç).
        kdvTotal:
          type: number
        allowanceTotal:
          type: number
          description: İskonto toplamı.
        payableTotal:
          type: number
          description: Ödenecek toplam.
    InvoiceLine:
      type: object
      properties:
        name:
          type: string
          nullable: true
        quantity:
          type: number
        unitType:
          type: string
          nullable: true
        stockCode:
          type: string
          nullable: true
        price:
          type: number
        amount:
          type: number
          description: KDV ve iskontosuz net tutar.
        lineTotal:
          type: number
        kdvPercent:
          type: number
        kdvTotal:
          type: number
        allowancePrice:
          type: number
        allowanceTotal:
          type: number
        ozelMatrahTotal:
          type: number
        isExtra:
          type: boolean
        isDefault:
          type: boolean
        isLabor:
          type: boolean
          description: İşçilik kalemi mi.
    ErrorDetail:
      type: object
      properties:
        field:
          type: string
        rule:
          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)

````