/** * 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/. */ /** Angular Imports */ import { Component, inject } from '@angular/core'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { MatIconModule } from '@angular/material/icon'; import { MatButtonModule } from '@angular/material/button'; import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; /** Custom Services */ import { ChequeBookService } from '../chequebook.service'; /** * The teller/counter quick-lookup: given a bare cheque-leaf serial number, is it active, stopped, lost, or * was it ever issued at all — one code path covers every case (issued or unissued-but-stolen stock). */ @Component({ selector: 'mifosx-leaf-lookup', templateUrl: './leaf-lookup.component.html', styleUrls: ['./leaf-lookup.component.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS, MatIconModule, MatButtonModule, MatSnackBarModule, FaIconComponent ] }) export class LeafLookupComponent { private formBuilder = inject(UntypedFormBuilder); private chequeBookService = inject(ChequeBookService); private snackBar = inject(MatSnackBar); private notify(message: string, isError = false): void { this.snackBar.open(message, 'Dismiss', { duration: isError ? 6000 : 3000 }); } searchForm: UntypedFormGroup; // a bare serial number is only unique within its own series — more than one series can share a number, // so the lookup can legitimately return more than one match results: any[] = []; searched = false; busy = false; constructor() { this.searchForm = this.formBuilder.group({ serialNo: [ '', Validators.required ] }); } search(): void { if (this.searchForm.invalid || this.busy) { return; } this.busy = true; this.searched = true; this.results = []; this.chequeBookService.lookupLeaf(this.searchForm.value.serialNo).subscribe({ next: (data: any) => { this.busy = false; this.results = Array.isArray(data) ? data : [data]; }, error: () => { this.busy = false; this.results = []; this.notify('No cheque leaf found with that serial number', true); } }); } }