openapi: 3.1.0 info: title: Accounting Module API version: 0.2.0 description: | Reduced delivery contract for the company-isolated accounting module. Except for login, every operation requires bearer authentication and derives company and role from persisted identity. Foreign-company identifiers are returned exactly like unknown identifiers. Official monetary values are two-decimal strings. servers: - url: http://localhost:8000 description: Local evaluator backend security: - BearerAuth: [] tags: - name: Authentication - name: Reference data - name: Vouchers - name: Ledger - name: Exogenous information paths: /api/auth/login: post: tags: [Authentication] summary: Authenticate a seeded active user operationId: login security: [] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/LoginRequest' responses: '200': description: Authenticated bearer token content: application/json: schema: $ref: '#/components/schemas/LoginResponse' '401': $ref: '#/components/responses/Unauthorized' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/auth/me: get: tags: [Authentication] summary: Read current persisted identity operationId: getCurrentUser responses: '200': description: Active user, company, and role derived from persistence content: application/json: schema: $ref: '#/components/schemas/CurrentUser' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '503': $ref: '#/components/responses/Recoverable' /api/accounts: get: tags: [Reference data] summary: List flat company accounts description: Returns same-company accounts for voucher and ledger selection. operationId: listAccounts parameters: - name: status in: query required: false schema: $ref: '#/components/schemas/ActiveStatus' responses: '200': description: Company-scoped flat accounts content: application/json: schema: type: array items: $ref: '#/components/schemas/Account' '401': $ref: '#/components/responses/Unauthorized' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/periods: get: tags: [Reference data] summary: List seeded company periods operationId: listAccountingPeriods parameters: - name: year in: query required: false schema: type: integer minimum: 2000 maximum: 9999 responses: '200': description: Company-scoped monthly periods content: application/json: schema: type: array items: $ref: '#/components/schemas/AccountingPeriod' '401': $ref: '#/components/responses/Unauthorized' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/periods/{period_id}/close: post: tags: [Reference data] summary: Close an open accounting period description: ADMIN-only, company-scoped, audited, and serialized with posting. operationId: closeAccountingPeriod parameters: - $ref: '#/components/parameters/PeriodId' responses: '200': description: Closed period content: application/json: schema: $ref: '#/components/schemas/AccountingPeriod' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/third-parties: get: tags: [Reference data] summary: List stable company third parties operationId: listThirdParties parameters: - name: status in: query required: false schema: $ref: '#/components/schemas/ActiveStatus' responses: '200': description: Company-scoped third-party choices content: application/json: schema: type: array items: $ref: '#/components/schemas/ThirdParty' '401': $ref: '#/components/responses/Unauthorized' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/exogenous-concepts: get: tags: [Reference data] summary: List seeded concepts and account mappings operationId: listExogenousConcepts responses: '200': description: Company-scoped concept and mapping choices content: application/json: schema: type: array items: $ref: '#/components/schemas/ExogenousConcept' '401': $ref: '#/components/responses/Unauthorized' '503': $ref: '#/components/responses/Recoverable' /api/vouchers: get: tags: [Vouchers] summary: List company vouchers operationId: listVouchers parameters: - name: status in: query required: false schema: $ref: '#/components/schemas/VoucherStatus' responses: '200': description: Company-scoped drafts and official vouchers content: application/json: schema: type: array items: $ref: '#/components/schemas/Voucher' '401': $ref: '#/components/responses/Unauthorized' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' post: tags: [Vouchers] summary: Create a voucher draft operationId: createVoucherDraft requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/VoucherDraftInput' responses: '201': description: Persisted company draft content: application/json: schema: $ref: '#/components/schemas/Voucher' '401': $ref: '#/components/responses/Unauthorized' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/vouchers/{voucher_id}: get: tags: [Vouchers] summary: Get a company voucher operationId: getVoucher parameters: - $ref: '#/components/parameters/VoucherId' responses: '200': description: Draft or immutable official voucher content: application/json: schema: $ref: '#/components/schemas/Voucher' '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' put: tags: [Vouchers] summary: Replace a voucher draft operationId: replaceVoucherDraft parameters: - $ref: '#/components/parameters/VoucherId' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/VoucherDraftInput' responses: '200': description: Replaced persisted draft content: application/json: schema: $ref: '#/components/schemas/Voucher' '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/vouchers/{voucher_id}/post: post: tags: [Vouchers] summary: Atomically post a balanced draft description: | Revalidates company, open period, active references, exact balance, numbering, and audit. Repeated success returns the same official voucher. operationId: postVoucher parameters: - $ref: '#/components/parameters/VoucherId' responses: '200': description: Existing result of a repeated successful post content: application/json: schema: $ref: '#/components/schemas/Voucher' '201': description: Newly posted immutable voucher content: application/json: schema: $ref: '#/components/schemas/Voucher' '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/vouchers/{voucher_id}/reversal: post: tags: [Vouchers] summary: Create one complete inverse voucher description: No partial reversal or reversal of reversal; repeated success is idempotent. operationId: reverseVoucher parameters: - $ref: '#/components/parameters/VoucherId' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ReversalRequest' responses: '200': description: Existing reversal returned for a repeated request content: application/json: schema: $ref: '#/components/schemas/Voucher' '201': description: Newly posted complete reversal content: application/json: schema: $ref: '#/components/schemas/Voucher' '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/ledger: get: tags: [Ledger] summary: Query exact company general ledger operationId: queryGeneralLedger parameters: - name: account_id in: query required: true schema: type: string format: uuid - name: from in: query required: true schema: type: string format: date - name: to in: query required: true schema: type: string format: date responses: '200': description: Opening and deterministic running balances for one company account content: application/json: schema: $ref: '#/components/schemas/LedgerResponse' '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/exogena/generar: post: tags: [Exogenous information] summary: Generate and store simplified exogenous XML operationId: generateExogenousXml requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ExogenousGenerateRequest' responses: '201': description: Stored immutable generation metadata and download identity content: application/json: schema: $ref: '#/components/schemas/ExogenousGeneration' '401': $ref: '#/components/responses/Unauthorized' '409': $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/exogena/historial: get: tags: [Exogenous information] summary: List company generation history operationId: listExogenousGenerationHistory parameters: - name: tax_year in: query required: false schema: type: integer minimum: 2000 maximum: 9999 responses: '200': description: Company-scoped immutable generation history content: application/json: schema: type: array items: $ref: '#/components/schemas/ExogenousGeneration' '401': $ref: '#/components/responses/Unauthorized' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' /api/exogena/historial/{id}/archivo: get: tags: [Exogenous information] summary: Download exact stored historical XML operationId: downloadHistoricalExogenousXml parameters: - name: id in: path required: true schema: type: string format: uuid responses: '200': description: Exact stored UTF-8 XML bytes; never regenerated headers: ETag: description: Stored SHA-256 hash schema: type: string pattern: '^[0-9a-f]{64}$' content: application/xml: schema: type: string format: binary '401': $ref: '#/components/responses/Unauthorized' '404': $ref: '#/components/responses/NotFound' '422': $ref: '#/components/responses/Validation' '503': $ref: '#/components/responses/Recoverable' components: securitySchemes: BearerAuth: type: http scheme: bearer bearerFormat: JWT parameters: VoucherId: name: voucher_id in: path required: true schema: type: string format: uuid PeriodId: name: period_id in: path required: true schema: type: string format: uuid responses: Unauthorized: description: Authentication is missing, invalid, expired, or inactive content: application/problem+json: schema: $ref: '#/components/schemas/ProblemDetails' Forbidden: description: Persisted role lacks authority content: application/problem+json: schema: $ref: '#/components/schemas/ProblemDetails' NotFound: description: Resource is unknown or belongs to another company content: application/problem+json: schema: $ref: '#/components/schemas/ProblemDetails' Validation: description: Input or accounting validation failed content: application/problem+json: schema: $ref: '#/components/schemas/ProblemDetails' Conflict: description: Current state, uniqueness, immutability, or idempotency conflict content: application/problem+json: schema: $ref: '#/components/schemas/ProblemDetails' Recoverable: description: Bounded transient processing failure; retry may be safe content: application/problem+json: schema: $ref: '#/components/schemas/ProblemDetails' schemas: ProblemDetails: type: object additionalProperties: false required: [type, title, status, code, detail, correlation_id] properties: type: type: string format: uri title: type: string status: type: integer minimum: 400 maximum: 599 code: type: string detail: type: string correlation_id: type: string format: uuid field_errors: type: object additionalProperties: type: array items: type: string Money: type: string pattern: '^-?(?:0|[1-9][0-9]{0,16})\.[0-9]{2}$' examples: ['0.00', '1190000.00'] NonNegativeMoney: allOf: - $ref: '#/components/schemas/Money' pattern: '^(?:0|[1-9][0-9]{0,16})\.[0-9]{2}$' ActiveStatus: type: string enum: [ACTIVE, INACTIVE] LoginRequest: type: object additionalProperties: false required: [email, password] properties: email: type: string format: email password: type: string minLength: 1 LoginResponse: type: object additionalProperties: false required: [access_token, token_type, expires_in] properties: access_token: type: string token_type: const: bearer expires_in: type: integer minimum: 1 CurrentUser: type: object additionalProperties: false required: [id, email, company_id, company_name, role] properties: id: type: string format: uuid email: type: string format: email company_id: type: string format: uuid company_name: type: string role: type: string enum: [ADMIN, ACCOUNTANT] Account: type: object additionalProperties: false required: [id, code, name, nature, status] properties: id: type: string format: uuid code: type: string name: type: string nature: type: string enum: [DEBIT, CREDIT] status: $ref: '#/components/schemas/ActiveStatus' AccountingPeriod: type: object additionalProperties: false required: [id, year, month, starts_on, ends_on, status] properties: id: type: string format: uuid year: type: integer month: type: integer minimum: 1 maximum: 12 starts_on: type: string format: date ends_on: type: string format: date status: type: string enum: [OPEN, CLOSED] closed_at: type: [string, 'null'] format: date-time ThirdParty: type: object additionalProperties: false required: [id, document_type, document_number, legal_name, status] properties: id: type: string format: uuid document_type: type: string document_number: type: string legal_name: type: string status: $ref: '#/components/schemas/ActiveStatus' AccountExogenousMapping: type: object additionalProperties: false required: [id, account_id, role, status] properties: id: type: string format: uuid account_id: type: string format: uuid role: type: string enum: [GROSS_VALUE, WITHHOLDING] status: $ref: '#/components/schemas/ActiveStatus' ExogenousConcept: type: object additionalProperties: false required: [id, code, name, status, mappings] properties: id: type: string format: uuid code: type: string name: type: string status: $ref: '#/components/schemas/ActiveStatus' mappings: type: array items: $ref: '#/components/schemas/AccountExogenousMapping' VoucherStatus: type: string enum: [DRAFT, POSTED, REVERSED] VoucherLineInput: type: object description: | Structurally complete persisted draft line. Nonnegative exact amounts may still be posting-invalid when both are zero or both are positive; posting enforces exactly one positive side. additionalProperties: false required: [position, account_id, debit, credit] properties: position: type: integer minimum: 1 account_id: type: string format: uuid third_party_id: type: [string, 'null'] format: uuid mapping_id: type: [string, 'null'] format: uuid debit: $ref: '#/components/schemas/NonNegativeMoney' credit: $ref: '#/components/schemas/NonNegativeMoney' description: type: [string, 'null'] VoucherDraftInput: type: object description: | Structurally valid persisted draft input. The lines array may contain zero or one line and submitted lines may be accounting-incomplete, but required fields, UUID syntax, and nonnegative exact decimal strings remain mandatory. Partially typed client rows are not persisted. additionalProperties: false required: [accounting_period_id, accounting_date, description, lines] properties: accounting_period_id: type: string format: uuid accounting_date: type: string format: date description: type: string lines: type: array items: $ref: '#/components/schemas/VoucherLineInput' VoucherLine: type: object description: Persisted voucher line returned by the API. additionalProperties: false required: [id, position, account_id, debit, credit] properties: id: type: string format: uuid position: type: integer minimum: 1 account_id: type: string format: uuid third_party_id: type: [string, 'null'] format: uuid mapping_id: type: [string, 'null'] format: uuid debit: $ref: '#/components/schemas/NonNegativeMoney' credit: $ref: '#/components/schemas/NonNegativeMoney' description: type: [string, 'null'] Voucher: type: object additionalProperties: false required: - id - status - kind - accounting_period_id - accounting_date - description - total_debit - total_credit - lines - created_at - updated_at properties: id: type: string format: uuid status: $ref: '#/components/schemas/VoucherStatus' kind: type: string enum: [STANDARD, REVERSAL] number: type: [integer, 'null'] minimum: 1 accounting_period_id: type: string format: uuid accounting_date: type: string format: date description: type: string original_voucher_id: type: [string, 'null'] format: uuid reversal_voucher_id: type: [string, 'null'] format: uuid reversal_reason: type: [string, 'null'] total_debit: $ref: '#/components/schemas/NonNegativeMoney' total_credit: $ref: '#/components/schemas/NonNegativeMoney' lines: type: array items: $ref: '#/components/schemas/VoucherLine' created_at: type: string format: date-time updated_at: type: string format: date-time posted_at: type: [string, 'null'] format: date-time ReversalRequest: type: object description: | Creates a new reversal voucher on accounting_date. The original may belong to a closed period, but the target period containing accounting_date must be OPEN when locked and revalidated; a closed target returns Conflict with no committed effect. additionalProperties: false required: [accounting_date, reason] properties: accounting_date: type: string format: date reason: type: string minLength: 1 LedgerEntry: type: object additionalProperties: false required: [voucher_id, voucher_number, accounting_date, line_position, description, debit, credit, running_balance] properties: voucher_id: type: string format: uuid voucher_number: type: integer minimum: 1 accounting_date: type: string format: date line_position: type: integer minimum: 1 description: type: string third_party_legal_name: type: [string, 'null'] debit: $ref: '#/components/schemas/NonNegativeMoney' credit: $ref: '#/components/schemas/NonNegativeMoney' running_balance: $ref: '#/components/schemas/Money' LedgerResponse: type: object additionalProperties: false required: [account, from, to, opening_balance, closing_balance, entries] properties: account: $ref: '#/components/schemas/Account' from: type: string format: date to: type: string format: date opening_balance: $ref: '#/components/schemas/Money' closing_balance: $ref: '#/components/schemas/Money' entries: type: array items: $ref: '#/components/schemas/LedgerEntry' ExogenousGenerateRequest: type: object description: | The evaluator uses simulated 2027 UVT 50000.00 and threshold_uvt 10.00, producing one ROUND_HALF_UP peso threshold of 500000.00. additionalProperties: false required: [tax_year, threshold_uvt] properties: tax_year: type: integer minimum: 2000 maximum: 9999 threshold_uvt: $ref: '#/components/schemas/NonNegativeMoney' ExogenousControlTotals: type: object additionalProperties: false required: [record_count, gross_total, withholding_total] properties: record_count: type: integer minimum: 0 gross_total: $ref: '#/components/schemas/Money' withholding_total: $ref: '#/components/schemas/Money' ExogenousExclusion: type: object additionalProperties: false required: [third_party_id, reason, gross_total] properties: third_party_id: type: [string, 'null'] format: uuid reason: type: string gross_total: $ref: '#/components/schemas/Money' ExogenousGeneration: type: object additionalProperties: false required: - id - tax_year - uvt_value - threshold_uvt - threshold_pesos - controls - exclusions - sha256 - created_at - download_path properties: id: type: string format: uuid tax_year: type: integer uvt_value: $ref: '#/components/schemas/Money' threshold_uvt: $ref: '#/components/schemas/Money' threshold_pesos: $ref: '#/components/schemas/Money' controls: $ref: '#/components/schemas/ExogenousControlTotals' exclusions: type: array items: $ref: '#/components/schemas/ExogenousExclusion' sha256: type: string pattern: '^[0-9a-f]{64}$' created_at: type: string format: date-time download_path: type: string pattern: '^/api/exogena/historial/[0-9a-f-]+/archivo$'