diff options
| author | Joe Carstairs <me@joeac.net> | 2024-09-05 22:44:37 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-09-05 22:44:37 +0100 |
| commit | 6e827308ce332a842c87f19d7adedf827544317e (patch) | |
| tree | 9509622166b56537469ec48bbe980efee75b6974 /gui/src/types | |
| parent | 95d4db4da725b74999524a1307e5e17b434dbfeb (diff) | |
Adds GUI with basic histogram
Diffstat (limited to 'gui/src/types')
| -rw-r--r-- | gui/src/types/account.ts | 11 | ||||
| -rw-r--r-- | gui/src/types/budget.ts | 8 | ||||
| -rw-r--r-- | gui/src/types/category.ts | 12 | ||||
| -rw-r--r-- | gui/src/types/currency/currency.ts | 6 | ||||
| -rw-r--r-- | gui/src/types/currency/gbp.ts | 46 | ||||
| -rw-r--r-- | gui/src/types/dtos/accountDto.ts | 8 |
6 files changed, 91 insertions, 0 deletions
diff --git a/gui/src/types/account.ts b/gui/src/types/account.ts new file mode 100644 index 0000000..4a3626c --- /dev/null +++ b/gui/src/types/account.ts @@ -0,0 +1,11 @@ +import { Moment } from "moment"; +import Currency from "./currency/currency"; + +interface Account { + readonly id: number; + readonly name: string; + readonly openingBalance: Currency; + readonly openingDate: Moment; +} + +export default Account; diff --git a/gui/src/types/budget.ts b/gui/src/types/budget.ts new file mode 100644 index 0000000..86bae2c --- /dev/null +++ b/gui/src/types/budget.ts @@ -0,0 +1,8 @@ +import Currency from "./currency/currency"; + +interface Budget { + quantity: Currency, + period: number, +}; + +export default Budget; diff --git a/gui/src/types/category.ts b/gui/src/types/category.ts new file mode 100644 index 0000000..af4526b --- /dev/null +++ b/gui/src/types/category.ts @@ -0,0 +1,12 @@ +import Budget from "./budget"; +import Currency from "./currency/currency"; + +interface Category { + id: number, + name: string, + currentBalance: Currency, + currentBudget: Budget, + balanceToBudgetRatio: number, +}; + +export default Category; diff --git a/gui/src/types/currency/currency.ts b/gui/src/types/currency/currency.ts new file mode 100644 index 0000000..7c15324 --- /dev/null +++ b/gui/src/types/currency/currency.ts @@ -0,0 +1,6 @@ +interface Currency { + valueOf(): number; + toString(): string; +} + +export default Currency; diff --git a/gui/src/types/currency/gbp.ts b/gui/src/types/currency/gbp.ts new file mode 100644 index 0000000..ce24e48 --- /dev/null +++ b/gui/src/types/currency/gbp.ts @@ -0,0 +1,46 @@ +import Currency from "./currency"; + +class Gbp implements Currency { + private readonly sign: 1 | -1; + private readonly pounds: number; + private readonly pence: number; + + constructor(pounds: number, pence: number, sign?: 1 | -1) { + sign = sign ?? 1; + + if (Math.round(pounds) !== pounds) { + throw new Error( + `Cannot construct GBP with non-whole number of pounds: ${pounds}`, + ); + } + if (Math.round(pence) !== pence) { + throw new Error( + `Cannot construct GBP with non-whole number of pence: ${pence}`, + ); + } + if (pounds < 0) { + throw new Error( + `Cannot construct GBP with negative number of pounds: ${pounds}`, + ); + } + if (pence < 0) { + throw new Error( + `Cannot construct GBP with negative number of pounds: ${pounds}`, + ); + } + + this.sign = sign; + this.pounds = pounds; + this.pence = pence; + } + + valueOf(): number { + return this.sign * (this.pounds * 100 + this.pence); + } + + toString(): string { + return `£${this.pounds}·${this.pence < 10 ? `0${this.pence}` : this.pence}`; + } +} + +export default Gbp; diff --git a/gui/src/types/dtos/accountDto.ts b/gui/src/types/dtos/accountDto.ts new file mode 100644 index 0000000..0ed7622 --- /dev/null +++ b/gui/src/types/dtos/accountDto.ts @@ -0,0 +1,8 @@ +interface AccountDto { + readonly id: number; + readonly name: string; + readonly openingBalance: number; + readonly openingDate: string; +} + +export default AccountDto; |
