Skip to content

Commit 3a8fb4e

Browse files
WEB-954: Migrate Subscription management : products
1 parent 9dab61b commit 3a8fb4e

115 files changed

Lines changed: 1785 additions & 1563 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/products/charges/charges.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import {
1515
ElementRef,
1616
ViewChild,
1717
AfterViewInit,
18+
DestroyRef,
1819
inject
1920
} from '@angular/core';
21+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2022
import { MatPaginator } from '@angular/material/paginator';
2123
import { MatSort, MatSortHeader } from '@angular/material/sort';
2224
import {
@@ -82,6 +84,7 @@ export class ChargesComponent implements OnInit, AfterViewInit {
8284
private configurationWizardService = inject(ConfigurationWizardService);
8385
private popoverService = inject(PopoverService);
8486
private charges = inject(Charges);
87+
private destroyRef = inject(DestroyRef);
8588

8689
/** Charge data. */
8790
chargeData: Charge[] = [];
@@ -122,7 +125,7 @@ export class ChargesComponent implements OnInit, AfterViewInit {
122125
* @param {PopoverService} popoverService PopoverService.
123126
*/
124127
constructor() {
125-
this.route.data.subscribe((data: { charges: any }) => {
128+
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((data: { charges: any }) => {
126129
this.chargeData = data.charges;
127130
});
128131
this.chargeAppliesToOptions = this.charges.getChargeAppliesToOptions();

src/app/products/charges/create-charge/create-charge.component.ts

Lines changed: 139 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,10 @@
77
*/
88

99
/** Angular Imports */
10-
import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/core';
11-
import {
12-
UntypedFormGroup,
13-
UntypedFormBuilder,
14-
UntypedFormControl,
15-
Validators,
16-
ReactiveFormsModule
17-
} from '@angular/forms';
18-
import { Router, ActivatedRoute, RouterLink } from '@angular/router';
10+
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject } from '@angular/core';
11+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
12+
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
13+
import { Router, ActivatedRoute } from '@angular/router';
1914

2015
/** Custom Services */
2116
import { ProductsService } from '../../products.service';
@@ -46,15 +41,16 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
4641
changeDetection: ChangeDetectionStrategy.OnPush
4742
})
4843
export class CreateChargeComponent implements OnInit {
49-
private formBuilder = inject(UntypedFormBuilder);
44+
private formBuilder = inject(FormBuilder);
5045
private productsService = inject(ProductsService);
5146
private route = inject(ActivatedRoute);
5247
private router = inject(Router);
5348
private dateUtils = inject(Dates);
5449
private settingsService = inject(SettingsService);
50+
private destroyRef = inject(DestroyRef);
5551

5652
/** Charge form. */
57-
chargeForm: UntypedFormGroup;
53+
chargeForm: FormGroup;
5854
/** Charges template data. */
5955
chargesTemplateData: any;
6056
/** Charge time type data. */
@@ -84,7 +80,7 @@ export class CreateChargeComponent implements OnInit {
8480
* @param {SettingsService} settingsService Settings Service
8581
*/
8682
constructor() {
87-
this.route.data.subscribe((data: { chargesTemplate: any }) => {
83+
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((data: { chargesTemplate: any }) => {
8884
this.chargesTemplateData = data.chargesTemplate;
8985
this.chargePaymentModeData = this.chargesTemplateData.chargePaymetModeOptions;
9086
const incomeOptions = data.chargesTemplate.incomeOrLiabilityAccountOptions.incomeAccountOptions || [];
@@ -156,35 +152,42 @@ export class CreateChargeComponent implements OnInit {
156152
* Sets the charge calculation type and charge time type data
157153
*/
158154
setChargeForm() {
159-
this.chargeForm.get('chargeAppliesTo').valueChanges.subscribe((chargeAppliesTo) => {
160-
switch (chargeAppliesTo) {
161-
case 1:
162-
this.chargeCalculationTypeData = this.chargesTemplateData.loanChargeCalculationTypeOptions;
163-
this.chargeTimeTypeData = this.chargesTemplateData.loanChargeTimeTypeOptions;
164-
break;
165-
case 2:
166-
this.chargeCalculationTypeData = this.chargesTemplateData.savingsChargeCalculationTypeOptions;
167-
this.chargeTimeTypeData = this.chargesTemplateData.savingsChargeTimeTypeOptions;
168-
break;
169-
case 3:
170-
this.chargeCalculationTypeData = this.chargesTemplateData.clientChargeCalculationTypeOptions;
171-
this.chargeTimeTypeData = this.chargesTemplateData.clientChargeTimeTypeOptions;
172-
break;
173-
case 4:
174-
this.chargeCalculationTypeData = this.chargesTemplateData.shareChargeCalculationTypeOptions;
175-
this.chargeTimeTypeData = this.chargesTemplateData.shareChargeTimeTypeOptions;
176-
break;
177-
case 5:
178-
this.chargeCalculationTypeData = this.chargesTemplateData.loanChargeCalculationTypeOptions;
179-
this.chargeTimeTypeData = this.chargesTemplateData.loanChargeTimeTypeOptions.filter((chargeTimeType: any) => {
180-
return [2].includes(chargeTimeType.id); // Only Specific Due Date
181-
});
182-
this.chargePaymentModeData = this.chargePaymentModeData.filter((chargePaymentMode: any) => {
183-
return chargePaymentMode.id === 0;
184-
});
185-
break;
186-
}
187-
});
155+
this.chargeForm
156+
.get('chargeAppliesTo')
157+
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
158+
.subscribe((chargeAppliesTo) => {
159+
const allPaymentModes = this.chargesTemplateData.chargePaymetModeOptions || [];
160+
this.chargePaymentModeData = allPaymentModes;
161+
switch (chargeAppliesTo) {
162+
case 1:
163+
this.chargeCalculationTypeData = this.chargesTemplateData.loanChargeCalculationTypeOptions;
164+
this.chargeTimeTypeData = this.chargesTemplateData.loanChargeTimeTypeOptions;
165+
break;
166+
case 2:
167+
this.chargeCalculationTypeData = this.chargesTemplateData.savingsChargeCalculationTypeOptions;
168+
this.chargeTimeTypeData = this.chargesTemplateData.savingsChargeTimeTypeOptions;
169+
break;
170+
case 3:
171+
this.chargeCalculationTypeData = this.chargesTemplateData.clientChargeCalculationTypeOptions;
172+
this.chargeTimeTypeData = this.chargesTemplateData.clientChargeTimeTypeOptions;
173+
break;
174+
case 4:
175+
this.chargeCalculationTypeData = this.chargesTemplateData.shareChargeCalculationTypeOptions;
176+
this.chargeTimeTypeData = this.chargesTemplateData.shareChargeTimeTypeOptions;
177+
break;
178+
case 5:
179+
this.chargeCalculationTypeData = this.chargesTemplateData.loanChargeCalculationTypeOptions;
180+
this.chargeTimeTypeData = this.chargesTemplateData.loanChargeTimeTypeOptions.filter(
181+
(chargeTimeType: any) => {
182+
return [2].includes(chargeTimeType.id); // Only Specific Due Date
183+
}
184+
);
185+
this.chargePaymentModeData = allPaymentModes.filter((chargePaymentMode: any) => {
186+
return chargePaymentMode.id === 0;
187+
});
188+
break;
189+
}
190+
});
188191
}
189192

190193
/**
@@ -245,95 +248,102 @@ export class CreateChargeComponent implements OnInit {
245248
* Sets the conditional controls of the user form
246249
*/
247250
setConditionalControls() {
248-
this.chargeForm.get('chargeAppliesTo').valueChanges.subscribe((chargeAppliesTo) => {
249-
this.chargeForm.get('penalty').enable();
250-
switch (chargeAppliesTo) {
251-
case 1: // Loan
252-
this.chargeForm.addControl('chargePaymentMode', new UntypedFormControl('', Validators.required));
253-
this.chargeForm.removeControl('incomeAccountId');
254-
break;
255-
case 2: // Savings
256-
this.chargeForm.removeControl('chargePaymentMode');
257-
this.chargeForm.removeControl('incomeAccountId');
258-
break;
259-
case 3: // Client
260-
this.chargeForm.removeControl('chargePaymentMode');
261-
this.chargeForm.addControl('incomeAccountId', new UntypedFormControl(''));
262-
break;
263-
case 4: // Shares
264-
this.chargeForm.removeControl('chargePaymentMode');
265-
this.chargeForm.removeControl('incomeAccountId');
266-
this.chargeForm.get('penalty').setValue(false);
267-
break;
268-
case 5: // Working Capital Loans
269-
this.chargeForm.addControl('chargePaymentMode', new UntypedFormControl('', Validators.required));
270-
this.chargeForm.removeControl('incomeAccountId');
271-
break;
272-
}
273-
this.chargeForm.get('chargeCalculationType').reset();
274-
this.chargeForm.get('chargeTimeType').reset();
275-
});
276-
this.chargeForm.get('chargeTimeType').valueChanges.subscribe((chargeTimeType) => {
277-
this.chargeForm.removeControl('feeFrequency');
278-
this.chargeForm.removeControl('feeInterval');
279-
this.chargeForm.removeControl('feeOnMonthDay');
280-
this.chargeForm.removeControl('addFeeFrequency');
281-
if (this.chargeForm.get('chargeAppliesTo').value !== 4) {
251+
this.chargeForm
252+
.get('chargeAppliesTo')
253+
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
254+
.subscribe((chargeAppliesTo) => {
282255
this.chargeForm.get('penalty').enable();
283-
}
284-
switch (chargeTimeType) {
285-
case 6: // Annual Fee
286-
this.chargeForm.addControl('feeOnMonthDay', new UntypedFormControl('', Validators.required));
287-
break;
288-
case 7: // Monthly Fee
289-
this.chargeForm.addControl('feeOnMonthDay', new UntypedFormControl(''));
290-
this.chargeForm.addControl(
291-
'feeInterval',
292-
new UntypedFormControl('', [
293-
Validators.required,
294-
Validators.min(1),
295-
Validators.max(12),
296-
Validators.pattern('^[1-9]\\d*$')
297-
])
298-
);
299-
this.repeatEveryLabel = 'Months';
300-
break;
301-
case 9: // Overdue Fee
302-
this.chargeForm.get('penalty').setValue(true);
303-
this.chargeForm.addControl('addFeeFrequency', new UntypedFormControl(false));
304-
this.chargeForm.get('addFeeFrequency').valueChanges.subscribe((addFeeFrequency) => {
305-
if (addFeeFrequency) {
306-
this.chargeForm.addControl('feeFrequency', new UntypedFormControl('', Validators.required));
307-
this.chargeForm.addControl(
308-
'feeInterval',
309-
new UntypedFormControl('', [
310-
Validators.required,
311-
Validators.pattern('^[1-9]\\d*$')
312-
])
313-
);
314-
} else {
315-
this.chargeForm.removeControl('feeFrequency');
316-
this.chargeForm.removeControl('feeInterval');
317-
}
318-
});
319-
break;
320-
case 11: // Weekly Fee
321-
this.chargeForm.addControl(
322-
'feeInterval',
323-
new UntypedFormControl('', [
324-
Validators.required,
325-
Validators.pattern('^[1-9]\\d*$')
326-
])
327-
);
328-
this.repeatEveryLabel = 'Weeks';
329-
break;
330-
}
331-
});
332-
this.chargeForm.get('currencyCode').valueChanges.subscribe((currencyCode) => {
333-
this.currencyDecimalPlaces = this.chargesTemplateData.currencyOptions.find(
334-
(currency: any) => currency.code === currencyCode
335-
).decimalPlaces;
336-
});
256+
this.chargeForm.removeControl('chargePaymentMode');
257+
this.chargeForm.removeControl('incomeAccountId');
258+
switch (chargeAppliesTo) {
259+
case 1: // Loan
260+
this.chargeForm.addControl('chargePaymentMode', new FormControl('', Validators.required));
261+
break;
262+
case 2: // Savings
263+
break;
264+
case 3: // Client
265+
this.chargeForm.addControl('incomeAccountId', new FormControl(''));
266+
break;
267+
case 4: // Shares
268+
this.chargeForm.get('penalty').setValue(false);
269+
break;
270+
case 5: // Working Capital Loans
271+
this.chargeForm.addControl('chargePaymentMode', new FormControl('', Validators.required));
272+
break;
273+
}
274+
this.chargeForm.get('chargeCalculationType').reset();
275+
this.chargeForm.get('chargeTimeType').reset();
276+
});
277+
this.chargeForm
278+
.get('chargeTimeType')
279+
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
280+
.subscribe((chargeTimeType) => {
281+
this.chargeForm.removeControl('feeFrequency');
282+
this.chargeForm.removeControl('feeInterval');
283+
this.chargeForm.removeControl('feeOnMonthDay');
284+
this.chargeForm.removeControl('addFeeFrequency');
285+
if (this.chargeForm.get('chargeAppliesTo').value !== 4) {
286+
this.chargeForm.get('penalty').enable();
287+
}
288+
switch (chargeTimeType) {
289+
case 6: // Annual Fee
290+
this.chargeForm.addControl('feeOnMonthDay', new FormControl('', Validators.required));
291+
break;
292+
case 7: // Monthly Fee
293+
this.chargeForm.addControl('feeOnMonthDay', new FormControl(''));
294+
this.chargeForm.addControl(
295+
'feeInterval',
296+
new FormControl('', [
297+
Validators.required,
298+
Validators.min(1),
299+
Validators.max(12),
300+
Validators.pattern('^[1-9]\\d*$')
301+
])
302+
);
303+
this.repeatEveryLabel = 'Months';
304+
break;
305+
case 9: // Overdue Fee
306+
this.chargeForm.get('penalty').setValue(true);
307+
this.chargeForm.addControl('addFeeFrequency', new FormControl(false));
308+
this.chargeForm
309+
.get('addFeeFrequency')
310+
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
311+
.subscribe((addFeeFrequency) => {
312+
if (addFeeFrequency) {
313+
this.chargeForm.addControl('feeFrequency', new FormControl('', Validators.required));
314+
this.chargeForm.addControl(
315+
'feeInterval',
316+
new FormControl('', [
317+
Validators.required,
318+
Validators.pattern('^[1-9]\\d*$')
319+
])
320+
);
321+
} else {
322+
this.chargeForm.removeControl('feeFrequency');
323+
this.chargeForm.removeControl('feeInterval');
324+
}
325+
});
326+
break;
327+
case 11: // Weekly Fee
328+
this.chargeForm.addControl(
329+
'feeInterval',
330+
new FormControl('', [
331+
Validators.required,
332+
Validators.pattern('^[1-9]\\d*$')
333+
])
334+
);
335+
this.repeatEveryLabel = 'Weeks';
336+
break;
337+
}
338+
});
339+
this.chargeForm
340+
.get('currencyCode')
341+
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
342+
.subscribe((currencyCode) => {
343+
this.currencyDecimalPlaces = this.chargesTemplateData.currencyOptions.find(
344+
(currency: any) => currency.code === currencyCode
345+
).decimalPlaces;
346+
});
337347
}
338348

339349
/**

src/app/products/charges/edit-charge/edit-charge.component.ts

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

99
/** Angular Imports */
10-
import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/core';
11-
import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms';
10+
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject } from '@angular/core';
11+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
12+
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
1213
import { ActivatedRoute, Router } from '@angular/router';
1314

1415
/** Custom Services */
@@ -38,15 +39,16 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
3839
})
3940
export class EditChargeComponent implements OnInit {
4041
private productsService = inject(ProductsService);
41-
private formBuilder = inject(UntypedFormBuilder);
42+
private formBuilder = inject(FormBuilder);
4243
private route = inject(ActivatedRoute);
4344
private router = inject(Router);
4445
private settingsService = inject(SettingsService);
46+
private destroyRef = inject(DestroyRef);
4547

4648
/** Selected Data. */
4749
chargeData: any;
4850
/** Charge form. */
49-
chargeForm: UntypedFormGroup;
51+
chargeForm: FormGroup;
5052
/** Select Income. */
5153
selectedIncome: any;
5254
/** Select Time Type. */
@@ -79,7 +81,7 @@ export class EditChargeComponent implements OnInit {
7981
* @param {SettingsService} settingsService Settings Service
8082
*/
8183
constructor() {
82-
this.route.data.subscribe((data: { chargesTemplate: any }) => {
84+
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((data: { chargesTemplate: any }) => {
8385
this.chargeData = data.chargesTemplate;
8486
});
8587
}
@@ -200,7 +202,7 @@ export class EditChargeComponent implements OnInit {
200202
this.formBuilder.control({ value: this.chargeData.taxGroup.id, disabled: true })
201203
);
202204
} else {
203-
this.chargeForm.addControl('taxGroupId', this.formBuilder.control({ value: '' }));
205+
this.chargeForm.addControl('taxGroupId', this.formBuilder.control(''));
204206
}
205207
}
206208

@@ -224,7 +226,7 @@ export class EditChargeComponent implements OnInit {
224226
submit() {
225227
const charges = this.chargeForm.getRawValue();
226228
charges.locale = this.settingsService.language.code;
227-
if (charges.taxGroupId.value === '') {
229+
if (!charges.taxGroupId) {
228230
delete charges.taxGroupId;
229231
}
230232
if (!charges.minCap) {

0 commit comments

Comments
 (0)