/** * 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 { CommonModule } from '@angular/common'; import { ActivatedRoute, Router } from '@angular/router'; import { MatDialog } from '@angular/material/dialog'; import { ChequeBookService } from '../../chequebook/chequebook.service'; import { LeafDetailDialogComponent } from '../../chequebook/cheque-book-detail/leaf-detail-dialog/leaf-detail-dialog.component'; import { ClerkLeafActionDialogComponent, LeafAction } from './leaf-action-dialog/leaf-action-dialog.component'; /** Cheque-book detail for the Clerk Dashboard — a fullscreen clerk-styled view of one book, its leaf * register, and the same maker-side leaf actions (stop-payment, revoke, report-lost, cancel-leaf, * mark-used) as the back-office ChequeBookDetailComponent, so a clerk can act on a leaf without leaving * the clerk shell/nav. Every action still goes through the existing maker-checker approval flow server-side. * Each action opens as a popup (ClerkLeafActionDialogComponent) rather than an inline form so it never * pushes the leaf grid around and gets the full dialog width to lay out its fields. */ @Component({ selector: 'mifosx-clerk-cheque-book-detail', standalone: true, imports: [CommonModule], styleUrl: './cheque-book-detail.component.scss', template: `
Cheque Book #{{ book.id }}
{{ book.accountNo || book.accountId }} @if (book.clientName) {  · {{ book.clientName }} }
@if (loading) {
Loading cheque book…
} @else {
Account Type {{ book.accountType }}
Office {{ book.officeName }}
Series {{ book.seriesCode ?? '—' }}
Leaf Range {{ book.rangeStart ? book.rangeStart + ' – ' + book.rangeEnd : '—' }}
Quantity {{ book.noOfBooks }} book{{ book.noOfBooks === 1 ? '' : 's' }}
Status {{ book.status }}
Issue Date {{ book.issueDate ?? '—' }}
@if (book.status === 'ISSUED') {
}
@if (leaves.length === 0) {
No leaves to display
} @else {
@for (l of leaves; track l.leafSerialNo) { }
}
}
` }) export class ClerkChequeBookDetailComponent implements OnInit { private route = inject(ActivatedRoute); private router = inject(Router); private chequeBookService = inject(ChequeBookService); private dialog = inject(MatDialog); bookId!: string; book: any = {}; leaves: any[] = []; loading = false; ngOnInit(): void { this.bookId = this.route.snapshot.paramMap.get('id') as string; this.loadAll(); } loadAll(): void { this.loading = true; this.chequeBookService.getBook(this.bookId).subscribe((data: any) => { this.book = data || {}; this.loading = false; }); this.chequeBookService.getLeaves(this.bookId).subscribe((data: any[]) => { this.leaves = data || []; }); } selectLeaf(leaf: any): void { this.dialog.open(LeafDetailDialogComponent, { data: leaf, width: '420px' }); } openAction(action: LeafAction): void { const ref = this.dialog.open(ClerkLeafActionDialogComponent, { width: '480px', data: { bookId: this.bookId, action } }); ref.afterClosed().subscribe((result) => { if (result?.success) { this.loadAll(); } }); } goBack(): void { this.router.navigate(['/clerk/account-facilities/cheque-book']); } }