Skip to content

Commit 87b9c7f

Browse files
committed
WEB-95 Fix problems with GLIM application: saved total ,Moratorium, Overdue Charges
1 parent 00da30b commit 87b9c7f

File tree

6 files changed

+151
-87
lines changed

6 files changed

+151
-87
lines changed

src/app/loans/glim-account/create-glim-account/create-glim-account.component.ts

Lines changed: 26 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -177,37 +177,36 @@ export class CreateGlimAccountComponent {
177177
};
178178
}
179179

180-
setData(client: any, totalLoan: number): any {
180+
setData(client: any, totalLoan: number, isParent?: boolean): any {
181181
const locale = this.settingsService.language.code;
182182
const dateFormat = this.settingsService.dateFormat;
183183
// const monthDayFormat = 'dd MMMM';
184-
const data = {
184+
const data: any = {
185185
...this.loansAccount,
186186
charges: this.loansAccount.charges.map((charge: any) => ({
187187
chargeId: charge.id,
188188
amount: charge.amount
189189
})),
190190
clientId: client.id,
191-
totalLoan: totalLoan,
192191
loanType: 'glim',
193192
amortizationType: 1,
194-
isParentAccount: true,
195193
principal: client.principal,
196194
syncDisbursementWithMeeting: false,
197195
expectedDisbursementDate: this.dateUtils.formatDate(this.loansAccount.expectedDisbursementDate, dateFormat),
198196
submittedOnDate: this.dateUtils.formatDate(this.loansAccount.submittedOnDate, dateFormat),
199-
dateFormat,
200-
// monthDayFormat,
201-
locale
197+
dateFormat: dateFormat,
198+
locale: locale,
199+
groupId: this.loansAccountTemplate.group.id
202200
};
203-
data.groupId = this.loansAccountTemplate.group.id;
204-
201+
if (isParent) {
202+
data.totalLoan = totalLoan;
203+
data.isParentAccount = true;
204+
}
205205
delete data.principalAmount;
206206
// TODO: 2025-03-17: Apparently (?!) unsupported for GLIM
207207
delete data.allowPartialPeriodInterestCalculation;
208208
delete data.multiDisburseLoan;
209209
delete data.isFloatingInterestRate;
210-
211210
return JSON.stringify(data);
212211
}
213212

@@ -216,12 +215,22 @@ export class CreateGlimAccountComponent {
216215
const requestData = [];
217216
const memberSelected = this.selectedMembers?.selectedMembers ?? [];
218217
const totalLoan = this.totalLoanAmount();
218+
requestData.push({
219+
requestId: '0',
220+
method: 'POST',
221+
relativeUrl: 'loans',
222+
body: this.setData(
223+
{ id: this.loansAccountTemplate.group.id, principal: totalLoan, isParentAccount: true },
224+
totalLoan,
225+
true
226+
)
227+
});
219228
for (let index = 0; index < memberSelected.length; index++) {
220229
requestData.push({
221-
requestId: index.toString(),
230+
requestId: (index + 1).toString(),
222231
method: 'POST',
223232
relativeUrl: 'loans',
224-
body: this.setData(memberSelected[index], totalLoan)
233+
body: this.setData(memberSelected[index], totalLoan, false)
225234
});
226235
}
227236
return requestData;
@@ -236,57 +245,10 @@ export class CreateGlimAccountComponent {
236245
return total;
237246
}
238247

239-
/**
240-
* Creates a new GLIM account.
241-
*/
242-
submit() {
243-
this.selectedMembers = this.loansActiveClientMembers?.selectedClientMembers;
244-
const memberSelected = this.loansActiveClientMembers?.selectedClientMembers?.selectedMembers ?? [];
245-
if (!memberSelected.length) return;
246-
const gsimMemberIds = new Set(this.dataSource.map((m: any) => Number(m.id)));
247-
for (const member of memberSelected) {
248-
const memberId = Number(member.id);
249-
// Validate savings account ownership
250-
const ownerId = Number(member.linkAccountOwnerId);
251-
if (member.linkAccountId && member.linkAccountOwnerId && ownerId !== memberId) {
252-
this.i18nService.translate('errors.linkedSavingsAccountOwnership').subscribe((msg: string) => {
253-
this.notify({ defaultUserMessage: msg, errors: [] }, { memberId });
254-
});
255-
return;
256-
}
257-
// Validate GSIM membership
258-
if (!gsimMemberIds.has(memberId)) {
259-
this.i18nService.translate('errors.clientNotInGSIM', { id: memberId }).subscribe((msg: string) => {
260-
this.notify({ defaultUserMessage: msg, errors: [] }, { memberId });
261-
});
262-
return;
263-
}
264-
}
265-
266-
// Use date format from settingsService for interestChargedFromDate
267-
const data = this.buildRequestData();
268-
this.loansService.createGlimAccount(data).subscribe((response: any) => {
269-
const body = JSON.parse(response[0].body);
270-
if (body.glimId) {
271-
this.router.navigate(
272-
[
273-
'../',
274-
body.glimId
275-
],
276-
{ relativeTo: this.route }
277-
);
278-
} else {
279-
this.notify(body, { batchSize: data.length });
280-
}
281-
});
282-
}
283-
284-
notify(body: any, context?: { [k: string]: unknown }) {
285-
const parts: string[] = [String(body?.defaultUserMessage ?? '')];
286-
if (Array.isArray(body?.errors)) {
287-
for (const e of body.errors) parts.push(String(e?.developerMessage ?? ''));
288-
}
289-
if (context) parts.push(`Context: ${JSON.stringify(context)}`);
290-
console.error(parts.join(' ').trim());
248+
notify(body: any, data: any) {
249+
let message = body.defaultUserMessage + ' ';
250+
body.errors?.forEach((error: any) => (message += error.developerMessage + ' '));
251+
message += 'Data: ' + JSON.stringify(data);
252+
console.error(message);
291253
}
292254
}

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@
3939
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.Amount' | translate }}</th>
4040
<td mat-cell *matCellDef="let charge">
4141
{{ charge.amount }}
42-
<button mat-icon-button color="primary" (click)="editChargeAmount(charge)">
42+
<button
43+
mat-icon-button
44+
color="primary"
45+
(click)="editChargeAmount(charge)"
46+
type="button"
47+
aria-label="Edit charge amount"
48+
>
4349
<fa-icon icon="pen"></fa-icon>
4450
</button>
4551
</td>
@@ -84,6 +90,8 @@
8490
charge.chargeTimeType.value === 'Specified due date'
8591
"
8692
(click)="editChargeDate(charge)"
93+
type="button"
94+
aria-label="Edit charge date"
8795
>
8896
<fa-icon icon="pen"></fa-icon>
8997
</button>
@@ -93,7 +101,7 @@
93101
<ng-container matColumnDef="action">
94102
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.Actions' | translate }}</th>
95103
<td mat-cell *matCellDef="let charge">
96-
<button mat-icon-button color="warn" (click)="deleteCharge(charge)">
104+
<button mat-icon-button color="warn" (click)="deleteCharge(charge)" type="button" aria-label="Delete charge">
97105
<fa-icon icon="trash"></fa-icon>
98106
</button>
99107
</td>
@@ -120,7 +128,18 @@ <h4 class="mat-h4 flex-98">{{ 'labels.heading.Overdue Charges' | translate }}</h
120128

121129
<ng-container matColumnDef="amount">
122130
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.Amount' | translate }}</th>
123-
<td mat-cell *matCellDef="let charge">{{ charge.amount | formatNumber }}</td>
131+
<td mat-cell *matCellDef="let charge">
132+
{{ charge.amount | formatNumber }}
133+
<button
134+
mat-icon-button
135+
color="primary"
136+
(click)="editOverdueChargeAmount(charge)"
137+
type="button"
138+
aria-label="Edit overdue charge amount"
139+
>
140+
<fa-icon icon="pen"></fa-icon>
141+
</button>
142+
</td>
124143
</ng-container>
125144

126145
<ng-container matColumnDef="collectedon">
@@ -134,15 +153,15 @@ <h4 class="mat-h4 flex-98">{{ 'labels.heading.Overdue Charges' | translate }}</h
134153
</div>
135154

136155
<div class="layout-row responsive-column align-center gap-2px margin-t">
137-
<button mat-raised-button matStepperPrevious>
156+
<button mat-raised-button matStepperPrevious type="button">
138157
<fa-icon icon="arrow-left" class="m-r-10"></fa-icon>
139158
{{ 'labels.buttons.Previous' | translate }}
140159
</button>
141-
<button mat-raised-button matStepperNext>
160+
<button mat-raised-button matStepperNext type="button">
142161
{{ 'labels.buttons.Next' | translate }}
143162
<fa-icon icon="arrow-right" class="m-l-10"></fa-icon>
144163
</button>
145-
<button mat-raised-button *ngIf="loanId" [routerLink]="['../', 'general']">
164+
<button mat-raised-button *ngIf="loanId" [routerLink]="['../', 'general']" type="button">
146165
{{ 'labels.buttons.Cancel' | translate }}
147166
</button>
148167
</div>

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,33 @@ export class LoansAccountChargesStepComponent implements OnInit, OnChanges {
326326
});
327327
}
328328

329+
editOverdueChargeAmount(charge: { amount: number; [key: string]: any }) {
330+
const formfields: FormfieldBase[] = [
331+
new InputBase({
332+
controlName: 'amount',
333+
label: 'Amount',
334+
value: charge.amount,
335+
type: 'number',
336+
required: false
337+
})
338+
339+
];
340+
const data = {
341+
title: 'Edit Overdue Charge Amount',
342+
layout: { addButtonText: 'Confirm' },
343+
formfields: formfields
344+
};
345+
const editNoteDialogRef = this.dialog.open(FormDialogComponent, { data });
346+
editNoteDialogRef.afterClosed().subscribe((response: { data?: { value: { amount: number } } }) => {
347+
if (response.data) {
348+
const newCharge = { ...charge, amount: response.data.value.amount };
349+
this.overDueChargesDataSource.splice(this.overDueChargesDataSource.indexOf(charge), 1, newCharge);
350+
this.overDueChargesDataSource = this.overDueChargesDataSource.concat([]);
351+
}
352+
});
353+
this.pristine = false;
354+
}
355+
329356
get isValid() {
330357
return true;
331358
// !this.activeClientMembers ||

0 commit comments

Comments
 (0)