Skip to content

Commit cee719f

Browse files
WEB-813: Working Capital loan account modification
1 parent 7886c79 commit cee719f

9 files changed

Lines changed: 152 additions & 46 deletions

File tree

src/app/loans/common-resolvers/loan-details.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class LoanDetailsResolver {
4040
if (resolvedProductType === LOAN_PRODUCT_TYPE.LOAN) {
4141
return this.loansService.getLoanAccountAssociationDetails(loanId);
4242
} else {
43-
return this.loansService.getWorkingCapitalLoannDetails(loanId);
43+
return this.loansService.getWorkingCapitalLoanDetails(loanId);
4444
}
4545
}
4646
}

src/app/loans/common-resolvers/loans-account-and-template.resolver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ import { Observable } from 'rxjs';
1515

1616
/** Custom Services */
1717
import { LoansService } from '../loans.service';
18+
import { LoanProductService } from 'app/products/loan-products/services/loan-product.service';
1819

1920
/**
2021
* Loan accounts template data resolver.
2122
*/
2223
@Injectable()
2324
export class LoansAccountAndTemplateResolver {
2425
private loansService = inject(LoansService);
26+
private loanProductService = inject(LoanProductService);
2527

2628
/**
2729
* Returns the loan account template data.
2830
* @returns {Observable<any>}
2931
*/
3032
resolve(route: ActivatedRouteSnapshot): Observable<any> {
3133
const loanId = route.paramMap.get('loanId') || route.parent.paramMap.get('loanId');
32-
return this.loansService.getLoansAccountAndTemplateResource(loanId);
34+
return this.loanProductService.isLoanProduct
35+
? this.loansService.getLoansAccountAndTemplateResource(loanId)
36+
: this.loansService.getWorkingCapitalLoanDetails(loanId);
3337
}
3438
}

src/app/loans/edit-loans-account/edit-loans-account.component.ts

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,22 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
7777
super();
7878
this.loanProductService.initialize(LoanProductBaseComponent.resolveProductTypeDefault(this.route, 'loan'));
7979

80+
this.loanId = this.route.snapshot.params['loanId'];
8081
this.route.data.subscribe(
8182
(data: { loansAccountAndTemplate: any; loanProductsBasicDetails: LoanProductBasicDetails[] }) => {
8283
this.loansAccountAndTemplate = data.loansAccountAndTemplate;
83-
this.loansAccountProductTemplate = data.loansAccountAndTemplate;
84+
if (this.loanProductService.isLoanProduct) {
85+
this.loansAccountProductTemplate = data.loansAccountAndTemplate;
86+
} else if (this.loanProductService.isWorkingCapital) {
87+
this.loansAccountProductTemplate = data.loansAccountAndTemplate;
88+
this.getWorkingCapitalLoanProductTemplate(
89+
this.loansAccountProductTemplate.client.id,
90+
this.loansAccountProductTemplate.product.id
91+
);
92+
}
8493
this.loanProductsBasicDetails = data.loanProductsBasicDetails;
8594
}
8695
);
87-
this.loanId = this.route.snapshot.params['loanId'];
8896
}
8997

