From 4a40b5eca7764ebb92e741b803246cf855217e95 Mon Sep 17 00:00:00 2001 From: Ramveer Date: Fri, 15 Jul 2022 19:22:34 +0530 Subject: [PATCH] feat: create group loan aplication functionality added (#1460) * feat: create group loan aplication functionality added * lint fixes * lint fix --- .../groups/groups-view/groups-view.component.html | 2 +- .../loans-account-template.resolver.ts | 5 +++-- .../create-loans-account.component.ts | 15 ++++++++++----- .../loans-account-details-step.component.ts | 5 +++-- src/app/loans/loans.service.ts | 10 ++++++---- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/app/groups/groups-view/groups-view.component.html b/src/app/groups/groups-view/groups-view.component.html index 3b9b5e274..e99e04cc4 100644 --- a/src/app/groups/groups-view/groups-view.component.html +++ b/src/app/groups/groups-view/groups-view.component.html @@ -72,7 +72,7 @@ - + diff --git a/src/app/loans/common-resolvers/loans-account-template.resolver.ts b/src/app/loans/common-resolvers/loans-account-template.resolver.ts index 76bd4b1d9..7577f8a8a 100644 --- a/src/app/loans/common-resolvers/loans-account-template.resolver.ts +++ b/src/app/loans/common-resolvers/loans-account-template.resolver.ts @@ -23,7 +23,8 @@ export class LoansAccountTemplateResolver implements Resolve { * @returns {Observable} */ resolve(route: ActivatedRouteSnapshot): Observable { - const clientId = route.parent.parent.paramMap.get('clientId'); - return this.loansService.getLoansAccountTemplateResource(clientId); + const entityId = route.parent.parent.paramMap.get('clientId') || route.parent.parent.paramMap.get('groupId'); + const isGroup = (route.parent.parent.paramMap.get('groupId')) ? true : false; + return this.loansService.getLoansAccountTemplateResource(entityId, isGroup); } } diff --git a/src/app/loans/create-loans-account/create-loans-account.component.ts b/src/app/loans/create-loans-account/create-loans-account.component.ts index fe031e3cf..e6ebf13df 100644 --- a/src/app/loans/create-loans-account/create-loans-account.component.ts +++ b/src/app/loans/create-loans-account/create-loans-account.component.ts @@ -67,9 +67,10 @@ export class CreateLoansAccountComponent implements OnInit { this.loansService.getLoansCollateralTemplateResource(this.loansAccountProductTemplate.loanProductId).subscribe((response: any) => { this.collateralOptions = response.loanCollateralOptions; }); - const clientId = this.loansAccountTemplate.clientId; + const entityId = (this.loansAccountTemplate.clientId) ? this.loansAccountTemplate.clientId : this.loansAccountTemplate.group.id; + const isGroup = (this.loansAccountTemplate.clientId) ? false : true; const productId = this.loansAccountProductTemplate.loanProductId; - this.loansService.getLoansAccountTemplateResource(clientId, productId).subscribe((response: any) => { + this.loansService.getLoansAccountTemplateResource(entityId, isGroup, productId).subscribe((response: any) => { this.multiDisburseLoan = response.multiDisburseLoan; }); } @@ -107,10 +108,8 @@ export class CreateLoansAccountComponent implements OnInit { submit() { const locale = this.settingsService.language.code; const dateFormat = this.settingsService.dateFormat; - const loanType = 'individual'; const loansAccountData = { ...this.loansAccount, - clientId: this.loansAccountTemplate.clientId, charges: this.loansAccount.charges.map((charge: any) => ({ chargeId: charge.id, amount: charge.amount, @@ -131,8 +130,14 @@ export class CreateLoansAccountComponent implements OnInit { expectedDisbursementDate: this.dateUtils.formatDate(this.loansAccount.expectedDisbursementDate, dateFormat), dateFormat, locale, - loanType }; + if (this.loansAccountTemplate.clientId) { + loansAccountData.clientId = this.loansAccountTemplate.clientId; + loansAccountData.loanType = 'individual'; + } else { + loansAccountData.groupId = this.loansAccountTemplate.group.id; + loansAccountData.loanType = 'group'; + } if (loansAccountData.syncRepaymentsWithMeeting) { loansAccountData.calendarId = this.loansAccountProductTemplate.calendarOptions[0].id; diff --git a/src/app/loans/loans-account-stepper/loans-account-details-step/loans-account-details-step.component.ts b/src/app/loans/loans-account-stepper/loans-account-details-step/loans-account-details-step.component.ts index 203e96c14..6eaf81a76 100644 --- a/src/app/loans/loans-account-stepper/loans-account-details-step/loans-account-details-step.component.ts +++ b/src/app/loans/loans-account-stepper/loans-account-details-step/loans-account-details-step.component.ts @@ -88,9 +88,10 @@ export class LoansAccountDetailsStepComponent implements OnInit { * Fetches loans account product template on productId value changes */ buildDependencies() { - const clientId = this.loansAccountTemplate.clientId; + const entityId = (this.loansAccountTemplate.clientId) ? this.loansAccountTemplate.clientId : this.loansAccountTemplate.group.id; + const isGroup = (this.loansAccountTemplate.clientId) ? false : true; this.loansAccountDetailsForm.get('productId').valueChanges.subscribe((productId: string) => { - this.loansService.getLoansAccountTemplateResource(clientId, productId).subscribe((response: any) => { + this.loansService.getLoansAccountTemplateResource(entityId, isGroup, productId).subscribe((response: any) => { this.loansAccountProductTemplate.emit(response); this.loanOfficerOptions = response.loanOfficerOptions; this.loanPurposeOptions = response.loanPurposeOptions; diff --git a/src/app/loans/loans.service.ts b/src/app/loans/loans.service.ts index 7c4d55991..8f944557c 100644 --- a/src/app/loans/loans.service.ts +++ b/src/app/loans/loans.service.ts @@ -268,12 +268,14 @@ export class LoansService { * @param {any} clientId Client ID * @param {any} productId Product ID */ - getLoansAccountTemplateResource(clientId: any, productId?: any): Observable { + getLoansAccountTemplateResource(entityId: any, isGroup: boolean, productId?: any): Observable { let httpParams = new HttpParams().set('activeOnly', 'true') - .set('clientId', clientId) - .set('staffInSelectedOfficeOnly', 'true') - .set('templateType', 'individual'); + .set('staffInSelectedOfficeOnly', 'true'); httpParams = productId ? httpParams.set('productId', productId) : httpParams; + httpParams = isGroup ? httpParams.set('groupId', entityId) + .set('templateType', 'group') : + httpParams.set('clientId', entityId) + .set('templateType', 'individual'); return this.http.get('/loans/template', { params: httpParams }); }