@diy-accounting-uk/diya-submit 0.1.4 → 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.
- package/README.md +6 -5
- package/lib/accounts-tools.js +1 -1
- package/lib/book-read-tools.js +134 -0
- package/lib/book-tools.js +123 -32
- package/lib/client-kind.js +44 -0
- package/lib/finance/bank-lines.js +4 -2
- package/lib/finance/paypal-statement-lines.js +117 -37
- package/lib/handoff-tools.js +131 -21
- package/lib/help-index.json +2959 -0
- package/lib/help-tools.js +111 -0
- package/lib/hosted-register-book.js +128 -0
- package/lib/hosted-tools.js +116 -16
- package/lib/hosted-write-tools.js +313 -0
- package/lib/http.js +3 -3
- package/lib/rules-data.json +1821 -0
- package/lib/rules-tools.js +165 -0
- package/lib/server.js +315 -62
- package/lib/submit-tools.js +171 -2
- package/lib/tool-annotations.js +4 -1
- package/lib/vat-tools.js +2 -0
- package/lib/vendored/app/services/ct600Figures.js +15 -19
- package/lib/vendored/app/services/microEntityAccounts.js +8 -6
- package/package.json +2 -2
|
@@ -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
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
|
|
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
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
//
|
|
370
|
-
//
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
420
|
-
|
|
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(
|
|
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 (
|
|
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
|
-
//
|
|
575
|
-
|
|
576
|
-
|
|
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
|
-
|
|
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
|
|
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 (
|
|
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 (
|
|
719
|
+
if (fee !== 0) {
|
|
640
720
|
lines.push(
|
|
641
721
|
walletLine({
|
|
642
722
|
record,
|
|
643
|
-
amount:
|
|
723
|
+
amount: fee,
|
|
644
724
|
side: "C",
|
|
645
725
|
bankCode: "CR",
|
|
646
726
|
entryNumber: `PAYPAL-WALLET-${record.id}-FEE`,
|
package/lib/handoff-tools.js
CHANGED
|
@@ -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
|
|
6
|
-
// - **Does:** prepareVatReturn in mcp/lib/handoff-tools.js
|
|
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:
|
|
9
|
-
// - **Files:** mcp/lib/handoff-tools.js, mcp/test/handoff-tools.test.js
|
|
10
|
-
// - **Keywords:** prepare_vat_return, hand off, books fragment,
|
|
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
|
|
15
|
-
//
|
|
16
|
-
//
|
|
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 = [
|
|
@@ -36,22 +41,36 @@ const VAT_FIGURE_NAMES = [
|
|
|
36
41
|
|
|
37
42
|
// The link goes to a person, so it carries the public address of the environment, the one the
|
|
38
43
|
// customer signs in on. DIYA_SUBMIT_BASE_URL is the deployment's own host, which the tools call.
|
|
39
|
-
function publicBaseUrl() {
|
|
44
|
+
export function publicBaseUrl() {
|
|
40
45
|
const value = process.env.DIY_SUBMIT_BASE_URL;
|
|
41
46
|
if (!value) throw new Error("DIY_SUBMIT_BASE_URL is not set");
|
|
42
47
|
return value.replace(/\/$/, "");
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
/**
|
|
46
|
-
* The link to
|
|
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
|
|
47
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
|
|
48
57
|
* @returns {string}
|
|
49
58
|
*/
|
|
50
|
-
export function
|
|
59
|
+
export function handoffLink(formPath, handoff, client) {
|
|
51
60
|
const encoded = Buffer.from(JSON.stringify(handoff), "utf8").toString("base64url");
|
|
52
|
-
|
|
61
|
+
const campaign = `?utm_source=${encodeURIComponent(client)}&utm_medium=mcp`;
|
|
62
|
+
return `${publicBaseUrl()}${formPath}${campaign}#books=${encoded}`;
|
|
53
63
|
}
|
|
54
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
|
+
|
|
55
74
|
/**
|
|
56
75
|
* prepare_vat_return: derives the return for the quarter ending on periodEnd from the session's
|
|
57
76
|
* loaded book, the way derive_vat_return does, and answers the link that opens the VAT form with
|
|
@@ -69,17 +88,108 @@ export async function prepareVatReturn(session, params = {}) {
|
|
|
69
88
|
figures[name] = value;
|
|
70
89
|
}
|
|
71
90
|
const period = { periodStart: derived.periodStart, periodEnd: derived.periodEnd };
|
|
72
|
-
const link =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
figures,
|
|
78
|
-
});
|
|
91
|
+
const link = handoffLink(
|
|
92
|
+
VAT_FORM_PATH,
|
|
93
|
+
{ kind: "vat", sourceFileName: sourceNameOf(session), packageVersion: await packageVersion(), period, figures },
|
|
94
|
+
session.client,
|
|
95
|
+
);
|
|
79
96
|
return {
|
|
80
97
|
link,
|
|
81
98
|
period,
|
|
82
99
|
figures,
|
|
83
|
-
instruction:
|
|
100
|
+
instruction: VAT_FILING_SENTENCE,
|
|
84
101
|
};
|
|
85
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
|
+
}
|