import type { IJournalDraft, IJournalLineDraft, TBuKey, TCents } from './core.types.js'; import { type IAccountPolicy } from './core.accountpolicy.js'; import { type IDatevBelegInfo } from './core.belegfeld.js'; export declare const DATEV_COLUMN_COUNT = 125; export declare const DATEV_HEADER_FIELD_COUNT = 31; export interface IDatevBuchungsstapelRow { umsatzCents: TCents; sollHaben: 'S' | 'H'; konto: string; gegenKonto: string; buSchluessel: TBuKey; belegDatum: Date; /** as DATEV takes it (`isDatevBelegfeld`); the writer maps any other text (`datevBelegfelderOf`), its original as a Beleginfo */ belegfeld1?: string; belegfeld2?: string; /** fields 21 to 36: 1 to 8 pairs of Art (at most 20 characters) and Inhalt (at most 210), both given (`datevBelegInfoFault`) */ belegInfo?: IDatevBelegInfo[]; buchungstext: string; /** document GUID; written as `BEDI "GUID"` (field 20) */ belegLink?: string; kost1?: string; kost2?: string; festschreibung?: boolean; /** * DATEV Buchungsstapel field 118 "Generalumkehr" (format description on * developer.datev.de, "Buchungsstapel", read 2026-09-25: `^(["](0|1)["])$`, * "G oder 1 = Generalumkehr, 0 = keine Generalumkehr"). `true` writes "1": * the row is a general reversal. `false` writes "0"; absent writes nothing. * `journalDraftsToDatevRows` sets it to `true` on every row of a draft * marked `generalumkehr`, and leaves it unset otherwise. */ generalumkehr?: boolean; /** * Field 115 "Leistungsdatum", written TTMMJJJJ. The format description * (developer.datev.de, "Buchungsstapel", read 2026-09-25) gives * `^((0[1-9]|[1-2]\d|3[0-1])(0[1-9]|1[0-2])([2])([0])(\d{2}))$`, so years * 2000 to 2099 only, and: "Beim Import des Leistungsdatums muss das Feld * ‚116 Datum Zuord. Steuerperiode' gefüllt sein. Der Einsatz des * Leistungsdatums muss in Absprache mit dem Steuerberater erfolgen." A row * with a Leistungsdatum and without field 116 is refused. */ leistungsdatum?: Date; /** * Field 116 "Datum Zuord. Steuerperiode", written TTMMJJJJ, with the same * expression as field 115. `journalDraftsToDatevRows` sets neither: which * day assigns a booking to its tax period is agreed with the advisor. */ datumZuordSteuerperiode?: Date; /** * DATEV Buchungsstapel field 40 "EU-Mitgliedstaat u. UStID (Bestimmung)" * (format description on developer.datev.de, "Buchungsstapel", read * 2026-09-25: `^(["].{0,15}["])$`; a 2-digit country code, Greece `EL`, * Northern Ireland `XI`, then at most 13 characters of the VAT ID). Written * quoted where given; absent writes nothing. What DATEV derives from it * (DATEV doc 9211462) is not public; the field only states the recipient's * VAT ID. */ euVatIdDestination?: string; } export interface IDatevExtfHeaderOptions { /** deterministic input — core never reads the clock */ createdAt: Date; consultantNumber: number; clientNumber: number; fiscalYearStart: Date; dateFrom: Date; dateTo: Date; label: string; festschreibung: boolean; accountLength?: number; /** 2-char producer id in the header */ origin?: string; exportedBy?: string; } export interface IDatevRowsOptions { festschreibung?: boolean; /** * Recognises VAT lines and Automatikkonten while consolidating; defaults to * the default policy of each draft's chart. */ policy?: IAccountPolicy; } /** * Consolidate one balanced draft into the lines that become DATEV bookings. * * 0. A line that counts in the VAT return as another account (`declaresAs`) * is plain before anything else (`plainIfDeclared`): no BU key, rate, VAT * account or § 13b paragraph, so it neither carries a tax of its own nor * makes a pair or a fold below. No row carries a tax field for it. A line * whose counter account no line is on any more takes the account the * lines declaring that counter account sit on (`countersResolved`; more * than one such account throws). * 1. VAT lines. A §13b / intra-EU pair (input and output VAT booked against * each other) is dropped when a base line of the draft carries the key * that makes DATEV compute both sides (94/91, 19/18); without such a key * the pair stays and becomes one explicit booking. Domestic VAT lines are * folded, per Gegenkonto and side, into the base lines whose BU key * carries their rate (9/8, 3/2), sharing the VAT in proportion; a VAT * line without a keyed base is folded into an Automatikkonto base (key * 40 becomes '') only when it is the single remaining VAT line, that * base is the single Automatikkonto candidate, the account's automatism * books the VAT line's rate (`accountRateMismatchOf`: the chart's rate of * the account; one a policy adds is taken at the VAT line's rate), and it * computes the same tax from the gross (a tax a document states, * `IDocumentVatGroup.vatCents`, may differ by a cent). An account whose * automatism books another rate, or none, would book its own tax from * the gross row (7 % VAT on SKR03 8820 booked at 19 %), so the VAT line * is not folded there. Everything else stays an explicit booking on the * tax account, next to a base that carries key 40: an Automatikkonto base * of its group whose automatism books a tax is written with key 40, so * DATEV books no tax of its own on top, as the draft books none on it. * 2. Two carried lines that book one amount against each other on one * account (`cancelOnOneAccount`: the § 13b pair of a closed year carried * onto the previous year's VAT) net to nothing there and give no booking. * Mirror lines (A against B and B against A with the same amount) become * one booking, taken from the line with a BU key, else from the debit * line. * 3. Split lines against one aggregate line (their signed sum cancels the * aggregate) become one booking each; the aggregate line is dropped. * Anything left over throws: writing it would double the booking on import; * so does a booking against its own account, which no row may state. */ export declare function consolidateJournalDraftForDatev(draft: IJournalDraft, policy: IAccountPolicy): IJournalLineDraft[]; /** * Convert journal drafts into DATEV rows: one row per booking after * consolidateJournalDraftForDatev, with the line's counterAccount as * Gegenkonto. A draft marked `generalumkehr` gives the rows of the booking it * reverses, with the same amounts and Soll/Haben marks, each with field 118 * set; one with a negative line is refused. */ export declare function journalDraftsToDatevRows(drafts: IJournalDraft[], options?: IDatevRowsOptions): IDatevBuchungsstapelRow[]; /** * The 125 fields of one Buchungsstapel row exactly as `writeExtfBuchungsstapel` * writes them, quoted and cut to their lengths, before they are joined with * `;`: the row's line in the file is `datevRowFields(row).join(';')`. What a * reader of one row needs to know without writing a whole file, for example * which of its characters an encoding of the file cannot carry. Throws as * the writer throws for a row it refuses. */ export declare function datevRowFields(row: IDatevBuchungsstapelRow): string[]; /** * Produce the complete EXTF file content (header, caption row, data rows). */ export declare function writeExtfBuchungsstapel(rows: IDatevBuchungsstapelRow[], header: IDatevExtfHeaderOptions): { csv: string; filename: string; };