@diy-accounting-uk/diya-submit 0.1.3 → 0.1.8

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.
@@ -125,10 +125,13 @@ const STATUS_TOKEN = /^[A-Za-z]+$/;
125
125
  const CURRENCY_TOKEN = /^[A-Z]{3}$/;
126
126
  const AMOUNT_TOKEN = /^-?[\d,]+\.\d\d$/;
127
127
  const ID_LINE = /^\s*ID:\s*(\S+)/;
128
- // Lines that never belong to a description: the page header repeated on
129
- // every page, the running column header, and the period banner that closes
130
- // each page.
131
- const NOISE_LINE = /^(Date\s+Description|Transaction History|Page \d|DIY Accounting|antony@|[A-Za-z]+ \d{1,2},? \d{4}\s+through)/;
128
+ // Each page opens with its header: the title, the period, the account
129
+ // holder's name and email address, then the column header. Every line from
130
+ // the title to the column header belongs to the header, whoever the account
131
+ // holder is. The period banner and the page number close each page.
132
+ const PAGE_TITLE = /^Transaction History$/;
133
+ const COLUMN_HEADER = /^Date\s+Description\s+Status\s+Currency\s+Gross\s+Fee\s+Net$/;
134
+ const PAGE_FOOTER = /^(Page \d|[A-Za-z]+ \d{1,2},? \d{4}\s+through)/;
132
135
 
133
136
  // A data row carries its date at the start of the line and its five other
134
137
  // fields -- Status, Currency, Gross, Fee, Net -- as the last five
@@ -152,19 +155,84 @@ function matchDataRow(rawLine) {
152
155
  return { date: dateMatch[1], descriptionTail: columns.slice(0, -5).join(" "), status, currency, gross, fee, net };
153
156
  }
154
157
 
158
+ // PayPal's "Transaction details" report, which replaced "Transaction History"
159
+ // from July 2025: one line per transaction holding the date, the type, the
160
+ // transaction id, the counterparty's name and email, and the Gross, Net and
161
+ // Fee figures as its last three columns, in that order. A type too long for
162
+ // its column carries on in the next line at the column's own indent. The
163
+ // report states no status or currency: its rows are pound movements, and an
164
+ // authorisation hold is the only row still open.
165
+ const TRANSACTION_DETAILS_TITLE = /Transaction details for all transactions/;
166
+ const TRANSACTION_DETAILS_NOISE = /^(Page \d|Transaction details|Merchant account)/;
167
+ const OPEN_AUTHORISATION_HOLD = /^account hold for open authorisation$/i;
168
+
169
+ function matchTransactionDetailsRow(rawLine) {
170
+ const dateMatch = LEADING_DATE.exec(rawLine);
171
+ if (!dateMatch) return null;
172
+ const columns = rawLine
173
+ .trim()
174
+ .split(/\s{2,}/)
175
+ .filter((column) => column !== "");
176
+ if (columns.length < 6) return null;
177
+ const [gross, net, fee] = columns.slice(-3);
178
+ if (!AMOUNT_TOKEN.test(gross) || !AMOUNT_TOKEN.test(net) || !AMOUNT_TOKEN.test(fee)) return null;
179
+ const counterparty = columns.slice(3, -3).find((column) => !column.includes("@"));
180
+ return { date: dateMatch[1], type: columns[1], id: columns[2], counterparty, typeIndent: dateMatch[0].length, gross, net, fee };
181
+ }
182
+
183
+ function parseTransactionDetailsRecords(text) {
184
+ const rows = [];
185
+ let current = null;
186
+ for (const rawLine of text.split(/\r?\n/)) {
187
+ const row = matchTransactionDetailsRow(rawLine);
188
+ if (row) {
189
+ current = row;
190
+ rows.push(row);
191
+ continue;
192
+ }
193
+ const trimmed = rawLine.trim();
194
+ if (trimmed === "" || TRANSACTION_DETAILS_NOISE.test(trimmed)) {
195
+ current = null;
196
+ continue;
197
+ }
198
+ if (current && rawLine.search(/\S/) === current.typeIndent) current.type += ` ${trimmed.split(/\s{2,}/)[0]}`;
199
+ }
200
+ return rows.map((row) => ({
201
+ date: isoDateFromUkDate(row.date),
202
+ description: row.counterparty ? `${row.type}: ${row.counterparty}` : row.type,
203
+ status: OPEN_AUTHORISATION_HOLD.test(row.type) ? "Pending" : "Completed",
204
+ currency: "GBP",
205
+ gross: parseAmount(row.gross),
206
+ fee: parseAmount(row.fee),
207
+ net: parseAmount(row.net),
208
+ id: row.id,
209
+ }));
210
+ }
211
+
155
212
  /**
156
- * Parse a PayPal "Transaction History" PDF's rendered text into raw
157
- * records, one per transaction: its description reassembled from whatever
158
- * lines wrapped around the date/amount row, its id, and its own posting
159
- * date, status, currency and Gross/Fee/Net figures.
213
+ * Parse a PayPal statement PDF's rendered text into raw records, one per
214
+ * transaction: its description, its id, and its own posting date, status,
215
+ * currency and Gross/Fee/Net figures. A "Transaction History" description is
216
+ * reassembled from whatever lines wrapped around the date/amount row; a
217
+ * "Transaction details" report is read by its own layout.
160
218
  * @param {string} text - pdftotext -layout output for one statement PDF
161
219
  * @returns {Array<{date: string, description: string, status: string, currency: string, gross: number, fee: number, net: number, id: string|undefined}>}
162
220
  */
