Skip to content

Commit

Permalink
Taxes on dividends added
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Mar 25, 2024
1 parent ef30a72 commit f50bef6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
26 changes: 21 additions & 5 deletions src/app/components/Portfolio/Report/ReportSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,47 @@ const ReportSummary: FunctionComponent<Props> = ({ ..._rest }): React.ReactNode
<VStack align="left">
<HStack alignContent="left">
<Box width="xs">Country</Box>
<Box width="xs">Amount</Box>
<Box width="xs" textAlign="right">
Gross Amount
</Box>
<Box width="xs" textAlign="right">
Taxes
</Box>
<Box width="xs" textAlign="right">
Net Amount
</Box>
<Spacer />
</HStack>
{theReport.dividendsSummary.map((item: DididendSummary) => (
<HStack key={item.country}>
<Box width="xs">{item.country}</Box>
<Box width="xs" textAlign="right">
<Number value={item.totalAmountInBase} />
<Number value={item.grossAmountInBase} />
</Box>
<Box width="xs" textAlign="right">
<Number value={item.taxes} />
</Box>
<Box width="xs" textAlign="right">
<Number value={item.grossAmountInBase + item.taxes} />
</Box>
<Spacer />
</HStack>
))}
<HStack>
<Box width="xs">Total</Box>
<Box width="xs">Amount</Box>
<Box width="xs">Gross Amount</Box>
<Box width="xs">Taxes</Box>
<Box width="xs">Net Amount</Box>
<Spacer />
</HStack>
</VStack>
<StatementsTable content={theReport.dividendsDetails} title="Dividends" />
{/* <InterestsTable /> */}
<h2>Interests</h2>
<SimpleGrid columns={2}>
<Box>Net credit</Box>
<Box>Gross credit</Box>
<Box textAlign="right">
<Number value={theReport.interestsSummary.netCredit} />
<Number value={theReport.interestsSummary.grossCredit} />
</Box>
<Box>Tax</Box>
<Box textAlign="right">
Expand Down
14 changes: 10 additions & 4 deletions src/routers/reports.types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -40,7 +46,7 @@ export type ReportEntry = {
year: number;
month: number;
dividendsSummary: DididendSummary[];
dividendsDetails: DividendStatementEntry[];
dividendsDetails: (DividendStatementEntry | TaxStatementEntry)[];
interestsSummary: InterestsSummary;
interestsDetails: (InterestStatementEntry | WithHoldingStatementEntry)[];
};
2 changes: 1 addition & 1 deletion src/routers/statements.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down
32 changes: 24 additions & 8 deletions src/routers/statements.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
OptionStatement,
Portfolio,
Statement,
TaxStatement,
} from "../models";
import { StatementTypes } from "../models/statement.types";
import { DididendSummary, ReportEntry } from "./reports.types";
Expand Down Expand Up @@ -71,6 +72,7 @@ export const statementModelToStatementEntry = (item: Statement): Promise<Stateme
};
} else return baseStatement as StatementEntry;
});

case StatementTypes.DividendStatement:
return DividendStatement.findByPk(item.id).then((thisStatement) => {
baseStatement.pnl = item.netCash;
Expand All @@ -82,11 +84,15 @@ export const statementModelToStatementEntry = (item: Statement): Promise<Stateme
});

case StatementTypes.TaxStatement:
baseStatement.pnl = item.netCash;
return Promise.resolve({
statementType: StatementTypes.TaxStatement,
...baseStatement,
return TaxStatement.findByPk(item.id).then((thisStatement) => {
baseStatement.pnl = item.netCash;
return {
statementType: StatementTypes.TaxStatement,
...baseStatement,
country: thisStatement!.country,
};
});

case StatementTypes.InterestStatement:
baseStatement.pnl = item.netCash;
return Promise.resolve({
Expand Down Expand Up @@ -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) => {
Expand All @@ -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;
Expand Down

0 comments on commit f50bef6

Please sign in to comment.