feat(fixed-deposits): FD Maturity Reports component (missed from prior commit)
The component, service and template for the FD Maturity Reports screen itself — the previous commit wired up its route, nav entry and the day-close/product-summary integration, but the new directory was never staged alongside them. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,406 @@
|
||||
<!--
|
||||
Copyright since 2025 Mifos Initiative
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
-->
|
||||
|
||||
<div class="fd">
|
||||
<div class="fd-head">
|
||||
<div>
|
||||
<h2 class="fd-head-t"><fa-icon icon="calendar-check"></fa-icon> FD Maturity Reports</h2>
|
||||
<div class="fd-head-s">
|
||||
Every branch gets its own report of the fixed deposits maturing with no closure instruction of their own,
|
||||
generated automatically at 12:00 noon. One user puts the figures up and a second approves them — whoever
|
||||
generated a report cannot approve it. Approving sets in motion the whole event: status, final interest, and any
|
||||
renewal, all together, when the branch closes its day. A deposit that already named Transfer to Savings or a
|
||||
Reinvest option settles itself the moment it matures, exactly as it always has — see "Matured automatically" for
|
||||
those.
|
||||
</div>
|
||||
</div>
|
||||
<div class="fd-head-a">
|
||||
<label class="fd-date">
|
||||
Posting date
|
||||
<input type="date" [(ngModel)]="postingDate" (change)="load()" />
|
||||
</label>
|
||||
<button class="fd-btn" (click)="load()" [disabled]="loading"><fa-icon icon="undo"></fa-icon>Reload</button>
|
||||
<button class="fd-btn" (click)="openAutoMatured()" [disabled]="autoMaturedLoading">
|
||||
<fa-icon icon="bolt"></fa-icon>Matured automatically
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!approvalEnabled) {
|
||||
<div class="fd-alert fd-alert--info">
|
||||
<fa-icon icon="info-circle"></fa-icon>
|
||||
<div>
|
||||
Fixed deposit maturities are currently settled directly by the nightly job, so there is nothing to approve here.
|
||||
Turn on <strong>fd-maturity-interest-posting-approval</strong> under System → Configurations to put
|
||||
maturities behind this report.
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (isHeadOffice) {
|
||||
<div class="fd-tabs">
|
||||
<button class="fd-tab" [class.is-active]="tab === 'own'" (click)="switchTab('own')">
|
||||
<fa-icon icon="building"></fa-icon>My branch{{ myBranch ? ' — ' + myBranch : '' }}
|
||||
</button>
|
||||
<button class="fd-tab" [class.is-active]="tab === 'others'" (click)="switchTab('others')">
|
||||
<fa-icon icon="sitemap"></fa-icon>Other branches
|
||||
</button>
|
||||
</div>
|
||||
@if (tab === 'others') {
|
||||
<div class="fd-alert fd-alert--info">
|
||||
<fa-icon icon="info-circle"></fa-icon>
|
||||
<div>
|
||||
Each branch generates and approves its own report. The head office can act here only for a branch that has not
|
||||
opened the day, and only once every other open branch has closed. Anything it approves is marked (HO).
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@if (errorMessage) {
|
||||
<div class="fd-alert fd-alert--error">
|
||||
<fa-icon icon="exclamation-triangle"></fa-icon>
|
||||
<div>{{ errorMessage }}</div>
|
||||
</div>
|
||||
}
|
||||
@if (notice) {
|
||||
<div class="fd-alert fd-alert--ok">
|
||||
<fa-icon icon="check"></fa-icon>
|
||||
<div>{{ notice }}</div>
|
||||
</div>
|
||||
}
|
||||
@if (pendingCount > 0) {
|
||||
<div class="fd-alert fd-alert--warn">
|
||||
<fa-icon icon="clock"></fa-icon>
|
||||
<div>
|
||||
<strong>{{ pendingCount }} report(s) waiting for approval.</strong> The day cannot be closed until they are
|
||||
approved, and the user who generated a report cannot be the one to approve it.
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (due.length > 0) {
|
||||
<div class="fd-alert fd-alert--warn">
|
||||
<fa-icon icon="exclamation-triangle"></fa-icon>
|
||||
<div class="fd-due-body">
|
||||
<div>Fixed deposits are maturing but no report has been generated yet for:</div>
|
||||
@for (d of due; track d.officeId) {
|
||||
<div class="fd-due-row">
|
||||
<strong>{{ d.officeName }}</strong>
|
||||
<span>
|
||||
· {{ d.postingDate }} · {{ d.accountCount }} deposit(s) · est. ₹{{
|
||||
d.totalInterest | number: '1.2-2'
|
||||
}}
|
||||
</span>
|
||||
@if (d.canAct) {
|
||||
<button class="fd-btn fd-btn--primary fd-btn--slim" (click)="generate(d)" [disabled]="busy">
|
||||
<fa-icon icon="sync"></fa-icon>{{ tab === 'others' ? 'Generate on behalf' : 'Generate report' }}
|
||||
</button>
|
||||
} @else if (d.blockedReason) {
|
||||
<span class="fd-blocked">{{ d.blockedReason }}</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Summary strip -->
|
||||
<div class="fd-summary">
|
||||
<div class="fd-stat">
|
||||
<div class="fd-stat__label">Maturing, no report</div>
|
||||
<div class="fd-stat__value">₹{{ dueTotal | number: '1.2-2' }}</div>
|
||||
<div class="fd-stat__sub">{{ dueAccountTotal }} deposit(s)</div>
|
||||
</div>
|
||||
<div class="fd-stat fd-stat--warn">
|
||||
<div class="fd-stat__label">Awaiting approval</div>
|
||||
<div class="fd-stat__value">₹{{ awaitingTotal | number: '1.2-2' }}</div>
|
||||
<div class="fd-stat__sub">{{ awaitingReports.length }} report(s) · blocking day close</div>
|
||||
</div>
|
||||
<div class="fd-stat fd-stat--ok">
|
||||
<div class="fd-stat__label">Approved — runs at close</div>
|
||||
<div class="fd-stat__value">₹{{ approvedTotal | number: '1.2-2' }}</div>
|
||||
<div class="fd-stat__sub">{{ approvedReports.length }} report(s)</div>
|
||||
</div>
|
||||
<div class="fd-stat fd-stat--posted">
|
||||
<div class="fd-stat__label">Matured today</div>
|
||||
<div class="fd-stat__value">₹{{ postedTotal | number: '1.2-2' }}</div>
|
||||
<div class="fd-stat__sub">{{ postedReports.length }} report(s)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (showAutoMatured) {
|
||||
<div class="fd-card">
|
||||
<div class="fd-detail-head">
|
||||
<div>
|
||||
<h3>Fixed deposits matured automatically</h3>
|
||||
<div class="muted">
|
||||
A deposit that named Transfer to Savings or a Reinvest option on its own closure needs no approval here — it
|
||||
settles the moment it matures, as it always has. Listed so nothing that moved is invisible, approved or not.
|
||||
</div>
|
||||
</div>
|
||||
<div class="fd-total">
|
||||
<span>Deposits</span>
|
||||
<strong>{{ autoMaturedRows.length }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 10px;
|
||||
padding: 14px 20px;
|
||||
border-bottom: 1px solid var(--fd-border-soft);
|
||||
"
|
||||
>
|
||||
<label class="fd-date">
|
||||
From
|
||||
<input type="date" [(ngModel)]="autoMaturedFrom" (change)="loadAutoMatured()" />
|
||||
</label>
|
||||
<label class="fd-date">
|
||||
To
|
||||
<input type="date" [(ngModel)]="autoMaturedTo" (change)="loadAutoMatured()" />
|
||||
</label>
|
||||
<button class="fd-btn fd-btn--slim" (click)="loadAutoMatured()" [disabled]="autoMaturedLoading">
|
||||
<fa-icon icon="undo"></fa-icon>Refresh
|
||||
</button>
|
||||
<button class="fd-btn fd-btn--slim" (click)="closeAutoMatured()"><fa-icon icon="times"></fa-icon>Close</button>
|
||||
</div>
|
||||
@if (autoMaturedLoading) {
|
||||
<div class="fd-empty">Looking for deposits that matured outside this report…</div>
|
||||
} @else {
|
||||
<div class="fd-table-wrap">
|
||||
<table class="fd-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Product</th>
|
||||
<th>Scheme</th>
|
||||
<th class="num">Deposits</th>
|
||||
<th class="num">Principal</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (g of autoMaturedGroups; track g.productName) {
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{{ g.productName }}</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span class="fd-chip" [ngClass]="fdTypeClass(g.fdType)">{{ fdTypeShort(g.fdType) }}</span>
|
||||
</td>
|
||||
<td class="num">{{ g.accounts }}</td>
|
||||
<td class="num">₹{{ g.deposit | number: '1.2-2' }}</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="4" class="fd-empty">No fixed deposit matured automatically in this period.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@if (autoMaturedRows.length > 0) {
|
||||
<div class="fd-table-wrap">
|
||||
<table class="fd-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Account no</th>
|
||||
<th>Customer</th>
|
||||
<th>Product</th>
|
||||
<th>Scheme</th>
|
||||
<th>Maturity date</th>
|
||||
<th class="num">Deposit</th>
|
||||
<th>On closure</th>
|
||||
<th>Matured on</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (r of autoMaturedRows; track r.fdAccountId) {
|
||||
<tr>
|
||||
<td class="fd-mono">{{ r.accountNo }}</td>
|
||||
<td>{{ r.clientName }}</td>
|
||||
<td>{{ r.productName }}</td>
|
||||
<td>
|
||||
<span class="fd-chip" [ngClass]="fdTypeClass(r.fdType)">{{ fdTypeShort(r.fdType) }}</span>
|
||||
</td>
|
||||
<td class="fd-mono">{{ r.maturityDate }}</td>
|
||||
<td class="num">₹{{ r.depositAmount | number: '1.2-2' }}</td>
|
||||
<td class="fd-sub">{{ closureLabel(r.closureInstruction) }}</td>
|
||||
<td class="fd-mono">{{ r.maturedOn }}</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="fd-card">
|
||||
<div class="fd-card-h">
|
||||
<h2>Reports{{ postingDate ? ' for ' + postingDate : '' }}</h2>
|
||||
<span class="fd-card-sub">One report per branch</span>
|
||||
</div>
|
||||
<div class="fd-table-wrap">
|
||||
<table class="fd-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Branch</th>
|
||||
<th>Posting date</th>
|
||||
<th class="num">Deposits</th>
|
||||
<th class="num">Est. interest</th>
|
||||
<th>Status</th>
|
||||
<th>Maker</th>
|
||||
<th>Checker</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (r of reports; track r.id) {
|
||||
<tr class="is-clickable" [class.is-selected]="selected?.id === r.id" (click)="open(r)">
|
||||
<td>{{ r.officeName }}</td>
|
||||
<td class="fd-mono">{{ r.postingDate }}</td>
|
||||
<td class="num">{{ r.accountCount }}</td>
|
||||
<td class="num">₹{{ r.totalInterest | number: '1.2-2' }}</td>
|
||||
<td>
|
||||
<span class="fd-badge" [ngClass]="statusClass(r.status)">{{ r.status }}</span>
|
||||
@if (r.failureReason) {
|
||||
<div class="fd-fail" [title]="r.failureReason">Some deposits could not mature — see detail</div>
|
||||
}
|
||||
</td>
|
||||
<td class="fd-sub">
|
||||
{{ r.generatedBy || 'System' }} · {{ r.generationMode }}<br />{{
|
||||
r.generatedAt | date: 'dd MMM, HH:mm'
|
||||
}}
|
||||
</td>
|
||||
<td class="fd-sub">
|
||||
@if (r.approvedAt) {
|
||||
{{ r.approvedBy }}
|
||||
@if (r.approvedOnBehalf) {
|
||||
<span class="fd-behalf">(HO)</span>
|
||||
}
|
||||
<br />{{ r.approvedAt | date: 'dd MMM, HH:mm' }}
|
||||
} @else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
<td (click)="$event.stopPropagation()">
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end">
|
||||
@if (canRegenerate(r)) {
|
||||
<button class="fd-btn fd-btn--slim" (click)="regenerate(r)" [disabled]="busy">
|
||||
<fa-icon icon="sync"></fa-icon>Regenerate
|
||||
</button>
|
||||
}
|
||||
@if (canApprove(r)) {
|
||||
<button class="fd-btn fd-btn--primary fd-btn--slim" (click)="approve(r)" [disabled]="busy">
|
||||
<fa-icon icon="check"></fa-icon>{{ tab === 'others' ? 'Approve on behalf' : 'Approve' }}
|
||||
</button>
|
||||
} @else if (r.status === 'GENERATED' && r.approveBlockedReason) {
|
||||
<span class="fd-blocked">{{ r.approveBlockedReason }}</span>
|
||||
}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="8" class="fd-empty">
|
||||
@if (loading) {
|
||||
Loading…
|
||||
} @else {
|
||||
No fixed deposit maturity report for {{ postingDate || 'this date' }}. Reports are generated at 12:00
|
||||
noon on the posting date.
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (selected) {
|
||||
<div class="fd-card">
|
||||
<div class="fd-detail-head">
|
||||
<div>
|
||||
<h3>
|
||||
{{ selected.officeName }} — {{ selected.postingDate }}
|
||||
<span class="fd-badge" [ngClass]="statusClass(selected.status)">{{ selected.status }}</span>
|
||||
</h3>
|
||||
<div class="muted">
|
||||
Approving runs the real maturity settlement for every deposit below — status, final interest and closure,
|
||||
together.
|
||||
</div>
|
||||
</div>
|
||||
<div class="fd-total">
|
||||
<span>Total estimated interest</span>
|
||||
<strong>₹{{ selected.totalInterest | number: '1.2-2' }}</strong>
|
||||
<span class="muted">{{ selected.accountCount }} deposit(s)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fd-table-wrap">
|
||||
<table class="fd-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Account no</th>
|
||||
<th>Account holder</th>
|
||||
<th>Scheme</th>
|
||||
<th>Maturity date</th>
|
||||
<th class="num">Deposit</th>
|
||||
<th class="num">Rate %</th>
|
||||
<th class="num">Est. interest</th>
|
||||
<th>On closure</th>
|
||||
<th>Matured</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (l of selected.lines; track l.fdAccountId) {
|
||||
<tr>
|
||||
<td class="fd-mono">{{ l.accountNo }}</td>
|
||||
<td>{{ l.clientName }}</td>
|
||||
<td>
|
||||
<span class="fd-chip" [ngClass]="fdTypeClass(l.fdType)">{{ fdTypeShort(l.fdType) }}</span>
|
||||
</td>
|
||||
<td class="fd-mono">{{ l.maturityDate }}</td>
|
||||
<td class="num">₹{{ l.depositAmount | number: '1.2-2' }}</td>
|
||||
<td class="num">{{ l.interestRate | number: '1.2-2' }}</td>
|
||||
<td class="num">₹{{ l.estimatedInterest | number: '1.2-2' }}</td>
|
||||
<td class="fd-sub">
|
||||
{{ closureLabel(l.closureInstruction) }}
|
||||
@if (l.closureAccountNo) {
|
||||
<br /><span class="fd-mono">{{ l.closureAccountNo }}</span>
|
||||
}
|
||||
</td>
|
||||
<td class="fd-sub">
|
||||
@if (l.postedAt) {
|
||||
{{ l.postedAt | date: 'dd MMM, HH:mm' }}
|
||||
} @else if (l.failureReason) {
|
||||
<span class="fd-fail" [title]="l.failureReason">Failed</span>
|
||||
} @else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="6"><strong>Total</strong></td>
|
||||
<td class="num">
|
||||
<strong>₹{{ selected.totalInterest | number: '1.2-2' }}</strong>
|
||||
</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,367 @@
|
||||
/**
|
||||
* Copyright since 2025 Mifos Initiative
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { Component, OnInit, inject } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
||||
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import {
|
||||
FdAutoMaturedRow,
|
||||
FdMaturityDue,
|
||||
FdMaturityReport,
|
||||
FdMaturityReportDetail,
|
||||
FdMaturityReportService,
|
||||
FdReportScope,
|
||||
FdType
|
||||
} from './fd-maturity-report.service';
|
||||
|
||||
/**
|
||||
* Fixed deposit maturity reports.
|
||||
*
|
||||
* Until a report here is approved, a deposit whose term has ended simply waits — ACTIVE, not MATURED.
|
||||
* Approving it is authorising the whole event: its final interest, the move to MATURED, and any
|
||||
* renewal or transfer-to-savings instruction, all of which run together, unchanged, the moment the
|
||||
* branch closes the day. The maker cannot be the checker, for the same reason as the interest report:
|
||||
* this moves a customer's principal, not only its interest.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-fd-maturity-report',
|
||||
templateUrl: './fd-maturity-report.component.html',
|
||||
styleUrls: ['../fd-interest-posting-report/fd-interest-posting-report.component.scss'],
|
||||
imports: [
|
||||
...STANDALONE_SHARED_IMPORTS,
|
||||
FormsModule,
|
||||
FaIconComponent
|
||||
]
|
||||
})
|
||||
export class FdMaturityReportComponent implements OnInit {
|
||||
private reportService = inject(FdMaturityReportService);
|
||||
private settingsService = inject(SettingsService);
|
||||
|
||||
postingDate = '';
|
||||
loading = false;
|
||||
busy = false;
|
||||
errorMessage = '';
|
||||
notice = '';
|
||||
|
||||
reports: FdMaturityReport[] = [];
|
||||
selected: FdMaturityReportDetail | null = null;
|
||||
due: FdMaturityDue[] = [];
|
||||
|
||||
tab: FdReportScope = 'own';
|
||||
isHeadOffice = false;
|
||||
myBranch = '';
|
||||
approvalEnabled = true;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.postingDate = this.businessDateIso();
|
||||
this.reportService.context().subscribe({
|
||||
next: (ctx) => {
|
||||
this.isHeadOffice = !!ctx?.headOffice;
|
||||
this.myBranch = ctx?.officeName ?? '';
|
||||
this.approvalEnabled = ctx?.approvalEnabled !== false;
|
||||
},
|
||||
error: () => (this.isHeadOffice = false)
|
||||
});
|
||||
this.load();
|
||||
}
|
||||
|
||||
switchTab(tab: FdReportScope): void {
|
||||
if (this.tab === tab) {
|
||||
return;
|
||||
}
|
||||
this.tab = tab;
|
||||
this.selected = null;
|
||||
this.notice = '';
|
||||
this.load();
|
||||
}
|
||||
|
||||
private confirmOnBehalf(officeName: string, action: string): boolean {
|
||||
if (this.tab !== 'others') {
|
||||
return true;
|
||||
}
|
||||
return confirm(
|
||||
`${officeName} has not opened today. You are about to ${action} its fixed deposit maturity report on its ` +
|
||||
'behalf, from the head office. Continue?'
|
||||
);
|
||||
}
|
||||
|
||||
load(): void {
|
||||
this.loading = true;
|
||||
this.errorMessage = '';
|
||||
this.reportService.list(this.postingDate || undefined, undefined, undefined, this.tab).subscribe({
|
||||
next: (reports) => {
|
||||
this.reports = reports ?? [];
|
||||
this.loading = false;
|
||||
const stillThere = this.selected && this.reports.find((r) => r.id === this.selected?.id);
|
||||
if (stillThere) {
|
||||
this.open(stillThere);
|
||||
} else {
|
||||
this.selected = null;
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
this.loading = false;
|
||||
this.errorMessage = this.messageOf(err, 'Could not load the fixed deposit maturity reports.');
|
||||
}
|
||||
});
|
||||
this.reportService.dueWithoutReport(this.postingDate || undefined, this.tab).subscribe({
|
||||
next: (due) => (this.due = due ?? []),
|
||||
error: () => (this.due = [])
|
||||
});
|
||||
}
|
||||
|
||||
generate(item: FdMaturityDue): void {
|
||||
if (!this.confirmOnBehalf(item.officeName, 'generate')) {
|
||||
return;
|
||||
}
|
||||
this.busy = true;
|
||||
this.notice = '';
|
||||
this.errorMessage = '';
|
||||
this.reportService.regenerate(item.officeId, item.postingDate).subscribe({
|
||||
next: (res) => {
|
||||
this.busy = false;
|
||||
this.notice = `Report generated for ${item.officeName}. Another user of the branch has to approve it.`;
|
||||
this.load();
|
||||
this.reportService.detail(res.reportId).subscribe((detail) => (this.selected = detail));
|
||||
},
|
||||
error: (err) => {
|
||||
this.busy = false;
|
||||
this.errorMessage = this.messageOf(err, 'Could not generate the report.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
open(report: FdMaturityReport): void {
|
||||
this.errorMessage = '';
|
||||
this.reportService.detail(report.id).subscribe({
|
||||
next: (detail) => (this.selected = detail),
|
||||
error: (err) => (this.errorMessage = this.messageOf(err, 'Could not load the report.'))
|
||||
});
|
||||
}
|
||||
|
||||
regenerate(report: FdMaturityReport): void {
|
||||
if (
|
||||
!confirm(
|
||||
`Regenerate the fixed deposit maturity report for ${report.officeName}? It will need approving again.`
|
||||
) ||
|
||||
!this.confirmOnBehalf(report.officeName, 'regenerate')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this.busy = true;
|
||||
this.notice = '';
|
||||
this.errorMessage = '';
|
||||
this.reportService.regenerate(report.officeId, report.postingDate).subscribe({
|
||||
next: (res) => {
|
||||
this.busy = false;
|
||||
this.notice = `Report regenerated for ${report.officeName}. Another user of the branch has to approve it.`;
|
||||
this.selected = null;
|
||||
this.load();
|
||||
this.reportService.detail(res.reportId).subscribe((detail) => (this.selected = detail));
|
||||
},
|
||||
error: (err) => {
|
||||
this.busy = false;
|
||||
this.errorMessage = this.messageOf(err, 'Could not regenerate the report.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
approve(report: FdMaturityReport): void {
|
||||
if (
|
||||
!confirm(
|
||||
`Approve ${report.accountCount} deposit(s) maturing in ${report.officeName}, for a final interest of ` +
|
||||
`₹${report.totalInterest}? Status, interest and any renewal or transfer instruction all run when the ` +
|
||||
'branch closes the day.'
|
||||
) ||
|
||||
!this.confirmOnBehalf(report.officeName, 'approve')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this.busy = true;
|
||||
this.notice = '';
|
||||
this.errorMessage = '';
|
||||
this.reportService.approve(report.id).subscribe({
|
||||
next: () => {
|
||||
this.busy = false;
|
||||
this.notice = `Approved. ${report.officeName}'s maturities will run when the branch closes the day.`;
|
||||
this.load();
|
||||
},
|
||||
error: (err) => {
|
||||
this.busy = false;
|
||||
this.errorMessage = this.messageOf(err, 'Could not approve the report.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
canRegenerate(report: FdMaturityReport): boolean {
|
||||
return report.canAct && (report.status === 'GENERATED' || report.status === 'APPROVED');
|
||||
}
|
||||
|
||||
canApprove(report: FdMaturityReport): boolean {
|
||||
return !!report.canApprove;
|
||||
}
|
||||
|
||||
statusClass(status: string): string {
|
||||
return (
|
||||
{
|
||||
GENERATED: 'fd-badge--pending',
|
||||
APPROVED: 'fd-badge--approved',
|
||||
POSTED: 'fd-badge--posted',
|
||||
SUPERSEDED: 'fd-badge--muted'
|
||||
}[status] ?? 'fd-badge--muted'
|
||||
);
|
||||
}
|
||||
|
||||
fdTypeShort(fdType: FdType | string): string {
|
||||
return (
|
||||
{
|
||||
SINGLE: 'Single',
|
||||
DOUBLE: 'Double',
|
||||
SPECIAL: 'Special'
|
||||
}[fdType] ?? String(fdType ?? '')
|
||||
);
|
||||
}
|
||||
|
||||
fdTypeClass(fdType: FdType | string): string {
|
||||
return (
|
||||
{
|
||||
SINGLE: 'fd-chip--single',
|
||||
DOUBLE: 'fd-chip--double',
|
||||
SPECIAL: 'fd-chip--special'
|
||||
}[fdType] ?? 'fd-chip--single'
|
||||
);
|
||||
}
|
||||
|
||||
/** What approving this line sets in motion beyond the interest, spelt out rather than left as a code. */
|
||||
closureLabel(closure: string): string {
|
||||
return (
|
||||
{
|
||||
NONE: 'Sits matured — renew from the FD Dashboard',
|
||||
WITHDRAW_DEPOSIT: 'Paid out on closure',
|
||||
TRANSFER_TO_SAVINGS: 'Transfers to linked savings',
|
||||
REINVEST_PRINCIPAL_AND_INTEREST: 'Reinvests principal + interest',
|
||||
REINVEST_PRINCIPAL_ONLY: 'Reinvests principal only',
|
||||
PARTIAL_REINVEST: 'Partially reinvests'
|
||||
}[closure] ?? closure
|
||||
);
|
||||
}
|
||||
|
||||
get pendingCount(): number {
|
||||
return this.tab === 'own' ? this.reports.filter((r) => r.status === 'GENERATED').length : 0;
|
||||
}
|
||||
|
||||
get dueTotal(): number {
|
||||
return this.due.reduce((sum, d) => sum + Number(d.totalInterest || 0), 0);
|
||||
}
|
||||
|
||||
get dueAccountTotal(): number {
|
||||
return this.due.reduce((sum, d) => sum + Number(d.accountCount || 0), 0);
|
||||
}
|
||||
|
||||
private reportsWithStatus(status: string): FdMaturityReport[] {
|
||||
return this.reports.filter((r) => r.status === status);
|
||||
}
|
||||
|
||||
private totalOf(list: FdMaturityReport[]): number {
|
||||
return list.reduce((sum, r) => sum + Number(r.totalInterest || 0), 0);
|
||||
}
|
||||
|
||||
get awaitingReports(): FdMaturityReport[] {
|
||||
return this.reportsWithStatus('GENERATED');
|
||||
}
|
||||
|
||||
get approvedReports(): FdMaturityReport[] {
|
||||
return this.reportsWithStatus('APPROVED');
|
||||
}
|
||||
|
||||
get postedReports(): FdMaturityReport[] {
|
||||
return this.reportsWithStatus('POSTED');
|
||||
}
|
||||
|
||||
get awaitingTotal(): number {
|
||||
return this.totalOf(this.awaitingReports);
|
||||
}
|
||||
|
||||
get approvedTotal(): number {
|
||||
return this.totalOf(this.approvedReports);
|
||||
}
|
||||
|
||||
get postedTotal(): number {
|
||||
return this.totalOf(this.postedReports);
|
||||
}
|
||||
|
||||
// ── Matured automatically: a deposit with its own closure instruction, settled by the scheduler ──
|
||||
|
||||
showAutoMatured = false;
|
||||
autoMaturedLoading = false;
|
||||
autoMaturedRows: FdAutoMaturedRow[] = [];
|
||||
autoMaturedFrom = '';
|
||||
autoMaturedTo = '';
|
||||
|
||||
openAutoMatured(): void {
|
||||
this.showAutoMatured = true;
|
||||
if (!this.autoMaturedTo) {
|
||||
this.autoMaturedTo = this.businessDateIso();
|
||||
this.autoMaturedFrom = `${this.autoMaturedTo.slice(0, 7)}-01`;
|
||||
}
|
||||
this.loadAutoMatured();
|
||||
}
|
||||
|
||||
loadAutoMatured(): void {
|
||||
this.autoMaturedLoading = true;
|
||||
this.errorMessage = '';
|
||||
this.reportService
|
||||
.autoMatured(this.autoMaturedFrom || undefined, this.autoMaturedTo || undefined, undefined, this.tab)
|
||||
.subscribe({
|
||||
next: (rows) => {
|
||||
this.autoMaturedRows = rows ?? [];
|
||||
this.autoMaturedLoading = false;
|
||||
},
|
||||
error: (err) => {
|
||||
this.autoMaturedLoading = false;
|
||||
this.autoMaturedRows = [];
|
||||
this.errorMessage = this.messageOf(err, 'Could not load deposits that matured automatically.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
closeAutoMatured(): void {
|
||||
this.showAutoMatured = false;
|
||||
}
|
||||
|
||||
/** Totals by product, so a branch can see at a glance which schemes settled themselves and how. */
|
||||
get autoMaturedGroups(): { productName: string; fdType: string; accounts: number; deposit: number }[] {
|
||||
const map = new Map<string, { productName: string; fdType: string; accounts: number; deposit: number }>();
|
||||
this.autoMaturedRows.forEach((r) => {
|
||||
const g = map.get(r.productName) ?? { productName: r.productName, fdType: r.fdType, accounts: 0, deposit: 0 };
|
||||
g.accounts += 1;
|
||||
g.deposit += Number(r.depositAmount || 0);
|
||||
map.set(r.productName, g);
|
||||
});
|
||||
return [...map.values()];
|
||||
}
|
||||
|
||||
private businessDateIso(): string {
|
||||
const businessDate = this.settingsService.businessDate as any;
|
||||
const parsed = businessDate ? new Date(businessDate) : new Date();
|
||||
if (isNaN(parsed.getTime())) {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
const month = String(parsed.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(parsed.getDate()).padStart(2, '0');
|
||||
return `${parsed.getFullYear()}-${month}-${day}`;
|
||||
}
|
||||
|
||||
private messageOf(err: any, fallback: string): string {
|
||||
return (
|
||||
err?.error?.errors?.[0]?.defaultUserMessage ?? err?.error?.defaultUserMessage ?? err?.error?.message ?? fallback
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Copyright since 2025 Mifos Initiative
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export type FdMaturityReportStatus = 'GENERATED' | 'APPROVED' | 'POSTED' | 'SUPERSEDED';
|
||||
export type FdReportScope = 'own' | 'others';
|
||||
export type FdType = 'SINGLE' | 'DOUBLE' | 'SPECIAL';
|
||||
|
||||
export interface FdMaturityReport {
|
||||
id: number;
|
||||
officeId: number;
|
||||
officeName: string;
|
||||
postingDate: string;
|
||||
status: FdMaturityReportStatus;
|
||||
totalInterest: number;
|
||||
accountCount: number;
|
||||
generationMode: 'AUTO' | 'MANUAL';
|
||||
generatedAt: string;
|
||||
generatedBy: string | null;
|
||||
approvedAt: string | null;
|
||||
approvedBy: string | null;
|
||||
approvedOnBehalf: boolean;
|
||||
postedAt: string | null;
|
||||
failureReason: string | null;
|
||||
canAct: boolean;
|
||||
blockedReason: string | null;
|
||||
canApprove: boolean;
|
||||
approveBlockedReason: string | null;
|
||||
}
|
||||
|
||||
export interface FdMaturityReportLine {
|
||||
fdAccountId: number;
|
||||
accountNo: string;
|
||||
clientName: string;
|
||||
productName: string;
|
||||
fdType: FdType;
|
||||
maturityDate: string;
|
||||
depositAmount: number | null;
|
||||
interestRate: number | null;
|
||||
/** What postMaturityInterest will still credit — zero where the last period was already posted. */
|
||||
estimatedInterest: number;
|
||||
/** NONE, WITHDRAW_DEPOSIT, TRANSFER_TO_SAVINGS, REINVEST_PRINCIPAL_AND_INTEREST, REINVEST_PRINCIPAL_ONLY, PARTIAL_REINVEST. */
|
||||
closureInstruction: string;
|
||||
closureAccountNo: string | null;
|
||||
/** Set once this deposit's maturity has actually run. */
|
||||
postedAt: string | null;
|
||||
/** Set where this one deposit's maturity failed — the rest of the report still posts. */
|
||||
failureReason: string | null;
|
||||
}
|
||||
|
||||
export interface FdMaturityReportDetail extends FdMaturityReport {
|
||||
lines: FdMaturityReportLine[];
|
||||
}
|
||||
|
||||
/**
|
||||
* One fixed deposit that matured without this report's approval — a deposit carrying its own closure
|
||||
* instruction, settled directly by the scheduler exactly as it always has been. View only.
|
||||
*/
|
||||
export interface FdAutoMaturedRow {
|
||||
fdAccountId: number;
|
||||
accountNo: string;
|
||||
clientName: string;
|
||||
officeId: number;
|
||||
officeName: string;
|
||||
productId: number;
|
||||
productName: string;
|
||||
fdType: FdType;
|
||||
maturityDate: string;
|
||||
depositAmount: number | null;
|
||||
maturedOn: string;
|
||||
closureInstruction: string;
|
||||
}
|
||||
|
||||
export interface FdMaturityDue {
|
||||
officeId: number;
|
||||
officeName: string;
|
||||
postingDate: string;
|
||||
accountCount: number;
|
||||
totalInterest: number;
|
||||
canAct: boolean;
|
||||
blockedReason: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed deposit maturities, one report per branch per date: every deposit maturing that day, what its
|
||||
* last posting would still come to, and how it closes, approved by a second user before the branch
|
||||
* closes the day and the real maturity — status, interest and any renewal or transfer — actually runs.
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class FdMaturityReportService {
|
||||
private http = inject(HttpClient);
|
||||
private readonly base = '/fixeddepositmaturityreports';
|
||||
|
||||
list(
|
||||
postingDate?: string,
|
||||
status?: string,
|
||||
officeId?: number,
|
||||
scope?: FdReportScope
|
||||
): Observable<FdMaturityReport[]> {
|
||||
let params = new HttpParams();
|
||||
if (scope) params = params.set('scope', scope);
|
||||
if (postingDate) params = params.set('postingDate', postingDate);
|
||||
if (status) params = params.set('status', status);
|
||||
if (officeId) params = params.set('officeId', String(officeId));
|
||||
return this.http.get<FdMaturityReport[]>(this.base, { params });
|
||||
}
|
||||
|
||||
dueWithoutReport(postingDate?: string, scope?: FdReportScope): Observable<FdMaturityDue[]> {
|
||||
let params = new HttpParams();
|
||||
if (scope) params = params.set('scope', scope);
|
||||
if (postingDate) params = params.set('postingDate', postingDate);
|
||||
return this.http.get<FdMaturityDue[]>(`${this.base}/due-without-report`, { params });
|
||||
}
|
||||
|
||||
/** Deposits that matured without this report — a closure instruction, settled by the scheduler directly. */
|
||||
autoMatured(
|
||||
fromDate?: string,
|
||||
toDate?: string,
|
||||
officeId?: number,
|
||||
scope?: FdReportScope
|
||||
): Observable<FdAutoMaturedRow[]> {
|
||||
let params = new HttpParams();
|
||||
if (scope) params = params.set('scope', scope);
|
||||
if (fromDate) params = params.set('fromDate', fromDate);
|
||||
if (toDate) params = params.set('toDate', toDate);
|
||||
if (officeId) params = params.set('officeId', String(officeId));
|
||||
return this.http.get<FdAutoMaturedRow[]>(`${this.base}/outside-approval`, { params });
|
||||
}
|
||||
|
||||
context(): Observable<{ officeId: number; officeName: string; headOffice: boolean; approvalEnabled: boolean }> {
|
||||
return this.http.get<{ officeId: number; officeName: string; headOffice: boolean; approvalEnabled: boolean }>(
|
||||
`${this.base}/context`
|
||||
);
|
||||
}
|
||||
|
||||
detail(reportId: number): Observable<FdMaturityReportDetail> {
|
||||
return this.http.get<FdMaturityReportDetail>(`${this.base}/${reportId}`);
|
||||
}
|
||||
|
||||
regenerate(officeId: number, postingDate: string): Observable<{ reportId: number; status: string }> {
|
||||
return this.http.post<{ reportId: number; status: string }>(
|
||||
this.base,
|
||||
{ officeId, postingDate },
|
||||
{ params: new HttpParams().set('command', 'regenerate') }
|
||||
);
|
||||
}
|
||||
|
||||
approve(reportId: number): Observable<{ reportId: number; status: string }> {
|
||||
return this.http.post<{ reportId: number; status: string }>(
|
||||
`${this.base}/${reportId}`,
|
||||
{},
|
||||
{ params: new HttpParams().set('command', 'approve') }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user