From 3b895afc9e3ab979b118e6004d3896a7d76a1b4a Mon Sep 17 00:00:00 2001 From: rodriguestiago0 Date: Fri, 15 Mar 2024 17:56:17 +0000 Subject: [PATCH] Enable account balance update for fee and interest activities (#3145) * Enable account balance update for fee and interest activities * Update changelog --- CHANGELOG.md | 2 ++ apps/api/src/app/order/order.service.ts | 2 +- ...ate-or-update-activity-dialog.component.ts | 22 +++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcf2ad4f..eafcc9d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added support to update the cash balance of an account when adding a fee activity +- Added support to update the cash balance of an account when adding an interest activity - Extended the content of the _General_ section by the product roadmap on the Frequently Asked Questions (FAQ) page ### Changed diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 1603ed53..3efb5fe9 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -148,7 +148,7 @@ export class OrderService { .plus(data.fee) .toNumber(); - if (data.type === 'BUY') { + if (['BUY', 'FEE'].includes(data.type)) { amount = new Big(amount).mul(-1).toNumber(); } diff --git a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts index 34da992f..b628aba4 100644 --- a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts +++ b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts @@ -260,6 +260,17 @@ export class CreateOrUpdateActivityDialog implements OnDestroy { this.activityForm.controls['currency'].setValue(currency); this.activityForm.controls['currencyOfFee'].setValue(currency); this.activityForm.controls['currencyOfUnitPrice'].setValue(currency); + + if (['FEE', 'INTEREST'].includes(type)) { + if (this.activityForm.controls['accountId'].value) { + this.activityForm.controls['updateAccountBalance'].enable(); + } else { + this.activityForm.controls['updateAccountBalance'].disable(); + this.activityForm.controls['updateAccountBalance'].setValue( + false + ); + } + } } } ); @@ -374,8 +385,15 @@ export class CreateOrUpdateActivityDialog implements OnDestroy { this.activityForm.controls['unitPriceInCustomCurrency'].setValue(0); } - this.activityForm.controls['updateAccountBalance'].disable(); - this.activityForm.controls['updateAccountBalance'].setValue(false); + if ( + ['FEE', 'INTEREST'].includes(type) && + this.activityForm.controls['accountId'].value + ) { + this.activityForm.controls['updateAccountBalance'].enable(); + } else { + this.activityForm.controls['updateAccountBalance'].disable(); + this.activityForm.controls['updateAccountBalance'].setValue(false); + } } else { this.activityForm.controls['accountId'].setValidators( Validators.required