SIE import
deccf/domainpacks/sie-import creates a statement flow group from SIE account data. It reads types 1 through 4 and finds the statement owner's accounts through the selected Business or Personal account plan. Keep the content as a normal string with input.textfile() or edit periods and balances in the Calculator's table with input.tableToSie(). A run can still replace either value with SIE text through deterministic.inputs.
import { currencies, defineModel, entity, input, periods } from "deccf";
import { stdaccount } from "deccf/domainpacks/accountplan";
import { sieStatement, thisYear } from "deccf/domainpacks/sie-import";
const year = thisYear();
const compactDate = date => date.replaceAll("-", "");
const sampleSie = [
"#SIETYP 1",
`#RAR 0 ${compactDate(year.start)} ${compactDate(year.end)}`,
'#KONTO 1930 "Cash at bank"',
'#KONTO 2091 "Retained earnings"',
"#UB 0 1930 100.00",
"#UB 0 2091 -100.00",
].join("\n");
const company = entity.asset();
const sieContent = input.tableToSie(sampleSie, {
dynamicAccounts: true,
personalAccounts: true,
businessAccounts: true,
splitResAndUb: true,
dynamicPeriods: true,
fileDrop: true,
});
const bank = stdaccount({ code: "1930", owner: company });
const retainedEarnings = stdaccount({ code: "2091", owner: company });
const importedBalances = sieStatement({
owner: company,
sieContent,
});
const model = defineModel({
name: "sie-balance-import",
currency: currencies.SEK,
timeline: periods.monthly({ from: "2025-01", count: 36 }),
preconditions: { sieContent },
entities: { company },
accounts: { bank, retainedEarnings },
flows: { importedBalances },
});
return model;When this model is opened in the Calculator, its example SIE text runs immediately. The Model inputs panel displays the periods and balances in a table. The enabled controls let you add or remove accounts and full years, switch between balance and result accounts, and import a local SIE file. An ordinary input.textfile() remains available for models that need direct text editing.
Choose a SIE text file in Model inputs. In a direct run, provide its text under the same precondition name:
const result = run(model, {
deterministic: { inputs: { sieContent: sieText } },
});The model timeline must use monthly periods and include the latest period in the file. The statement posts at each month's end. It reads the latest date from #OMFATTN, #PSALDO, or a dated #TRANS, and falls back to the end date of the latest #RAR year when the file only has annual balances. parseLatestSieSnapshot() exposes historyStart and monthlyActivity, with each monthly activity item containing a period, account code, signed amount, and source (period or transaction).
Type 1 files continue to use annual #IB, #UB, and #RES balances. They expose no fabricated monthly amounts. Types 2 and 3 read account-level #PSALDO period movements; type 3 object-specific rows are ignored when the account total is present. Type 4 reads #TRANS inside #VER blocks. A transaction's own date takes precedence over its voucher date. Debit amounts are positive and credit amounts are negative.
When a file has periods or transactions, the statement accumulates them from #IB to create month-end balances. At a financial-year end, #UB and #RES provide the reported ending values when present. If both #PSALDO and #TRANS provide data for the same account and month, the period rows take precedence so the movement is counted once. #BTRANS and #RTRANS are change markers, not additional amounts. The SIE Group's format specification describes these record types and their signs.
If the timeline covers historyStart, the importer posts the available month-end balances before the latest SIE period. A timeline beginning after historyStart uses only the latest snapshot. Annual-only files also use the snapshot-only behavior. The configured trigger is emitted after the latest snapshot is applied, so triggered forecasts can begin in the following month.
For each SIE account code, the module registers a matching account from the selected Business or Personal plan, reusing an existing account for the same owner when available. Discovery uses the text supplied to the run, including a textfile override. When both a known parent account and its known descendants occur in the file, their amounts are added to the parent account according to the plan's explicit hierarchy. A trailing zero alone does not establish that relationship.
Personal account choices use the numeric SIE aliases 9900–9950, with the account name written in the ordinary #KONTO row. The importer maps an alias to the Personal plan when its account name matches that plan entry. These aliases stay numeric in the SIE text, so models can pass the resulting value directly to sieStatement().
thisYear(offset = 0) returns { year, start, end } for a complete calendar year. Use thisYear(-1) for the previous year and thisYear(1) for the next year when creating #RAR rows.
If a code is absent from the plan, SIE import creates a separate account with that original number. It inherits its type and title from the nearest higher known account, or from a group with a single account type. The inherited title is placed in parentheses, for example (Sales within the country), and appears in the existing category_label output field. The imported account has its own category beneath the inherited account's category parent, so it remains distinct from other accounts with the same inherited title. This behavior belongs to SIE import; calling stdaccount() directly still requires a recognized account or category code. If no suitable parent can supply the metadata, the import reports an error.
Previous-year result and book closing
Some exports carry the previous year's closing balance accounts into the next year before transferring the previous result to equity. The importer recognizes this when the opening balances match the previous closing balances account by account, and the previous closing balances plus previous result balance to zero. It adds the missing previous result to account 2098 — Profit or loss from the previous year. Profit produces a credit; loss produces a debit. An existing imported balance on 2098 is retained and the adjustment is added to it.
Some year-end exports already include the current year's result in their balance accounts while also reporting it in #RES. When the balance accounts balance after any verified previous-year adjustment, the importer adds an equal and opposite amount to 2098. This keeps the result visible in the income statement without counting it twice in the balance sheet. parseLatestSieSnapshot() exposes that offset as bookedCurrentResultAdjustment. Result balances that are not already included in equity remain unadjusted.
parseLatestSieSnapshot() preserves the original balances and exposes the previous-year amount and source year end as openingResultAdjustment when that reconciliation succeeds. The run's account postings show each required adjustment on 2098 as part of the balanced SIE import. Unexplained differences still produce an error with the period, currency, and amount.
bookClosing() subsequently transfers the current income and expense balances to retained earnings (2091). It leaves the 2098 adjustments in equity, preventing a result that was already included in the imported balance from being counted a second time. A later closing with no further income or expenses makes no additional result transfer.
The statement sets each registered Business-plan account owned by the company to the imported snapshot, including any verified opening-result adjustment described above. The final postings must balance. The SIE currency must match the model currency; when #VALUTA is absent, the format's default SEK is used.