core PK: id 16 required 1 unique

Description

Records each batch export of approved expenses and reimbursements to an external accounting system (Xledger, Dynamics/Visma). Tracks export status, line-item results, and external reference IDs for idempotent re-exports and audit compliance.

23
Attributes
7
Indexes
10
Validation Rules
21
CRUD Operations

Data Structure

Name Type Description Constraints
id uuid Unique identifier for the export batch
PKrequiredunique
organization_id uuid Organization that owns this export batch (foreign key to organizations)
required
provider enum Target accounting system provider
required
status enum Current status of the export batch
required
export_type enum Type of data being exported
required
period_start datetime Start date of the reporting period covered by this export
required
period_end datetime End date of the reporting period covered by this export
required
total_items integer Total number of line items included in the export batch
required
successful_items integer Number of line items successfully exported to the accounting system
required
failed_items integer Number of line items that failed to export
required
total_amount decimal Total monetary amount of the exported batch in NOK
required
external_batch_id string Reference ID returned by the external accounting system for this batch
-
line_items json Array of per-item export results with reimbursement_id, external_reference_id, status, and error_message
-
field_mapping_snapshot json Snapshot of the expense-type-to-account-code mappings used at export time for audit reproducibility
-
error_details text Error message or details if the export batch failed or partially failed
-
format enum Output format of the export
required
file_path string Storage path or signed URL for file-based exports (xlsx, csv)
-
is_dry_run boolean Whether this was a preview/dry-run export that did not push to the external system
required
initiated_by uuid User ID of the administrator who initiated the export
required
started_at datetime Timestamp when export processing began
-
completed_at datetime Timestamp when export processing finished (success or failure)
-
created_at datetime Record creation timestamp
required
updated_at datetime Record last update timestamp
required

Database Indexes

idx_accounting_exports_organization_id
btree

Columns: organization_id

idx_accounting_exports_org_status
btree

Columns: organization_id, status

idx_accounting_exports_org_period
btree

Columns: organization_id, period_start, period_end

idx_accounting_exports_org_provider
btree

Columns: organization_id, provider

idx_accounting_exports_created_at
btree

Columns: created_at

idx_accounting_exports_initiated_by
btree

Columns: initiated_by

idx_accounting_exports_external_batch_id
btree

Columns: external_batch_id

Validation Rules

period_end_after_start error

Validation failed

item_counts_consistency error

Validation failed

valid_organization_reference error

Validation failed

valid_initiator_reference error

Validation failed

total_amount_non_negative error

Validation failed

total_items_minimum error

Validation failed

external_batch_id_on_completion warning

Validation failed

file_path_required_for_file_exports warning

Validation failed

line_items_json_structure error

Validation failed

completed_at_requires_started_at error

Validation failed

Business Rules

organization_scoped_exports
always

All exports must belong to exactly one organization. Queries must always scope by organization_id for multi-tenant isolation.

idempotent_re_export
on_create

If an export batch with the same organization, provider, period, and export_type already exists in completed status, re-export must attach new external_reference_ids rather than creating duplicate accounting entries. The external_batch_id is used for idempotency checks.

transactional_batch_semantics
on_update

When format is api_push, either all line items in the batch must succeed or the entire batch must be rolled back. Partial pushes set status to partial_failure with per-item error details in line_items JSON.

approved_reimbursements_only
on_create

Only reimbursements with approved expense_approvals status may be included in an accounting export batch. Pending or rejected expenses must be excluded.

mapping_completeness_required
on_create

Export cannot proceed unless all expense types in the batch have valid account-code mappings configured for the target provider. Missing mappings block the export with a descriptive error.

no_deletion_audit_compliance
on_delete

Export records must never be deleted. They serve as an immutable audit trail for financial compliance. Status may be set to cancelled but the record persists.

field_mapping_snapshot_on_create
on_create

At export creation time, the current field mappings must be snapshotted into field_mapping_snapshot so the exact mapping used can be audited later, even if mappings are subsequently changed.

Enforced by: Accounting API Service
role_based_export_access
on_create

Only Organization Admins and Global Admins may initiate accounting exports. Coordinators and Peer Mentors are denied access.

Storage Configuration

Storage Type
primary_table
Location
main_db
Partitioning
by_date
Retention
Permanent Storage