Skip to content

Commit

Permalink
Tax reports WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Mar 27, 2024
1 parent f50bef6 commit 38696ec
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"formik": "^2.4.5",
"framer-motion": "^11.0.20",
"json-stringify-safe": "^5.0.1",
"react": "^18.2.69",
"react": "^18.2.0",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.22",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3",
"reflect-metadata": "^0.2.1",
"sequelize": "^6.37.1",
Expand Down
9 changes: 9 additions & 0 deletions src/app/components/Portfolio/Report/ReportSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ const ReportSummary: FunctionComponent<Props> = ({ ..._rest }): React.ReactNode
</Box>
</SimpleGrid>
<StatementsTable content={theReport.interestsDetails} title="Interests" />
<h2>Fees</h2>
<HStack align="left">
<Box>Total</Box>
<Box textAlign="right">
<Number value={theReport.feesSummary.totalAmountInBase} />
</Box>
<Spacer />
</HStack>
<StatementsTable content={theReport.feesDetails} title="Fees" />
</>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/models/bond_statement.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class BondStatement extends Model<
@BelongsTo(() => Statement, "id")
public statement: Statement;

@Column({ type: DataType.STRING(2), field: "country" })
declare country: string;

@Column({ type: DataType.FLOAT, field: "accruedInt" })
declare accruedInterests: number;

Expand Down
5 changes: 4 additions & 1 deletion src/models/interest_statement.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreationOptional, InferAttributes, InferCreationAttributes } from "sequelize";
import { BelongsTo, Model, Table } from "sequelize-typescript";
import { BelongsTo, Column, DataType, Model, Table } from "sequelize-typescript";
import { Statement } from ".";

@Table({ tableName: "interest_statement", timestamps: false, createdAt: false, updatedAt: false })
Expand All @@ -17,4 +17,7 @@ export class InterestStatement extends Model<

@BelongsTo(() => Statement, "id")
public statement: Statement;

@Column({ type: DataType.STRING(2), field: "country" })
declare country: string;
}
3 changes: 3 additions & 0 deletions src/models/portfolio.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class Portfolio extends Model<
@Column({ type: DataType.STRING(3), field: "base_currency" })
declare baseCurrency: string;

@Column({ type: DataType.STRING(2), field: "country" })
declare country: string;

@Column({ type: DataType.FLOAT, field: "put_ratio", defaultValue: 0 })
declare putRatio?: number;