9098
/**
@@ -95,6 +103,15 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
95103
const templateData: any = $event;
96104
this.loansAccountProductTemplate = templateData.loanData ? templateData.loanData : templateData;
97105
this.currencyCode = this.loansAccountProductTemplate.currency.code;
106+
this.productDetails = this.loansAccountProductTemplate.product;
107+
if (templateData.loanData) {
108+
this.loansAccountProductTemplate = templateData.loanData;
109+
this.loansAccountProductTemplate.options = {
110+
delinquencyBucketOptions: templateData.delinquencyBucketOptions,
111+
fundOptions: templateData.fundOptions,
112+
periodFrequencyTypeOptions: templateData.periodFrequencyTypeOptions
113+
};
114+
}
98115
if (this.loansAccountProductTemplate.loanProductId) {
99116
this.loansService
100117
.getLoansCollateralTemplateResource(this.loansAccountProductTemplate.loanProductId)
@@ -104,6 +121,12 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
104121
}
105122
}
106123

124+
getWorkingCapitalLoanProductTemplate(clientId: number, productId: number) {
125+
this.loansService.getWorkingCapitalLoansAccountTemplate(clientId, productId).subscribe((response: any) => {
126+
this.setTemplate(response);
127+
});
128+
}
129+
107130
setProductType($event: any): void {
108131
this.productType = $event;
109132
this.loanProductService.initialize(this.productType);
@@ -131,7 +154,11 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
131154
!this.loansAccountChargesStep?.pristine)
132155
);
133156
} else if (this.loanProductService.isWorkingCapital) {
134-
return false;
157+
return (
158+
this.loansAccountDetailsForm.valid &&
159+
this.loansAccountTermsForm.valid &&
160+
(!this.loansAccountDetailsForm.pristine || !this.loansAccountTermsForm.pristine)
161+
);
135162
}
136163
}
137164

@@ -241,15 +268,60 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
241268
loansAccountData.allowPartialPeriodInterestCalculation = loansAccountData.allowPartialPeriodInterestCalculation;
242269
delete loansAccountData.allowPartialPeriodInterestCalculation;
243270

244-
this.loansService.updateLoansAccount(this.loanId, loansAccountData).subscribe((response: any) => {
245-
this.router.navigate(['../'], {
246-
queryParams: {
247-
productType: this.loanProductService.productType.value
248-
},
249-
relativeTo: this.route
271+
this.loansService
272+
.updateLoansAccount(this.loanProductService.loanAccountPath, this.loanId, loansAccountData)
273+
.subscribe((response: any) => {
274+
this.router.navigate(['../'], {
275+
queryParams: {
276+
productType: this.loanProductService.productType.value
277+
},
278+
relativeTo: this.route
279+
});
250280
});
251-
});
252281
}
253282

254-
submitWorkingCapitalProduct(): void {}
283+
submitWorkingCapitalProduct(): void {
284+
const locale = this.settingsService.language.code;
285+
const dateFormat = this.settingsService.dateFormat;
286+
const payload = {
287+
...this.loansAccount,
288+
clientId: this.loansAccountProductTemplate.client.id,
289+
submittedOnDate: this.dateUtils.formatDate(this.loansAccount.submittedOnDate, dateFormat),
290+
expectedDisbursementDate: this.dateUtils.formatDate(this.loansAccount.expectedDisbursementDate, dateFormat),
291+
locale,
292+
dateFormat
293+
};
294+
295+
if (this.productDetails.allowAttributeOverrides) {
296+
if (
297+
!Object.hasOwn(this.productDetails.allowAttributeOverrides, 'periodPaymentFrequency') ||
298+
this.productDetails.allowAttributeOverrides.periodPaymentFrequency === false
299+
) {
300+
delete payload['repaymentEvery'];
301+
}
302+
if (
303+
!Object.hasOwn(this.productDetails.allowAttributeOverrides, 'periodPaymentFrequencyType') ||
304+
this.productDetails.allowAttributeOverrides.periodPaymentFrequencyType === false
305+
) {
306+
delete payload['repaymentFrequencyType'];
307+
}
308+
if (
309+
!Object.hasOwn(this.productDetails.allowAttributeOverrides, 'discountDefault') ||
310+
this.productDetails.allowAttributeOverrides.discountDefault === false
311+
) {
312+
delete payload['discount'];
313+
}
314+
}
315+
316+
this.loansService
317+
.updateLoansAccount(this.loanProductService.loanAccountPath, this.loanId, payload)
318+
.subscribe((response: any) => {
319+
this.router.navigate(['../'], {
320+
queryParams: {
321+
productType: this.loanProductService.productType.value
322+
},
323+
relativeTo: this.route
324+
});
325+
});
326+
}
255327
}

src/app/loans/loans-account-stepper/loans-account-details-step/loans-account-details-step.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ <h3 class="mat-h3 flex-fill">{{ 'labels.heading.Savings Linkage' | translate }}<
172172
<fa-icon icon="arrow-right" class="m-l-10"></fa-icon>
173173
</button>
174174
@if (loanId) {
175-
<button mat-raised-button [routerLink]="['../', 'general']">
175+
<button
176+
mat-raised-button
177+
[routerLink]="['../', 'general']"
178+
[queryParams]="{ productType: loanProductService.productType.value }"
179+
>
176180
{{ 'labels.buttons.Cancel' | translate }}
177181
</button>
178182
}

src/app/loans/loans-account-stepper/loans-account-details-step/loans-account-details-step.component.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,34 +118,40 @@ export class LoansAccountDetailsStepComponent extends LoanProductBaseComponent i
118118
this.placeHolderLabel = this.translateService.instant('labels.text.Search');
119119
this.noEntriesFoundLabel = this.translateService.instant('labels.text.No data found');
120120
this.maxDate = this.settingsService.maxFutureDate;
121-
this.productList = this.loanProductsBasicDetails.sort(this.commons.dynamicSort('name'));
121+
this.productList = this.loanProductsBasicDetails
122+
? this.loanProductsBasicDetails.sort(this.commons.dynamicSort('name'))
123+
: [];
122124
if (this.loansAccountTemplate) {
125+
this.addFormControlsBasedOnProductType();
126+
let loanProductId: number | null = null;
127+
this.loansAccountDetailsForm.patchValue({
128+
fundId: this.loansAccountTemplate.fundId,
129+
submittedOnDate:
130+
this.loansAccountTemplate.timeline.submittedOnDate &&
131+
new Date(this.loansAccountTemplate.timeline.submittedOnDate),
132+
expectedDisbursementDate:
133+
this.loansAccountTemplate.timeline.expectedDisbursementDate &&
134+
new Date(this.loansAccountTemplate.timeline.expectedDisbursementDate),
135+
externalId: this.loansAccountTemplate.externalId
136+
});
123137
if (this.loansAccountTemplate.loanProductId) {
124-
this.addFormControlsBasedOnProductType();
138+
loanProductId = this.loansAccountTemplate.loanProductId;
125139
this.loansAccountDetailsForm.patchValue({
126-
productId: this.loansAccountTemplate.loanProductId,
127-
submittedOnDate:
128-
this.loansAccountTemplate.timeline.submittedOnDate &&
129-
new Date(this.loansAccountTemplate.timeline.submittedOnDate),
130140
loanOfficerId: this.loansAccountTemplate.loanOfficerId,
131-
loanPurposeId: this.loansAccountTemplate.loanPurposeId,
132-
fundId: this.loansAccountTemplate.fundId,
133-
expectedDisbursementDate:
134-
this.loansAccountTemplate.timeline.expectedDisbursementDate &&
135-
new Date(this.loansAccountTemplate.timeline.expectedDisbursementDate),
136-
externalId: this.loansAccountTemplate.externalId
141+
loanPurposeId: this.loansAccountTemplate.loanPurposeId
137142
});
138-
this.productSelected = this.loanProductsBasicDetails.find(
139-
(p: LoanProductBasicDetails) =>
140-
p.productType === this.loanProductService.productType.value &&
141-
p.id === this.loansAccountTemplate.loanProductId
142-
);
143-
if (this.productSelected) {
144-
this.loansAccountDetailsForm.patchValue({
145-
productId: this.productSelected.shortName
146-
});
147-
this.loanProductSelected = true;
148-
}
143+
} else if (this.loanProductService.isWorkingCapital) {
144+
loanProductId = this.loansAccountTemplate.product.id;
145+
}
146+
this.productSelected = this.loanProductsBasicDetails.find(
147+
(p: LoanProductBasicDetails) =>
148+
p.productType === this.loanProductService.productType.value && p.id === loanProductId
149+
);
150+
if (this.productSelected) {
151+
this.loansAccountDetailsForm.patchValue({
152+
productId: this.productSelected.shortName
153+
});
154+
this.loanProductSelected = true;
149155
}
150156
}
151157
this.filterFormCtrl.valueChanges.pipe(takeUntil(this._onDestroy)).subscribe(() => {

src/app/loans/loans-account-stepper/loans-account-preview-step/loans-account-preview-step.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,11 @@ <h3 class="mat-h3 flex-98">{{ 'labels.heading.Overdue Charges' | translate }}</h
457457
<fa-icon icon="arrow-left" class="m-r-10"></fa-icon>
458458
{{ 'labels.buttons.Previous' | translate }}
459459
</button>
460-
<button mat-raised-button [routerLink]="['../..']">
460+
<button
461+
mat-raised-button
462+
[routerLink]="['../..']"
463+
[queryParams]="{ productType: loanProductService.productType.value }"
464+
>
461465
{{ 'labels.buttons.Cancel' | translate }}
462466
</button>
463467
<button mat-raised-button color="primary" (click)="submitEvent.emit()">

src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,11 @@ <h4 class="mat-h4 flex-98">{{ 'labels.heading.Collaterals Data' | translate }}</
791791
<fa-icon icon="arrow-right" class="m-l-10"></fa-icon>
792792
</button>
793793
@if (loanId) {
794-
<button mat-raised-button [routerLink]="['../', 'general']">
794+
<button
795+
mat-raised-button
796+
[routerLink]="['../', 'general']"
797+
[queryParams]="{ productType: loanProductService.productType.value }"
798+
>
795799
{{ 'labels.buttons.Cancel' | translate }}
796800
</button>
797801
}

src/app/loans/loans-account-stepper/loans-account-terms-step/loans-account-terms-step.component.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,22 @@ export class LoansAccountTermsStepComponent extends LoanProductBaseComponent imp
317317
} else if (this.loanProductService.isWorkingCapital && this.loansAccountProductTemplate) {
318318
this.loansAccountTermsData = this.loansAccountProductTemplate;
319319
this.currency = this.loansAccountTermsData.currency;
320-
this.termFrequencyTypeData = this.loansAccountTermsData.options.periodFrequencyTypeOptions;
321-
this.loansAccountTermsForm.patchValue({
322-
principalAmount: this.loansAccountTermsData.product.principal
323-
});
320+
this.termFrequencyTypeData = this.loansAccountTermsData.options?.periodFrequencyTypeOptions;
321+
if (this.loanId != null && 'accountNo' in this.loansAccountTemplate) {
322+
this.loansAccountTermsData = this.loansAccountTemplate;
323+
this.loansAccountTermsForm.patchValue({
324+
discount: this.loansAccountTermsData.discount || '',
325+
principalAmount: this.loansAccountTermsData.proposedPrincipal,
326+
periodPaymentRate: this.loansAccountTermsData.periodPaymentRate,
327+
totalPayment: this.loansAccountTermsData.balance?.totalPayment,
328+
repaymentEvery: this.loansAccountTermsData.repaymentEvery,
329+
repaymentFrequencyType: this.loansAccountTermsData.repaymentFrequencyType?.id
330+
});
331+
} else {
332+
this.loansAccountTermsForm.patchValue({
333+
principalAmount: this.loansAccountTermsData.product.principal
334+
});
335+
}
324336
this.allowAttributeOverrides = this.loansAccountProductTemplate.product.allowAttributeOverrides;
325337
if (
326338
!this.allowAttributeOverrides.periodPaymentFrequency ||

src/app/loans/loans.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class LoansService {
203203
return this.http.get(`/loans/${loanId}`, { params: httpParams });
204204
}
205205

206-
getWorkingCapitalLoannDetails(loanId: string) {
206+
getWorkingCapitalLoanDetails(loanId: string) {
207207
const httpParams = new HttpParams().set('associations', 'all');
208208
return this.http.get(`/working-capital-loans/${loanId}`, { params: httpParams });
209209
}
@@ -536,8 +536,8 @@ export class LoansService {
536536
return this.http.get(`/standinginstructions`, { params: httpParams });
537537
}
538538

539-
updateLoansAccount(loanId: any, loanData: any): Observable<any> {
540-
return this.http.put(`/loans/${loanId}`, loanData);
539+
updateLoansAccount(productType: string, loanId: any, loanData: any): Observable<any> {
540+
return this.http.put(`/${productType}/${loanId}`, loanData);
541541
}
542542

543543
getTemplateData(templateId: any, loanId: any): Observable<any> {

0 commit comments

Comments
 (0)