WEB-627 Implement Report Service in the Loan Application Print Icon (#3049)
This commit is contained in:
@@ -893,4 +893,14 @@
|
|||||||
[routerLink]="['../', 'client-collateral', row.collateralId]"
|
[routerLink]="['../', 'client-collateral', row.collateralId]"
|
||||||
></tr>
|
></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<!-- PDF Viewer Modal -->
|
||||||
|
<div *ngIf="showPdf" class="pdf-modal-overlay">
|
||||||
|
<div class="pdf-modal-content">
|
||||||
|
<button mat-icon-button class="pdf-modal-close" (click)="closePdf()" aria-label="Close PDF">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
<embed [src]="pdfUrl" type="application/pdf" width="100%" height="600px" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** Angular Imports */
|
/** Angular Imports */
|
||||||
import { Component, OnInit, inject } from '@angular/core';
|
import { Component, OnInit, OnDestroy, inject } from '@angular/core';
|
||||||
import { environment } from '../../../../environments/environment';
|
|
||||||
import { Router, ActivatedRoute, RouterLink } from '@angular/router';
|
import { Router, ActivatedRoute, RouterLink } from '@angular/router';
|
||||||
|
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
|
||||||
|
|
||||||
/** Custom Services. */
|
/** Custom Services. */
|
||||||
import { ClientsService } from 'app/clients/clients.service';
|
import { ClientsService } from 'app/clients/clients.service';
|
||||||
@@ -35,6 +35,12 @@ import { DateFormatPipe } from '../../../pipes/date-format.pipe';
|
|||||||
import { FormatNumberPipe } from '../../../pipes/format-number.pipe';
|
import { FormatNumberPipe } from '../../../pipes/format-number.pipe';
|
||||||
import { CurrencyPipe } from '@angular/common';
|
import { CurrencyPipe } from '@angular/common';
|
||||||
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
||||||
|
import { ReportsService } from 'app/reports/reports.service';
|
||||||
|
import { SettingsService } from 'app/settings/settings.service';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
import { takeUntil, catchError } from 'rxjs/operators';
|
||||||
|
import { AlertService } from 'app/core/alert/alert.service';
|
||||||
|
import { EMPTY } from 'rxjs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General Tab component.
|
* General Tab component.
|
||||||
@@ -66,21 +72,76 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
|||||||
CurrencyPipe
|
CurrencyPipe
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class GeneralTabComponent {
|
export class GeneralTabComponent implements OnDestroy {
|
||||||
|
private destroy$ = new Subject<void>();
|
||||||
|
private alertService = inject(AlertService);
|
||||||
|
private sanitizer = inject(DomSanitizer);
|
||||||
|
pdfUrl: SafeResourceUrl | null = null;
|
||||||
|
rawPdfUrl: string | null = null;
|
||||||
|
showPdf: boolean = false;
|
||||||
|
|
||||||
openLoanApplicationReport(event: MouseEvent, loanId: string) {
|
openLoanApplicationReport(event: MouseEvent, loanId: string) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const baseApiUrl = environment.baseApiUrl?.replace(/\/$/, '') || '';
|
const tenantIdentifier = this.settingsService.tenantIdentifier || 'default';
|
||||||
const apiProvider = environment.apiProvider?.replace(/\/$/, '') || '';
|
const locale = this.settingsService.languageCode || 'en-US';
|
||||||
const apiVersion = environment.apiVersion?.replace(/\/$/, '') || '';
|
const dateFormat = this.settingsService.dateFormat || 'dd MMMM yyyy';
|
||||||
const tenantIdentifier = environment.fineractPlatformTenantId || 'default';
|
const formData = { R_loanId: loanId, 'output-type': 'PDF' };
|
||||||
const locale = environment.defaultLanguage || 'en';
|
this.reportsService
|
||||||
const dateFormat = 'dd MMMM yyyy';
|
.getPentahoRunReportData('LoanApplicationReport', formData, tenantIdentifier, locale, dateFormat)
|
||||||
const reportUrl = `${baseApiUrl}${apiProvider}${apiVersion}/runreports/LoanApplicationReport?tenantIdentifier=${tenantIdentifier}&locale=${locale}&dateFormat=${encodeURIComponent(dateFormat)}&R_loanId=${loanId}&output-type=PDF`;
|
.pipe(
|
||||||
window.open(reportUrl, '_blank', 'noopener,noreferrer');
|
takeUntil(this.destroy$),
|
||||||
|
catchError((error): any => {
|
||||||
|
this.showPdf = false;
|
||||||
|
if (this.rawPdfUrl) {
|
||||||
|
URL.revokeObjectURL(this.rawPdfUrl);
|
||||||
|
this.rawPdfUrl = null;
|
||||||
|
}
|
||||||
|
this.pdfUrl = null;
|
||||||
|
this.alertService.alert({
|
||||||
|
type: 'error',
|
||||||
|
message: 'Failed to load Loan Application PDF report.'
|
||||||
|
});
|
||||||
|
return EMPTY;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.subscribe((res: any) => {
|
||||||
|
if (this.rawPdfUrl) {
|
||||||
|
URL.revokeObjectURL(this.rawPdfUrl);
|
||||||
|
this.rawPdfUrl = null;
|
||||||
|
this.pdfUrl = null;
|
||||||
|
}
|
||||||
|
const contentType = res.headers.get('Content-Type') || 'application/pdf';
|
||||||
|
const file = new Blob([res.body], { type: contentType });
|
||||||
|
this.rawPdfUrl = URL.createObjectURL(file);
|
||||||
|
this.pdfUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.rawPdfUrl);
|
||||||
|
this.showPdf = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closePdf() {
|
||||||
|
this.showPdf = false;
|
||||||
|
if (this.rawPdfUrl) {
|
||||||
|
URL.revokeObjectURL(this.rawPdfUrl);
|
||||||
|
this.rawPdfUrl = null;
|
||||||
|
}
|
||||||
|
this.pdfUrl = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.destroy$.next();
|
||||||
|
this.destroy$.complete();
|
||||||
|
if (this.rawPdfUrl) {
|
||||||
|
URL.revokeObjectURL(this.rawPdfUrl);
|
||||||
|
this.rawPdfUrl = null;
|
||||||
|
}
|
||||||
|
this.pdfUrl = null;
|
||||||
|
}
|
||||||
|
|
||||||
private route = inject(ActivatedRoute);
|
private route = inject(ActivatedRoute);
|
||||||
private clientService = inject(ClientsService);
|
private clientService = inject(ClientsService);
|
||||||
private router = inject(Router);
|
private router = inject(Router);
|
||||||
|
private reportsService = inject(ReportsService);
|
||||||
|
private settingsService = inject(SettingsService);
|
||||||
|
|
||||||
/** Open Loan Accounts Columns */
|
/** Open Loan Accounts Columns */
|
||||||
openLoansColumns: string[] = [
|
openLoansColumns: string[] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user