/** * 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, inject, OnInit } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { MatDialog } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; import { MatTooltip } from '@angular/material/tooltip'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; import { CertificatePreviewDialogComponent, CertificatePreviewDialogData } from '../certificate-preview-dialog/certificate-preview-dialog.component'; import { downloadBalanceCertificatePdf } from '../certificate-pdf'; export type BalanceAccountType = 'SAVINGS' | 'CURRENT' | 'FIXED_DEPOSIT' | 'RD' | 'NRE' | 'NRO'; export interface BalanceCertificateRecord { accountNo: string; customerId: string; customerName: string; customerPan: string; customerAddress: string; branch: string; accountType: BalanceAccountType; productName: string; openedOn: string; /** Balance available as on the snapshot date. */ availableBalance: number; /** Total ledger balance (incl. accrued interest, hold amounts). */ ledgerBalance: number; /** Accrued but uncredited interest. */ accruedInterest: number; /** Interest rate p.a. (for FDs / RD / interest-bearing accounts). */ interestRate?: number; /** Joint-holder names if any. */ jointHolders?: string; } @Component({ selector: 'mifosx-balance-certificate', templateUrl: './balance-certificate.component.html', styleUrls: ['../certificates.shared.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS, CommonModule, FormsModule, FaIconComponent, MatTooltip ] }) export class BalanceCertificateComponent implements OnInit { private dialog = inject(MatDialog); private snack = inject(MatSnackBar); // ── Filters ── search = ''; accountTypeFilter: '' | BalanceAccountType = ''; /** Snapshot date for the balance "as on". */ asOnDate = todayIso(); records: BalanceCertificateRecord[] = []; readonly accountTypeOptions: { value: BalanceAccountType; label: string }[] = [ { value: 'SAVINGS', label: 'Savings' }, { value: 'CURRENT', label: 'Current' }, { value: 'FIXED_DEPOSIT', label: 'Fixed Deposit' }, { value: 'RD', label: 'Recurring Deposit' }, { value: 'NRE', label: 'NRE Savings' }, { value: 'NRO', label: 'NRO Savings' } ]; ngOnInit(): void { this.records = seedBalanceCertificates(); } get filteredRecords(): BalanceCertificateRecord[] { const q = this.search.trim().toLowerCase(); return this.records.filter((r) => { if (this.accountTypeFilter && r.accountType !== this.accountTypeFilter) return false; if (!q) return true; return ( r.accountNo.toLowerCase().includes(q) || r.customerName.toLowerCase().includes(q) || r.customerId.toLowerCase().includes(q) || r.customerPan.toLowerCase().includes(q) ); }); } accountTypeLabel(t: BalanceAccountType): string { return this.accountTypeOptions.find((o) => o.value === t)?.label || t; } totalBalance(): number { return this.filteredRecords.reduce((s, r) => s + r.availableBalance, 0); } clearFilters(): void { this.search = ''; this.accountTypeFilter = ''; this.asOnDate = todayIso(); } viewCertificate(r: BalanceCertificateRecord): void { const data: CertificatePreviewDialogData = { kind: 'balance', balance: { record: r, asOnDate: this.asOnDate } }; this.dialog.open(CertificatePreviewDialogComponent, { width: '880px', maxWidth: '96vw', maxHeight: '92vh', autoFocus: false, panelClass: 'cert-preview-dialog', data }); } downloadCertificate(r: BalanceCertificateRecord): void { downloadBalanceCertificatePdf(r, this.asOnDate); this.snack.open(`Balance Certificate (${r.accountNo}) downloaded.`, 'OK', { duration: 2400 }); } } function todayIso(): string { const d = new Date(); const pad = (n: number) => String(n).padStart(2, '0'); return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`; } // ───────────────────── Mock seed (top-level export) ───────────────────── export function seedBalanceCertificates(): BalanceCertificateRecord[] { return [ { accountNo: 'SB10029384', customerId: 'CUST112233', customerName: 'Rohan S. Mehta', customerPan: 'ABCPM1234E', customerAddress: 'Flat 902, Skyline Apt, Andheri (E), Mumbai 400069', branch: 'Mumbai — Andheri (E)', accountType: 'SAVINGS', productName: 'Savings — Premium', openedOn: '2018-04-22', availableBalance: 482500, ledgerBalance: 482500, accruedInterest: 1820, interestRate: 3.5, jointHolders: 'Priya Mehta' }, { accountNo: 'CA20034112', customerId: 'CUST334455', customerName: 'Anita Verma', customerPan: 'EFGHV5678A', customerAddress: 'B-12, Connaught Pl, New Delhi 110001', branch: 'New Delhi — Connaught Place', accountType: 'CURRENT', productName: 'Current — Business', openedOn: '2019-08-11', availableBalance: 1245300, ledgerBalance: 1245300, accruedInterest: 0 }, { accountNo: 'FD50200077', customerId: 'CUST556677', customerName: 'Karthik Rao', customerPan: 'PQRSR2233Z', customerAddress: '24, MG Road, Bengaluru 560001', branch: 'Bengaluru — MG Road', accountType: 'FIXED_DEPOSIT', productName: 'FD — Senior 18 months', openedOn: '2024-02-15', availableBalance: 500000, ledgerBalance: 526500, accruedInterest: 26500, interestRate: 7.25 }, { accountNo: 'RD60012345', customerId: 'CUST667788', customerName: 'Lakshmi Naidu', customerPan: 'XYZAN7788Q', customerAddress: 'Plot 14, Road No. 3, Banjara Hills, Hyderabad 500034', branch: 'Hyderabad — Banjara Hills', accountType: 'RD', productName: 'Recurring Deposit — 24m', openedOn: '2023-08-18', availableBalance: 180000, ledgerBalance: 188750, accruedInterest: 8750, interestRate: 6.85 }, { accountNo: 'NRE70010023', customerId: 'CUST889900', customerName: 'Vikram Joshi', customerPan: 'LMNOJ9988X', customerAddress: 'Office 3B, Koregaon Park Road, Pune 411001', branch: 'Pune — Koregaon Park', accountType: 'NRE', productName: 'NRE Savings — Premium', openedOn: '2020-11-05', availableBalance: 3850000, ledgerBalance: 3850000, accruedInterest: 12400, interestRate: 3.5 }, { accountNo: 'SB88990022', customerId: 'CUST990011', customerName: 'Arjun Banerjee', customerPan: 'TUVWB4455F', customerAddress: '42, Park Street, Kolkata 700016', branch: 'Kolkata — Park Street', accountType: 'SAVINGS', productName: 'Savings — Regular', openedOn: '2021-09-08', availableBalance: 92300, ledgerBalance: 92300, accruedInterest: 450, interestRate: 3.0 } ]; }