{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/lumabill-ch/json-schema/lumabill-ch-bank-transaction-update-schema.json",
  "title": "BankTransactionUpdate",
  "description": "Reconcile a single bank transaction. Setting `status=MATCHED` requires one of `matchedInvoiceIds` (or the legacy `matchedInvoiceId`), `matchedExpenseIds` (or the legacy `matchedExpenseId`), or `matchedRevenueId`. One bank payment can settle several invoices: the bank amount plus adjustments is allocated in the order of `matchedInvoiceIds`, each invoice getting min(open balance, money left), so only the last one can end partially paid. Errors (400): PAYMENT_EXCEEDS_OPEN_BALANCE (more money than the combined open balance), INVOICE_ALLOCATION_ZERO (an invoice would receive nothing), ADJUSTMENTS_EXCEED_ALLOCATION (adjustments are booked on the largest allocation and must be smaller than it), DUPLICATE_INVOICE, INVALID_MATCHED_INVOICES (both fields sent, or not 1-50 UUIDs). One DEBIT bank transaction can likewise pay several expenses (`matchedExpenseIds`, same rule; invoices only match CREDIT lines, expenses only DEBIT lines). An expense payment credits the bank with its allocation plus the signed adjustments, so positive adjustments (bank fees) are paid on top and negative ones (FX gain) reduce the bank amount. Expense-side codes: EXPENSE_ALLOCATION_ZERO, DUPLICATE_EXPENSE, INVALID_MATCHED_EXPENSES, ADJUSTMENTS_EXCEED_BANK_AMOUNT. Every journal entry of a group gets the bank date and a description starting with \"Sammelzahlung\" plus the bank reference. Undo a group by setting the transaction back to UNMATCHED; undoing one of its documents is refused with 409 (PAYMENT_IN_BANK_GROUP_MATCH / EXPENSE_PAYMENT_IN_BANK_GROUP_MATCH). Setting `status=CATEGORIZED` requires `bookToAccountId`. The journal entry is posted automatically and rejected if the affected fiscal year is closed.\n",
  "x-generated": "2026-11-17",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/lumabill-ch-openapi.yaml#/components/schemas/BankTransactionUpdate",
  "type": "object",
  "required": [
    "status"
  ],
  "properties": {
    "status": {
      "type": "string",
      "enum": [
        "MATCHED",
        "UNMATCHED",
        "CATEGORIZED",
        "IGNORED"
      ]
    },
    "matchedInvoiceId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "Legacy single-invoice match, treated as `matchedInvoiceIds = [id]`. Do not send together with `matchedInvoiceIds`."
    },
    "matchedInvoiceIds": {
      "type": [
        "array",
        "null"
      ],
      "minItems": 1,
      "maxItems": 50,
      "uniqueItems": true,
      "description": "Invoices paid by this bank transaction, in allocation order.",
      "items": {
        "type": "string",
        "format": "uuid"
      }
    },
    "matchedExpenseId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "Legacy single-expense match, treated as `matchedExpenseIds = [id]`. Do not send together with `matchedExpenseIds`."
    },
    "matchedExpenseIds": {
      "type": [
        "array",
        "null"
      ],
      "minItems": 1,
      "maxItems": 50,
      "uniqueItems": true,
      "description": "Expenses paid by this DEBIT bank transaction, in allocation order.",
      "items": {
        "type": "string",
        "format": "uuid"
      }
    },
    "matchedRevenueId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid"
    },
    "bookToAccountId": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "Chart-of-accounts UUID (required when status=CATEGORIZED)"
    },
    "adjustments": {
      "type": [
        "array",
        "null"
      ],
      "description": "On a foreign-currency line the adjustments are in the line currency.",
      "items": {
        "$ref": "#/$defs/BankTransactionAdjustment"
      }
    },
    "dryRun": {
      "type": "boolean",
      "default": false,
      "description": "Preview: runs the exact booking (every check and refusal, the CHF value of the line, the released book value, the realized FX, the zero-saldo realization) in a transaction that is rolled back. Answers 200 `{ message, dryRun: true, fx? }`; nothing is booked. Only for a request that books (status MATCHED with a document, or CATEGORIZED with `bookToAccountId`). A rate lookup during the preview may still fill the shared rate cache. Read strictly: `true`/`false` or the strings \"true\"/\"false\" (any case); any other value answers 400 and nothing is booked.\n"
    },
    "allowCrossCurrency": {
      "type": "boolean",
      "default": false,
      "description": "Confirms a cross-currency payment: a base-currency (CHF) line that settles a foreign-currency document. Without it such a match is refused with BANK_CURRENCY_MISMATCH and `crossCurrencyPossible: true` (see BankCurrencyMismatch). The CHF moved is the bank amount; the difference to the document's CHF book value is booked as realized FX. The rate it implies (bank amount per FW settled) must lie within 0.5x to 2x of the ESTV/BAZG rate of the value date, else 400 EXCHANGE_RATE_IMPLAUSIBLE (with `impliedRate`, `officialRate`, `min`, `max`). Read strictly like `dryRun`.\n"
    },
    "fwAmount": {
      "type": "number",
      "format": "double",
      "description": "Cross-currency match only: the foreign-currency amount this line settles across the selected documents (default: everything still open). Positive; 400 INVALID_FW_AMOUNT otherwise. A part payment must send it: against everything open its implied rate is refused as EXCHANGE_RATE_IMPLAUSIBLE.\n"
    },
    "exchangeRate": {
      "type": "number",
      "format": "double",
      "description": "Line on a foreign-currency bank account: override its CHF value with this rate (CHF per 1 unit of the line currency). Default: the statement's own CHF figure, else the ESTV/BAZG rate of the value date. Ignored in a cross-currency match.\n"
    },
    "baseAmount": {
      "type": "number",
      "format": "double",
      "description": "Line on a foreign-currency bank account: the CHF amount that actually moved; wins over `exchangeRate`. Ignored in a cross-currency match.\n"
    }
  },
  "$defs": {
    "BankTransactionAdjustment": {
      "type": "object",
      "required": [
        "description",
        "amount",
        "chartAccountId"
      ],
      "properties": {
        "description": {
          "type": "string"
        },
        "amount": {
          "type": "number",
          "format": "double",
          "description": "Signed. Positive books a DEBIT (bank fee, Skonto, FX loss), negative a CREDIT (FX gain, overpayment). Must not be zero."
        },
        "chartAccountId": {
          "type": "string",
          "format": "uuid"
        }
      }
    }
  }
}