Bugfix/fix total calculation for sell and dividend (#850)
* Fix calculation for sell and dividend activities * Update changelog
This commit is contained in:
parent
20358d9105
commit
beb12637ce
@ -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
|
- Persisted the savings rate in the _FIRE_ calculator
|
||||||
- Upgraded `yahoo-finance2` from version `2.3.0` to `2.3.1`
|
- 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
|
## 1.139.0 - 18.04.2022
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -46,6 +46,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|||||||
public filteredLookupItemsObservable: Observable<LookupItem[]>;
|
public filteredLookupItemsObservable: Observable<LookupItem[]>;
|
||||||
public isLoading = false;
|
public isLoading = false;
|
||||||
public platforms: { id: string; name: string }[];
|
public platforms: { id: string; name: string }[];
|
||||||
|
public total = 0;
|
||||||
public Validators = Validators;
|
public Validators = Validators;
|
||||||
|
|
||||||
private unsubscribeSubject = new Subject<void>();
|
private unsubscribeSubject = new Subject<void>();
|
||||||
@ -89,6 +90,25 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|||||||
unitPrice: [this.data.activity?.unitPrice, Validators.required]
|
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[
|
this.filteredLookupItemsObservable = this.activityForm.controls[
|
||||||
'searchSymbol'
|
'searchSymbol'
|
||||||
].valueChanges.pipe(
|
].valueChanges.pipe(
|
||||||
@ -100,9 +120,11 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|||||||
const filteredLookupItemsObservable =
|
const filteredLookupItemsObservable =
|
||||||
this.dataService.fetchSymbols(query);
|
this.dataService.fetchSymbols(query);
|
||||||
|
|
||||||
filteredLookupItemsObservable.subscribe((filteredLookupItems) => {
|
filteredLookupItemsObservable
|
||||||
this.filteredLookupItems = filteredLookupItems;
|
.pipe(takeUntil(this.unsubscribeSubject))
|
||||||
});
|
.subscribe((filteredLookupItems) => {
|
||||||
|
this.filteredLookupItems = filteredLookupItems;
|
||||||
|
});
|
||||||
|
|
||||||
return filteredLookupItemsObservable;
|
return filteredLookupItemsObservable;
|
||||||
}
|
}
|
||||||
@ -111,45 +133,47 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.activityForm.controls['type'].valueChanges.subscribe((type: Type) => {
|
this.activityForm.controls['type'].valueChanges
|
||||||
if (type === 'ITEM') {
|
.pipe(takeUntil(this.unsubscribeSubject))
|
||||||
this.activityForm.controls['accountId'].removeValidators(
|
.subscribe((type: Type) => {
|
||||||
Validators.required
|
if (type === 'ITEM') {
|
||||||
);
|
this.activityForm.controls['accountId'].removeValidators(
|
||||||
this.activityForm.controls['accountId'].updateValueAndValidity();
|
Validators.required
|
||||||
this.activityForm.controls['currency'].setValue(
|
);
|
||||||
this.data.user.settings.baseCurrency
|
this.activityForm.controls['accountId'].updateValueAndValidity();
|
||||||
);
|
this.activityForm.controls['currency'].setValue(
|
||||||
this.activityForm.controls['dataSource'].removeValidators(
|
this.data.user.settings.baseCurrency
|
||||||
Validators.required
|
);
|
||||||
);
|
this.activityForm.controls['dataSource'].removeValidators(
|
||||||
this.activityForm.controls['dataSource'].updateValueAndValidity();
|
Validators.required
|
||||||
this.activityForm.controls['name'].setValidators(Validators.required);
|
);
|
||||||
this.activityForm.controls['name'].updateValueAndValidity();
|
this.activityForm.controls['dataSource'].updateValueAndValidity();
|
||||||
this.activityForm.controls['quantity'].setValue(1);
|
this.activityForm.controls['name'].setValidators(Validators.required);
|
||||||
this.activityForm.controls['searchSymbol'].removeValidators(
|
this.activityForm.controls['name'].updateValueAndValidity();
|
||||||
Validators.required
|
this.activityForm.controls['quantity'].setValue(1);
|
||||||
);
|
this.activityForm.controls['searchSymbol'].removeValidators(
|
||||||
this.activityForm.controls['searchSymbol'].updateValueAndValidity();
|
Validators.required
|
||||||
} else {
|
);
|
||||||
this.activityForm.controls['accountId'].setValidators(
|
this.activityForm.controls['searchSymbol'].updateValueAndValidity();
|
||||||
Validators.required
|
} else {
|
||||||
);
|
this.activityForm.controls['accountId'].setValidators(
|
||||||
this.activityForm.controls['accountId'].updateValueAndValidity();
|
Validators.required
|
||||||
this.activityForm.controls['dataSource'].setValidators(
|
);
|
||||||
Validators.required
|
this.activityForm.controls['accountId'].updateValueAndValidity();
|
||||||
);
|
this.activityForm.controls['dataSource'].setValidators(
|
||||||
this.activityForm.controls['dataSource'].updateValueAndValidity();
|
Validators.required
|
||||||
this.activityForm.controls['name'].removeValidators(
|
);
|
||||||
Validators.required
|
this.activityForm.controls['dataSource'].updateValueAndValidity();
|
||||||
);
|
this.activityForm.controls['name'].removeValidators(
|
||||||
this.activityForm.controls['name'].updateValueAndValidity();
|
Validators.required
|
||||||
this.activityForm.controls['searchSymbol'].setValidators(
|
);
|
||||||
Validators.required
|
this.activityForm.controls['name'].updateValueAndValidity();
|
||||||
);
|
this.activityForm.controls['searchSymbol'].setValidators(
|
||||||
this.activityForm.controls['searchSymbol'].updateValueAndValidity();
|
Validators.required
|
||||||
}
|
);
|
||||||
});
|
this.activityForm.controls['searchSymbol'].updateValueAndValidity();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.activityForm.controls['type'].setValue(this.data.activity?.type);
|
this.activityForm.controls['type'].setValue(this.data.activity?.type);
|
||||||
|
|
||||||
|
@ -138,9 +138,9 @@
|
|||||||
<div class="d-flex" mat-dialog-actions>
|
<div class="d-flex" mat-dialog-actions>
|
||||||
<gf-value
|
<gf-value
|
||||||
class="flex-grow-1"
|
class="flex-grow-1"
|
||||||
[currency]="activityForm.controls['currency'].value"
|
[currency]="activityForm.controls['currency']?.value ?? data.user?.settings?.baseCurrency"
|
||||||
[locale]="data.user?.settings?.locale"
|
[locale]="data.user?.settings?.locale"
|
||||||
[value]="activityForm.controls['fee'].value + (activityForm.controls['quantity'].value * activityForm.controls['unitPrice'].value) ?? 0"
|
[value]="total"
|
||||||
></gf-value>
|
></gf-value>
|
||||||
<div>
|
<div>
|
||||||
<button i18n mat-button type="button" (click)="onCancel()">Cancel</button>
|
<button i18n mat-button type="button" (click)="onCancel()">Cancel</button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user