Expand Down
17 changes: 15 additions & 2 deletions src/routers/reports.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
DividendStatementEntry,
FeeStatementEntry,
InterestStatementEntry,
TaxStatementEntry,
WithHoldingStatementEntry,
Expand All @@ -21,8 +22,8 @@ import {
* Dididend Summary entry data transfered between frontend and backend
*/
export type DididendSummary = {
// year: number;
// month: number;
// year: number;
// month: number;
country: string;
grossAmountInBase: number;
taxes: number;
Expand All @@ -32,12 +33,22 @@ export type DididendSummary = {
* Dididend Summary entry data transfered between frontend and backend
*/
export type InterestsSummary = {
// year: number;
// month: number;
// country: string;
grossCredit: number;
netDebit: number;
withHolding: number;
totalAmountInBase: number;
};

/**
* Fees summary
*/
export type FeesSummary = {
totalAmountInBase: number;
};

/**
* Report entry data transfered between frontend and backend
*/
Expand All @@ -49,4 +60,6 @@ export type ReportEntry = {
dividendsDetails: (DividendStatementEntry | TaxStatementEntry)[];
interestsSummary: InterestsSummary;
interestsDetails: (InterestStatementEntry | WithHoldingStatementEntry)[];
feesSummary: FeesSummary;
feesDetails: FeeStatementEntry[];
};
13 changes: 10 additions & 3 deletions src/routers/statements.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ export const prepareReport = (portfolio: Portfolio, year: number, month: number)
dividendsDetails: [],
interestsSummary: { totalAmountInBase: 0, grossCredit: 0, netDebit: 0, withHolding: 0 },
interestsDetails: [],
feesSummary: { totalAmountInBase: 0 },
feesDetails: [],
};
statements.forEach((statement) => {
// const date = statement.date.toString();
// const year = parseInt(date.substring(0, 4));
// const month = parseInt(date.substring(5, 7));
// const date = statement.date.toString();
// const year = parseInt(date.substring(0, 4));
// const month = parseInt(date.substring(5, 7));
let entry: DididendSummary | undefined;
switch (statement.statementType) {
case StatementTypes.DividendStatement:
Expand Down Expand Up @@ -205,6 +207,11 @@ export const prepareReport = (portfolio: Portfolio, year: number, month: number)
report.interestsSummary.withHolding += statement.amount * statement.fxRateToBase;
report.interestsDetails.push(statement);
break;

case StatementTypes.FeeStatement:
report.feesSummary.totalAmountInBase += statement.amount * statement.fxRateToBase;
report.feesDetails.push(statement);
break;
}
});
console.log(report.dividendsSummary);
Expand Down
26 changes: 2 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8808,22 +8808,14 @@ react-docgen@^7.0.0:
resolve "^1.22.1"
strip-indent "^4.0.0"

"react-dom@^16.8.0 || ^17.0.0 || ^18.0.0":
"react-dom@^16.8.0 || ^17.0.0 || ^18.0.0", react-dom@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
integrity sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==
dependencies:
loose-envify "^1.1.0"
scheduler "^0.23.0"

react-dom@^18.2.22:
version "18.3.0-next-fecc288b7-20221025"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.3.0-next-fecc288b7-20221025.tgz#f06afce21f68a6797eb4c740637aa844c7918bcd"
integrity sha512-EczZNIcOXzLFyPhSXpplVFekfUvbtHRC68TVAPfCopn8YxjMg2ROVgYs1VdSnEu2JlXKvpeIbjexAuhDprsp/A==
dependencies:
loose-envify "^1.1.0"
scheduler "0.24.0-next-fecc288b7-20221025"

react-element-to-jsx-string@^15.0.0:
version "15.0.0"
resolved "https://registry.yarnpkg.com/react-element-to-jsx-string/-/react-element-to-jsx-string-15.0.0.tgz#1cafd5b6ad41946ffc8755e254da3fc752a01ac6"
Expand Down Expand Up @@ -8943,20 +8935,13 @@ react-transition-group@^4.3.0:
loose-envify "^1.4.0"
prop-types "^15.6.2"

"react@^16.8.0 || ^17.0.0 || ^18.0.0":
"react@^16.8.0 || ^17.0.0 || ^18.0.0", react@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==
dependencies:
loose-envify "^1.1.0"

react@^18.2.69:
version "18.3.0-next-fecc288b7-20221025"
resolved "https://registry.yarnpkg.com/react/-/react-18.3.0-next-fecc288b7-20221025.tgz#8da77f8c8221bb2761ed817b7638feb108ba791c"
integrity sha512-lKvCNWRO9XPy8q7hLd0ODK/4Oqr54r3Vr49Y7EyNBz/kfsmNT6Vx0F69KRz/eGcbt1XDvtbA7KZd+mh8w3wONQ==
dependencies:
loose-envify "^1.1.0"

read-pkg-up@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-7.0.1.tgz#f3a6135758459733ae2b95638056e1854e7ef507"
Expand Down Expand Up @@ -9288,13 +9273,6 @@ safe-stable-stringify@^2.3.1:
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

scheduler@0.24.0-next-fecc288b7-20221025:
version "0.24.0-next-fecc288b7-20221025"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.24.0-next-fecc288b7-20221025.tgz#0f4b174cf0ee5866b78855f4bf41142cc3cecc0e"
integrity sha512-D2r7z/2EbRXXz4k8XRQab2l71zARIwmZzLLGPAM936/dW1iF835+FMwnOe4Iep96vNJAdQavqJBP4Fm+/MadsQ==
dependencies:
loose-envify "^1.1.0"

scheduler@^0.23.0:
version "0.23.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe"
Expand Down

0 comments on commit 38696ec

Please sign in to comment.