From f50bef6144217273e4cd1a1e9aa35c173bd2e47e Mon Sep 17 00:00:00 2001 From: Ronan-Yann Lorin Date: Mon, 25 Mar 2024 07:32:10 +0100 Subject: [PATCH] Taxes on dividends added --- .../Portfolio/Report/ReportSummary.tsx | 26 ++++++++++++--- src/routers/reports.types.ts | 14 +++++--- src/routers/statements.types.ts | 2 +- src/routers/statements.utils.ts | 32 ++++++++++++++----- 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/app/components/Portfolio/Report/ReportSummary.tsx b/src/app/components/Portfolio/Report/ReportSummary.tsx index 6b6a546..ec66b79 100644 --- a/src/app/components/Portfolio/Report/ReportSummary.tsx +++ b/src/app/components/Portfolio/Report/ReportSummary.tsx @@ -31,21 +31,37 @@ const ReportSummary: FunctionComponent = ({ ..._rest }): React.ReactNode Country - Amount + + Gross Amount + + + Taxes + + + Net Amount + {theReport.dividendsSummary.map((item: DididendSummary) => ( {item.country} - + + + + + + + ))} Total - Amount + Gross Amount + Taxes + Net Amount @@ -53,9 +69,9 @@ const ReportSummary: FunctionComponent = ({ ..._rest }): React.ReactNode {/* */}

Interests

- Net credit + Gross credit - + Tax diff --git a/src/routers/reports.types.ts b/src/routers/reports.types.ts index 6a36158..b215be1 100644 --- a/src/routers/reports.types.ts +++ b/src/routers/reports.types.ts @@ -1,4 +1,9 @@ -import { DividendStatementEntry, InterestStatementEntry, WithHoldingStatementEntry } from "./statements.types"; +import { + DividendStatementEntry, + InterestStatementEntry, + TaxStatementEntry, + WithHoldingStatementEntry, +} from "./statements.types"; /** * Dididend details entry data transfered between frontend and backend @@ -19,14 +24,15 @@ export type DididendSummary = { // year: number; // month: number; country: string; - totalAmountInBase: number; + grossAmountInBase: number; + taxes: number; }; /** * Dididend Summary entry data transfered between frontend and backend */ export type InterestsSummary = { - netCredit: number; + grossCredit: number; netDebit: number; withHolding: number; totalAmountInBase: number; @@ -40,7 +46,7 @@ export type ReportEntry = { year: number; month: number; dividendsSummary: DididendSummary[]; - dividendsDetails: DividendStatementEntry[]; + dividendsDetails: (DividendStatementEntry | TaxStatementEntry)[]; interestsSummary: InterestsSummary; interestsDetails: (InterestStatementEntry | WithHoldingStatementEntry)[]; }; diff --git a/src/routers/statements.types.ts b/src/routers/statements.types.ts index ee6a2a8..236acf6 100644 --- a/src/routers/statements.types.ts +++ b/src/routers/statements.types.ts @@ -47,7 +47,7 @@ export type DividendStatementEntry = BaseStatement & { statementType: "Dividend"; country: string; }; -export type TaxStatementEntry = BaseStatement & { statementType: "Tax" }; +export type TaxStatementEntry = BaseStatement & { statementType: "Tax"; country: string }; export type InterestStatementEntry = BaseStatement & { statementType: "Interest" }; export type WithHoldingStatementEntry = BaseStatement & { statementType: "WithHolding" }; export type FeeStatementEntry = BaseStatement & { statementType: "OtherFee" }; diff --git a/src/routers/statements.utils.ts b/src/routers/statements.utils.ts index 604144f..b03b0d9 100644 --- a/src/routers/statements.utils.ts +++ b/src/routers/statements.utils.ts @@ -8,6 +8,7 @@ import { OptionStatement, Portfolio, Statement, + TaxStatement, } from "../models"; import { StatementTypes } from "../models/statement.types"; import { DididendSummary, ReportEntry } from "./reports.types"; @@ -71,6 +72,7 @@ export const statementModelToStatementEntry = (item: Statement): Promise { baseStatement.pnl = item.netCash; @@ -82,11 +84,15 @@ export const statementModelToStatementEntry = (item: Statement): Promise { + baseStatement.pnl = item.netCash; + return { + statementType: StatementTypes.TaxStatement, + ...baseStatement, + country: thisStatement!.country, + }; }); + case StatementTypes.InterestStatement: baseStatement.pnl = item.netCash; return Promise.resolve({ @@ -158,7 +164,7 @@ export const prepareReport = (portfolio: Portfolio, year: number, month: number) month, dividendsSummary: [], dividendsDetails: [], - interestsSummary: { totalAmountInBase: 0, netCredit: 0, netDebit: 0, withHolding: 0 }, + interestsSummary: { totalAmountInBase: 0, grossCredit: 0, netDebit: 0, withHolding: 0 }, interestsDetails: [], }; statements.forEach((statement) => { @@ -170,16 +176,26 @@ export const prepareReport = (portfolio: Portfolio, year: number, month: number) case StatementTypes.DividendStatement: entry = report.dividendsSummary.find((item) => item.country == statement.country); if (!entry) { - entry = { country: statement.country, totalAmountInBase: 0 }; + entry = { country: statement.country, grossAmountInBase: 0, taxes: 0 }; + report.dividendsSummary.push(entry); + } + entry.grossAmountInBase += statement.amount * statement.fxRateToBase; + report.dividendsDetails.push(statement); + break; + + case StatementTypes.TaxStatement: + entry = report.dividendsSummary.find((item) => item.country == statement.country); + if (!entry) { + entry = { country: statement.country, grossAmountInBase: 0, taxes: 0 }; report.dividendsSummary.push(entry); } - entry.totalAmountInBase += statement.amount * statement.fxRateToBase; + entry.taxes += statement.amount * statement.fxRateToBase; report.dividendsDetails.push(statement); break; case StatementTypes.InterestStatement: report.interestsSummary.totalAmountInBase += statement.amount * statement.fxRateToBase; - if (statement.amount > 0) report.interestsSummary.netCredit += statement.amount * statement.fxRateToBase; + if (statement.amount > 0) report.interestsSummary.grossCredit += statement.amount * statement.fxRateToBase; else report.interestsSummary.netDebit += statement.amount * statement.fxRateToBase; report.interestsDetails.push(statement); break;