From c17b52ad895d52d5bde2805acef7ee644cdb9a8e Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sun, 17 Sep 2023 09:21:04 +0200 Subject: [PATCH] Add business logic for fees --- apps/api/src/app/order/order.service.ts | 20 ++- .../portfolio-summary.component.html | 14 +- ...ate-or-update-activity-dialog.component.ts | 24 +++- .../create-or-update-activity-dialog.html | 127 ++++++++++-------- .../activities-table.component.html | 6 + .../activities-table.component.scss | 4 + .../activities-table.component.ts | 3 +- libs/ui/src/lib/i18n.ts | 1 + .../migration.sql | 0 9 files changed, 135 insertions(+), 64 deletions(-) rename prisma/migrations/{20230509124205_added_fee_to_order_type => 20230917074305_added_fee_to_order_type}/migration.sql (100%) diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 0f7da5da3..13709fad1 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -97,7 +97,11 @@ export class OrderService { const updateAccountBalance = data.updateAccountBalance ?? false; const userId = data.userId; - if (data.type === 'ITEM' || data.type === 'LIABILITY') { + if ( + data.type === 'FEE' || + data.type === 'ITEM' || + data.type === 'LIABILITY' + ) { const assetClass = data.assetClass; const assetSubClass = data.assetSubClass; currency = data.SymbolProfile.connectOrCreate.create.currency; @@ -151,7 +155,7 @@ export class OrderService { const orderData: Prisma.OrderCreateInput = data; const isDraft = - data.type === 'LIABILITY' + data.type === 'FEE' || data.type === 'ITEM' || data.type === 'LIABILITY' ? false : isAfter(data.date as Date, endOfToday()); @@ -197,7 +201,11 @@ export class OrderService { where }); - if (order.type === 'ITEM' || order.type === 'LIABILITY') { + if ( + order.type === 'FEE' || + order.type === 'ITEM' || + order.type === 'LIABILITY' + ) { await this.symbolProfileService.deleteById(order.symbolProfileId); } @@ -368,7 +376,11 @@ export class OrderService { let isDraft = false; - if (data.type === 'ITEM' || data.type === 'LIABILITY') { + if ( + data.type === 'FEE' || + data.type === 'ITEM' || + data.type === 'LIABILITY' + ) { delete data.SymbolProfile.connect; } else { delete data.SymbolProfile.update; diff --git a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html index 81c25bf75..a84fbebaf 100644 --- a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html +++ b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html @@ -5,6 +5,15 @@ +
+
+ {{ summary?.ordersCount }} {summary?.ordersCount, plural, =1 {transaction} + other {transactions}} +
+

@@ -75,10 +84,7 @@
-
- Fees for {{ summary?.ordersCount }} {summary?.ordersCount, plural, =1 - {transaction} other {transactions}} -
+
Fees
- {{ typesTranslationMap['BUY'] }} -
- Stocks, ETFs, bonds, cryptocurrencies, commodities
+ + {{ typesTranslationMap['FEE'] }} + One-time fee, annual account fees + {{ typesTranslationMap['DIVIDEND'] }} + Distribution of corporate earnings {{ typesTranslationMap['LIABILITY'] }} -
- Mortgages, personal loans, credit cards
{{ typesTranslationMap['SELL'] }} -
- Stocks, ETFs, bonds, cryptocurrencies, commodities
{{ typesTranslationMap['ITEM'] }} -
- Luxury items, real estate, private companies
@@ -125,60 +134,71 @@
Quantity
-
- - - Dividend +
+ + + Dividend + Value + Value + Unit Price + + + +
+ + + {{ currency }} + + +
+ Oops! Could not get the historical exchange rate + from - Value - Value - Unit Price - - - -
- - - {{ currency }} - - -
- Oops! Could not get the historical exchange rate from - {{ activityForm.controls['date']?.value | date: defaultDateFormat - }} + + + +
@@ -187,6 +207,7 @@ Dividend + Value Value Value Unit Price diff --git a/libs/ui/src/lib/activities-table/activities-table.component.html b/libs/ui/src/lib/activities-table/activities-table.component.html index 328f34374..e09fa0d18 100644 --- a/libs/ui/src/lib/activities-table/activities-table.component.html +++ b/libs/ui/src/lib/activities-table/activities-table.component.html @@ -161,6 +161,7 @@ [ngClass]="{ buy: element.type === 'BUY', dividend: element.type === 'DIVIDEND', + fee: element.type === 'FEE', item: element.type === 'ITEM', liability: element.type === 'LIABILITY', sell: element.type === 'SELL' @@ -170,6 +171,10 @@ *ngIf="element.type === 'BUY' || element.type === 'DIVIDEND'" name="arrow-up-circle-outline" > +