/** * 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, Input } from '@angular/core'; import { CommonModule } from '@angular/common'; /** Where a voucher stands after a voucher correction. */ export type VoucherStatus = | 'ACTIVE' | 'REVOKED' | 'UNPASS_PENDING' | 'UNPASSED' | 'CORRECTION_PENDING' | 'CORRECTED' | 'CLOSED' | null | undefined; /** * A small badge saying whether a voucher was revoked, is under correction, or replaced another one. * Nothing is shown for an ordinary (active) voucher, so the registers read as before. */ @Component({ selector: 'mifosx-voucher-status', standalone: true, imports: [CommonModule], template: ` @if (label) { {{ label }} @if (note) {
{{ note }}
} } `, styles: [ ` .vs { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: #e2e8f0; color: #334155; font-size: 10px; font-weight: 700; white-space: nowrap; vertical-align: middle; } .vs-note { margin-top: 2px; max-width: 280px; font-size: 11px; line-height: 1.3; color: #64748b; } .vs--REVOKED { background: #fee2e2; color: #991b1b; } .vs--UNPASS_PENDING, .vs--CORRECTION_PENDING { background: #fef3c7; color: #92400e; } .vs--UNPASSED { background: #dbeafe; color: #1e40af; } .vs--CLOSED { background: #f1f5f9; color: #475569; } .vs--CORRECTED { background: #d1fae5; color: #065f46; } ` ] }) export class VoucherStatusComponent { @Input() status: VoucherStatus; /** The voucher that replaced this one, when it is revoked. */ @Input() revokedBy: string | null | undefined; /** The voucher this one replaced, when it is the corrected one. */ @Input() replaces: string | null | undefined; /** Why: the reason the voucher was unpassed, or why the correction was closed. */ @Input() note: string | null | undefined; get label(): string { switch (this.status) { case 'REVOKED': return this.revokedBy ? `Revoked → ${this.revokedBy}` : 'Revoked'; case 'UNPASS_PENDING': return 'Unpass pending'; case 'UNPASSED': return 'Unpassed'; case 'CORRECTION_PENDING': return 'Correction pending'; case 'CLOSED': return 'Closed — cashier deposits separately'; case 'CORRECTED': return this.replaces ? `Corrected (replaces ${this.replaces})` : 'Corrected'; default: return ''; } } get hint(): string { switch (this.status) { case 'REVOKED': return 'This voucher was revoked: its deposit was moved to another account and a new voucher replaced it.'; case 'UNPASS_PENDING': return 'A manager has not yet approved unpassing this voucher.'; case 'UNPASSED': return 'Unpassed: waiting for the cashier to enter the correct account.'; case 'CORRECTION_PENDING': return 'The correct account is entered; waiting for a manager to approve.'; case 'CLOSED': return 'The correction was closed by the cashier; the voucher stays as it was.'; case 'CORRECTED': return 'This voucher was raised by a correction and replaces the earlier one.'; default: return ''; } } }