/** * 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 } from '@angular/core'; import { CommonModule, DecimalPipe } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { MatDialogRef, MatDialogModule } from '@angular/material/dialog'; import { MatButtonModule } from '@angular/material/button'; import { MatTooltipModule } from '@angular/material/tooltip'; import { MatSnackBar } from '@angular/material/snack-bar'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; type DepositType = 'FD-SINGLE' | 'FD-JOINT' | 'RD-MONTHLY' | 'RD-QUARTERLY'; interface DemoClient { id: string; name: string; } @Component({ selector: 'mifosx-fd-rd-entry-dialog', standalone: true, templateUrl: './fd-rd-entry-dialog.component.html', styleUrls: ['./fd-rd-entry-dialog.component.scss'], imports: [CommonModule, DecimalPipe, FormsModule, MatDialogModule, MatButtonModule, MatTooltipModule, FaIconComponent] }) export class FdRdEntryDialogComponent { private dialogRef = inject(MatDialogRef); private snackBar = inject(MatSnackBar); bank = { name: 'CBSNexora Bank Ltd', branch: 'Head Office' }; depositTypes: { code: DepositType; label: string; defaultRate: number }[] = [ { code: 'FD-SINGLE', label: 'Fixed Deposit — Single A/c', defaultRate: 7.25 }, { code: 'FD-JOINT', label: 'Fixed Deposit — Joint A/c', defaultRate: 7.25 }, { code: 'RD-MONTHLY', label: 'Recurring Deposit — Monthly', defaultRate: 7.0 }, { code: 'RD-QUARTERLY', label: 'Recurring Deposit — Quarterly', defaultRate: 7.0 } ]; clients: DemoClient[] = [ { id: 'C-10231', name: 'Ramesh Kumar Sharma' }, { id: 'C-10344', name: 'Priya Enterprises' }, { id: 'C-10412', name: 'Anjali Verma' }, { id: 'C-10567', name: 'Suresh & Sons HUF' }, { id: 'C-10689', name: 'Vikram Traders' } ]; payModes = ['Cash', 'Cheque', 'Transfer from Savings A/c']; interestPayoutOptions = ['Cumulative (Paid on Maturity)', 'Monthly Payout', 'Quarterly Payout']; maturityInstructions = [ 'Renew Principal & Interest', 'Renew Principal Only, Payout Interest', 'Payout on Maturity (No Renewal)' ]; depositType: DepositType = 'FD-SINGLE'; clientId = ''; principal: number | null = null; interestRate = 7.25; tenureYears = 1; tenureMonths = 0; tenureDays = 0; interestPayout = this.interestPayoutOptions[0]; payMode = this.payModes[0]; nomineeName = ''; maturityInstruction = this.maturityInstructions[0]; saved = false; lastAccountNo = ''; lastClientName = ''; get selectedClient(): DemoClient | undefined { return this.clients.find((c) => c.id === this.clientId); } onDepositTypeChange(): void { const dt = this.depositTypes.find((d) => d.code === this.depositType); if (dt) this.interestRate = dt.defaultRate; } get isRecurring(): boolean { return this.depositType.startsWith('RD'); } get tenureInYears(): number { return this.tenureYears + this.tenureMonths / 12 + this.tenureDays / 365; } get maturityDate(): Date { const d = new Date(); d.setFullYear(d.getFullYear() + this.tenureYears); d.setMonth(d.getMonth() + this.tenureMonths); d.setDate(d.getDate() + this.tenureDays); return d; } /** Quarterly-compounded maturity value, the standard FD/RD convention */ get maturityAmount(): number { const p = this.principal || 0; const t = this.tenureInYears; if (p <= 0 || t <= 0) return 0; return p * Math.pow(1 + this.interestRate / 100 / 4, 4 * t); } get isValid(): boolean { return !!this.clientId && (this.principal ?? 0) > 0 && this.tenureInYears > 0; } save(): void { if (!this.isValid) return; const prefix = this.isRecurring ? 'RD' : 'FD'; this.lastAccountNo = `${prefix}${Math.floor(1000000 + Math.random() * 8999999)}`; this.lastClientName = this.selectedClient?.name ?? ''; this.saved = true; this.snackBar.open(`${prefix} account ${this.lastAccountNo} created for ${this.lastClientName}`, 'Close', { duration: 4000 }); } resetForm(): void { this.depositType = 'FD-SINGLE'; this.clientId = ''; this.principal = null; this.interestRate = 7.25; this.tenureYears = 1; this.tenureMonths = 0; this.tenureDays = 0; this.nomineeName = ''; this.interestPayout = this.interestPayoutOptions[0]; this.payMode = this.payModes[0]; this.maturityInstruction = this.maturityInstructions[0]; this.saved = false; } close(): void { this.dialogRef.close(); } }