/** * 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 { CurrencyPipe, DatePipe } from '@angular/common'; import { Router } from '@angular/router'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { MatButton } from '@angular/material/button'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; /** What the account view hands the dialog: the line, its account, and how to name its type. */ export interface DdsTransactionViewData { transaction: any; account: any; typeLabel: string; /** Opened from the Receipt menu item: print the receipt straight away. */ printOnOpen?: boolean; } /** * One DDS passbook line in full - everything the line was saved with - the way a savings account's * View Transaction shows one: what it was, when, how much, and who keyed it, with the voucher, its * own reference and the journal it was booked under. Prints as a receipt. */ @Component({ selector: 'mifosx-dds-transaction-view-dialog', templateUrl: './dds-transaction-view-dialog.component.html', styleUrls: ['./dds-transaction-view-dialog.component.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS, CurrencyPipe, DatePipe, MatButton, FaIconComponent ] }) export class DdsTransactionViewDialogComponent { private dialogRef = inject(MatDialogRef); private router = inject(Router); data = inject(MAT_DIALOG_DATA); get txn(): any { return this.data.transaction || {}; } get account(): any { return this.data.account || {}; } get isCredit(): boolean { return this.txn.direction === 'CREDIT'; } get currency(): string { return this.account.currencyCode || 'INR'; } constructor() { if (this.data.printOnOpen) { // After the view has drawn, so the receipt has something in it to print. setTimeout(() => this.printReceipt(), 300); } } viewJournalEntries(): void { if (!this.txn.journalTransactionId) { return; } this.dialogRef.close(); this.router.navigate([ '/', 'journal-entry', 'view', this.txn.journalTransactionId ]); } /** The receipt block alone, in a window of its own - as the savings receipt prints. */ printReceipt(): void { const receipt = document.getElementById('dds-txn-receipt'); const popup = window.open('', '_blank', 'width=720,height=800'); if (!receipt || !popup) { return; } popup.document.write(`${this.txn.refNo || 'DDS'} Receipt${receipt.innerHTML}
CustomerAuthorised Signatory
`); popup.document.close(); popup.focus(); popup.print(); } close(): void { this.dialogRef.close(); } }