/** * 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 } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { MatTooltip } from '@angular/material/tooltip'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; import { NoticeEvent, OverdueLoan } from '../notice.component'; export interface SpeedPostDialogData { loan: OverdueLoan; notice: NoticeEvent; } export interface SpeedPostDialogResult { confirmed: boolean; consignmentNo?: string; postOffice?: string; bookedDate?: string; postage?: number; } @Component({ selector: 'mifosx-speed-post-dialog', templateUrl: './speed-post-dialog.component.html', styleUrls: ['./speed-post-dialog.component.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS, CommonModule, FormsModule, FaIconComponent, MatTooltip ] }) export class SpeedPostDialogComponent { private dialogRef = inject(MatDialogRef); data: SpeedPostDialogData = inject(MAT_DIALOG_DATA); consignmentNo = ''; postOffice = ''; bookedDate = todayIso(); postage: number | null = 45; /** Suggested India-post Speed Post 13-char article ID format: 2 letters + 9 digits + 2 letters (e.g. "EM123456789IN"). Loose pattern — operator can paste any tracking ID. */ readonly consignmentPattern = /^[A-Z]{2}\d{9}[A-Z]{2}$|^[A-Za-z0-9]{6,20}$/; get isConsignmentValid(): boolean { const c = (this.consignmentNo || '').trim(); return c.length >= 6 && this.consignmentPattern.test(c); } get isFormValid(): boolean { return this.isConsignmentValid && (this.postOffice || '').trim().length >= 2 && !!this.bookedDate; } /** Force the consignment number to uppercase for the India-Post-style ID. */ upperCaseConsignment(value: string): void { this.consignmentNo = (value || '').toUpperCase(); } confirm(): void { if (!this.isFormValid) return; this.dialogRef.close({ confirmed: true, consignmentNo: this.consignmentNo.trim(), postOffice: this.postOffice.trim(), bookedDate: this.bookedDate, postage: this.postage != null ? Number(this.postage) : undefined }); } cancel(): void { this.dialogRef.close({ confirmed: false }); } } 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())}`; }