Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/app/products/charges/charges.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import {
ElementRef,
ViewChild,
AfterViewInit,
DestroyRef,
inject
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort, MatSortHeader } from '@angular/material/sort';
import {
Expand Down Expand Up @@ -82,6 +84,7 @@ export class ChargesComponent implements OnInit, AfterViewInit {
private configurationWizardService = inject(ConfigurationWizardService);
private popoverService = inject(PopoverService);
private charges = inject(Charges);
private destroyRef = inject(DestroyRef);

/** Charge data. */
chargeData: Charge[] = [];
Expand Down Expand Up @@ -122,7 +125,7 @@ export class ChargesComponent implements OnInit, AfterViewInit {
* @param {PopoverService} popoverService PopoverService.
*/
constructor() {
this.route.data.subscribe((data: { charges: any }) => {
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((data: { charges: any }) => {
this.chargeData = data.charges;
});
this.chargeAppliesToOptions = this.charges.getChargeAppliesToOptions();
Expand Down
268 changes: 139 additions & 129 deletions src/app/products/charges/create-charge/create-charge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
*/

/** Angular Imports */
import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/core';
import {
UntypedFormGroup,
UntypedFormBuilder,
UntypedFormControl,
Validators,
ReactiveFormsModule
} from '@angular/forms';
import { Router, ActivatedRoute, RouterLink } from '@angular/router';
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';

/** Custom Services */
import { ProductsService } from '../../products.service';
Expand Down Expand Up @@ -46,15 +41,16 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CreateChargeComponent implements OnInit {
private formBuilder = inject(UntypedFormBuilder);
private formBuilder = inject(FormBuilder);
private productsService = inject(ProductsService);
private route = inject(ActivatedRoute);
private router = inject(Router);
private dateUtils = inject(Dates);
private settingsService = inject(SettingsService);
private destroyRef = inject(DestroyRef);

/** Charge form. */
chargeForm: UntypedFormGroup;
chargeForm: FormGroup;
/** Charges template data. */
chargesTemplateData: any;
/** Charge time type data. */
Expand Down Expand Up @@ -84,7 +80,7 @@ export class CreateChargeComponent implements OnInit {
* @param {SettingsService} settingsService Settings Service
*/
constructor() {
this.route.data.subscribe((data: { chargesTemplate: any }) => {
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((data: { chargesTemplate: any }) => {
this.chargesTemplateData = data.chargesTemplate;
this.chargePaymentModeData = this.chargesTemplateData.chargePaymetModeOptions;
const incomeOptions = data.chargesTemplate.incomeOrLiabilityAccountOptions.incomeAccountOptions || [];
Expand Down Expand Up @@ -156,35 +152,42 @@ export class CreateChargeComponent implements OnInit {
* Sets the charge calculation type and charge time type data
*/
setChargeForm() {
this.chargeForm.get('chargeAppliesTo').valueChanges.subscribe((chargeAppliesTo) => {
switch (chargeAppliesTo) {
case 1:
this.chargeCalculationTypeData = this.chargesTemplateData.loanChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.loanChargeTimeTypeOptions;
break;
case 2:
this.chargeCalculationTypeData = this.chargesTemplateData.savingsChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.savingsChargeTimeTypeOptions;
break;
case 3:
this.chargeCalculationTypeData = this.chargesTemplateData.clientChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.clientChargeTimeTypeOptions;
break;
case 4:
this.chargeCalculationTypeData = this.chargesTemplateData.shareChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.shareChargeTimeTypeOptions;
break;
case 5:
this.chargeCalculationTypeData = this.chargesTemplateData.loanChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.loanChargeTimeTypeOptions.filter((chargeTimeType: any) => {
return [2].includes(chargeTimeType.id); // Only Specific Due Date
});
this.chargePaymentModeData = this.chargePaymentModeData.filter((chargePaymentMode: any) => {
return chargePaymentMode.id === 0;
});
break;
}
});
this.chargeForm
.get('chargeAppliesTo')
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((chargeAppliesTo) => {
const allPaymentModes = this.chargesTemplateData.chargePaymetModeOptions || [];
this.chargePaymentModeData = allPaymentModes;
switch (chargeAppliesTo) {
case 1:
this.chargeCalculationTypeData = this.chargesTemplateData.loanChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.loanChargeTimeTypeOptions;
break;
case 2:
this.chargeCalculationTypeData = this.chargesTemplateData.savingsChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.savingsChargeTimeTypeOptions;
break;
case 3:
this.chargeCalculationTypeData = this.chargesTemplateData.clientChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.clientChargeTimeTypeOptions;
break;
case 4:
this.chargeCalculationTypeData = this.chargesTemplateData.shareChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.shareChargeTimeTypeOptions;
break;
case 5:
this.chargeCalculationTypeData = this.chargesTemplateData.loanChargeCalculationTypeOptions;
this.chargeTimeTypeData = this.chargesTemplateData.loanChargeTimeTypeOptions.filter(
(chargeTimeType: any) => {
return [2].includes(chargeTimeType.id); // Only Specific Due Date
}
);
this.chargePaymentModeData = allPaymentModes.filter((chargePaymentMode: any) => {
return chargePaymentMode.id === 0;
});
break;
}
});
}

/**
Expand Down Expand Up @@ -245,95 +248,102 @@ export class CreateChargeComponent implements OnInit {
* Sets the conditional controls of the user form
*/
setConditionalControls() {
this.chargeForm.get('chargeAppliesTo').valueChanges.subscribe((chargeAppliesTo) => {
this.chargeForm.get('penalty').enable();
switch (chargeAppliesTo) {
case 1: // Loan
this.chargeForm.addControl('chargePaymentMode', new UntypedFormControl('', Validators.required));
this.chargeForm.removeControl('incomeAccountId');
break;
case 2: // Savings
this.chargeForm.removeControl('chargePaymentMode');
this.chargeForm.removeControl('incomeAccountId');
break;
case 3: // Client
this.chargeForm.removeControl('chargePaymentMode');
this.chargeForm.addControl('incomeAccountId', new UntypedFormControl(''));
break;
case 4: // Shares
this.chargeForm.removeControl('chargePaymentMode');
this.chargeForm.removeControl('incomeAccountId');
this.chargeForm.get('penalty').setValue(false);
break;
case 5: // Working Capital Loans
this.chargeForm.addControl('chargePaymentMode', new UntypedFormControl('', Validators.required));
this.chargeForm.removeControl('incomeAccountId');
break;
}
this.chargeForm.get('chargeCalculationType').reset();
this.chargeForm.get('chargeTimeType').reset();
});
this.chargeForm.get('chargeTimeType').valueChanges.subscribe((chargeTimeType) => {
this.chargeForm.removeControl('feeFrequency');
this.chargeForm.removeControl('feeInterval');
this.chargeForm.removeControl('feeOnMonthDay');
this.chargeForm.removeControl('addFeeFrequency');
if (this.chargeForm.get('chargeAppliesTo').value !== 4) {
this.chargeForm
.get('chargeAppliesTo')
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((chargeAppliesTo) => {
this.chargeForm.get('penalty').enable();
}
switch (chargeTimeType) {
case 6: // Annual Fee
this.chargeForm.addControl('feeOnMonthDay', new UntypedFormControl('', Validators.required));
break;
case 7: // Monthly Fee
this.chargeForm.addControl('feeOnMonthDay', new UntypedFormControl(''));
this.chargeForm.addControl(
'feeInterval',
new UntypedFormControl('', [
Validators.required,
Validators.min(1),
Validators.max(12),
Validators.pattern('^[1-9]\\d*$')
])
);
this.repeatEveryLabel = 'Months';
break;
case 9: // Overdue Fee
this.chargeForm.get('penalty').setValue(true);
this.chargeForm.addControl('addFeeFrequency', new UntypedFormControl(false));
this.chargeForm.get('addFeeFrequency').valueChanges.subscribe((addFeeFrequency) => {
if (addFeeFrequency) {
this.chargeForm.addControl('feeFrequency', new UntypedFormControl('', Validators.required));
this.chargeForm.addControl(
'feeInterval',
new UntypedFormControl('', [
Validators.required,
Validators.pattern('^[1-9]\\d*$')
])
);
} else {
this.chargeForm.removeControl('feeFrequency');
this.chargeForm.removeControl('feeInterval');
}
});
break;
case 11: // Weekly Fee
this.chargeForm.addControl(
'feeInterval',
new UntypedFormControl('', [
Validators.required,
Validators.pattern('^[1-9]\\d*$')
])
);
this.repeatEveryLabel = 'Weeks';
break;
}
});
this.chargeForm.get('currencyCode').valueChanges.subscribe((currencyCode) => {
this.currencyDecimalPlaces = this.chargesTemplateData.currencyOptions.find(
(currency: any) => currency.code === currencyCode
).decimalPlaces;
});
this.chargeForm.removeControl('chargePaymentMode');
this.chargeForm.removeControl('incomeAccountId');
switch (chargeAppliesTo) {
case 1: // Loan
this.chargeForm.addControl('chargePaymentMode', new FormControl('', Validators.required));
break;
case 2: // Savings
break;
case 3: // Client
this.chargeForm.addControl('incomeAccountId', new FormControl(''));
break;
case 4: // Shares
this.chargeForm.get('penalty').setValue(false);
break;
case 5: // Working Capital Loans
this.chargeForm.addControl('chargePaymentMode', new FormControl('', Validators.required));
break;
Comment thread
alberto-art3ch marked this conversation as resolved.
}
this.chargeForm.get('chargeCalculationType').reset();
this.chargeForm.get('chargeTimeType').reset();
});
this.chargeForm
.get('chargeTimeType')
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((chargeTimeType) => {
this.chargeForm.removeControl('feeFrequency');
this.chargeForm.removeControl('feeInterval');
this.chargeForm.removeControl('feeOnMonthDay');
this.chargeForm.removeControl('addFeeFrequency');
if (this.chargeForm.get('chargeAppliesTo').value !== 4) {
this.chargeForm.get('penalty').enable();
}
switch (chargeTimeType) {
case 6: // Annual Fee
this.chargeForm.addControl('feeOnMonthDay', new FormControl('', Validators.required));
break;
case 7: // Monthly Fee
this.chargeForm.addControl('feeOnMonthDay', new FormControl(''));
this.chargeForm.addControl(
'feeInterval',
new FormControl('', [
Validators.required,
Validators.min(1),
Validators.max(12),
Validators.pattern('^[1-9]\\d*$')
])
);
this.repeatEveryLabel = 'Months';
break;
case 9: // Overdue Fee
this.chargeForm.get('penalty').setValue(true);
this.chargeForm.addControl('addFeeFrequency', new FormControl(false));
this.chargeForm
.get('addFeeFrequency')
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((addFeeFrequency) => {
if (addFeeFrequency) {
this.chargeForm.addControl('feeFrequency', new FormControl('', Validators.required));
this.chargeForm.addControl(
'feeInterval',
new FormControl('', [
Validators.required,
Validators.pattern('^[1-9]\\d*$')
])
);
} else {
this.chargeForm.removeControl('feeFrequency');
this.chargeForm.removeControl('feeInterval');
}
});
break;
case 11: // Weekly Fee
this.chargeForm.addControl(
'feeInterval',
new FormControl('', [
Validators.required,
Validators.pattern('^[1-9]\\d*$')
])
);
this.repeatEveryLabel = 'Weeks';
break;
}
});
this.chargeForm
.get('currencyCode')
.valueChanges.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((currencyCode) => {
this.currencyDecimalPlaces = this.chargesTemplateData.currencyOptions.find(
(currency: any) => currency.code === currencyCode
).decimalPlaces;
});
}

/**
Expand Down
16 changes: 9 additions & 7 deletions src/app/products/charges/edit-charge/edit-charge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
*/

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

/** Custom Services */
Expand Down Expand Up @@ -38,15 +39,16 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
})
export class EditChargeComponent implements OnInit {
private productsService = inject(ProductsService);
private formBuilder = inject(UntypedFormBuilder);
private formBuilder = inject(FormBuilder);
private route = inject(ActivatedRoute);
private router = inject(Router);
private settingsService = inject(SettingsService);
private destroyRef = inject(DestroyRef);

/** Selected Data. */
chargeData: any;
/** Charge form. */
chargeForm: UntypedFormGroup;
chargeForm: FormGroup;
/** Select Income. */
selectedIncome: any;
/** Select Time Type. */
Expand Down Expand Up @@ -79,7 +81,7 @@ export class EditChargeComponent implements OnInit {
* @param {SettingsService} settingsService Settings Service
*/
constructor() {
this.route.data.subscribe((data: { chargesTemplate: any }) => {
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((data: { chargesTemplate: any }) => {
this.chargeData = data.chargesTemplate;
});
}
Expand Down Expand Up @@ -200,7 +202,7 @@ export class EditChargeComponent implements OnInit {
this.formBuilder.control({ value: this.chargeData.taxGroup.id, disabled: true })
);
} else {
this.chargeForm.addControl('taxGroupId', this.formBuilder.control({ value: '' }));
this.chargeForm.addControl('taxGroupId', this.formBuilder.control(''));
Comment thread
alberto-art3ch marked this conversation as resolved.
}
}

Expand All @@ -224,7 +226,7 @@ export class EditChargeComponent implements OnInit {
submit() {
const charges = this.chargeForm.getRawValue();
charges.locale = this.settingsService.language.code;
if (charges.taxGroupId.value === '') {
if (!charges.taxGroupId) {
delete charges.taxGroupId;
}
if (!charges.minCap) {
Expand Down
Loading
Loading