Skip to content

Commit 4faf0c4

Browse files
Merge pull request #3547 from alberto-art3ch/WEB-657/fix-working-capital-product-currency-issue
WEB-657: Working Capital currency fix for multiples of
2 parents 37615bd + 55b6fcc commit 4faf0c4

2 files changed

Lines changed: 55 additions & 112 deletions

File tree

src/app/products/loan-products/loan-product-stepper/loan-product-currency-step/loan-product-currency-step.component.html

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,55 +51,40 @@
5151
}
5252
</mat-form-field>
5353

54-
<mat-checkbox labelPosition="before" formControlName="setMultiples" class="flex-98 margin-t checkbox-align-center">
55-
{{ 'labels.inputs.Set the multiples of the loan and its installment' | translate }}
56-
</mat-checkbox>
57-
58-
@if (loanProductCurrencyForm.value.setMultiples) {
59-
<mat-form-field class="flex-48">
60-
<mat-label>{{ 'labels.inputs.Currency in multiples of' | translate }}</mat-label>
61-
<input
62-
type="number"
63-
min="1"
64-
matInput
65-
matTooltip="{{ 'tooltips.Enter multiples of currency value' | translate }}"
66-
formControlName="inMultiplesOf"
67-
/>
68-
@if (loanProductCurrencyForm.get('inMultiplesOf')?.hasError('min')) {
69-
<mat-error>
70-
{{ 'labels.inputs.Currency in multiples of' | translate }}
71-
{{ 'labels.commons.Minimum Value must be' | translate }} <strong>1</strong>
72-
</mat-error>
73-
}
74-
@if (loanProductCurrencyForm.get('inMultiplesOf')?.hasError('required')) {
75-
<mat-error>
76-
{{ 'labels.inputs.Currency in multiples of' | translate }} {{ 'labels.commons.is' | translate }}
77-
<strong>{{ 'labels.commons.required' | translate }}</strong>
78-
</mat-error>
79-
}
80-
</mat-form-field>
54+
<mat-form-field class="flex-48">
55+
<mat-label>{{ 'labels.inputs.Currency in multiples of' | translate }}</mat-label>
56+
<input
57+
type="number"
58+
min="1"
59+
matInput
60+
required
61+
matTooltip="{{ 'tooltips.Enter multiples of currency value' | translate }}"
62+
formControlName="inMultiplesOf"
63+
/>
64+
@if (loanProductCurrencyForm.get('inMultiplesOf')?.hasError('min')) {
65+
<mat-error>
66+
{{ 'labels.inputs.Currency in multiples of' | translate }}
67+
{{ 'labels.commons.Minimum Value must be' | translate }} <strong>1</strong>
68+
</mat-error>
69+
}
70+
@if (loanProductCurrencyForm.get('inMultiplesOf')?.hasError('required')) {
71+
<mat-error>
72+
{{ 'labels.inputs.Currency in multiples of' | translate }} {{ 'labels.commons.is' | translate }}
73+
<strong>{{ 'labels.commons.required' | translate }}</strong>
74+
</mat-error>
75+
}
76+
</mat-form-field>
8177

78+
@if (loanProductService.isLoanProduct) {
8279
<mat-form-field class="flex-48">
8380
<mat-label>{{ 'labels.inputs.Installment in multiples of' | translate }}</mat-label>
84-
<input
85-
type="number"
86-
min="1"
87-
matInput
88-
matTooltip="{{ 'tooltips.Enter multiples of installment value' | translate }}"
89-
formControlName="installmentInMultiplesOf"
90-
/>
91-
@if (loanProductCurrencyForm.get('installmentInMultiplesOf')?.hasError('min')) {
81+
<input type="number" min="1" matInput formControlName="installmentAmountInMultiplesOf" />
82+
@if (loanProductCurrencyForm.get('installmentAmountInMultiplesOf')?.hasError('min')) {
9283
<mat-error>
9384
{{ 'labels.inputs.Installment in multiples of' | translate }}
9485
{{ 'labels.commons.Minimum Value must be' | translate }} <strong>1</strong>
9586
</mat-error>
9687
}
97-
@if (loanProductCurrencyForm.get('installmentInMultiplesOf')?.hasError('required')) {
98-
<mat-error>
99-
{{ 'labels.inputs.Installment in multiples of' | translate }} {{ 'labels.commons.is' | translate }}
100-
<strong>{{ 'labels.commons.required' | translate }}</strong>
101-
</mat-error>
102-
}
10388
</mat-form-field>
10489
}
10590
</div>

src/app/products/loan-products/loan-product-stepper/loan-product-currency-step/loan-product-currency-step.component.ts

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
*/
88

99
import { Component, OnInit, Input, inject, DestroyRef } from '@angular/core';
10-
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1110
import { UntypedFormGroup, UntypedFormBuilder, Validators, UntypedFormControl } from '@angular/forms';
1211
import { MatTooltip } from '@angular/material/tooltip';
1312
import { MatStepperPrevious, MatStepperNext } from '@angular/material/stepper';
14-
import { MatCheckbox } from '@angular/material/checkbox';
1513
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
1614
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
1715
import { LoanProductService } from '../../services/loan-product.service';
@@ -25,8 +23,7 @@ import { LoanProductService } from '../../services/loan-product.service';
2523
MatTooltip,
2624
MatStepperPrevious,
2725
FaIconComponent,
28-
MatStepperNext,
29-
MatCheckbox
26+
MatStepperNext
3027
]
3128
})
3229
export class LoanProductCurrencyStepComponent implements OnInit {
@@ -49,21 +46,31 @@ export class LoanProductCurrencyStepComponent implements OnInit {
4946
const currency = this.loanProductsTemplate.currency ? this.loanProductsTemplate.currency : this.currencyData[0];
5047

5148
let decimalPlacesValue = '';
52-
// Only populate decimal places for existing products (when editing)
53-
if (this.loanProductsTemplate.id) {
49+
if (this.loanProductService.isWorkingCapital && !this.loanProductsTemplate.id) {
50+
decimalPlacesValue = '';
51+
} else {
5452
decimalPlacesValue =
5553
currency.decimalPlaces === undefined || currency.decimalPlaces === null ? '' : currency.decimalPlaces;
5654
}
5755

5856
this.loanProductCurrencyForm.patchValue({
5957
currencyCode: currency.code,
6058
digitsAfterDecimal: decimalPlacesValue,
61-
setMultiples: !!(this.loanProductsTemplate.inMultiplesOf || this.loanProductsTemplate.installmentInMultiplesOf),
62-
inMultiplesOf: this.loanProductsTemplate.inMultiplesOf ?? '',
63-
installmentInMultiplesOf: this.loanProductsTemplate.installmentInMultiplesOf ?? ''
59+
inMultiplesOf:
60+
currency.inMultiplesOf === 0 || currency.inMultiplesOf === undefined || currency.inMultiplesOf === null
61+
? ''
62+
: currency.inMultiplesOf
6463
});
65-
66-
this.setupConditionalValidation();
64+
if (this.loanProductService.isLoanProduct) {
65+
this.loanProductCurrencyForm.patchValue({
66+
installmentAmountInMultiplesOf:
67+
this.loanProductsTemplate.installmentAmountInMultiplesOf === 0 ||
68+
this.loanProductsTemplate.installmentAmountInMultiplesOf === undefined ||
69+
this.loanProductsTemplate.installmentAmountInMultiplesOf === null
70+
? ''
71+
: this.loanProductsTemplate.installmentAmountInMultiplesOf
72+
});
73+
}
6774
}
6875

6976
createLoanProductCurrencyForm() {
@@ -79,75 +86,26 @@ export class LoanProductCurrencyStepComponent implements OnInit {
7986
Validators.min(0)
8087
]
8188
],
82-
setMultiples: [false],
83-
inMultiplesOf: [''],
84-
installmentInMultiplesOf: ['']
89+
inMultiplesOf: [
90+
'',
91+
[
92+
Validators.required,
93+
Validators.min(0)
94+
]
95+
]
8596
});
86-
}
8797