163
221
  export function parsePaypalStatementRecords(text) {
222
+ if (TRANSACTION_DETAILS_TITLE.test(text)) return parseTransactionDetailsRecords(text);
164
223
  const records = [];
165
224
  let descriptionParts = [];
225
+ let inPageHeader = false;
166
226
 
167
227
  for (const rawLine of text.split(/\r?\n/)) {
228
+ const trimmed = rawLine.trim();
229
+ if (PAGE_TITLE.test(trimmed)) inPageHeader = true;
230
+ if (inPageHeader) {
231
+ if (COLUMN_HEADER.test(trimmed)) inPageHeader = false;
232
+ descriptionParts = [];
233
+ continue;
234
+ }
235
+
168
236
  const dataRow = matchDataRow(rawLine);
169
237
  if (dataRow) {
170
238
  const description = [...descriptionParts, dataRow.descriptionTail]
@@ -192,8 +260,7 @@ export function parsePaypalStatementRecords(text) {
192
260
  continue;
193
261
  }
194
262
 
195
- const trimmed = rawLine.trim();
196
- if (trimmed === "" || NOISE_LINE.test(trimmed)) {
263
+ if (trimmed === "" || PAGE_FOOTER.test(trimmed)) {
197
264
  descriptionParts = [];
198
265
  continue;
199
266
  }
@@ -364,10 +431,15 @@ function isPostable(record, chosenReleaseIds, poundAmounts) {
364
431
  return true;
365
432
  }
366
433
 
367
- // The pound figure of each completed foreign-currency record: the amount of
368
- // the same-day GBP "General Currency Conversion" row that funded it. Each
369
- // conversion leg is used once, in statement order, so two bills on one day
370
- // take their own legs.
434
+ const pence = (value) => Math.round(value * 100) / 100;
435
+
436
+ // The pound figures of each completed foreign-currency record, from the
437
+ // same-day GBP "General Currency Conversion" row that funded it. PayPal
438
+ // converts what the record left in the wallet, its net, so the foreign leg
439
+ // is the net with the sign turned; the pound leg is then the pound net, and
440
+ // a fee splits it at the conversion's own rate into a pound gross and a
441
+ // pound fee that add up to it. Each conversion leg is used once, in
442
+ // statement order, so two bills on one day take their own legs.
371
443
  function poundAmountsOfForeignRecords(records) {
372
444
  const amounts = new Map();
373
445
  const conversions = records.filter((record) => record.status === "Completed" && isCurrencyConversion(record.description));
@@ -375,7 +447,7 @@ function poundAmountsOfForeignRecords(records) {
375
447
  for (const record of records) {
376
448
  if (record.currency === "GBP" || record.status !== "Completed" || isCurrencyConversion(record.description)) continue;
377
449
  const foreignLeg = conversions.find(
378
- (leg) => !used.has(leg) && leg.currency === record.currency && leg.date === record.date && leg.gross === -record.gross,
450
+ (leg) => !used.has(leg) && leg.currency === record.currency && leg.date === record.date && pence(leg.gross + record.net) === 0,
379
451
  );
380
452
  const poundLeg = conversions.find(
381
453
  (leg) => !used.has(leg) && leg.currency === "GBP" && leg.date === record.date && Math.sign(leg.gross) === Math.sign(record.gross),
@@ -383,7 +455,8 @@ function poundAmountsOfForeignRecords(records) {
383
455
  if (!foreignLeg || !poundLeg) continue;
384
456
  used.add(foreignLeg);
385
457
  used.add(poundLeg);
386
- amounts.set(record, poundLeg.gross);
458
+ const gross = record.fee === 0 ? poundLeg.gross : pence((poundLeg.gross * record.gross) / record.net);
459
+ amounts.set(record, { gross, fee: pence(poundLeg.gross - gross) });
387
460
  }
388
461
  return amounts;
389
462
  }
@@ -416,10 +489,8 @@ function postableRecords(text, statementText) {
416
489
  return records
417
490
  .filter((record) => isPostable(record, chosenReleaseIds, poundAmounts))
418
491
  .map((record) => {
419
- if (record.currency !== "GBP" && record.fee !== 0) {
420
- throw new Error(`PayPal ${record.currency} record ${record.id} carries a fee; no pound figure for it`);
421
- }
422
- return { record, gross: record.currency === "GBP" ? record.gross : poundAmounts.get(record), currency: "GBP" };
492
+ const { gross, fee } = record.currency === "GBP" ? record : poundAmounts.get(record);
493
+ return { record, gross, fee, currency: "GBP" };
423
494
  });
424
495
  }
425
496
 
@@ -455,13 +526,13 @@ function billGrossLine({ record, gross, currency }, { sourceJournalID, accountMa
455
526
  });
456
527
  }
457
528
 
458
- function feeLine({ record, currency }, { feeAccountMainID, taxCode }) {
529
+ function feeLine({ record, fee, currency }, { feeAccountMainID, taxCode }) {
459
530
  return compact({
460
531
  entryNumber: `PAYPAL-${record.id}-FEE`,
461
532
  sourceJournalID: "purchases",
462
533
  postingDate: record.date,
463
534
  accountMainID: feeAccountMainID,
464
- amount: Math.abs(record.fee),
535
+ amount: Math.abs(fee),
465
536
  amountCurrency: currency,
466
537
  documentType: "receipt",
467
538
  documentReference: record.id,
@@ -530,7 +601,7 @@ export function paypalLinesFromStatementText(
530
601
  };
531
602
  lines.push(gross >= 0 ? receiptGrossLine(posting, coding) : billGrossLine(posting, coding));
532
603
  }
533
- if (record.fee !== 0) {
604
+ if (posting.fee !== 0) {
534
605
  lines.push(feeLine(posting, { feeAccountMainID, taxCode }));
535
606
  }
536
607
  }
@@ -571,20 +642,29 @@ function walletLine({ record, amount, side, bankCode, entryNumber, detailComment
571
642
  };
572
643
  }
573
644
 
574
- // A credit that returns exactly what a completed hold took on the same day:
575
- // the hold and its release leave the wallet's balance where it was.
576
- function releasesSameDayHold(record, records) {
645
+ // The most days PayPal takes to release a hold.
646
+ const HOLD_RELEASE_DAYS = 3;
647
+ const DAY_MS = 86_400_000;
648
+
649
+ // A credit that returns exactly what a completed hold took, on the hold's
650
+ // day or up to HOLD_RELEASE_DAYS later: the hold and its release leave the
651
+ // wallet's balance where it was.
652
+ function releasesHold(record, records) {
653
+ const creditDay = Date.parse(record.date);
577
654
  return (
578
655
  record.gross > 0 &&
579
- records.some(
580
- (other) =>
656
+ records.some((other) => {
657
+ const daysAfterHold = (creditDay - Date.parse(other.date)) / DAY_MS;
658
+ return (
581
659
  other !== record &&
582
660
  other.status === "Completed" &&
583
661
  other.currency === record.currency &&
584
- other.date === record.date &&
662
+ daysAfterHold >= 0 &&
663
+ daysAfterHold <= HOLD_RELEASE_DAYS &&
585
664
  isHoldCandidate(other) &&
586
- other.gross === -record.gross,
587
- )
665
+ other.gross === -record.gross
666
+ );
667
+ })
588
668
  );
589
669
  }
590
670
 
@@ -593,8 +673,8 @@ function releasesSameDayHold(record, records) {
593
673
  * each postable receipt's gross comes in (bank code DR, or the matching
594
674
  * label rule's walletBankCode) and each fee and bill goes out (bank code
595
675
  * CR), so the wallet account moves the way PayPal's balance does. A credit
596
- * that returns the same amount as a completed hold on the same day moves
597
- * nothing, because the hold and the credit cancel inside the wallet. The
676
+ * that returns the same amount as a completed hold, on its day or up to
677
+ * three days later, moves nothing, because the hold and the credit cancel inside the wallet. The
598
678
  * transfers to and from the linked bank are the bank statement's own lines
599
679
  * and are not posted here. With the bank statement's top-up and withdrawal
600
680
  * lines added, the net of these lines is the month's Available-balance
@@ -608,8 +688,8 @@ export function paypalWalletLinesFromStatementText(text, { walletAccountMainID,
608
688
 
609
689
  const records = parsePaypalStatementRecords(text);
610
690
  const lines = [];
611
- for (const { record, gross } of postableRecords(text, statementText)) {
612
- if (releasesSameDayHold(record, records)) continue;
691
+ for (const { record, gross, fee } of postableRecords(text, statementText)) {
692
+ if (releasesHold(record, records)) continue;
613
693
  const rule = matchLabel(record.description, labels);
614
694
  if (gross >= 0) {
615
695
  lines.push(
@@ -636,11 +716,11 @@ export function paypalWalletLinesFromStatementText(text, { walletAccountMainID,
636
716
  }),
637
717
  );
638
718
  }
639
- if (record.fee !== 0) {
719
+ if (fee !== 0) {
640
720
  lines.push(
641
721
  walletLine({
642
722
  record,
643
- amount: record.fee,
723
+ amount: fee,
644
724
  side: "C",
645
725
  bankCode: "CR",
646
726
  entryNumber: `PAYPAL-WALLET-${record.id}-FEE`,
@@ -1,27 +1,32 @@
1
1
  // SPDX-License-Identifier: LicenseRef-PolyForm-Internal-Use-1.0.0
2
2
  // Copyright (C) 2006-2026 DIY Accounting Limited
3
3
 
4
- // @capability MCP-24 Hand the VAT figures to the browser to file
5
- // - **Use when:** an assistant has derived a VAT return and the user must check, declare and file it on the Submit page.
6
- // - **Does:** prepareVatReturn in mcp/lib/handoff-tools.js derives the return again from the loaded book and builds the link to the VAT form with the seven figures in the URL fragment as "#books=<base64url JSON>". It files nothing and calls no service; the fragment never reaches a server.
4
+ // @capability MCP-24 Hand the VAT, accounts and Company Tax Return figures to the browser to file
5
+ // - **Use when:** an assistant has derived a VAT return, a company's micro-entity or small company accounts or a Company Tax Return, and the user must check and file it on the Submit page.
6
+ // - **Does:** prepareVatReturn, prepareMicroEntityAccounts, prepareSmallCompanyAccounts and prepareCompanyTaxReturn in mcp/lib/handoff-tools.js derive the figures again from the loaded book and build the link to the form with them in the URL fragment as "#books=<base64url JSON>", after a query that names the assistant as the campaign source ("?utm_source=<client kind>&utm_medium=mcp"). They file nothing and call no service; the fragment never reaches a server.
7
7
  // - **Run:** no command; see Does and Entry
8
- // - **Entry:** `mcp/lib/handoff-tools.js:prepareVatReturn`; `mcp/lib/handoff-tools.js:vatHandoffLink`
9
- // - **Files:** mcp/lib/handoff-tools.js, mcp/test/handoff-tools.test.js
10
- // - **Keywords:** prepare_vat_return, hand off, books fragment, vat form link, file in the browser
8
+ // - **Entry:** `mcp/lib/handoff-tools.js:prepareVatReturn`; `mcp/lib/handoff-tools.js:prepareMicroEntityAccounts`; `mcp/lib/handoff-tools.js:prepareSmallCompanyAccounts`; `mcp/lib/handoff-tools.js:prepareCompanyTaxReturn`; `mcp/lib/handoff-tools.js:handoffLink`
9
+ // - **Files:** mcp/lib/handoff-tools.js, mcp/test/handoff-tools.test.js, web/public/widgets/books-import.js
10
+ // - **Keywords:** prepare_vat_return, prepare_micro_entity_accounts, prepare_small_company_accounts, prepare_company_tax_return, hand off, books fragment, form link, file in the browser
11
11
  // - **Related:** MCP-05
12
12
  // @end-capability
13
13
 
14
- // handoff-tools.js -- prepare_vat_return: the link that opens the VAT form with the figures
15
- // filled in. The page decodes the fragment in web/public/lib/auth-url-builder.js and fills the
16
- // form in web/public/widgets/books-import.js; this module writes what those two read.
14
+ // handoff-tools.js -- prepare_vat_return, prepare_micro_entity_accounts, prepare_small_company_accounts
15
+ // and prepare_company_tax_return: the links that open each form with the figures filled in. The page
16
+ // decodes the fragment in web/public/lib/auth-url-builder.js and fills the form in
17
+ // web/public/widgets/books-import.js; this module writes what those two read.
17
18
 
18
19
  import { basename } from "node:path";
19
20
 
20
21
  import { packageVersion } from "@diy-accounting-uk/diya-gl/dist/app/lib/package-version.js";
21
22
 
23
+ import { deriveCompanyTaxReturn, deriveMicroEntityAccounts, deriveSmallCompanyAccounts } from "./accounts-tools.js";
22
24
  import { deriveVatReturn } from "./vat-tools.js";
23
25
 
24
26
  const VAT_FORM_PATH = "/hmrc/vat/submitVat.html";
27
+ const MICRO_ENTITY_ACCOUNTS_FORM_PATH = "/companies-house/fileMicroEntityAccounts.html";
28
+ const SMALL_COMPANY_ACCOUNTS_FORM_PATH = "/companies-house/fileSmallCompanyAccounts.html";
29
+ const COMPANY_TAX_RETURN_FORM_PATH = "/companies-house/fileCompanyTaxReturn.html";
25
30
 
26
31
  // The seven figures the form takes. The page computes boxes 3 and 5 itself.
27
32
  const VAT_FIGURE_NAMES = [
@@ -34,22 +39,38 @@ const VAT_FIGURE_NAMES = [
34
39
  "totalAcquisitionsExVAT",
35
40
  ];
36
41
 
37
- function baseUrl() {
38
- const value = process.env.DIYA_SUBMIT_BASE_URL;
39
- if (!value) throw new Error("DIYA_SUBMIT_BASE_URL is not set");
42
+ // The link goes to a person, so it carries the public address of the environment, the one the
43
+ // customer signs in on. DIYA_SUBMIT_BASE_URL is the deployment's own host, which the tools call.
44
+ export function publicBaseUrl() {
45
+ const value = process.env.DIY_SUBMIT_BASE_URL;
46
+ if (!value) throw new Error("DIY_SUBMIT_BASE_URL is not set");
40
47
  return value.replace(/\/$/, "");
41
48
  }
42
49
 
43
50
  /**
44
- * The link to the VAT form that carries a handoff in its fragment.
51
+ * The link to a form that carries a handoff in its fragment. The query names the assistant as the
52
+ * campaign source, so the page's landing capture and the account's acquisition record say which
53
+ * assistant sent the person.
54
+ * @param {string} formPath - the form's path on the site
45
55
  * @param {{kind: string, sourceFileName: string, packageVersion: string, period: Object, figures: Object}} handoff
56
+ * @param {string} client - the assistant's kind, from client-kind.js
46
57
  * @returns {string}
47
58
  */
48
- export function vatHandoffLink(handoff) {
59
+ export function handoffLink(formPath, handoff, client) {
49
60
  const encoded = Buffer.from(JSON.stringify(handoff), "utf8").toString("base64url");
50
- return `${baseUrl()}${VAT_FORM_PATH}#books=${encoded}`;
61
+ const campaign = `?utm_source=${encodeURIComponent(client)}&utm_medium=mcp`;
62
+ return `${publicBaseUrl()}${formPath}${campaign}#books=${encoded}`;
51
63
  }
52
64
 
65
+ // The name the page shows for where the figures came from: the opened file, or the business.
66
+ function sourceNameOf(session) {
67
+ return session.sourcePath ? basename(session.sourcePath) : session.book.entityInformation?.organizationDescription || "book";
68
+ }
69
+
70
+ // What the person does with the link: the plugin files nothing, so the return is filed in the browser.
71
+ export const VAT_FILING_SENTENCE =
72
+ "Open this link, check the figures on the page, tick the declaration and file the return there in your browser. Nothing has been filed.";
73
+
53
74
  /**
54
75
  * prepare_vat_return: derives the return for the quarter ending on periodEnd from the session's
55
76
  * loaded book, the way derive_vat_return does, and answers the link that opens the VAT form with
@@ -67,17 +88,108 @@ export async function prepareVatReturn(session, params = {}) {
67
88
  figures[name] = value;
68
89
  }
69
90
  const period = { periodStart: derived.periodStart, periodEnd: derived.periodEnd };
70
- const link = vatHandoffLink({
71
- kind: "vat",
72
- sourceFileName: session.sourcePath ? basename(session.sourcePath) : session.book.entityInformation?.organizationDescription || "book",
73
- packageVersion: await packageVersion(),
74
- period,
75
- figures,
76
- });
91
+ const link = handoffLink(
92
+ VAT_FORM_PATH,
93
+ { kind: "vat", sourceFileName: sourceNameOf(session), packageVersion: await packageVersion(), period, figures },
94
+ session.client,
95
+ );
77
96
  return {
78
97
  link,
79
98
  period,
80
99
  figures,
81
- instruction: "Open this link, check the figures on the page, tick the declaration and file the return there. Nothing has been filed.",
100
+ instruction: VAT_FILING_SENTENCE,
82
101
  };
83
102
  }
103
+
104
+ // What the person does with an accounts link: the page asks for the company first, then fills.
105
+ export const ACCOUNTS_FILING_SENTENCE =
106
+ "Open this link, look up the company, check the figures on the page, add what it asks for and file the accounts there in your browser. Nothing has been filed.";
107
+
108
+ export const COMPANY_TAX_RETURN_FILING_SENTENCE =
109
+ "Open this link, look up the company, check the figures on the page, fill the rest of the return and file it there in your browser. Nothing has been filed.";
110
+
111
+ // What each accounts form fills from the derivation; the derivation's working and notes stay out of the link.
112
+ const MICRO_ENTITY_FIGURE_NAMES = [
113
+ "companyNumber",
114
+ "companyName",
115
+ "periodStart",
116
+ "periodEnd",
117
+ "averageNumberOfEmployees",
118
+ "directorName",
119
+ "dormant",
120
+ "profitAndLoss",
121
+ "balanceSheet",
122
+ ];
123
+ const SMALL_COMPANY_FIGURE_NAMES = [
124
+ "companyNumber",
125
+ "companyName",
126
+ "periodStart",
127
+ "periodEnd",
128
+ "averageNumberOfEmployees",
129
+ "directors",
130
+ "directorName",
131
+ "profitAndLoss",
132
+ "profitAndLossFormat2",
133
+ "balanceSheet",
134
+ "fixedAssetNote",
135
+ ];
136
+
137
+ function pick(accounts, names) {
138
+ return Object.fromEntries(names.filter((name) => accounts[name] !== undefined).map((name) => [name, accounts[name]]));
139
+ }
140
+
141
+ async function accountsHandoff(session, { kind, formPath, accounts, names }) {
142
+ const figures = pick(accounts, names);
143
+ const period = { periodStart: accounts.periodStart, periodEnd: accounts.periodEnd };
144
+ const link = handoffLink(
145
+ formPath,
146
+ { kind, sourceFileName: sourceNameOf(session), packageVersion: await packageVersion(), period, figures },
147
+ session.client,
148
+ );
149
+ return { link, period, companyNumber: accounts.companyNumber, instruction: ACCOUNTS_FILING_SENTENCE };
150
+ }
151
+
152
+ /**
153
+ * prepare_micro_entity_accounts: derives the micro-entity accounts from the session's loaded book,
154
+ * as derive_micro_entity_accounts does, and answers the link that opens the micro-entity accounts
155
+ * form with those figures.
156
+ * @param {Object} session
157
+ */
158
+ export async function prepareMicroEntityAccounts(session) {
159
+ const accounts = await deriveMicroEntityAccounts(session);
160
+ return accountsHandoff(session, {
161
+ kind: "micro-entity-accounts",
162
+ formPath: MICRO_ENTITY_ACCOUNTS_FORM_PATH,
163
+ accounts,
164
+ names: MICRO_ENTITY_FIGURE_NAMES,
165
+ });
166
+ }
167
+
168
+ /**
169
+ * prepare_small_company_accounts: derives the small company accounts from the session's loaded
170
+ * book, as derive_small_company_accounts does, and answers the link that opens the small company
171
+ * accounts form with those figures.
172
+ * @param {Object} session
173
+ */
174
+ export async function prepareSmallCompanyAccounts(session) {
175
+ const accounts = await deriveSmallCompanyAccounts(session);
176
+ return accountsHandoff(session, {
177
+ kind: "small-company-accounts",
178
+ formPath: SMALL_COMPANY_ACCOUNTS_FORM_PATH,
179
+ accounts,
180
+ names: SMALL_COMPANY_FIGURE_NAMES,
181
+ });
182
+ }
183
+
184
+ /**
185
+ * prepare_company_tax_return: derives the Company Tax Return figures from the session's loaded
186
+ * book, as derive_company_tax_return does, and answers the link that opens the Company Tax Return
187
+ * form with them. The figures are the profit and loss account and the computation; the person
188
+ * fills the balance sheet and the rest of the return on the page.
189
+ * @param {Object} session
190
+ */
191
+ export async function prepareCompanyTaxReturn(session) {
192
+ const handoff = await deriveCompanyTaxReturn(session, {});
193
+ const link = handoffLink(COMPANY_TAX_RETURN_FORM_PATH, handoff, session.client);
194
+ return { link, period: handoff.period, instruction: COMPANY_TAX_RETURN_FILING_SENTENCE };
195
+ }