diff --git a/README.md b/README.md index 76763a6..fa7b6c0 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ One way: Fidelity -> your Google Sheet -> the viewer. The viewer only asks for a - Every 6 hours (no market hours or weekdays in the timing), the script also reads Fidelity's own daily account values (the data of its Summary balance chart): since each account opened the first time, then the last month. The Balance card draws them for the chosen accounts with periods from 1D to 3Y (the card shows the main ones, the big chart every step: 1D..3D, WTD, 1W..3W, MTD, 1M..11M, QTD, 1Q..3Q, YTD, 1Y..3Y); ⤢ grows the card into a big window, ✕, a click outside or Esc shrinks it back. The change shown is the balance change (deposits are in it), not a return - Right after that it reads the transactions history of every account (the same read the Activity page makes): the first time month by month since the account's first daily value, then the last 10 days again. That read runs every 6 hours; with 👀 on it also reads yesterday and today every 10 minutes and writes the sheet only when something new came. A read missed because the Fidelity tab was closed runs when a Fidelity page opens next. The Income card shows the dividends and interest really received this year, quarter and month next to the plan (received plus what still comes at today's holdings) with a progress bar; until the history is read it shows -- - After the transactions, every 6 hours, Fidelity's tax info of every account (the read its Tax Info YTD page makes): which dividend payments are qualified and which are not. The current year is read with every read (its numbers are preliminary until the 1099), an earlier year once. The mark is put on the dividend transaction of the same account, day and CUSIP and written to the `qualified` column of `fidelity_transactions`. The first time after an update to 0.1.42 or later the transactions of every account are read once more from their first day, to get each security's CUSIP +- Along with those reads (every hour, and after each read of Positions, never twice within 5 minutes), Fidelity's Tax Info YTD summary of the taxable accounts (the read its Tax Info YTD page makes; Roth and other retirement accounts get no 1099): every box of the year's 1099-DIV, 1099-INT, 1099-MISC and 1099-OID so far, the margin interest paid and the realized short and long term gain or loss, written to `fidelity_tax_summary`. From January 1 to April 15 the year before is read too. A box with a text instead of a number (Various, N/A) is left out, a zero is kept - Then, once a day, the beta of every holding, all read only from Fidelity and measured against the S&P 500 the way Fidelity defines beta: stocks from its stock screener (5Y beta, else 3Y, else 1Y); ETFs, mutual funds and everything else computed by the script from Fidelity's own price history: total monthly returns against SPY over the last 36 months (at least 12), daily over the last year when the history is shorter. Only a fund too young for both gets the ETF screener's 3Y beta, which is Morningstar's and may be measured against the fund's category index rather than the S&P 500 (marked ETFs 3Y). Cash is 0. The Accounts card shows each account's beta on the right as 1.17β: the average of its positions' betas weighted by their value. When some positions have no beta (bonds and CDs by CUSIP, options) the share of the value that has one shows under it in grey, for example 62%. A click on the beta opens the breakdown: every position with its value, weight, beta, source, date and contribution (the contributions add up to the account's beta), the ones without a beta last - The ADP 401k (since 0.1.45): on a mykplan.adp.com page you are logged in to, the script reads the Transaction History month by month (a query form, read only; about 2 minutes the first time, then the last two months at most once an hour, ⬇ on its panel reads at once) and writes every row to the `adp_mykplan_transactions` tab of the same spreadsheet. - The script's panel on Fidelity and mykplan (since 0.1.52): one line with its name and the buttons 👀 (a slowly blinking blue dot while watching, the same switch as in the viewer; on mykplan an open tab reads the history again every hour; switched on in the viewer it opens Fidelity, and the script opens mykplan in a background tab when none is open), {} downloads the read data as JSON, 🔔 notifications. It opens minimized to a round icon; a click on it, or ⚙️ Settings -> User preferences in the viewer, opens it for every page and tab, and a question that waits (a spreadsheet to allow) shows "!" on the icon. A reload of the viewer asks an open mykplan tab to read the new days (at most every 10 minutes); if its session ended, mykplan opens again, signs in with the saved login and reads on. A settings export carries 👀, 🔔 and the panel switch, an import hands them back to the script @@ -70,7 +71,8 @@ Sheet tabs: | `adp_mykplan_balances_monthly` | the 401k balance of each fund at the end of every month read and on the last price day: date, fund, quantity, price, balance | rewritten after each read on mykplan | | `fidelity_transactions_synced` | how far each account's transactions were read | rewritten with it | | `fidelity_betas` | the beta of each held symbol, its source and months behind it | rewritten after its daily run | -| `fidelity_updates` | when each data set (summary, positions, transactions, betas) was last written | updated after every write | +| `fidelity_tax_summary` | Fidelity's Tax Info YTD summary: account, tax year, form, box, amount, as of; the gains as form `gain-loss`, box `short-term` or `long-term` | rewritten after each read | +| `fidelity_updates` | when each data set (summary, positions, transactions, betas, performance, taxes, adp) was last written | updated after every write | One thing has one name in every tab, the names of `fidelity_positions_all`: `account_number`, `account_name`, `symbol_name`, `symbol_description`, `quantity`, `week_52_low` and so on, all in snake_case. A tab written under earlier names gets its header renamed in place on the next write, the rows stay @@ -80,7 +82,7 @@ Everything this app relies on at Fidelity is listed in `src/shared/contract.ts`: ## Safety -- Read only: the script never trades, transfers or submits anything on Fidelity; besides the pages it runs on it asks only Fidelity's daily values, transactions, screeners and price history, each through a fixed list of addresses; the only form it fills is the login, with your saved login, only on a page with exactly one password field and a username, at most once per 30 minutes, and it stops for good when the password is refused. Syncs asked from the viewer are taken at least 10 seconds apart +- Read only: the script never trades, transfers or submits anything on Fidelity; besides the pages it runs on it asks only Fidelity's daily values, transactions, tax info, investment results, screeners and price history, each through a fixed list of addresses; the only form it fills is the login, with your saved login, only on a page with exactly one password field and a username, at most once per 30 minutes, and it stops for good when the password is refused. Syncs asked from the viewer are taken at least 10 seconds apart - Your data goes from your browser to your Google Sheet and nowhere else: other pages on daggerok.github.io share the viewer's storage, so the script keeps the allowed spreadsheet in its own Tampermonkey storage and asks on the Fidelity panel before writing to any other one (Full reset in the viewer does not change that). The repo holds no account data: tests use made-up numbers ## Develop diff --git a/package.json b/package.json index f419636..8c89bfb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "accounts", - "version": "0.1.88", + "version": "0.1.89", "private": true, "description": "Own viewer of your accounts (Fidelity first): a Tampermonkey script reads your positions (read only) into your Google Sheet", "source": "src/viewer/index.html", diff --git a/src/shared/fixtures/tax-summary.json b/src/shared/fixtures/tax-summary.json new file mode 100644 index 0000000..4497aa5 --- /dev/null +++ b/src/shared/fixtures/tax-summary.json @@ -0,0 +1,1118 @@ +{ + "data": { + "getTaxInfoSummary": { + "sysMsgs": null, + "taxActivitySummary": { + "taxYear": "2026", + "acctDetails": [ + { + "acctNum": "X10000001", + "asOfDate": "2026-12-03", + "asOfTime": "02:28:39", + "taxIncomeSummary": [ + { + "boxDescription": "Ordinary Dividends", + "boxNumber": "1A", + "correctionInd": null, + "detailInd": "Y", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "125.40", + "transactionCount": 3, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Non-Qualified Dividends", + "boxNumber": "1C", + "correctionInd": null, + "detailInd": "Y", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "25.40", + "transactionCount": 3, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Qualified Dividends", + "boxNumber": "1B", + "correctionInd": null, + "detailInd": "Y", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "100.00", + "transactionCount": 3, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Section 897 Ordinary Dividends", + "boxNumber": "2E", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Section 199A Dividends", + "boxNumber": "5", + "correctionInd": null, + "detailInd": "Y", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "12.10", + "transactionCount": 3, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Total Capital Gain Distributions", + "boxNumber": "2", + "correctionInd": null, + "detailInd": "Y", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "3.50", + "transactionCount": 3, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Unrecaptured Section 1250 Gain", + "boxNumber": "2B", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Section 1202 Gain", + "boxNumber": "2C", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Collectibles (28%) Gain", + "boxNumber": "2D", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Section 897 Capital Gain", + "boxNumber": "2F", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Other Capital Gain Distributions", + "boxNumber": "20", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Nondividend Distributions", + "boxNumber": "3", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Federal Income Tax Withheld", + "boxNumber": "4", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Investment Expenses", + "boxNumber": "6", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Foreign Tax Paid", + "boxNumber": "7", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Foreign Country or U.S. Possession", + "boxNumber": "8", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "Various", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Cash Liquidation Distributions", + "boxNumber": "9", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Noncash Liquidation Distributions", + "boxNumber": "10", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Exempt-Interest Dividends", + "boxNumber": "12", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Specified Private Activity Bond Interest Dividends", + "boxNumber": "13", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Interest Income", + "boxNumber": "1", + "correctionInd": null, + "detailInd": "Y", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "4.75", + "transactionCount": 3, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Early Withdrawal Penalty", + "boxNumber": "2", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Interest on U.S. Savings Bonds and Treasury Obligations", + "boxNumber": "3", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Federal Income Tax Withheld", + "boxNumber": "4", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Investment Expenses", + "boxNumber": "5", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Foreign Tax Paid", + "boxNumber": "6", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Foreign Country or U.S. Possession", + "boxNumber": "7", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "N/A", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Tax-Exempt Interest", + "boxNumber": "8", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Specified Private Activity Bond Interest", + "boxNumber": "9", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Royalties", + "boxNumber": "2", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Federal Income Tax Withheld", + "boxNumber": "4", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Substitute Payments in Lieu of Dividends or Interest", + "boxNumber": "8", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Qualified Substitute Payments", + "boxNumber": "8Q", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Non-Qualified Substitute Payments", + "boxNumber": "8U", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Other Income", + "boxNumber": "3", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Original Issue Discount", + "boxNumber": "1", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-OID", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Original Issue Discount on U.S. Treasury Obligations", + "boxNumber": "8", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-OID", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Margin Interest Paid", + "boxNumber": "3", + "correctionInd": null, + "detailInd": "Y", + "displayIndentLevel": 0, + "formType": "1099-OIF", + "recordType": "A", + "sortCode": null, + "transactionAmount": "1.25", + "transactionCount": 3, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": null, + "boxNumber": null, + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": null, + "sortCode": null, + "transactionAmount": "125.40", + "transactionCount": 0, + "transactionDescription": "ORDINARY DIVIDENDS AND DISTRIBUTIONS" + }, + { + "boxDescription": null, + "boxNumber": null, + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": null, + "sortCode": null, + "transactionAmount": "4.75", + "transactionCount": 0, + "transactionDescription": "INTEREST INCOME" + }, + { + "boxDescription": null, + "boxNumber": null, + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "-", + "recordType": null, + "sortCode": null, + "transactionAmount": "133.65", + "transactionCount": 0, + "transactionDescription": "TOTAL INCOME" + } + ], + "gainLossSummary": { + "shortTermNet": null, + "longTermNet": null, + "allBasisInd": true, + "intradayInd": "SUCCESSFUL_RECALC", + "fixedIncome": { + "realizedAccuredMarketDiscountIncome": null, + "reportableBondPremium": 0, + "reportableAcquisitionPremium": 0, + "ordinaryIncomeGainLoss": null + }, + "international": null + } + }, + { + "acctNum": "X10000002", + "asOfDate": "2026-12-03", + "asOfTime": "02:28:39", + "taxIncomeSummary": [ + { + "boxDescription": "Ordinary Dividends", + "boxNumber": "1A", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "1,050.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Non-Qualified Dividends", + "boxNumber": "1C", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Qualified Dividends", + "boxNumber": "1B", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "1,050.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Section 897 Ordinary Dividends", + "boxNumber": "2E", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Section 199A Dividends", + "boxNumber": "5", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Total Capital Gain Distributions", + "boxNumber": "2", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Unrecaptured Section 1250 Gain", + "boxNumber": "2B", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Section 1202 Gain", + "boxNumber": "2C", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Collectibles (28%) Gain", + "boxNumber": "2D", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Section 897 Capital Gain", + "boxNumber": "2F", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Other Capital Gain Distributions", + "boxNumber": "20", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Nondividend Distributions", + "boxNumber": "3", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Federal Income Tax Withheld", + "boxNumber": "4", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Investment Expenses", + "boxNumber": "6", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Foreign Tax Paid", + "boxNumber": "7", + "correctionInd": null, + "detailInd": "Y", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "2.20", + "transactionCount": 3, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Foreign Country or U.S. Possession", + "boxNumber": "8", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "Various", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Cash Liquidation Distributions", + "boxNumber": "9", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Noncash Liquidation Distributions", + "boxNumber": "10", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Exempt-Interest Dividends", + "boxNumber": "12", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Specified Private Activity Bond Interest Dividends", + "boxNumber": "13", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Interest Income", + "boxNumber": "1", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Early Withdrawal Penalty", + "boxNumber": "2", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Interest on U.S. Savings Bonds and Treasury Obligations", + "boxNumber": "3", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Federal Income Tax Withheld", + "boxNumber": "4", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Investment Expenses", + "boxNumber": "5", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Foreign Tax Paid", + "boxNumber": "6", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Foreign Country or U.S. Possession", + "boxNumber": "7", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "N/A", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Tax-Exempt Interest", + "boxNumber": "8", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Specified Private Activity Bond Interest", + "boxNumber": "9", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Royalties", + "boxNumber": "2", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Federal Income Tax Withheld", + "boxNumber": "4", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Substitute Payments in Lieu of Dividends or Interest", + "boxNumber": "8", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Qualified Substitute Payments", + "boxNumber": "8Q", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "- Non-Qualified Substitute Payments", + "boxNumber": "8U", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 1, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Other Income", + "boxNumber": "3", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-MISC", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Original Issue Discount", + "boxNumber": "1", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-OID", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Original Issue Discount on U.S. Treasury Obligations", + "boxNumber": "8", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-OID", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": "Margin Interest Paid", + "boxNumber": "3", + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-OIF", + "recordType": "A", + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "BOX SUMMARY TOTALS" + }, + { + "boxDescription": null, + "boxNumber": null, + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-DIV", + "recordType": null, + "sortCode": null, + "transactionAmount": "1,050.00", + "transactionCount": 0, + "transactionDescription": "ORDINARY DIVIDENDS AND DISTRIBUTIONS" + }, + { + "boxDescription": null, + "boxNumber": null, + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "1099-INT", + "recordType": null, + "sortCode": null, + "transactionAmount": "0.00", + "transactionCount": 0, + "transactionDescription": "INTEREST INCOME" + }, + { + "boxDescription": null, + "boxNumber": null, + "correctionInd": null, + "detailInd": "N", + "displayIndentLevel": 0, + "formType": "-", + "recordType": null, + "sortCode": null, + "transactionAmount": "1,050.00", + "transactionCount": 0, + "transactionDescription": "TOTAL INCOME" + } + ], + "gainLossSummary": { + "shortTermNet": 12.34, + "longTermNet": null, + "allBasisInd": true, + "intradayInd": "SUCCESSFUL_RECALC", + "fixedIncome": { + "realizedAccuredMarketDiscountIncome": null, + "reportableBondPremium": 0, + "reportableAcquisitionPremium": 0, + "ordinaryIncomeGainLoss": null + }, + "international": null + } + } + ] + } + } + } +} diff --git a/src/shared/model.test.ts b/src/shared/model.test.ts index 16eba07..233da2f 100644 --- a/src/shared/model.test.ts +++ b/src/shared/model.test.ts @@ -36,3 +36,16 @@ test('the betas survive a stored copy and a later read of the grid; broken entri expect(m.betas).toEqual(withBetas.betas); expect(m.betasAt).toBe('2026-11-20T11:00:00.000Z'); }); + +test('the tax summary survives a stored copy and a later read of the grid; a broken one is dropped', () => { + const taxSummary = { years: { '2026': { X10000001: { asOf: '2026-12-03', boxes: { '1099-DIV 1A': 12.5, '1099-INT 1': 0 }, shortTerm: 1.5, longTerm: null } } } }; + const back = parseDataset(JSON.stringify({ ...full, taxSummary, taxSummaryAt: '2026-12-03T15:00:00.000Z' }))!; + expect(back.taxSummary).toEqual(taxSummary); + expect(back.taxSummaryAt).toBe('2026-12-03T15:00:00.000Z'); + const m = mergeDatasets(back, buildDataset({ rows: ROWS, sidebar: SIDEBAR, asOf: null, builtAt: '2026-12-03T16:00:00.000Z' })); + expect(m.taxSummary).toEqual(taxSummary); + expect(m.taxSummaryAt).toBe('2026-12-03T15:00:00.000Z'); + const broken = parseDataset(JSON.stringify({ ...full, taxSummary: { years: 'x' }, taxSummaryAt: 5 }))!; + expect(broken.taxSummary).toBeUndefined(); + expect(broken.taxSummaryAt).toBeUndefined(); +}); diff --git a/src/shared/model.ts b/src/shared/model.ts index 4c4a5ba..3928d46 100644 --- a/src/shared/model.ts +++ b/src/shared/model.ts @@ -6,6 +6,7 @@ import { fieldNames } from './snake'; import { cleanBetas, type Betas } from './beta'; import { cleanPerf, type Performance } from './performance'; +import { cleanTaxSummary, type TaxSummary } from './tax-summary'; import { mergeHistory, type History } from './history'; export const DATASET_VERSION = 1; @@ -83,6 +84,9 @@ export interface Dataset { // Fidelity's own investment results per account and standard period (src/shared/performance.ts), read once a day performance?: Performance; performanceAt?: string; // ISO time of the last read + // Fidelity's Tax Info YTD summary per tax year and account (src/shared/tax-summary.ts), read along with the other reads + taxSummary?: TaxSummary; + taxSummaryAt?: string; // ISO time of the last read } export const emptyDataset = (builtAt: string): Dataset => ({ version: DATASET_VERSION, builtAt, asOf: null, accounts: [], positions: [], warnings: [] }); @@ -97,7 +101,7 @@ export function parseDataset(json: string): Dataset | null { const d = JSON.parse(json) as Partial; if (!d || d.version !== DATASET_VERSION || typeof d.builtAt !== 'string') return null; const history = d.history && typeof d.history === 'object' && !Array.isArray(d.history) ? d.history : undefined; - return { version: d.version, builtAt: d.builtAt, asOf: d.asOf ?? null, accounts: Array.isArray(d.accounts) ? d.accounts : [], positions: Array.isArray(d.positions) ? d.positions.map(snakeFields) : [], warnings: Array.isArray(d.warnings) ? d.warnings : [], history, historyAt: typeof d.historyAt === 'string' ? d.historyAt : undefined, betas: cleanBetas(d.betas), betasAt: typeof d.betasAt === 'string' ? d.betasAt : undefined, performance: cleanPerf(d.performance), performanceAt: typeof d.performanceAt === 'string' ? d.performanceAt : undefined }; + return { version: d.version, builtAt: d.builtAt, asOf: d.asOf ?? null, accounts: Array.isArray(d.accounts) ? d.accounts : [], positions: Array.isArray(d.positions) ? d.positions.map(snakeFields) : [], warnings: Array.isArray(d.warnings) ? d.warnings : [], history, historyAt: typeof d.historyAt === 'string' ? d.historyAt : undefined, betas: cleanBetas(d.betas), betasAt: typeof d.betasAt === 'string' ? d.betasAt : undefined, performance: cleanPerf(d.performance), performanceAt: typeof d.performanceAt === 'string' ? d.performanceAt : undefined, taxSummary: cleanTaxSummary(d.taxSummary), taxSummaryAt: typeof d.taxSummaryAt === 'string' ? d.taxSummaryAt : undefined }; } catch { return null; } @@ -114,5 +118,5 @@ export function mergeDatasets(prev: Dataset | null, next: Dataset): Dataset { const history = prev.history || next.history ? mergeHistory(prev.history, next.history) : undefined; const historyAt = [prev.historyAt, next.historyAt].filter(Boolean).sort().pop(); // the betas come from their own daily run, a read of the grid has none: the stored ones stay - return { ...next, accounts: Array.from(accounts.values()), positions, history, historyAt, betas: next.betas ?? prev.betas, betasAt: next.betasAt ?? prev.betasAt, performance: next.performance ?? prev.performance, performanceAt: next.performanceAt ?? prev.performanceAt }; + return { ...next, accounts: Array.from(accounts.values()), positions, history, historyAt, betas: next.betas ?? prev.betas, betasAt: next.betasAt ?? prev.betasAt, performance: next.performance ?? prev.performance, performanceAt: next.performanceAt ?? prev.performanceAt, taxSummary: next.taxSummary ?? prev.taxSummary, taxSummaryAt: next.taxSummaryAt ?? prev.taxSummaryAt }; } diff --git a/src/shared/notice-words.test.ts b/src/shared/notice-words.test.ts index 5a9965d..1d052d7 100644 --- a/src/shared/notice-words.test.ts +++ b/src/shared/notice-words.test.ts @@ -2,7 +2,7 @@ /// import { describe, expect, test } from 'bun:test'; import { freshNotice, makeNotice } from './notice'; -import { NOTICE_KEYS, NOTICE_LINES, NO_POSITIONS, NO_READER, SHEETS_WAITING, adpSiteDown, balancesRead, loginNotForm, loginTooSoon, perfRead, betasFailed, betasRead, fidelityChanged, jobFailed, lines, positionsRead, say, sheetWaitsAllow, sheetsFailed, transactionsFailed, transactionsRead, wordsOf } from './notice-words'; +import { NOTICE_KEYS, NOTICE_LINES, NO_POSITIONS, NO_READER, SHEETS_WAITING, adpSiteDown, balancesRead, loginNotForm, loginTooSoon, perfRead, taxSummaryRead, betasFailed, betasRead, fidelityChanged, jobFailed, lines, positionsRead, say, sheetWaitsAllow, sheetsFailed, transactionsFailed, transactionsRead, wordsOf } from './notice-words'; import { RU } from '../viewer/app/i18n/ru'; describe('notification words', () => { @@ -27,7 +27,7 @@ describe('notification words', () => { }); test('no line is glued from several things and no notice is longer than the popup holds', () => { - const all = [positionsRead(6, 1090, true), balancesRead(6, 6, true), transactionsRead(10, 1, true), transactionsFailed(2), adpSiteDown('noPrice'), adpSiteDown('trouble'), loginTooSoon('ADP'), loginNotForm('ADP'), perfRead(6, '2026-11-27', true), perfRead(6, '2026-11-27', false), jobFailed('performance', 'x'), betasRead(1, 2, true), betasFailed(1, 2, ['betas.etf']), jobFailed('page', 'x'), fidelityChanged(['POSITION.qty is gone', 'a', 'b', 'c', 'd', 'e']), SHEETS_WAITING, sheetsFailed('x'), sheetWaitsAllow('…abc123'), NO_READER, NO_POSITIONS]; + const all = [positionsRead(6, 1090, true), balancesRead(6, 6, true), transactionsRead(10, 1, true), transactionsFailed(2), adpSiteDown('noPrice'), adpSiteDown('trouble'), loginTooSoon('ADP'), loginNotForm('ADP'), perfRead(6, '2026-11-27', true), perfRead(6, '2026-11-27', false), jobFailed('performance', 'x'), taxSummaryRead(4, '2025, 2026', true), taxSummaryRead(4, '2026', false), jobFailed('taxSummary', 'x'), betasRead(1, 2, true), betasFailed(1, 2, ['betas.etf']), jobFailed('page', 'x'), fidelityChanged(['POSITION.qty is gone', 'a', 'b', 'c', 'd', 'e']), SHEETS_WAITING, sheetsFailed('x'), sheetWaitsAllow('…abc123'), NO_READER, NO_POSITIONS]; all.forEach((w) => { expect(w.length).toBeLessThanOrEqual(NOTICE_LINES); expect(wordsOf(JSON.parse(JSON.stringify(w)))).not.toBeNull(); diff --git a/src/shared/notice-words.ts b/src/shared/notice-words.ts index 49f1bce..b3087d1 100644 --- a/src/shared/notice-words.ts +++ b/src/shared/notice-words.ts @@ -42,6 +42,9 @@ const K = { perf: 'Investment results updated', perfAccounts: 'Accounts: {n}, as of {day}', failPerf: 'Failed investment results read', + taxSummary: 'Tax summary updated', + taxSummaryOf: 'Accounts: {n}, tax years: {years}', + failTaxSummary: 'Failed tax summary read', betasFailed: 'Failed betas update', found: 'Found: {found} of {held}', failedParts: 'Failed: {parts}', @@ -118,7 +121,9 @@ export const betasFailed = (found: number, held: number, parts: string[]): Word[ /** Fidelity's investment results were read (shared/performance.ts) */ export const perfRead = (n: number, day: string, saved: boolean): Word[] => (saved ? sheet(line(K.perf), line(K.perfAccounts, { n, day })) : [line(K.perf), line(K.perfAccounts, { n, day })]); -const FAIL = { positions: K.failPositions, balances: K.failBalances, transactions: K.failTransactions, betas: K.failBetas, page: K.failPage, tax: K.failTax, adp: K.failAdp, performance: K.failPerf } as const; +/** Fidelity's Tax Info YTD summary was read (shared/tax-summary.ts): how many accounts, which years */ +export const taxSummaryRead = (n: number, years: string, saved: boolean): Word[] => (saved ? sheet(line(K.taxSummary), line(K.taxSummaryOf, { n, years })) : [line(K.taxSummary), line(K.taxSummaryOf, { n, years })]); +const FAIL = { positions: K.failPositions, balances: K.failBalances, transactions: K.failTransactions, betas: K.failBetas, page: K.failPage, tax: K.failTax, adp: K.failAdp, performance: K.failPerf, taxSummary: K.failTaxSummary } as const; /** a job that threw */ export const jobFailed = (job: keyof typeof FAIL, err: unknown): Word[] => [line(FAIL[job]), line(K.reason, { error: why(err) })]; /** Fidelity's page or answers no longer look as this version expects (contract.ts ids) */ diff --git a/src/shared/sheets/sync.test.ts b/src/shared/sheets/sync.test.ts index 42c7ae0..a7dd0f2 100644 --- a/src/shared/sheets/sync.test.ts +++ b/src/shared/sheets/sync.test.ts @@ -5,8 +5,9 @@ import { expect, test } from 'bun:test'; import { ROWS, SIDEBAR } from '../fixtures/grid'; import { buildDataset } from '../parse'; import { SheetsError } from './client'; -import { balanceRows, betaRows, betasFromRows, changedSets, readSets, datasetFromTabs, dayOf, fingerprint, parseSignal, positionRows, syncedRows, txnStoreFromTabs, wideRows } from './sync'; -import { ACCOUNTS, ADP_BALANCES, ADP_TRANSACTIONS, BALANCES, BETAS, POSITIONS, TAB_NAMES, TRANSACTIONS, TXN_SYNCED } from './tabs'; +import { DATA_SETS, SET_TABS, balanceRows, betaRows, betasFromRows, changedSets, readSets, datasetFromTabs, dayOf, fingerprint, parseSignal, positionRows, syncedRows, txnStoreFromTabs, wideRows } from './sync'; +import { ACCOUNTS, ADP_BALANCES, ADP_TRANSACTIONS, BALANCES, BETAS, POSITIONS, TAB_NAMES, TAX_SUMMARY, TRANSACTIONS, TXN_SYNCED } from './tabs'; +import { taxSummaryRows, type TaxSummary } from '../tax-summary'; import type { TxnStore } from '../transactions'; const ds = buildDataset({ rows: ROWS, sidebar: SIDEBAR, asOf: 'As of Nov-20-2026 4:01 p.m. ET', builtAt: '2026-11-21T02:00:00.000Z' }); @@ -151,3 +152,35 @@ test('a payment posted after its "as of" day keeps both days through fidelity_tr expect([back.date, back.traded]).toEqual(['2026-12-02', '2026-11-27']); expect(txnStoreFromTabs([back], [{ account: 'X1', synced: '2026-12-02', at: '2026-12-02T23:00:00Z' }])!.rows[0]!.traded).toBe('2026-11-27'); }); + +test('the tax summary round-trips through fidelity_tax_summary, goes into the shown dataset and prints by its content', async () => { + // made-up boxes of two accounts and two years + const tax: TaxSummary = { years: { + '2025': { X1: { asOf: '2026-01-31', boxes: { '1099-DIV 1A': 40.5, '1099-DIV 1B': 30 }, shortTerm: null, longTerm: 12 } }, + '2026': { X1: { asOf: '2026-12-03', boxes: { '1099-DIV 1A': 12.25, '1099-INT 1': 0 }, shortTerm: -3.5, longTerm: null }, X2: { asOf: '2026-12-03', boxes: { '1099-MISC 8': 1 }, shortTerm: null, longTerm: null } }, + } }; + expect(TAX_SUMMARY.name).toBe('fidelity_tax_summary'); + expect(TAX_SUMMARY.columns).toEqual(['account_number', 'tax_year', 'form_type', 'box_number', 'amount', 'as_of']); + expect(TAB_NAMES).toContain('fidelity_tax_summary'); + expect(DATA_SETS).toContain('taxes'); + expect(SET_TABS.taxes).toEqual(['fidelity_tax_summary']); + const rows = taxSummaryRows(tax).map((r) => TAX_SUMMARY.fromRow(TAX_SUMMARY.toRow(r))!); + expect(TAX_SUMMARY.idOf(rows[0]!)).toBe('X1|2025|1099-DIV|1A'); + const shown = datasetFromTabs(ds, { taxes: rows })!; + expect(shown.taxSummary).toEqual(tax); + expect(shown.taxSummaryAt).toBe(ds.builtAt); + expect(shown.positions).toEqual(ds.positions); + expect(datasetFromTabs(shown, { taxes: [] })!.taxSummary).toEqual(tax); // an empty tab keeps the shown one + expect(datasetFromTabs({ ...shown, taxSummaryAt: '2026-12-03T15:00:00.000Z' }, { taxes: rows })!.taxSummaryAt).toBe('2026-12-03T15:00:00.000Z'); + const data = { ds: { ...ds, taxSummary: tax }, store }; + expect(fingerprint('taxes', { ds: { ...ds, taxSummary: JSON.parse(JSON.stringify(tax)) as TaxSummary }, store })).toBe(fingerprint('taxes', data)!); + const moved: TaxSummary = { years: { ...tax.years, '2026': { ...tax.years['2026']!, X2: { ...tax.years['2026']!.X2!, boxes: { '1099-MISC 8': 2 } } } } }; + expect(fingerprint('taxes', { ds: { ...ds, taxSummary: moved }, store })).not.toBe(fingerprint('taxes', data)!); + expect(fingerprint('taxes', { ds, store })).toBeNull(); + expect(fingerprint('taxes', { ds: { ...ds, taxSummary: { years: {} } }, store })).toBeNull(); + expect(parseSignal(JSON.stringify({ at: 1, sets: ['taxes'] }))).toEqual({ at: 1, sets: ['taxes'] }); + const fake = { readRows: async (spec: { name: string }): Promise => (spec.name === TAX_SUMMARY.name ? (rows as unknown as T[]) : []) }; + expect(await readSets(fake, ['taxes'])).toEqual({ taxes: rows }); + const missing = { readRows: async (spec: { name: string }): Promise => { throw new SheetsError(`Google Sheets 400 on read ${spec.name}`, 400); } }; + expect(await readSets(missing, ['taxes'])).toEqual({ taxes: [] }); +}); diff --git a/src/shared/sheets/sync.ts b/src/shared/sheets/sync.ts index fdbf605..978e6af 100644 --- a/src/shared/sheets/sync.ts +++ b/src/shared/sheets/sync.ts @@ -5,20 +5,23 @@ // viewer reads only those back. Three sets, as Fidelity changes them apart (owner: "and summary, and positions, and // even transactions"): summary = fidelity_accounts + fidelity_balances_daily, positions = fidelity_positions (+ the // wide fidelity_positions_all, written only), transactions = fidelity_transactions + fidelity_transactions_synced. -// betas = fidelity_betas (shared/beta.ts, a daily run of their own). +// betas = fidelity_betas (shared/beta.ts, a daily run of their own), performance = fidelity_performance, taxes = +// fidelity_tax_summary (shared/tax-summary.ts). // Accounts, positions, transactions and betas are the state now (rewritten), balances_daily is history (upsert by date|account) import { perfFromRows, perfRows, type PerfRow } from '../performance'; +import { taxSummaryFromRows, taxSummaryRows, type TaxSummaryRow } from '../tax-summary'; import type { Betas } from '../beta'; import { DATASET_VERSION, parseDataset, type Account, type Dataset } from '../model'; import type { Txn, TxnStore } from '../transactions'; import type { AdpBalance, AdpStore, AdpTxn } from '../adp/mykplan'; import { statusOf, type ChunkPrint, type SheetsClient } from './client'; import type { TabSpec } from './tabs'; -import { ACCOUNTS, ADP_BALANCES, ADP_TRANSACTIONS, BALANCES, BETAS, PERFORMANCE, POSITIONS, TRANSACTIONS, TXN_SYNCED, UPDATES, WIDE_FIRST, WIDE_TAB, growHeader, wideSpec, type BalanceRow, type BetaRow, type PositionRow, type TxnSyncedRow, type UpdateRow } from './tabs'; +import { ACCOUNTS, ADP_BALANCES, ADP_TRANSACTIONS, BALANCES, BETAS, PERFORMANCE, POSITIONS, TAX_SUMMARY, TRANSACTIONS, TXN_SYNCED, UPDATES, WIDE_FIRST, WIDE_TAB, growHeader, wideSpec, type BalanceRow, type BetaRow, type PositionRow, type TxnSyncedRow, type UpdateRow } from './tabs'; -// adp: the ADP 401k history, written from a mykplan tab (owner 2026-11-30) -export type DataSet = 'summary' | 'positions' | 'transactions' | 'betas' | 'adp' | 'performance'; -export const DATA_SETS: readonly DataSet[] = ['summary', 'positions', 'transactions', 'betas', 'adp', 'performance']; +// adp: the ADP 401k history, written from a mykplan tab (owner 2026-11-30); taxes: Fidelity's Tax Info YTD summary +// (owner 2026-12-03; `tax` is the name of the qualified marks' read time, here.ts) +export type DataSet = 'summary' | 'positions' | 'transactions' | 'betas' | 'adp' | 'performance' | 'taxes'; +export const DATA_SETS: readonly DataSet[] = ['summary', 'positions', 'transactions', 'betas', 'adp', 'performance', 'taxes']; /** what the script holds for the sets: the Fidelity copy, its transactions and the ADP history */ export interface SetData { ds: Dataset | null; store: TxnStore | null; adp?: AdpStore | null } /** the tabs each set writes: a set whose tab is gone from the spreadsheet is written again whatever its print says */ @@ -29,6 +32,7 @@ export const SET_TABS: Record = { betas: [BETAS.name], adp: [ADP_TRANSACTIONS.name, ADP_BALANCES.name], performance: [PERFORMANCE.name], + taxes: [TAX_SUMMARY.name], }; /** the signal the Fidelity tab leaves after a write: when, and which sets the sheet has new */ @@ -140,6 +144,13 @@ export async function pushPerformance(client: SheetsClient, ds: Dataset, log: Lo log(`${PERFORMANCE.name}: ${r.written} rows`); } +/** Fidelity's tax summary: one row per account, tax year and box */ +export async function pushTaxSummary(client: SheetsClient, ds: Dataset, log: Log): Promise { + if (!ds.taxSummary) return; + const r = await client.writeAll(TAX_SUMMARY, taxSummaryRows(ds.taxSummary)); + log(`${TAX_SUMMARY.name}: ${r.written} rows`); +} + /** * A short print of a set's content, to skip a write that would change nothing (owner 2026-11-24: signal "when anything * useful was sent, not just empty try"). The read time is left out: accounts carry it in asOf, a refresh of a closed @@ -162,6 +173,10 @@ export function fingerprint(set: DataSet, data: SetData): string | null { const perf = data.ds?.performance; if (!perf || !Object.keys(perf.accounts).length) return null; json = JSON.stringify(perfRows(perf)); + } else if (set === 'taxes') { + const rows = data.ds?.taxSummary ? taxSummaryRows(data.ds.taxSummary) : []; + if (!rows.length) return null; + json = JSON.stringify(rows); } else if (set === 'adp') { if (!data.adp?.rows.length) return null; json = JSON.stringify([data.adp.rows, data.adp.balances ?? []]); @@ -198,7 +213,7 @@ export function changedSets(sheet: Partial>, seen: Parti } /** what the viewer reads back for some sets; a set left out stays undefined */ -export interface SheetTabs { accounts?: Account[]; positions?: PositionRow[]; days?: BalanceRow[]; txns?: Txn[]; synced?: TxnSyncedRow[]; betas?: BetaRow[]; adp?: AdpTxn[]; adpBalances?: AdpBalance[]; performance?: PerfRow[] } +export interface SheetTabs { accounts?: Account[]; positions?: PositionRow[]; days?: BalanceRow[]; txns?: Txn[]; synced?: TxnSyncedRow[]; betas?: BetaRow[]; adp?: AdpTxn[]; adpBalances?: AdpBalance[]; performance?: PerfRow[]; taxes?: TaxSummaryRow[] } /** the rows of a tab; a tab not created yet (400 "Unable to parse range") reads as empty, other errors surface */ export async function readTab(client: Pick, spec: TabSpec): Promise { try { @@ -217,6 +232,7 @@ export async function readSets(client: Pick, sets: rea sets.includes('transactions') ? Promise.all([readTab(client, TRANSACTIONS), readTab(client, TXN_SYNCED)]).then(([t, s]) => { out.txns = t; out.synced = s; }) : null, sets.includes('betas') ? readTab(client, BETAS).then((b) => { out.betas = b; }) : null, sets.includes('performance') ? readTab(client, PERFORMANCE).then((p) => { out.performance = p; }) : null, + sets.includes('taxes') ? readTab(client, TAX_SUMMARY).then((t) => { out.taxes = t; }) : null, sets.includes('adp') ? Promise.all([readTab(client, ADP_TRANSACTIONS), readTab(client, ADP_BALANCES)]).then(([a, b]) => { out.adp = a; out.adpBalances = b; }) : null, ]); return out; @@ -224,7 +240,7 @@ export async function readSets(client: Pick, sets: rea /** * The shown dataset with the sets read from the sheet put in: accounts and the daily history from summary, positions - * from positions, the betas from betas; what was not read stays as it was. The read time is the newest asOf of the rows read (the time + * from positions, the betas from betas, the tax summary from taxes; what was not read stays as it was. The read time is the newest asOf of the rows read (the time * the Fidelity tab read them), never older than the shown one. Null when nothing is there yet */ export function datasetFromTabs(prev: Dataset | null, tabs: SheetTabs): Dataset | null { @@ -243,9 +259,11 @@ export function datasetFromTabs(prev: Dataset | null, tabs: SheetTabs): Dataset const betasAt = read && Object.keys(read).length ? tabs.betas!.reduce((m, b) => (b.asOf > m ? b.asOf : m), '') || prev?.betasAt : prev?.betasAt; const perfRead = tabs.performance ? perfFromRows(tabs.performance) : undefined; const performance = perfRead ?? prev?.performance; + const taxRead = tabs.taxes ? taxSummaryFromRows(tabs.taxes) : undefined; + const taxSummary = taxRead ?? prev?.taxSummary; const times = (tabs.accounts ?? []).map((a) => a.asOf).concat((tabs.positions ?? []).map((p) => p.asOf), prev ? [prev.builtAt] : []).filter(Boolean); const builtAt = times.reduce((m, x) => (x > m ? x : m), '') || new Date().toISOString(); - return parseDataset(JSON.stringify({ version: DATASET_VERSION, builtAt, asOf: null, accounts, positions, warnings: [], history, betas, betasAt, performance, performanceAt: perfRead ? prev?.performanceAt ?? builtAt : prev?.performanceAt })); + return parseDataset(JSON.stringify({ version: DATASET_VERSION, builtAt, asOf: null, accounts, positions, warnings: [], history, betas, betasAt, performance, performanceAt: perfRead ? prev?.performanceAt ?? builtAt : prev?.performanceAt, taxSummary, taxSummaryAt: taxRead ? prev?.taxSummaryAt ?? builtAt : prev?.taxSummaryAt })); } /** the transactions store from its two tabs, or null when the history was never written */ diff --git a/src/shared/sheets/tabs.ts b/src/shared/sheets/tabs.ts index 30562a7..81d4d54 100644 --- a/src/shared/sheets/tabs.ts +++ b/src/shared/sheets/tabs.ts @@ -4,6 +4,7 @@ // account numbers as text), rows come back as UNFORMATTED_VALUE and text is parsed too (a hand-edited cell must not // break a read) import type { PerfRow } from '../performance'; +import type { TaxSummaryRow } from '../tax-summary'; import { oldFieldNames, snakeCase } from '../snake'; import { BETA_SOURCES, type BetaSource } from '../beta'; import type { Account, Position } from '../model'; @@ -319,6 +320,17 @@ export const PERFORMANCE = defineTab('fidelity_performance', [ { key: 'asOf', as: 'as_of', kind: 'text' }, ], (r) => key(r.account, r.period)); +// Fidelity's Tax Info YTD summary (shared/tax-summary.ts): one row per account, tax year and 1099 box, the realized +// gains as form gain-loss, box short-term or long-term; rewritten after each read +export const TAX_SUMMARY = defineTab('fidelity_tax_summary', [ + { key: 'account', as: 'account_number', kind: 'text' }, + { key: 'year', as: 'tax_year', kind: 'text' }, + { key: 'form', as: 'form_type', kind: 'text' }, + { key: 'box', as: 'box_number', kind: 'text' }, + { key: 'amount', kind: 'num' }, + { key: 'asOf', as: 'as_of', kind: 'text' }, +], (r) => key(r.account, r.year, r.form, r.box)); + // the ADP 401k history from mykplan (shared/adp/mykplan.ts), rewritten as a whole after each read; the tab names of // another source start with it (owner 2026-11-30: "adp_mykplan_*"), the columns use the words of the other tabs export const ADP_TRANSACTIONS = defineTab('adp_mykplan_transactions', [ @@ -343,7 +355,7 @@ export const ADP_BALANCES = defineTab('adp_mykplan_balances_monthly' { key: 'value', as: 'balance', kind: 'num' }, ], (r) => key(r.date, r.fund)); -// when each data set was last written (one row per set: summary, positions, transactions, betas): the viewer watches this +// when each data set was last written (one row per set: summary, positions, transactions, betas, performance, taxes, adp): the viewer watches this // small tab and reads back only the sets that changed export interface UpdateRow { set: string; at: string } export const UPDATES = defineTab('fidelity_updates', [ @@ -351,4 +363,4 @@ export const UPDATES = defineTab('fidelity_updates', [ { key: 'at', as: 'updated_at', kind: 'text' }, ], (r) => r.set); -export const TAB_NAMES = [ACCOUNTS.name, POSITIONS.name, BALANCES.name, WIDE_TAB, TRANSACTIONS.name, TXN_SYNCED.name, BETAS.name, PERFORMANCE.name, UPDATES.name, ADP_TRANSACTIONS.name, ADP_BALANCES.name]; +export const TAB_NAMES = [ACCOUNTS.name, POSITIONS.name, BALANCES.name, WIDE_TAB, TRANSACTIONS.name, TXN_SYNCED.name, BETAS.name, PERFORMANCE.name, TAX_SUMMARY.name, UPDATES.name, ADP_TRANSACTIONS.name, ADP_BALANCES.name]; diff --git a/src/shared/tax-summary.test.ts b/src/shared/tax-summary.test.ts new file mode 100644 index 0000000..2825636 --- /dev/null +++ b/src/shared/tax-summary.test.ts @@ -0,0 +1,102 @@ +/// +/// +/// +import { expect, test } from 'bun:test'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { TAX_SUMMARY_URL, cleanTaxSummary, parseTaxSummary, taxSummaryDue, taxSummaryFromRows, taxSummaryRequest, taxSummaryRows, taxYearsToRead, withTaxYear, type TaxSummary } from './tax-summary'; + +// the shape of Fidelity's answer with made-up accounts and amounts: 38 box rows an account, the total rows, texts +const ANSWER: unknown = JSON.parse(readFileSync(join(__dirname, 'fixtures', 'tax-summary.json'), 'utf8')); + +test('the request of the Tax Info YTD page: every account in one body, the year, the gains asked for', () => { + expect(TAX_SUMMARY_URL).toBe('/ftgw/digital/api-ytd-tax-info/api/tax-info-summary/v1'); + expect(taxSummaryRequest([{ number: 'X10000001' }, { number: 'X10000002' }], 2026)).toEqual({ returnGainLoss: true, acctDetails: [{ acctNum: 'X10000001' }, { acctNum: 'X10000002' }], taxYear: 2026 }); +}); + +test('the boxes with a number, zeros kept; texts and total rows left out; the gains, a missing one null', () => { + const s = parseTaxSummary(ANSWER); + expect(s.year).toBe('2026'); + expect(Object.keys(s.accounts)).toEqual(['X10000001', 'X10000002']); + const one = s.accounts.X10000001!; + expect(one.asOf).toBe('2026-12-03'); + // 38 box rows: "Various" (1099-DIV 8) and "N/A" (1099-INT 7) are not numbers + expect(Object.keys(one.boxes).length).toBe(36); + expect(one.boxes['1099-DIV 1A']).toBe(125.4); + expect(one.boxes['1099-DIV 1B']).toBe(100); + expect(one.boxes['1099-DIV 1C']).toBe(25.4); + expect(one.boxes['1099-OIF 3']).toBe(1.25); + expect(one.boxes['1099-DIV 13']).toBe(0); + expect('1099-DIV 8' in one.boxes).toBe(false); + expect('1099-INT 7' in one.boxes).toBe(false); + // the total rows (no recordType, no box) never show up as a box + expect(Object.keys(one.boxes).some((k) => k.startsWith('-') || k.endsWith(' '))).toBe(false); + expect(one.shortTerm).toBeNull(); + expect(one.longTerm).toBeNull(); + const two = s.accounts.X10000002!; + expect(two.boxes['1099-DIV 1A']).toBe(1050); // "1,050.00" + expect(two.shortTerm).toBe(12.34); + expect(two.longTerm).toBeNull(); +}); + +test('a blank amount, a row of another record type and an account without a number are left out', () => { + const s = parseTaxSummary({ data: { getTaxInfoSummary: { taxActivitySummary: { taxYear: 2025, acctDetails: [ + { acctNum: 'X1', asOfDate: '12/31/2025', taxIncomeSummary: [{ formType: '1099-DIV', boxNumber: '1A', recordType: 'A', transactionAmount: '' }, { formType: '1099-DIV', boxNumber: '1B', recordType: 'B', transactionAmount: '5' }, { formType: '1099-INT', boxNumber: '1', recordType: 'A', transactionAmount: 7 }], gainLossSummary: null }, + { asOfDate: '2025-12-31', taxIncomeSummary: [] }, + ] } } } }); + expect(s).toEqual({ year: '2025', accounts: { X1: { asOf: '2025-12-31', boxes: { '1099-INT 1': 7 }, shortTerm: null, longTerm: null } } }); +}); + +test('an answer without the accounts list throws (Fidelity changed it)', () => { + expect(() => parseTaxSummary({ data: { getTaxInfoSummary: { taxActivitySummary: {} } } })).toThrow('no acctDetails'); + expect(() => parseTaxSummary(null)).toThrow('no acctDetails'); +}); + +test('the year before is read too from January 1 to April 15', () => { + expect(taxYearsToRead('2027-01-02')).toEqual([2026, 2027]); + expect(taxYearsToRead('2027-04-15')).toEqual([2026, 2027]); + expect(taxYearsToRead('2027-04-16')).toEqual([2027]); + expect(taxYearsToRead('2026-12-03')).toEqual([2026]); +}); + +test('a read replaces the accounts it read in that year, the rest stays', () => { + const ytd = (n: number) => ({ asOf: '2026-12-01', boxes: { '1099-DIV 1A': n }, shortTerm: null, longTerm: null }); + const old: TaxSummary = { years: { '2025': { X1: ytd(1) }, '2026': { X1: ytd(2), X2: ytd(3) } } }; + const next = withTaxYear(old, '2026', { X1: ytd(20) }); + expect(next.years['2026']).toEqual({ X1: ytd(20), X2: ytd(3) }); + expect(next.years['2025']).toEqual({ X1: ytd(1) }); + expect(old.years['2026']!.X1).toEqual(ytd(2)); // the old copy is not changed + expect(withTaxYear(undefined, '2026', { X1: ytd(5) })).toEqual({ years: { '2026': { X1: ytd(5) } } }); +}); + +test('due: never read; a Positions read after it; an hour after it; never within 5 minutes', () => { + const t = Date.parse('2026-12-03T15:00:00Z'); + const min = 60_000; + expect(taxSummaryDue(null, null, t)).toBe(true); + expect(taxSummaryDue(null, t, t)).toBe(true); + expect(taxSummaryDue(t - 10 * min, t - 20 * min, t)).toBe(false); // the grid was read before it + expect(taxSummaryDue(t - 10 * min, t - 2 * min, t)).toBe(true); // the grid was read after it + expect(taxSummaryDue(t - 4 * min, t - 1 * min, t)).toBe(false); // too soon after the last read + expect(taxSummaryDue(t - 59 * min, null, t)).toBe(false); + expect(taxSummaryDue(t - 60 * min, null, t)).toBe(true); +}); + +test('the sheet rows and back: one row a box, the gains as gain-loss, a null gain no row', () => { + const s: TaxSummary = { years: { '2026': withTaxYear(undefined, '2026', parseTaxSummary(ANSWER).accounts).years['2026']! } }; + const rows = taxSummaryRows(s); + expect(rows.length).toBe(36 + 36 + 1); + expect(rows[0]).toEqual({ account: 'X10000001', year: '2026', form: '1099-DIV', box: '1A', amount: 125.4, asOf: '2026-12-03' }); + expect(rows.filter((r) => r.form === 'gain-loss')).toEqual([{ account: 'X10000002', year: '2026', form: 'gain-loss', box: 'short-term', amount: 12.34, asOf: '2026-12-03' }]); + expect(taxSummaryFromRows(rows)).toEqual(s); + expect(taxSummaryFromRows([])).toBeUndefined(); + const both: TaxSummary = { years: { '2025': { X1: { asOf: '2025-12-31', boxes: { '1099-INT 1': 0 }, shortTerm: -1.5, longTerm: 2 } } } }; + expect(taxSummaryFromRows(taxSummaryRows(both))).toEqual(both); +}); + +test('a stored copy is checked', () => { + expect(cleanTaxSummary({ years: { '2026': {} } })).toEqual({ years: { '2026': {} } }); + expect(cleanTaxSummary({ years: [] })).toBeUndefined(); + expect(cleanTaxSummary({ years: { '2026': 'x' } })).toBeUndefined(); + expect(cleanTaxSummary('junk')).toBeUndefined(); + expect(cleanTaxSummary(undefined)).toBeUndefined(); +}); diff --git a/src/shared/tax-summary.ts b/src/shared/tax-summary.ts new file mode 100644 index 0000000..e4e7007 --- /dev/null +++ b/src/shared/tax-summary.ts @@ -0,0 +1,142 @@ +/// +// Fidelity's Tax Info YTD summary (owner 2026-12-03: "so we will have like a Fidelity Tax Summary info"): the boxes of +// the year's 1099 forms per account as they stand so far (1099-DIV, 1099-INT, 1099-MISC, 1099-OID and the margin +// interest paid) and the realized short and long term gain or loss, read with the page's session (a read: the request +// Fidelity's own Tax Info YTD page makes; owner 2026-12-03: "no read as you reading, its not so hard", so it goes along +// with the other reads). One request carries several accounts. The numbers are preliminary until the 1099 comes: the +// current year is read again and again, the year before too while its forms may still change. Framework-free: the +// userscript reads, the sheet keeps it in fidelity_tax_summary, the viewer sums what it shows +export const TAX_SUMMARY_URL = '/ftgw/digital/api-ytd-tax-info/api/tax-info-summary/v1'; + +/** one account's year so far */ +export interface TaxYtd { + asOf: string; // ISO day of Fidelity's numbers + // "
" -> dollars, e.g. "1099-DIV 1A"; a zero says "read, nothing there"; a box with a text instead of a + // number ("Various", "N/A") is left out + boxes: Record; + shortTerm: number | null; // the realized short term net gain or loss; null when Fidelity gives none + longTerm: number | null; +} +/** tax year -> account number -> its year so far */ +export interface TaxSummary { years: Record> } + +/** the request body of the Tax Info YTD page for some accounts and one year (no `parameters` wrapper: that gives 400) */ +export function taxSummaryRequest(accounts: ReadonlyArray<{ number: string }>, year: number): unknown { + return { returnGainLoss: true, acctDetails: accounts.map((a) => ({ acctNum: a.number })), taxYear: year }; +} + +const str = (v: unknown): string => (typeof v === 'string' ? v : typeof v === 'number' ? String(v) : ''); +// "1,234.56" or a number reads as a number; a text, an empty cell or a blank reads as null +const amount = (v: unknown): number | null => { + if (typeof v === 'number') return Number.isFinite(v) ? v : null; + const s = str(v).replace(/[$,\s]/g, ''); + if (!/^[-+]?\d*\.?\d+$/.test(s)) return null; + const n = Number(s); + return Number.isFinite(n) ? n : null; +}; +// an ISO day as it is, a US one (MM/DD/YYYY) turned around, anything else none +const isoDay = (v: unknown): string => { + const s = str(v); + if (/^\d{4}-\d\d-\d\d/.test(s)) return s.slice(0, 10); + const m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(s); + return m ? `${m[3]}-${m[1]!.padStart(2, '0')}-${m[2]!.padStart(2, '0')}` : ''; +}; + +/** + * One answer: the year and each account's boxes and gains. Only the box rows (recordType A) whose amount is a number + * count; the total rows (no recordType) are left out, the viewer sums by itself. Throws when the answer has no + * accounts list (Fidelity changed it) + */ +export function parseTaxSummary(json: unknown): { year: string; accounts: Record } { + const sum = (json as { data?: { getTaxInfoSummary?: { taxActivitySummary?: { taxYear?: unknown; acctDetails?: unknown } } } } | null)?.data?.getTaxInfoSummary?.taxActivitySummary; + const list = sum?.acctDetails; + if (!Array.isArray(list)) throw new Error('tax summary: no acctDetails in the answer'); + const accounts: Record = {}; + list.forEach((a) => { + const acct = (a ?? {}) as { acctNum?: unknown; asOfDate?: unknown; taxIncomeSummary?: unknown; gainLossSummary?: unknown }; + const number = str(acct.acctNum); + if (!number) return; + const boxes: Record = {}; + (Array.isArray(acct.taxIncomeSummary) ? acct.taxIncomeSummary : []).forEach((r) => { + const row = (r ?? {}) as Record; + const form = str(row.formType); + const box = str(row.boxNumber); + const n = amount(row.transactionAmount); + const k = `${form} ${box}`; + if (row.recordType === 'A' && form && box && n !== null && !(k in boxes)) boxes[k] = n; + }); + const gl = (acct.gainLossSummary ?? {}) as { shortTermNet?: unknown; longTermNet?: unknown }; + accounts[number] = { asOf: isoDay(acct.asOfDate), boxes, shortTerm: amount(gl.shortTermNet), longTerm: amount(gl.longTermNet) }; + }); + return { year: str(sum?.taxYear), accounts }; +} + +/** + * The years to ask for on `today` (YYYY-MM-DD), oldest first: the current one always, and the year before from + * January 1 to April 15, while its forms come and may still be corrected (the filing season) + */ +export function taxYearsToRead(today: string): number[] { + const year = Number(today.slice(0, 4)); + return today.slice(5, 10) <= '04-15' ? [year - 1, year] : [year]; +} + +/** the summary after a read of one year: the accounts read replace theirs of that year, every other one is kept */ +export function withTaxYear(old: TaxSummary | undefined, year: string, accounts: Record): TaxSummary { + const years: Record> = { ...(old?.years ?? {}) }; + years[year] = { ...(years[year] ?? {}), ...accounts }; + return { years }; +} + +/** a stored copy, checked; anything else is undefined */ +export function cleanTaxSummary(v: unknown): TaxSummary | undefined { + const obj = (x: unknown): boolean => !!x && typeof x === 'object' && !Array.isArray(x); + const s = v as TaxSummary | null; + if (!obj(s) || !obj(s!.years)) return undefined; + return Object.keys(s!.years).every((y) => obj(s!.years[y])) ? s! : undefined; +} + +// the due rule: every hour, and after each read of Positions (its numbers moved), but never sooner than 5 minutes after +// the last read +export const TAX_SUMMARY_GAP_MS = 60 * 60_000; +export const TAX_SUMMARY_MIN_MS = 5 * 60_000; +/** times in ms; null = never */ +export function taxSummaryDue(lastRead: number | null, lastGridRead: number | null, now: number): boolean { + if (lastRead === null) return true; + if (now - lastRead < TAX_SUMMARY_MIN_MS) return false; + return (lastGridRead !== null && lastGridRead > lastRead) || now - lastRead >= TAX_SUMMARY_GAP_MS; +} + +/** the rows of the sheet's fidelity_tax_summary tab: one per account, year and box; the gains as form "gain-loss" */ +export interface TaxSummaryRow { account: string; year: string; form: string; box: string; amount: number; asOf: string } +export const GAIN_LOSS = 'gain-loss'; +export function taxSummaryRows(s: TaxSummary): TaxSummaryRow[] { + const out: TaxSummaryRow[] = []; + Object.keys(s.years).sort().forEach((year) => { + const accounts = s.years[year]!; + Object.keys(accounts).sort().forEach((account) => { + const t = accounts[account]!; + Object.keys(t.boxes).forEach((k) => { + const at = k.indexOf(' '); + out.push({ account, year, form: k.slice(0, at), box: k.slice(at + 1), amount: t.boxes[k]!, asOf: t.asOf }); + }); + if (t.shortTerm !== null) out.push({ account, year, form: GAIN_LOSS, box: 'short-term', amount: t.shortTerm, asOf: t.asOf }); + if (t.longTerm !== null) out.push({ account, year, form: GAIN_LOSS, box: 'long-term', amount: t.longTerm, asOf: t.asOf }); + }); + }); + return out; +} +/** the summary back from its rows; undefined when there are none */ +export function taxSummaryFromRows(rows: TaxSummaryRow[]): TaxSummary | undefined { + const years: Record> = {}; + rows.forEach((r) => { + if (!r.account || !r.year || !r.form || !r.box || typeof r.amount !== 'number' || !Number.isFinite(r.amount)) return; + const accounts = years[r.year] = years[r.year] ?? {}; + const t = accounts[r.account] = accounts[r.account] ?? { asOf: '', boxes: {}, shortTerm: null, longTerm: null }; + if ((r.asOf ?? '') > t.asOf) t.asOf = r.asOf; + if (r.form === GAIN_LOSS) { + if (r.box === 'short-term') t.shortTerm = r.amount; + if (r.box === 'long-term') t.longTerm = r.amount; + } else t.boxes[`${r.form} ${r.box}`] = r.amount; + }); + return Object.keys(years).length ? { years } : undefined; +} diff --git a/src/userscript/here.test.ts b/src/userscript/here.test.ts index 7f18aab..f477654 100644 --- a/src/userscript/here.test.ts +++ b/src/userscript/here.test.ts @@ -32,3 +32,10 @@ test('stored times that are not what we wrote read as none', () => { expect(readsOf('x')).toEqual({}); expect(readsOf({ A1: { history: 'not a date', txns: '2026-11-26T01:30:00.000Z' }, A2: 5 })).toEqual({ A1: { txns: '2026-11-26T01:30:00.000Z' } }); }); + +test('the tax summary keeps its own read time, read back from storage', () => { + const at = '2026-12-03T15:00:00.000Z'; + const reads = readsOf(JSON.parse(JSON.stringify(markRead({}, mine, 'taxSummary', at)))); + expect(oldestRead(reads, mine, 'taxSummary')).toBe(at); + expect(oldestRead(reads, mine, 'tax')).toBeUndefined(); +}); diff --git a/src/userscript/here.ts b/src/userscript/here.ts index 04b2afc..5fc117c 100644 --- a/src/userscript/here.ts +++ b/src/userscript/here.ts @@ -6,8 +6,9 @@ import type { Account } from '../shared/model'; export const READS_KEY = 'accounts.readsAt'; // ReadsAt as an object -// txnsFull: the last full transactions read (schedule.ts txnsPlan), txns: the last one of either kind -export type ReadKind = 'history' | 'txns' | 'txnsFull' | 'tax'; +// txnsFull: the last full transactions read (schedule.ts txnsPlan), txns: the last one of either kind; taxSummary: the +// Tax Info YTD summary (shared/tax-summary.ts), of the taxable accounts only +export type ReadKind = 'history' | 'txns' | 'txnsFull' | 'tax' | 'taxSummary'; export type ReadsAt = Record>>; /** the stored accounts of the login on this page: those in its account list; none while the list is not there */ @@ -24,7 +25,7 @@ export function readsOf(raw: unknown): ReadsAt { const v = (raw as Record)[n]; if (!v || typeof v !== 'object') return; const one: Partial> = {}; - (['history', 'txns', 'txnsFull', 'tax'] as const).forEach((k) => { const t = (v as Record)[k]; if (typeof t === 'string' && !Number.isNaN(Date.parse(t))) one[k] = t; }); + (['history', 'txns', 'txnsFull', 'tax', 'taxSummary'] as const).forEach((k) => { const t = (v as Record)[k]; if (typeof t === 'string' && !Number.isNaN(Date.parse(t))) one[k] = t; }); out[n] = one; }); return out; diff --git a/src/userscript/history-sync.test.ts b/src/userscript/history-sync.test.ts index bf70f6a..6fb1977 100644 --- a/src/userscript/history-sync.test.ts +++ b/src/userscript/history-sync.test.ts @@ -26,3 +26,22 @@ test('3Y for an account without points, 1M for one with points, a failure skips test('the page POST refuses any other URL', async () => { await expect(pagePost('/ftgw/digital/trade/api/order', {})).rejects.toThrow('not allowed'); }); + +test('the tax info summary is one of the allowed reads: a same-origin POST of its body, no extra headers', async () => { + const { TAX_SUMMARY_URL, taxSummaryRequest } = await import('../shared/tax-summary'); + const real = globalThis.fetch; + const asked: Array<{ url: string; init: RequestInit }> = []; + const fake = async (url: string, init: RequestInit) => { asked.push({ url, init }); return new Response('{"data":{}}', { status: 200 }); }; + globalThis.fetch = fake as unknown as typeof fetch; + try { + expect(await pagePost(TAX_SUMMARY_URL, taxSummaryRequest([{ number: 'X1' }], 2026))).toEqual({ data: {} }); + } finally { + globalThis.fetch = real; + } + expect(asked.length).toBe(1); + expect(asked[0]!.url).toBe(TAX_SUMMARY_URL); + expect(asked[0]!.init.method).toBe('POST'); + expect(asked[0]!.init.credentials).toBe('include'); + expect(asked[0]!.init.headers).toEqual({ 'content-type': 'application/json', accept: 'application/json' }); + expect(JSON.parse(String(asked[0]!.init.body))).toEqual({ returnGainLoss: true, acctDetails: [{ acctNum: 'X1' }], taxYear: 2026 }); +}); diff --git a/src/userscript/history-sync.ts b/src/userscript/history-sync.ts index b659c46..cba5bf6 100644 --- a/src/userscript/history-sync.ts +++ b/src/userscript/history-sync.ts @@ -6,6 +6,7 @@ import { BALANCE_HISTORY_URL, parseBalanceHistory, type History } from '../share import { TRANSACTIONS_HEADERS, TRANSACTIONS_URL } from '../shared/transactions'; import { TAX_DETAIL_URL } from '../shared/tax'; import { PERF_FLOW_URL } from '../shared/performance'; +import { TAX_SUMMARY_URL } from '../shared/tax-summary'; import type { Account } from '../shared/model'; export type Post = (url: string, body: unknown) => Promise; @@ -24,13 +25,15 @@ export async function readHistory(accounts: Account[], have: History | undefined } /** - * same-origin POST with the owner's session; only four reads are allowed: BalanceHistory (the Summary chart's data), - * the transactions history (the Activity page's data, with the page's own appId and appName headers) and the tax info - * detail of the year (the Tax Info YTD page's data: which dividends are qualified) + * same-origin POST with the owner's session; only five reads are allowed: BalanceHistory (the Summary chart's data), + * the transactions history (the Activity page's data, with the page's own appId and appName headers), the tax info + * detail of the year (the Tax Info YTD page's data: which dividends are qualified), the Performance page's Balance + * change data and the tax info summary of the year (the Tax Info YTD page's own totals per 1099 box and the gains) */ -// and since 2026-12-01 the Performance page's Balance change data (owner: "yes I'm allow it", Fidelity's own investment -// results per account and period) -const ALLOWED: Record> = { [BALANCE_HISTORY_URL]: {}, [TRANSACTIONS_URL]: { ...TRANSACTIONS_HEADERS }, [TAX_DETAIL_URL]: {}, [PERF_FLOW_URL]: {} }; +// the Balance change data since 2026-12-01 (owner: "yes I'm allow it", Fidelity's own investment results per account +// and period); the tax info summary since 2026-12-03 (owner: "no read as you reading, its not so hard": read along with +// the other reads) +const ALLOWED: Record> = { [BALANCE_HISTORY_URL]: {}, [TRANSACTIONS_URL]: { ...TRANSACTIONS_HEADERS }, [TAX_DETAIL_URL]: {}, [PERF_FLOW_URL]: {}, [TAX_SUMMARY_URL]: {} }; export const pagePost: Post = async (url, body) => { const extra = ALLOWED[url]; if (!extra) throw new Error(`not allowed: ${url}`); diff --git a/src/userscript/main.ts b/src/userscript/main.ts index 7b6aaf1..1843385 100644 --- a/src/userscript/main.ts +++ b/src/userscript/main.ts @@ -16,9 +16,10 @@ import { NEWEST_KEY, versionStep } from './version-sync'; import { PAGE_TAG, askGrid, injectPageReader } from './inject'; import { pagePost, readHistory } from './history-sync'; import { PERF_FLOW_URL, parsePerf, perfDue, perfRequest } from '../shared/performance'; +import { TAX_SUMMARY_URL, parseTaxSummary, taxSummaryDue, taxSummaryRequest, taxYearsToRead, withTaxYear } from '../shared/tax-summary'; import { mergeHistory } from '../shared/history'; import { parseTxnStore, type TxnStore } from '../shared/transactions'; -import { TAX_DETAIL_URL, markQualified, mergeMarks, parseTaxDetail, parseTaxStore, taxRequest, withYear, yearsToRead, type TaxStore } from '../shared/tax'; +import { TAX_DETAIL_URL, markQualified, mergeMarks, parseTaxDetail, parseTaxStore, taxRequest, taxable, withYear, yearsToRead, type TaxStore } from '../shared/tax'; import { EMPTY_STORE, OVERLAP_DAYS, RECENT_DAYS, lastTxnsRead, needRefill, readTransactions, refill, refilled, sameTxns } from './transactions-sync'; import { betaRequest, betasDue, readBetas } from './beta-sync'; import { brokenProblems, checkBalanceHistory, checkGridRows, checkPage, checkTransactions, findingsOf, mergeReport, type Finding, type Report } from '../shared/contract'; @@ -31,7 +32,7 @@ import { TRIP_KEY, backNow, pageName, tripFrom, tripOfPositions } from './trip'; import { NOTICE_KEY, NOTIFY_KEY, makeNotice, type NoticeLevel, type NoticeSite } from '../shared/notice'; import { readAsOf, readSidebar } from './read'; import { GOOGLE_KEY, gmFetch, handoffSheet, usableHandoff, setsAfterRead, writeKept, type KeptPrints } from './sheets-gm'; -import { NO_POSITIONS, NO_READER, SHEETS_WAITING, balancesRead, betasFailed, betasRead, fidelityChanged, adpRead, adpSiteDown, perfRead, codeAsked, loginNotForm, loginRefused, loginTooSoon, jobFailed, positionsRead, say, taxRead, sheetWaitsAllow, sheetsFailed, transactionsFailed, transactionsRead, type Word } from '../shared/notice-words'; +import { NO_POSITIONS, NO_READER, SHEETS_WAITING, balancesRead, betasFailed, betasRead, fidelityChanged, adpRead, adpSiteDown, perfRead, taxSummaryRead, codeAsked, loginNotForm, loginRefused, loginTooSoon, jobFailed, positionsRead, say, taxRead, sheetWaitsAllow, sheetsFailed, transactionsFailed, transactionsRead, type Word } from '../shared/notice-words'; import { PIN_KEY, allowPin, declinePin, idTail, pinStep, readPin, type PinStep } from './pin'; import { DATA_SETS, type DataSet } from '../shared/sheets/sync'; import { memoByRaw } from './memo'; @@ -513,6 +514,51 @@ function onPortfolio(): void { } }; + // Fidelity's Tax Info YTD summary (shared/tax-summary.ts): the 1099 boxes and the gains of the taxable accounts on + // this page (a Roth or another retirement account gets no 1099), one request a year for all of them (taxYearsToRead). + // Due every hour and after a read of Positions, never within 5 minutes of the last read or try (taxSummaryDue) + let taxSummaryTried = 0; + const taxSummaryMine = () => here().filter(taxable); + const taxSummaryNext = (): boolean => { + // the oldest last read among the taxable accounts of this page (the others are never read, so never marked) + const at = oldestRead(readsOf(gmGet(READS_KEY, null)), taxSummaryMine(), 'taxSummary'); + const stored = at ? Date.parse(at) : NaN; + const last = Math.max(Number.isNaN(stored) ? 0 : stored, taxSummaryTried); + const grid = Date.parse(storedDataset()?.builtAt ?? ''); + return taxSummaryDue(last || null, Number.isNaN(grid) ? null : grid, Date.now()); + }; + const syncTaxSummary = async () => { + const mine = taxSummaryMine(); + if (!mine.length) return; + taxSummaryTried = Date.now(); + try { + const stored = storedDataset(); + if (!stored) return; + badge.status('tax summary: reading…'); + const years = taxYearsToRead(nyDay(new Date())); + let summary = stored.taxSummary; + let n = 0; + for (const y of years) { + const fresh = parseTaxSummary(await pagePost(TAX_SUMMARY_URL, taxSummaryRequest(mine, y))); + const read = Object.keys(fresh.accounts).length; + if (!read) throw new Error(`the answer of ${y} named no account`); + n = Math.max(n, read); + summary = withTaxYear(summary, fresh.year || String(y), fresh.accounts); + } + const latest = storedDataset() ?? stored; + gmSet(DATASET_KEY, JSON.stringify({ ...latest, taxSummary: summary, taxSummaryAt: new Date().toISOString() })); + wasRead(mine, 'taxSummary'); + const saved = await saveSets(['taxes']); + badge.status(`tax summary: ${n} accounts, ${years.join(', ')} · ${time()}`); + // it speaks the first time and when the sheet got new numbers, so a read every hour or after each read of + // Positions does not ring for nothing + if (saved || !stored.taxSummary) announce('ok', taxSummaryRead(n, years.join(', '), saved)); + } catch (err) { + badge.status(`!tax summary: ${err instanceof Error ? err.message : String(err)}`.slice(0, 200)); + announce('error', jobFailed('taxSummary', err)); + } + }; + // the API reads, one after the other when schedule.ts says they are due: on any portfolio page (they need no grid), // a few seconds after it opens, after each read of the grid and every 5 minutes while the page stays open let dueBusy = false; @@ -530,6 +576,7 @@ function onPortfolio(): void { if (taxDue(readAt('tax'), new Date())) await syncTax(); if (betasDue(storedDataset(), new Date())) await syncBetas(); if (perfDue(storedDataset(), new Date())) await syncPerformance(); + if (taxSummaryMine().length && taxSummaryNext()) await syncTaxSummary(); } finally { dueBusy = false; } diff --git a/src/userscript/sheets-gm.test.ts b/src/userscript/sheets-gm.test.ts index 98a9426..bc16471 100644 --- a/src/userscript/sheets-gm.test.ts +++ b/src/userscript/sheets-gm.test.ts @@ -139,6 +139,6 @@ describe('fidelity_transactions in parts, prints kept per spreadsheet (writeKept }); test('a read that is a job offers every set to the sheet, a quiet read of the watch only what it read', () => { - expect(setsAfterRead(true)).toEqual(['summary', 'positions', 'transactions', 'betas', 'performance']); + expect(setsAfterRead(true)).toEqual(['summary', 'positions', 'transactions', 'betas', 'performance', 'taxes']); expect(setsAfterRead(false)).toEqual(['summary', 'positions']); }); diff --git a/src/userscript/sheets-gm.ts b/src/userscript/sheets-gm.ts index a4e6b7f..8086b95 100644 --- a/src/userscript/sheets-gm.ts +++ b/src/userscript/sheets-gm.ts @@ -3,7 +3,7 @@ // sync.ts): the viewer hands over its Google token and the spreadsheet id through Tampermonkey storage after ☁️ and on // every silent renew; requests to sheets.googleapis.com go through GM_xmlhttpRequest (page CSP and CORS do not apply) import { SheetsClient, chunkPrintsOf, type ChunkPrint, type FetchLike } from '../shared/sheets/client'; -import { SET_TABS, fingerprint, markUpdated, pushAdp, pushBetas, pushPerformance, pushPositions, pushSummary, pushTransactions, type DataSet, type SetData } from '../shared/sheets/sync'; +import { SET_TABS, fingerprint, markUpdated, pushAdp, pushBetas, pushPerformance, pushPositions, pushSummary, pushTaxSummary, pushTransactions, type DataSet, type SetData } from '../shared/sheets/sync'; import { TRANSACTIONS } from '../shared/sheets/tabs'; export const GOOGLE_KEY = 'accounts.google'; // JSON { token, expiresAt, spreadsheetId } @@ -94,6 +94,7 @@ export async function writeSets(sets: readonly DataSet[], data: SetData, prints: if (set === 'transactions') chunks[TRANSACTIONS.name] = await pushTransactions(client, data.store!, log, chunkPrintsOf(chunks[TRANSACTIONS.name])); if (set === 'betas') await pushBetas(client, data.ds!, log); if (set === 'performance') await pushPerformance(client, data.ds!, log); + if (set === 'taxes') await pushTaxSummary(client, data.ds!, log); if (set === 'adp') await pushAdp(client, data.adp!, log); next[set] = print; done.push(set); @@ -110,7 +111,7 @@ export async function writeSets(sets: readonly DataSet[], data: SetData, prints: * own copy. The quiet reads of 👀 between them offer only what they read. Seen live 2026-11-27: the round trip was not * counted as a job, so the transactions tab was never offered */ -export const setsAfterRead = (job: boolean): DataSet[] => (job ? ['summary', 'positions', 'transactions', 'betas', 'performance'] : ['summary', 'positions']); +export const setsAfterRead = (job: boolean): DataSet[] => (job ? ['summary', 'positions', 'transactions', 'betas', 'performance', 'taxes'] : ['summary', 'positions']); /** what the script keeps in Tampermonkey storage about its writes (main.ts PRINTS_KEY), for one spreadsheet */ export interface KeptPrints { id?: string; prints?: Prints; chunks?: TabChunks } diff --git a/src/viewer/app/i18n/ru.ts b/src/viewer/app/i18n/ru.ts index 9801ddf..62c5c11 100644 --- a/src/viewer/app/i18n/ru.ts +++ b/src/viewer/app/i18n/ru.ts @@ -543,6 +543,9 @@ export const RU: Record = { 'Investment results updated': 'Результаты инвестиций обновлены', 'Accounts: {n}, as of {day}': 'Счетов: {n}, на {day}', 'Failed investment results read': 'Не удалось прочитать результаты инвестиций', + 'Tax summary updated': 'Налоговая сводка обновлена', + 'Accounts: {n}, tax years: {years}': 'Счетов: {n}, налоговые годы: {years}', + 'Failed tax summary read': 'Не удалось прочитать налоговую сводку', 'mykplan is not answering (its side)': 'mykplan не отвечает (проблема на его стороне)', 'It gives no last price day right now (its nightly update?)': 'У него сейчас нет даты последней цены (ночное обновление?)', 'It shows its own error page: "An error occurred while processing this request"': 'Он показывает свою страницу ошибки: "An error occurred while processing this request"',