88-
setupConditionalValidation() {
89-
const inMultiplesOfControl = this.loanProductCurrencyForm.get('inMultiplesOf');
90-
const installmentInMultiplesOfControl = this.loanProductCurrencyForm.get('installmentInMultiplesOf');
91-
const setMultiplesControl = this.loanProductCurrencyForm.get('setMultiples');
92-
93-
if (setMultiplesControl?.value) {
94-
inMultiplesOfControl?.setValidators([
95-
Validators.required,
96-
Validators.min(1)
97-
]);
98-
inMultiplesOfControl?.updateValueAndValidity();
99-
installmentInMultiplesOfControl?.setValidators([
100-
Validators.required,
101-
Validators.min(1)
102-
]);
103-
installmentInMultiplesOfControl?.updateValueAndValidity();
98+
if (this.loanProductService.isLoanProduct) {
99+
this.loanProductCurrencyForm.addControl('installmentAmountInMultiplesOf', new UntypedFormControl(''));
104100
}
105-
106-
setMultiplesControl?.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((checked) => {
107-
if (checked) {
108-
inMultiplesOfControl?.setValidators([
109-
Validators.required,
110-
Validators.min(1)
111-
]);
112-
installmentInMultiplesOfControl?.setValidators([
113-
Validators.required,
114-
Validators.min(1)
115-
]);
116-
} else {
117-
inMultiplesOfControl?.clearValidators();
118-
inMultiplesOfControl?.setValue('');
119-
installmentInMultiplesOfControl?.clearValidators();
120-
installmentInMultiplesOfControl?.setValue('');
121-
}
122-
inMultiplesOfControl?.updateValueAndValidity();
123-
installmentInMultiplesOfControl?.updateValueAndValidity();
124-
});
125101
}
126102

127103
get loanProductCurrency() {
128-
const formValue = this.loanProductCurrencyForm.value;
104+
const formValue = this.loanProductCurrencyForm.getRawValue();
129105
const result: any = {
130-
currencyCode: formValue.currencyCode,
131-
digitsAfterDecimal: formValue.digitsAfterDecimal
106+
...formValue
132107
};
133108

134-
// Always include inMultiplesOf: null when unchecked to explicitly clear server value
135-
if (formValue.setMultiples) {
136-
result.inMultiplesOf =
137-
formValue.inMultiplesOf !== '' && formValue.inMultiplesOf !== null && formValue.inMultiplesOf !== undefined
138-
? formValue.inMultiplesOf
139-
: null;
140-
result.installmentInMultiplesOf =
141-
formValue.installmentInMultiplesOf !== '' &&
142-
formValue.installmentInMultiplesOf !== null &&
143-
formValue.installmentInMultiplesOf !== undefined
144-
? formValue.installmentInMultiplesOf
145-
: null;
146-
} else {
147-
result.inMultiplesOf = null;
148-
result.installmentInMultiplesOf = null;
149-
}
150-
151109
return result;
152110
}
153111
}

0 commit comments

Comments
 (0)