Skip to main content
InvoiceTransaction is the reconciliation pivot record that links one Invoice to one Transaction, recording the exact amount (and optional accounting-currency equivalent) that the bank movement satisfies on the invoice. It is written exclusively by the reconciliation pipeline and by connector sync mapping targets; it is not mutated directly by the user-facing API. Key associations are Workspace (tenant scope), Invoice, Transaction, and optionally Subscription (for subscription-driven payments) and ExchangeRate (for multi-currency accounting conversion).

API operations

Data model

Attributes

Relationships

System-computed

  • invoice_transaction_id is generated via gen_random_uuid() as the Postgres column default and mirrored by randomUUID() in the TypeScript initializer — both guarantee a unique UUID on every insert without application-level collision risk.
  • created_at is set to new Date() by an onCreate MikroORM lifecycle hook on the entity property initializer; it is never updated after insert.
  • updated_at is set by both onCreate and onUpdate hooks, so it reflects the timestamp of the most recent flush for any property change.
  • deleted_at is null on creation and is set to a non-null Date by soft-delete callers (reconciliation pipeline / connector sync unlink). All active-record queries must include deleted_at: null in their filter predicates.
  • is_partial defaults to false at the TypeScript level; this maps to DEFAULT false in Postgres. It is a deprecated surrogate for allocation_type and will be dropped in a future migration once W19-P13 is complete.
  • allocation_type defaults to AllocationTypeEnum.FULL (‘full’) at both the TypeScript level and the Postgres column default (DEFAULT ‘full’). The reconciliation P5 recompute service treats NULL and ‘full’ as semantically identical.
  • accounting_amount and accounting_currency are pipeline-computed from the linked ExchangeRate at reconciliation time; they are null when the transaction currency already matches the workspace accounting currency or when FX data was unavailable.
  • This entity is one of the 12 target models in the MCP connector sync mapping pipeline (ConnectorMapping target model: invoice_transaction). Records may be created or soft-deleted by the connector sync persister as well as the Well reconciliation agent.
  • Three indexes are declared at the entity class level: composite (workspace_pk, invoice_pk), composite (workspace_pk, transaction_pk), and a partial expression index idx_invoice_transactions_invoice_active on (invoice_pk) WHERE deleted_at IS NULL — the last index is required specifically for the invoice-merge UPDATE path that rewrites foreign keys without a workspace bound.

Example

Source: apps/api/src/database/entities/InvoiceTransaction.ts · domain: financial-graph · tier: Supporting