@diy-accounting-uk/diya-submit 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,73 +0,0 @@
1
- // SPDX-License-Identifier: LicenseRef-PolyForm-Internal-Use-1.0.0
2
- // Copyright (C) 2006-2026 DIY Accounting Limited
3
-
4
- // app/lib/xmlDom.js
5
- // Minimal XML parsing built on happy-dom's DOMParser, already a dependency for this repo's
6
- // DOM-based tests. Used wherever code needs to parse or well-formedness-check XML: the
7
- // Companies House GovTalk envelope and the generated iXBRL document.
8
-
9
- import { Window } from "happy-dom";
10
-
11
- export class XmlParseError extends Error {
12
- constructor(message) {
13
- super(message);
14
- this.name = "XmlParseError";
15
- }
16
- }
17
-
18
- /**
19
- * Parse an XML string into a Document, throwing XmlParseError if the XML is not well-formed.
20
- * @param {string} xml
21
- * @returns {Document}
22
- */
23
- export function parseXmlDocument(xml) {
24
- const window = new Window();
25
- const parser = new window.DOMParser();
26
- const document = parser.parseFromString(xml, "text/xml");
27
- const parseErrors = document.getElementsByTagName("parsererror");
28
- if (parseErrors.length > 0) {
29
- throw new XmlParseError(parseErrors[0].textContent);
30
- }
31
- return document;
32
- }
33
-
34
- /**
35
- * Text content of the first descendant element with the given tag name, or undefined if absent.
36
- * @param {Document|Element} node
37
- * @param {string} tagName
38
- * @returns {string|undefined}
39
- */
40
- export function firstElementText(node, tagName) {
41
- const elements = node.getElementsByTagName(tagName);
42
- return elements.length > 0 ? elements[0].textContent : undefined;
43
- }
44
-
45
- /**
46
- * The first descendant element with the given tag name, or undefined if absent.
47
- * @param {Document|Element} node
48
- * @param {string} tagName
49
- * @returns {Element|undefined}
50
- */
51
- export function firstElement(node, tagName) {
52
- const elements = node.getElementsByTagName(tagName);
53
- return elements.length > 0 ? elements[0] : undefined;
54
- }
55
-
56
- /**
57
- * All descendant elements with the given tag name, as a plain array.
58
- * @param {Document|Element} node
59
- * @param {string} tagName
60
- * @returns {Element[]}
61
- */
62
- export function allElements(node, tagName) {
63
- return Array.from(node.getElementsByTagName(tagName));
64
- }
65
-
66
- /**
67
- * Escape a string for use as XML text content.
68
- * @param {string} value
69
- * @returns {string}
70
- */
71
- export function escapeXmlText(value) {
72
- return String(value).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
73
- }
@@ -1,414 +0,0 @@
1
- // SPDX-License-Identifier: LicenseRef-PolyForm-Internal-Use-1.0.0
2
- // Copyright (C) 2006-2026 DIY Accounting Limited
3
-
4
- // app/services/accountsIxbrlCommon.js
5
- // The parts of a Companies House annual accounts iXBRL document that every accounting regime
6
- // shares: the FRS 102 entry point and namespaces, the concept, dimension and member names,
7
- // context and fact writers, the fixed-wording statements and the document shell. The regime
8
- // builders (microEntityAccountsIxbrl.js, smallCompanyAccountsIxbrl.js) choose which facts to write.
9
-
10
- import { readFileSync } from "node:fs";
11
- import { fileURLToPath } from "node:url";
12
- import { dirname, join } from "node:path";
13
- import { escapeXmlText } from "../lib/xmlDom.js";
14
-
15
- export const FRS_102_ENTRY_POINT = "https://xbrl.frc.org.uk/FRS-102/2026-01-01/FRS-102-2026-01-01.xsd";
16
-
17
- // Namespace identifiers, not fetched URLs: they are compared as exact strings against the FRC
18
- // taxonomy schema (see fixtures/frc-taxonomy/frs-102-2026-concepts.json), which defines them as
19
- // http, and a validator rejects a document whose namespace doesn't match byte for byte.
20
- export const NAMESPACES = {
21
- // eslint-disable-next-line sonarjs/no-clear-text-protocols -- taxonomy namespace, not a fetch; see comment above
22
- bus: "http://xbrl.frc.org.uk/cd/2026-01-01/business",
23
- // eslint-disable-next-line sonarjs/no-clear-text-protocols -- taxonomy namespace, not a fetch; see comment above
24
- core: "http://xbrl.frc.org.uk/fr/2026-01-01/core",
25
- // eslint-disable-next-line sonarjs/no-clear-text-protocols -- taxonomy namespace, not a fetch; see comment above
26
- direp: "http://xbrl.frc.org.uk/reports/2026-01-01/direp",
27
- };
28
-
29
- // Resolved from the FRS 102 entry point by scripts/generate-frc-taxonomy-concepts.js (see
30
- // fixtures/frc-taxonomy/frs-102-2026-concepts.json), not guessed from the accounts TIS prose. The
31
- // TIS names UKCompaniesHouseRegisteredNumber .. AccountingStandardsApplied by their concept names
32
- // directly; the balance sheet figures and AccountsTypeFullOrAbbreviated are not named in the TIS,
33
- // so their entries below are resolved substitutes:
34
- // - "AccountsTypeFullOrAbbreviated" does not exist in the taxonomy. The real concept is
35
- // AccountsType, dimensioned by AccountsTypeDimension; abbreviated accounts were abolished in
36
- // 2016, so every filing reports the FullAccounts member.
37
- // - The balance sheet lines (fixed assets, current assets, creditors, called up share capital,
38
- // profit and loss account, capital and reserves) are core:FixedAssets, core:CurrentAssets,
39
- // core:Creditors (dimensioned by MaturitiesOrExpirationPeriodsDimension for the within/after
40
- // one year split) and core:Equity (dimensioned by EquityClassesDimension for the share capital
41
- // and profit and loss account components; the total capital and reserves figure is core:Equity
42
- // at its default, undimensioned member).
43
- export const CONCEPTS = {
44
- companiesHouseRegisteredNumber: { prefix: "bus", name: "UKCompaniesHouseRegisteredNumber" },
45
- entityCurrentLegalOrRegisteredName: { prefix: "bus", name: "EntityCurrentLegalOrRegisteredName" },
46
- balanceSheetDate: { prefix: "bus", name: "BalanceSheetDate" },
47
- dateAuthorisationFinancialStatementsForIssue: { prefix: "core", name: "DateAuthorisationFinancialStatementsForIssue" },
48
- directorSigningFinancialStatements: { prefix: "core", name: "DirectorSigningFinancialStatements" },
49
- entityDormantTruefalse: { prefix: "bus", name: "EntityDormantTruefalse" },
50
- startDateForPeriodCoveredByReport: { prefix: "bus", name: "StartDateForPeriodCoveredByReport" },
51
- endDateForPeriodCoveredByReport: { prefix: "bus", name: "EndDateForPeriodCoveredByReport" },
52
- entityTradingStatus: { prefix: "bus", name: "EntityTradingStatus" },
53
- accountsStatusAuditedOrUnaudited: { prefix: "bus", name: "AccountsStatusAuditedOrUnaudited" },
54
- accountsType: { prefix: "bus", name: "AccountsType" },
55
- accountingStandardsApplied: { prefix: "bus", name: "AccountingStandardsApplied" },
56
- applicableLegislation: { prefix: "bus", name: "ApplicableLegislation" },
57
-
58
- statementAuditExemptionSection477: {
59
- prefix: "direp",
60
- name: "StatementThatCompanyEntitledToExemptionFromAuditUnderSection477CompaniesAct2006RelatingToSmallCompanies",
61
- },
62
- statementAuditExemptionSection480: {
63
- prefix: "direp",
64
- name: "StatementThatCompanyEntitledToExemptionFromAuditUnderSection480CompaniesAct2006RelatingToDormantCompanies",
65
- },
66
- statementMembersNotRequiredAudit: { prefix: "direp", name: "StatementThatMembersHaveNotRequiredCompanyToObtainAnAudit" },
67
- statementDirectorsResponsibilities: { prefix: "direp", name: "StatementThatDirectorsAcknowledgeTheirResponsibilitiesUnderCompaniesAct" },
68
- statementMicroEntityProvisions: {
69
- prefix: "direp",
70
- name: "StatementThatAccountsHaveBeenPreparedInAccordanceWithProvisionsSmallCompaniesRegime",
71
- },
72
- statementSmallCompaniesRegimeAccounts: {
73
- prefix: "direp",
74
- name: "StatementThatAccountsHaveBeenPreparedInAccordanceWithProvisionsSmallCompaniesRegime",
75
- },
76
- statementSmallCompaniesRegimeDirectorsReport: {
77
- prefix: "direp",
78
- name: "StatementThatDirectorsReportHasBeenPreparedInAccordanceWithProvisionsSmallCompaniesRegime",
79
- },
80
- statementProfitAndLossNotDelivered: {
81
- prefix: "direp",
82
- name: "StatementThatDirectorsHaveElectedNotToDeliverProfitLossAccountUnderSection4445ACompaniesAct2006",
83
- },
84
-
85
- descriptionPrincipalActivities: { prefix: "bus", name: "DescriptionPrincipalActivities" },
86
- nameEntityOfficer: { prefix: "bus", name: "NameEntityOfficer" },
87
- directorSigningDirectorsReport: { prefix: "direp", name: "DirectorSigningDirectorsReport" },
88
-
89
- turnoverRevenue: { prefix: "core", name: "TurnoverRevenue" },
90
- costSales: { prefix: "core", name: "CostSales" },
91
- grossProfitLoss: { prefix: "core", name: "GrossProfitLoss" },
92
- administrativeExpenses: { prefix: "core", name: "AdministrativeExpenses" },
93
- operatingProfitLoss: { prefix: "core", name: "OperatingProfitLoss" },
94
- otherInterestReceivable: { prefix: "core", name: "OtherInterestReceivableSimilarIncomeFinanceIncome" },
95
- profitLossBeforeTax: { prefix: "core", name: "ProfitLossOnOrdinaryActivitiesBeforeTax" },
96
- taxOnProfitLoss: { prefix: "core", name: "TaxTaxCreditOnProfitOrLossOnOrdinaryActivities" },
97
- profitLoss: { prefix: "core", name: "ProfitLoss" },
98
-
99
- fixedAssets: { prefix: "core", name: "FixedAssets" },
100
- currentAssets: { prefix: "core", name: "CurrentAssets" },
101
- netCurrentAssetsLiabilities: { prefix: "core", name: "NetCurrentAssetsLiabilities" },
102
- totalAssetsLessCurrentLiabilities: { prefix: "core", name: "TotalAssetsLessCurrentLiabilities" },
103
- creditors: { prefix: "core", name: "Creditors" },
104
- netAssetsLiabilities: { prefix: "core", name: "NetAssetsLiabilities" },
105
- equity: { prefix: "core", name: "Equity" },
106
- totalInventories: { prefix: "core", name: "TotalInventories" },
107
- debtors: { prefix: "core", name: "Debtors" },
108
- cashBankOnHand: { prefix: "core", name: "CashBankOnHand" },
109
- tradeCreditors: { prefix: "core", name: "TradeCreditorsTradePayables" },
110
- corporationTaxPayable: { prefix: "core", name: "CorporationTaxPayable" },
111
- otherCreditors: { prefix: "core", name: "OtherCreditors" },
112
- averageNumberEmployeesDuringPeriod: { prefix: "core", name: "AverageNumberEmployeesDuringPeriod" },
113
- numberSharesIssuedFullyPaid: { prefix: "core", name: "NumberSharesIssuedFullyPaid" },
114
- nominalValueAllottedShareCapital: { prefix: "core", name: "NominalValueAllottedShareCapital" },
115
-
116
- propertyPlantEquipment: { prefix: "core", name: "PropertyPlantEquipment" },
117
- propertyPlantEquipmentGrossCost: { prefix: "core", name: "PropertyPlantEquipmentGrossCost" },
118
- additionsPropertyPlantEquipment: { prefix: "core", name: "AdditionsOtherThanThroughBusinessCombinationsPropertyPlantEquipment" },
119
- disposalsPropertyPlantEquipment: { prefix: "core", name: "DisposalsPropertyPlantEquipment" },
120
- accumulatedDepreciationPropertyPlantEquipment: { prefix: "core", name: "AccumulatedDepreciationImpairmentPropertyPlantEquipment" },
121
- depreciationChargePropertyPlantEquipment: { prefix: "core", name: "IncreaseFromDepreciationChargeForYearPropertyPlantEquipment" },
122
- depreciationDisposalsPropertyPlantEquipment: { prefix: "core", name: "DisposalsDecreaseInDepreciationImpairmentPropertyPlantEquipment" },
123
- };
124
-
125
- export const DIMENSIONS = {
126
- entityTradingStatus: { prefix: "bus", name: "EntityTradingStatusDimension" },
127
- entityShareClasses: { prefix: "bus", name: "EntityShareClassesDimension" },
128
- entityOfficers: { prefix: "bus", name: "EntityOfficersDimension" },
129
- accountingStandards: { prefix: "bus", name: "AccountingStandardsDimension" },
130
- applicableLegislation: { prefix: "bus", name: "ApplicableLegislationDimension" },
131
- accountsStatus: { prefix: "bus", name: "AccountsStatusDimension" },
132
- accountsType: { prefix: "bus", name: "AccountsTypeDimension" },
133
- equityClasses: { prefix: "core", name: "EquityClassesDimension" },
134
- maturities: { prefix: "core", name: "MaturitiesOrExpirationPeriodsDimension" },
135
- propertyPlantEquipmentClasses: { prefix: "core", name: "PropertyPlantEquipmentClassesDimension" },
136
- };
137
-
138
- export const MEMBERS = {
139
- microEntities: { prefix: "bus", name: "Micro-entities" },
140
- frs102: { prefix: "bus", name: "FRS102" },
141
- smallCompaniesRegimeForAccounts: { prefix: "bus", name: "SmallCompaniesRegimeForAccounts" },
142
- auditExemptNoAccountantsReport: { prefix: "bus", name: "AuditExempt-NoAccountantsReport" },
143
- fullAccounts: { prefix: "bus", name: "FullAccounts" },
144
- shareCapital: { prefix: "core", name: "ShareCapital" },
145
- neverTraded: { prefix: "bus", name: "EntityHasNeverTraded" },
146
- noLongerTrading: { prefix: "bus", name: "EntityNoLongerTradingButTradedInPast" },
147
- ordinaryShares: { prefix: "bus", name: "OrdinaryShareClass1" },
148
- preferenceShares: { prefix: "bus", name: "PreferenceShareClass1" },
149
- deferredShares: { prefix: "bus", name: "DeferredShareClass1" },
150
- otherShares: { prefix: "bus", name: "OtherShareClass1" },
151
- retainedEarningsAccumulatedLosses: { prefix: "core", name: "RetainedEarningsAccumulatedLosses" },
152
- withinOneYear: { prefix: "core", name: "WithinOneYear" },
153
- afterOneYear: { prefix: "core", name: "AfterOneYear" },
154
- landBuildings: { prefix: "core", name: "LandBuildings" },
155
- plantMachinery: { prefix: "core", name: "PlantMachinery" },
156
- furnitureFittings: { prefix: "core", name: "FurnitureFittings" },
157
- computerEquipment: { prefix: "core", name: "ComputerEquipment" },
158
- motorVehicles: { prefix: "core", name: "MotorVehicles" },
159
- };
160
-
161
- export const STATEMENT_TEXT = {
162
- statementAuditExemptionSection480:
163
- "The company is entitled to exemption from audit under section 480 of the Companies Act 2006 relating to dormant companies.",
164
- statementAuditExemptionSection477:
165
- "The company is entitled to exemption from audit under section 477 of the Companies Act 2006 relating to small companies.",
166
- statementMembersNotRequiredAudit:
167
- "The members have not required the company to obtain an audit in accordance with section 476 of the Companies Act 2006.",
168
- statementDirectorsResponsibilities:
169
- "The directors acknowledge their responsibilities for complying with the requirements of the Companies Act 2006 with respect to accounting records and the preparation of accounts.",
170
- statementMicroEntityProvisions:
171
- "These accounts have been prepared in accordance with the provisions applicable to companies subject to the micro-entities regime.",
172
- statementSmallCompaniesRegimeAccounts:
173
- "These accounts have been prepared in accordance with the provisions applicable to companies subject to the small companies regime.",
174
- statementSmallCompaniesRegimeDirectorsReport:
175
- "This report has been prepared in accordance with the provisions applicable to companies entitled to the small companies regime.",
176
- statementProfitAndLossNotDelivered:
177
- "The directors have elected not to deliver a copy of the profit and loss account to the registrar of companies in accordance with section 444(5A) of the Companies Act 2006.",
178
- };
179
-
180
- export function qname(concept) {
181
- return `${concept.prefix}:${concept.name}`;
182
- }
183
-
184
- export function previousDay(isoDate) {
185
- const date = new Date(`${isoDate}T00:00:00Z`);
186
- date.setUTCDate(date.getUTCDate() - 1);
187
- return date.toISOString().slice(0, 10);
188
- }
189
-
190
- function sameDayOneYearEarlier(isoDate) {
191
- const date = new Date(`${isoDate}T00:00:00Z`);
192
- date.setUTCFullYear(date.getUTCFullYear() - 1);
193
- return date.toISOString().slice(0, 10);
194
- }
195
-
196
- /**
197
- * Build the xbrli contexts an accounts document needs: one duration context for the current
198
- * period, one instant context for the current balance sheet date (period end), one instant
199
- * context for the period start (StartDateForPeriodCoveredByReport is itself an instant-typed
200
- * fact), and, when comparatives are supplied, a prior-year instant context and a prior-year
201
- * duration context.
202
- *
203
- * @param {object} input - periodStart, periodEnd, companyNumber, and optionally priorBalanceSheetDate and priorPeriodStart
204
- * @param {object} [options]
205
- * @param {boolean} [options.includePriorInstant] - defaults to whether input.balanceSheet.prior is present
206
- * @param {boolean} [options.includePriorPeriod] - add the prior-year duration context (profit and loss comparatives)
207
- * @returns {{xml: string, refs: object, entityIdentifierXml: string, periodXml: Record<string,string>}}
208
- */
209
- export function buildContexts(input, options = {}) {
210
- const { includePriorInstant = Boolean(input.balanceSheet?.prior), includePriorPeriod = false } = options;
211
- const currentYear = input.periodEnd.slice(0, 4);
212
- const refs = {
213
- current: `y${currentYear}`,
214
- currentInstant: `e${currentYear}`,
215
- periodStartInstant: `p${currentYear}`,
216
- };
217
-
218
- const entityIdentifierXml = `<xbrli:identifier scheme="http://www.companieshouse.gov.uk/">${escapeXmlText(input.companyNumber)}</xbrli:identifier>`;
219
-
220
- const periodXml = {
221
- [refs.current]: `<xbrli:period><xbrli:startDate>${input.periodStart}</xbrli:startDate><xbrli:endDate>${input.periodEnd}</xbrli:endDate></xbrli:period>`,
222
- [refs.currentInstant]: `<xbrli:period><xbrli:instant>${input.periodEnd}</xbrli:instant></xbrli:period>`,
223
- [refs.periodStartInstant]: `<xbrli:period><xbrli:instant>${input.periodStart}</xbrli:instant></xbrli:period>`,
224
- };
225
-
226
- const priorBalanceSheetDate = input.priorBalanceSheetDate || previousDay(input.periodStart);
227
- const priorYear = priorBalanceSheetDate.slice(0, 4);
228
- if ((includePriorInstant || includePriorPeriod) && priorYear === currentYear) {
229
- throw new Error(`The prior period ends in ${priorYear}, the same year as the current period, so their context ids would collide`);
230
- }
231
- if (includePriorInstant) {
232
- refs.priorInstant = `e${priorYear}`;
233
- periodXml[refs.priorInstant] = `<xbrli:period><xbrli:instant>${priorBalanceSheetDate}</xbrli:instant></xbrli:period>`;
234
- }
235
- if (includePriorPeriod) {
236
- const priorPeriodStart = input.priorPeriodStart || sameDayOneYearEarlier(input.periodStart);
237
- refs.prior = `y${priorYear}`;
238
- periodXml[refs.prior] =
239
- `<xbrli:period><xbrli:startDate>${priorPeriodStart}</xbrli:startDate><xbrli:endDate>${priorBalanceSheetDate}</xbrli:endDate></xbrli:period>`;
240
- }
241
-
242
- const contextsXml = Object.entries(periodXml)
243
- .map(([id, period]) => `<xbrli:context id="${id}"><xbrli:entity>${entityIdentifierXml}</xbrli:entity>${period}</xbrli:context>`)
244
- .join("");
245
-
246
- return { xml: contextsXml, refs, entityIdentifierXml, periodXml };
247
- }
248
-
249
- /**
250
- * Format a monetary value as whole pounds, matching decimals="0". Returns the absolute value;
251
- * callers add sign="-" to the ix:nonFraction tag when the underlying figure is negative, per the
252
- * XBRL convention of reporting magnitudes against the concept's declared balance direction.
253
- * @param {number} value
254
- * @returns {string}
255
- */
256
- export function formatMonetary(value) {
257
- return String(Math.round(Math.abs(value)));
258
- }
259
-
260
- /**
261
- * Render one of the fixed-wording statements as a tagged ix:nonNumeric fact. The wording is fixed
262
- * (the page never lets a user edit it), matching the phrase checks Companies House runs on each
263
- * statement.
264
- * @param {keyof typeof STATEMENT_TEXT} key
265
- * @param {string} contextRef
266
- * @returns {string}
267
- */
268
- export function renderStatement(key, contextRef) {
269
- const concept = CONCEPTS[key];
270
- const text = STATEMENT_TEXT[key];
271
- return `<ix:nonNumeric name="${qname(concept)}" contextRef="${contextRef}">${escapeXmlText(text)}</ix:nonNumeric>`;
272
- }
273
-
274
- export function renderFixedFact(conceptKey, contextRef) {
275
- return `<ix:nonNumeric name="${qname(CONCEPTS[conceptKey])}" contextRef="${contextRef}"></ix:nonNumeric>`;
276
- }
277
-
278
- export function renderTextFact(conceptKey, contextRef, text) {
279
- return `<ix:nonNumeric name="${qname(CONCEPTS[conceptKey])}" contextRef="${contextRef}">${escapeXmlText(text)}</ix:nonNumeric>`;
280
- }
281
-
282
- export function renderMonetaryFact(conceptKey, contextRef, unitRef, value) {
283
- const signAttribute = value < 0 ? ' sign="-"' : "";
284
- return `<ix:nonFraction name="${qname(CONCEPTS[conceptKey])}" contextRef="${contextRef}" unitRef="${unitRef}" decimals="0"${signAttribute}>${formatMonetary(value)}</ix:nonFraction>`;
285
- }
286
-
287
- export function dimensionMemberXml(dimension, member) {
288
- return `<xbrldi:explicitMember dimension="${qname(dimension)}">${qname(member)}</xbrldi:explicitMember>`;
289
- }
290
-
291
- // A dimensionally-qualified fact needs its own context (an XBRL context is identified by its
292
- // full period + entity + dimensional segment, not by period alone). Builds one such context on
293
- // top of an existing base context's period, and appends it to additionalContexts.
294
- export function buildDimensionedContext({ additionalContexts, entityIdentifierXml, periodXml, dimensionXml, id }) {
295
- additionalContexts.push(
296
- `<xbrli:context id="${id}"><xbrli:entity>${entityIdentifierXml}<xbrli:segment>${dimensionXml}</xbrli:segment></xbrli:entity>${periodXml}</xbrli:context>`,
297
- );
298
- return id;
299
- }
300
-
301
- /**
302
- * The balance sheet facts for one balance sheet date: fixed assets, current assets, net current
303
- * assets, total assets less current liabilities, creditors by maturity, net assets and the equity
304
- * components. Throws when capital and reserves does not equal the net assets derived from the lines.
305
- */
306
- export function assembleBalanceSheetFacts({ contextRef, entityIdentifierXml, periodXml, additionalContexts, unitRef, figures }) {
307
- const facts = [];
308
-
309
- facts.push(renderMonetaryFact("fixedAssets", contextRef, unitRef, figures.fixedAssets));
310
- facts.push(renderMonetaryFact("currentAssets", contextRef, unitRef, figures.currentAssets));
311
-
312
- const netCurrentAssets = figures.currentAssets - figures.creditorsWithinOneYear;
313
- const totalAssetsLessCurrentLiabilities = figures.fixedAssets + netCurrentAssets;
314
- const netAssets = totalAssetsLessCurrentLiabilities - figures.creditorsAfterOneYear;
315
-
316
- if (Math.round(netAssets) !== Math.round(figures.capitalAndReserves)) {
317
- throw new Error(
318
- `Capital and reserves (${figures.capitalAndReserves}) does not equal net assets (${netAssets}) for context ${contextRef}`,
319
- );
320
- }
321
-
322
- facts.push(renderMonetaryFact("netCurrentAssetsLiabilities", contextRef, unitRef, netCurrentAssets));
323
- facts.push(renderMonetaryFact("totalAssetsLessCurrentLiabilities", contextRef, unitRef, totalAssetsLessCurrentLiabilities));
324
-
325
- const withinOneYearContextId = buildDimensionedContext({
326
- additionalContexts,
327
- entityIdentifierXml,
328
- periodXml,
329
- dimensionXml: dimensionMemberXml(DIMENSIONS.maturities, MEMBERS.withinOneYear),
330
- id: `${contextRef}-within-one-year`,
331
- });
332
- facts.push(renderMonetaryFact("creditors", withinOneYearContextId, unitRef, figures.creditorsWithinOneYear));
333
-
334
- const afterOneYearContextId = buildDimensionedContext({
335
- additionalContexts,
336
- entityIdentifierXml,
337
- periodXml,
338
- dimensionXml: dimensionMemberXml(DIMENSIONS.maturities, MEMBERS.afterOneYear),
339
- id: `${contextRef}-after-one-year`,
340
- });
341
- facts.push(renderMonetaryFact("creditors", afterOneYearContextId, unitRef, figures.creditorsAfterOneYear));
342
-
343
- facts.push(renderMonetaryFact("netAssetsLiabilities", contextRef, unitRef, netAssets));
344
-
345
- const shareCapitalContextId = buildDimensionedContext({
346
- additionalContexts,
347
- entityIdentifierXml,
348
- periodXml,
349
- dimensionXml: dimensionMemberXml(DIMENSIONS.equityClasses, MEMBERS.shareCapital),
350
- id: `${contextRef}-share-capital`,
351
- });
352
- facts.push(renderMonetaryFact("equity", shareCapitalContextId, unitRef, figures.calledUpShareCapital));
353
-
354
- const profitAndLossContextId = buildDimensionedContext({
355
- additionalContexts,
356
- entityIdentifierXml,
357
- periodXml,
358
- dimensionXml: dimensionMemberXml(DIMENSIONS.equityClasses, MEMBERS.retainedEarningsAccumulatedLosses),
359
- id: `${contextRef}-profit-and-loss-account`,
360
- });
361
- facts.push(renderMonetaryFact("equity", profitAndLossContextId, unitRef, figures.profitAndLossAccount));
362
-
363
- facts.push(renderMonetaryFact("equity", contextRef, unitRef, figures.capitalAndReserves));
364
-
365
- return facts.join("");
366
- }
367
-
368
- /**
369
- * Wrap rendered contexts, facts and visible prose in the iXBRL document shell.
370
- * @param {object} parts
371
- * @param {string} parts.companyName
372
- * @param {string} parts.contextsXml - every xbrli:context, already concatenated
373
- * @param {string} parts.bodyHtml - the visible document with its tagged facts
374
- * @returns {string}
375
- */
376
- export function renderAccountsDocument({ companyName, contextsXml, bodyHtml }) {
377
- const namespaceAttributes = Object.entries(NAMESPACES)
378
- .map(([prefix, uri]) => `xmlns:${prefix}="${uri}"`)
379
- .join(" ");
380
-
381
- return `<?xml version="1.0"?>
382
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ix="http://www.xbrl.org/2013/inlineXBRL" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" ${namespaceAttributes}>
383
- <head><title>${escapeXmlText(companyName)} - annual accounts</title></head>
384
- <body>
385
- <ix:header>
386
- <ix:references><link:schemaRef xlink:type="simple" xlink:href="${FRS_102_ENTRY_POINT}"/></ix:references>
387
- <ix:resources>
388
- ${contextsXml}
389
- <xbrli:unit id="GBP"><xbrli:measure>iso4217:GBP</xbrli:measure></xbrli:unit>
390
- <xbrli:unit id="pure"><xbrli:measure>pure</xbrli:measure></xbrli:unit>
391
- <xbrli:unit id="shares"><xbrli:measure>xbrli:shares</xbrli:measure></xbrli:unit>
392
- </ix:resources>
393
- </ix:header>
394
- ${bodyHtml}
395
- </body>
396
- </html>
397
- `;
398
- }
399
-
400
- let cachedConceptList;
401
-
402
- /**
403
- * The checked-in list of concept qualified names the FRS 102 entry point declares, produced by
404
- * scripts/generate-frc-taxonomy-concepts.js. Cached across calls within one process.
405
- * @returns {string[]}
406
- */
407
- export function loadFrcTaxonomyConcepts() {
408
- if (!cachedConceptList) {
409
- const fixturePath = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "fixtures", "frc-taxonomy", "frs-102-2026-concepts.json");
410
- const data = JSON.parse(readFileSync(fixturePath, "utf8"));
411
- cachedConceptList = data.concepts;
412
- }
413
- return cachedConceptList;
414
- }