From 3c84a838e0b7f0e47315e118fa9125987514eaf4 Mon Sep 17 00:00:00 2001 From: Ronan-Yann Lorin Date: Sat, 13 Apr 2024 07:32:03 +0200 Subject: [PATCH] Fees details refactored --- .../{FeeComponent.tsx => FeesComponent.tsx} | 0 .../Portfolio/Report/FeesDetails.tsx | 82 +++++++++++++++++++ .../Portfolio/Report/ReportDetails.tsx | 18 +--- .../Portfolio/Report/ReportSummary.tsx | 2 +- 4 files changed, 85 insertions(+), 17 deletions(-) rename src/app/components/Portfolio/Report/{FeeComponent.tsx => FeesComponent.tsx} (100%) create mode 100644 src/app/components/Portfolio/Report/FeesDetails.tsx diff --git a/src/app/components/Portfolio/Report/FeeComponent.tsx b/src/app/components/Portfolio/Report/FeesComponent.tsx similarity index 100% rename from src/app/components/Portfolio/Report/FeeComponent.tsx rename to src/app/components/Portfolio/Report/FeesComponent.tsx diff --git a/src/app/components/Portfolio/Report/FeesDetails.tsx b/src/app/components/Portfolio/Report/FeesDetails.tsx new file mode 100644 index 0000000..a6e6a1d --- /dev/null +++ b/src/app/components/Portfolio/Report/FeesDetails.tsx @@ -0,0 +1,82 @@ +import { SearchIcon } from "@chakra-ui/icons"; +import { IconButton, Link, Tooltip } from "@chakra-ui/react"; +import { createColumnHelper } from "@tanstack/react-table"; +import { default as React } from "react"; +import { Link as RouterLink, useParams } from "react-router-dom"; +import { StatementTypes } from "../../../../models/types"; +import { FeeStatementEntry, ReportEntry } from "../../../../routers/types"; +import Number from "../../Number/Number"; +import { StatementLink } from "../Statement/links"; +import { DataTable } from "./DataTable"; +type Props = { theReports: ReportEntry[] }; + +type FeesDetails = { + id: number; + date: Date; + amount: number; + description: string; +}; + +const columnHelper = createColumnHelper(); + +/** + * Dividends table component + * @param theReports Tax reports to summarize. Assume their summaries are sorted by date + * @returns + */ +const FeesDetails = ({ theReports, ..._rest }: Props): React.ReactNode => { + const { portfolioId } = useParams(); + + let totalFees = 0; + + const data: FeesDetails[] = theReports + .reduce((p, report) => p.concat(report.feesDetails), [] as FeeStatementEntry[]) + .map((statement) => { + let result: FeesDetails; + switch (statement.statementType) { + case StatementTypes.FeeStatement: + result = { + id: statement.id, + date: new Date(statement.date), + amount: statement.fees * statement.fxRateToBase, + description: statement.description, + }; + break; + } + totalFees += result.amount; + return result; + }); + + const columns = [ + columnHelper.accessor("id", { + cell: (info) => ( + + } size="xs" variant="ghost" /> + + ), + header: "#", + }), + columnHelper.accessor("date", { + cell: (info) => ( + + {info.getValue().toISOString().substring(0, 10)} + + ), + footer: "Total", + }), + columnHelper.accessor("amount", { + cell: (info) => , + meta: { + isNumeric: true, + }, + footer: () => , + }), + columnHelper.accessor("description", { + cell: (info) => info.getValue(), + }), + ]; + + return ; +}; + +export default FeesDetails; diff --git a/src/app/components/Portfolio/Report/ReportDetails.tsx b/src/app/components/Portfolio/Report/ReportDetails.tsx index 45fb263..29409a0 100644 --- a/src/app/components/Portfolio/Report/ReportDetails.tsx +++ b/src/app/components/Portfolio/Report/ReportDetails.tsx @@ -3,6 +3,7 @@ import { FunctionComponent, default as React } from "react"; import { Link as RouterLink, useLoaderData, useParams } from "react-router-dom"; import { ReportEntry } from "../../../../routers/reports.types"; import StatementsTable from "../Statement/StatementsTable"; +import FeesDetails from "./FeesDetails"; import InterestsDetails from "./InterestsDetails"; import { ReportLink } from "./links"; @@ -39,24 +40,9 @@ const ReportDetails: FunctionComponent = ({ ..._rest }): React.ReactNode

Interests

- {/* {theReports.map((theReport) => ( - -

- {theReport.year}-{theReport.month} -

- -
- ))} */}

Fees

- {theReports.map((theReport) => ( - -

- {theReport.year}-{theReport.month} -

- -
- ))} +

P/L

{theReports.map((theReport) => ( diff --git a/src/app/components/Portfolio/Report/ReportSummary.tsx b/src/app/components/Portfolio/Report/ReportSummary.tsx index 383bb58..a8d7b73 100644 --- a/src/app/components/Portfolio/Report/ReportSummary.tsx +++ b/src/app/components/Portfolio/Report/ReportSummary.tsx @@ -3,7 +3,7 @@ import { FunctionComponent, default as React } from "react"; import { Link as RouterLink, useLoaderData, useParams } from "react-router-dom"; import { ReportEntry } from "../../../../routers/reports.types"; import Dividends from "./DividendsComponent"; -import Fees from "./FeeComponent"; +import Fees from "./FeesComponent"; import Interests from "./InterestsComponent"; import PnL from "./PnLComponent"; import { ReportLink } from "./links";