Skip to content

Commit 35f5839

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

9 files changed

Lines changed: 153 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: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,23 @@ 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+
this.loansAccountAndTemplate['edit'] = true;
85+
if (this.loanProductService.isLoanProduct) {
86+
this.loansAccountProductTemplate = data.loansAccountAndTemplate;
87+
} else if (this.loanProductService.isWorkingCapital) {
88+
this.loansAccountProductTemplate = data.loansAccountAndTemplate;
89+
this.getWorkingCapitalLoanProductTemplate(
90+
this.loansAccountProductTemplate.client.id,
91+
this.loansAccountProductTemplate.product.id
92+
);
93+
}
8494
this.loanProductsBasicDetails = data.loanProductsBasicDetails;
8595
}
8696
);
87-
this.loanId = this.route.snapshot.params['loanId'];
8897
}
8998

9099
/**
@@ -95,6 +104,15 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
95104
const templateData: any = $event;
96105
this.loansAccountProductTemplate = templateData.loanData ? templateData.loanData : templateData;
97106
this.currencyCode = this.loansAccountProductTemplate.currency.code;
107+
this.productDetails = this.loansAccountProductTemplate.product;
108+
if (templateData.loanData) {
109+
this.loansAccountProductTemplate = templateData.loanData;
110+
this.loansAccountProductTemplate.options = {
111+
delinquencyBucketOptions: templateData.delinquencyBucketOptions,
112+
fundOptions: templateData.fundOptions,
113+
periodFrequencyTypeOptions: templateData.periodFrequencyTypeOptions
114+
};
115+
}
98116
if (this.loansAccountProductTemplate.loanProductId) {
99117
this.loansService
100118
.getLoansCollateralTemplateResource(this.loansAccountProductTemplate.loanProductId)
@@ -104,6 +122,12 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
104122
}
105123
}
106124

125+
getWorkingCapitalLoanProductTemplate(clientId: number, productId: number) {
126+
this.loansService.getWorkingCapitalLoansAccountTemplate(clientId, productId).subscribe((response: any) => {
127+
this.setTemplate(response);
128+
});
129+
}
130+
107131
setProductType($event: any): void {
108132
this.productType = $event;
109133
this.loanProductService.initialize(this.productType);
@@ -131,7 +155,11 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
131155
!this.loansAccountChargesStep?.pristine)
132156
);
133157
} else if (this.loanProductService.isWorkingCapital) {
134-
return false;
158+
return (
159+
this.loansAccountDetailsForm.valid &&
160+
this.loansAccountTermsForm.valid &&
161+
(!this.loansAccountDetailsForm.pristine || !this.loansAccountTermsForm.pristine)
162+
);
135163
}
136164
}
137165

@@ -241,15 +269,60 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
241269
loansAccountData.allowPartialPeriodInterestCalculation = loansAccountData.allowPartialPeriodInterestCalculation;
242270
delete loansAccountData.allowPartialPeriodInterestCalculation;
243271

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
272+
this.loansService
273+
.updateLoansAccount(this.loanProductService.loanAccountPath, this.loanId, loansAccountData)
274+
.subscribe((response: any) => {
275+
this.router.navigate(['../'], {
276+
queryParams: {
277+
productType: this.loanProductService.productType.value
278+
},
279+
relativeTo: this.route
280+
});
250281
});
251-
});
252282
}
253283

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

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+
periodPaymentFrequencyType: 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)