-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
17 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FeesDetails>(); | ||
|
||
/** | ||
* 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) => ( | ||
<Link to={StatementLink.toItem(portfolioId, info.getValue())} as={RouterLink}> | ||
<IconButton aria-label="Show detail" icon={<SearchIcon />} size="xs" variant="ghost" /> | ||
</Link> | ||
), | ||
header: "#", | ||
}), | ||
columnHelper.accessor("date", { | ||
cell: (info) => ( | ||
<Tooltip label={info.getValue().toLocaleTimeString()} placement="auto" hasArrow={true}> | ||
{info.getValue().toISOString().substring(0, 10)} | ||
</Tooltip> | ||
), | ||
footer: "Total", | ||
}), | ||
columnHelper.accessor("amount", { | ||
cell: (info) => <Number value={info.getValue()} decimals={2} />, | ||
meta: { | ||
isNumeric: true, | ||
}, | ||
footer: () => <Number value={totalFees} />, | ||
}), | ||
columnHelper.accessor("description", { | ||
cell: (info) => info.getValue(), | ||
}), | ||
]; | ||
|
||
return <DataTable columns={columns} data={data} title="Interests" />; | ||
}; | ||
|
||
export default FeesDetails; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters