Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Bugfix/fix total calculation for sell and dividend (#850)
Thomas Kaulbeb12637cef8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 49d2b21298..7475266569 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Persisted the savings rate in the _FIRE_ calculator- Upgraded `yahoo-finance2` from version `2.3.0` to `2.3.1`+### Fixed++- Fixed the calculation of the total value for sell and dividend activities in the create or edit transaction dialog+## 1.139.0 - 18.04.2022### Addeddiff --git a/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts b/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.tsindex 134adcdc55..920120900c 100644--- a/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts+++ b/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts@@ -46,6 +46,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {public filteredLookupItemsObservable: Observable<LookupItem[]>;public isLoading = false;public platforms: { id: string; name: string }[];+ public total = 0;public Validators = Validators;private unsubscribeSubject = new Subject<void>();@@ -89,6 +90,25 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {unitPrice: [this.data.activity?.unitPrice, Validators.required]});+ this.activityForm.valueChanges+ .pipe(takeUntil(this.unsubscribeSubject))+ .subscribe(() => {+ if (+ this.activityForm.controls['type'].value === 'BUY' ||+ this.activityForm.controls['type'].value === 'ITEM'+ ) {+ this.total =+ this.activityForm.controls['quantity'].value *+ this.activityForm.controls['unitPrice'].value ++ this.activityForm.controls['fee'].value ?? 0;+ } else {+ this.total =+ this.activityForm.controls['quantity'].value *+ this.activityForm.controls['unitPrice'].value -+ this.activityForm.controls['fee'].value ?? 0;+ }+ });+this.filteredLookupItemsObservable = this.activityForm.controls['searchSymbol'].valueChanges.pipe(@@ -100,9 +120,11 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {const filteredLookupItemsObservable =this.dataService.fetchSymbols(query);- filteredLookupItemsObservable.subscribe((filteredLookupItems) => {- this.filteredLookupItems = filteredLookupItems;- });+ filteredLookupItemsObservable+ .pipe(takeUntil(this.unsubscribeSubject))+ .subscribe((filteredLookupItems) => {+ this.filteredLookupItems = filteredLookupItems;+ });return filteredLookupItemsObservable;}@@ -111,45 +133,47 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {}));- this.activityForm.controls['type'].valueChanges.subscribe((type: Type) => {- if (type === 'ITEM') {- this.activityForm.controls['accountId'].removeValidators(- Validators.required- );- this.activityForm.controls['accountId'].updateValueAndValidity();- this.activityForm.controls['currency'].setValue(- this.data.user.settings.baseCurrency- );- this.activityForm.controls['dataSource'].removeValidators(- Validators.required- );- this.activityForm.controls['dataSource'].updateValueAndValidity();- this.activityForm.controls['name'].setValidators(Validators.required);- this.activityForm.controls['name'].updateValueAndValidity();- this.activityForm.controls['quantity'].setValue(1);- this.activityForm.controls['searchSymbol'].removeValidators(- Validators.required- );- this.activityForm.controls['searchSymbol'].updateValueAndValidity();- } else {- this.activityForm.controls['accountId'].setValidators(- Validators.required- );- this.activityForm.controls['accountId'].updateValueAndValidity();- this.activityForm.controls['dataSource'].setValidators(- Validators.required- );- this.activityForm.controls['dataSource'].updateValueAndValidity();- this.activityForm.controls['name'].removeValidators(- Validators.required- );- this.activityForm.controls['name'].updateValueAndValidity();- this.activityForm.controls['searchSymbol'].setValidators(- Validators.required- );- this.activityForm.controls['searchSymbol'].updateValueAndValidity();- }- });+ this.activityForm.controls['type'].valueChanges+ .pipe(takeUntil(this.unsubscribeSubject))+ .subscribe((type: Type) => {+ if (type === 'ITEM') {+ this.activityForm.controls['accountId'].removeValidators(+ Validators.required+ );+ this.activityForm.controls['accountId'].updateValueAndValidity();+ this.activityForm.controls['currency'].setValue(+ this.data.user.settings.baseCurrency+ );+ this.activityForm.controls['dataSource'].removeValidators(+ Validators.required+ );+ this.activityForm.controls['dataSource'].updateValueAndValidity();+ this.activityForm.controls['name'].setValidators(Validators.required);+ this.activityForm.controls['name'].updateValueAndValidity();+ this.activityForm.controls['quantity'].setValue(1);+ this.activityForm.controls['searchSymbol'].removeValidators(+ Validators.required+ );+ this.activityForm.controls['searchSymbol'].updateValueAndValidity();+ } else {+ this.activityForm.controls['accountId'].setValidators(+ Validators.required+ );+ this.activityForm.controls['accountId'].updateValueAndValidity();+ this.activityForm.controls['dataSource'].setValidators(+ Validators.required+ );+ this.activityForm.controls['dataSource'].updateValueAndValidity();+ this.activityForm.controls['name'].removeValidators(+ Validators.required+ );+ this.activityForm.controls['name'].updateValueAndValidity();+ this.activityForm.controls['searchSymbol'].setValidators(+ Validators.required+ );+ this.activityForm.controls['searchSymbol'].updateValueAndValidity();+ }+ });this.activityForm.controls['type'].setValue(this.data.activity?.type);diff --git a/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html b/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.htmlindex 212b3c245e..3ce720b370 100644--- a/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html+++ b/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html@@ -138,9 +138,9 @@<div class="d-flex" mat-dialog-actions><gf-valueclass="flex-grow-1"- [currency]="activityForm.controls['currency'].value"+ [currency]="activityForm.controls['currency']?.value ?? data.user?.settings?.baseCurrency"[locale]="data.user?.settings?.locale"- [value]="activityForm.controls['fee'].value + (activityForm.controls['quantity'].value * activityForm.controls['unitPrice'].value) ?? 0"+ [value]="total"></gf-value><div><button i18n mat-button type="button" (click)="onCancel()">Cancel</button>