import { Component, OnInit } from '@angular/core'; import { Employee } from 'src/app/_models/Employee/employee'; import { SearchEmployee } from 'src/app/_models/Employee/searchEmployee'; import { EmployeeServices } from 'src/app/_services/employee/employee.service'; import { ReportServices } from 'src/app/_services/reports/report.service'; import { HRMNotificationService } from 'src/app/app.notification.service'; import { loadingPanelService } from 'src/app/hrm-loding panel/loding.panel.service'; @Component({ selector: 'app-letter-generate', templateUrl: './letter-generate.component.html', styleUrls: ['./letter-generate.component.scss'] }) export class LetterGenerateComponent implements OnInit { employees: Employee[] = []; selectedEmployees: SearchEmployee[] = []; empIDs : string =''; showPopUp: boolean = false; reportType : string = "PDF"; src: any; constructor(public employeeService: EmployeeServices, public loadingPanelService : loadingPanelService, public reportService : ReportServices, public notificationService : HRMNotificationService) { } ngOnInit(): void { } public GetSelectedEmployee(childData) { debugger; this.selectedEmployees = childData; if(this.selectedEmployees !== undefined){ this.selectedEmployees.forEach(x=>{ if(this.empIDs === ''){ this.empIDs = x.employeeID.toString(); } else{ this.empIDs +=','+x.employeeID.toString(); } }); this.GetEmployee(this.empIDs); } } forStuffOrWorker(dataItem: Employee, type : string): void { debugger; let data = undefined if(type === 'for Staff'){ data = { employeeID : dataItem.id, employeeType : type, reportType : this.reportType }; } else{ data = { employeeID : dataItem.id, employeeType : type, reportType : this.reportType }; } this.showPopUp = true; this.reportService.getAppointmentLetter(data).subscribe( (resp: any) => { if (this.reportType === 'PDF'){ this.src = URL.createObjectURL(this.b64toBlob(resp, 'application/pdf', 1024)); var element = (document.getElementById("pdf-viewer-ml")); element.src = this.src; } }, (err) => { this.showPopUp = false; console.log(err); this.notificationService.showError(err.error); this.loadingPanelService.ShowLoadingPanel = false; }, () => { this.loadingPanelService.ShowLoadingPanel = false; } ); } public GetEmployee(allEmpIDs : string ) { const data = { dataList : allEmpIDs, }; this.employeeService.getEmployeesByEmpIDs(data).subscribe( (x) => { this.employees = x; }, (x) => { this.loadingPanelService.ShowLoadingPanel = false; }, () => { this.loadingPanelService.ShowLoadingPanel = false; }); } b64toBlob(b64Data, contentType, sliceSize) { const byteCharacters = atob(b64Data); const byteArrays = []; for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) { const slice = byteCharacters.slice(offset, offset + sliceSize); const byteNumbers = new Array(slice.length); for (let i = 0; i < slice.length; i++) { byteNumbers[i] = slice.charCodeAt(i); } const byteArray = new Uint8Array(byteNumbers); byteArrays.push(byteArray); } const blob = new Blob(byteArrays, { type: contentType }); return blob; } closeForm(): void { this.showPopUp = false; this.loadingPanelService.ShowLoadingPanel = false; } }