153 lines
5.0 KiB
TypeScript
153 lines
5.0 KiB
TypeScript
|
import { Component, OnInit } from '@angular/core';
|
||
|
import { saveAs } from 'file-saver';
|
||
|
import { SearchEmployee } from 'src/app/_models/Employee/searchEmployee';
|
||
|
import { BasicService } from 'src/app/_services/Basic/basic.service';
|
||
|
import { EmployeeServices } from 'src/app/_services/employee/employee.service';
|
||
|
import { ReportServices } from 'src/app/_services/reports/report.service';
|
||
|
import { AuthorizedPerson } from 'src/app/adhoc-feature/authorized-persons/authorizedPerson';
|
||
|
import { ApiService } from 'src/app/app.api.service';
|
||
|
import { HRMNotificationService } from 'src/app/app.notification.service';
|
||
|
import { loadingPanelService } from 'src/app/hrm-loding panel/loding.panel.service';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-id-card-print',
|
||
|
templateUrl: './id-card-print.component.html',
|
||
|
styleUrls: ['./id-card-print.component.scss']
|
||
|
})
|
||
|
export class IdCardPrintComponent implements OnInit {
|
||
|
selectedEmps: SearchEmployee[];
|
||
|
issueDate: Date = new Date();
|
||
|
src: any;
|
||
|
showPopUp: boolean = false;
|
||
|
isThreeYear:boolean = false;
|
||
|
isFiveYear:boolean = false;
|
||
|
expireYear: number;
|
||
|
authorizedPersons: AuthorizedPerson[]=[];
|
||
|
selectedAuthorizePersonid = undefined;
|
||
|
selectedReportTypeid = undefined;
|
||
|
reportTypes: { id: number, name: string }[] = [];
|
||
|
constructor(public notificctionService : HRMNotificationService,
|
||
|
public reportService: ReportServices,
|
||
|
public basicService: BasicService,
|
||
|
public employeeService: EmployeeServices,
|
||
|
public apiService: ApiService,public loadingPanel: loadingPanelService) {
|
||
|
this.apiService.selectedMenuName = "ID Card Print";
|
||
|
this.reportTypes.push({
|
||
|
'id': 1, 'name': 'Single Side'
|
||
|
});
|
||
|
this.reportTypes.push({
|
||
|
'id': 2, 'name': 'Both Side'
|
||
|
});
|
||
|
this.reportTypes.push({
|
||
|
'id': 3, 'name': 'Bangla Single Side'
|
||
|
});
|
||
|
this.reportTypes.push({
|
||
|
'id': 4, 'name': 'Bangla Both Side'
|
||
|
});
|
||
|
}
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
this.loadAuthorizedPerson();
|
||
|
}
|
||
|
public GetSelectedEmployee(childData) {
|
||
|
this.selectedEmps = childData;
|
||
|
}
|
||
|
loadAuthorizedPerson(){
|
||
|
let authors = []
|
||
|
this.employeeService.getAuthorizedPerson().subscribe(
|
||
|
(resp)=>{
|
||
|
this.authorizedPersons = resp;
|
||
|
},
|
||
|
(x)=>{
|
||
|
console.log(x);
|
||
|
},
|
||
|
()=>{
|
||
|
}
|
||
|
)
|
||
|
}
|
||
|
preview(reportType: string) {
|
||
|
if(this.selectedAuthorizePersonid === undefined){
|
||
|
this.notificctionService.showWarning("Please select Authorized Person first!","Warning");
|
||
|
return;
|
||
|
}
|
||
|
if(this.selectedReportTypeid === undefined){
|
||
|
this.notificctionService.showWarning("Please select Report Type first!","Warning");
|
||
|
return;
|
||
|
}
|
||
|
if(this.isThreeYear!= true && this.isFiveYear!=true){
|
||
|
this.notificctionService.showWarning("Please select Expire Date first!","Warning");
|
||
|
return;
|
||
|
}
|
||
|
let empIds = SearchEmployee.getEmpIds(this.selectedEmps);
|
||
|
debugger;
|
||
|
const data = {
|
||
|
reportType: reportType,
|
||
|
empIds: empIds,
|
||
|
selectedAuthorizePersonid: this.selectedAuthorizePersonid,
|
||
|
selectedReportTypeid: this.selectedReportTypeid,
|
||
|
issueDate: this.issueDate,
|
||
|
expireYear: this.expireYear,
|
||
|
};
|
||
|
|
||
|
this.showPopUp = true;
|
||
|
this.reportService.getIdCardPrintData(data).subscribe(
|
||
|
(resp: any) => {
|
||
|
if (reportType === 'PDF'){
|
||
|
this.src = URL.createObjectURL(this.b64toBlob(resp, 'application/pdf', 1024));
|
||
|
var element = <HTMLIFrameElement>(document.getElementById("pdf-viewer-idCardPrint"));
|
||
|
element.src = this.src;
|
||
|
}
|
||
|
if(reportType === 'EXCEL'){
|
||
|
this.downloadFile(resp);
|
||
|
}
|
||
|
},
|
||
|
(err) => {
|
||
|
console.log(err);
|
||
|
this.loadingPanel.ShowLoadingPanel = false;
|
||
|
this.closeForm();
|
||
|
},
|
||
|
() => {
|
||
|
this.loadingPanel.ShowLoadingPanel = false;
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
changeCheckbox(checkedCheckbox: 'Three' | 'Five') {
|
||
|
debugger;
|
||
|
if (checkedCheckbox === 'Three' && this.isThreeYear) {
|
||
|
this.isFiveYear = false;
|
||
|
this.expireYear=3;
|
||
|
} else if (checkedCheckbox === 'Five' && this.isFiveYear) {
|
||
|
this.isThreeYear = false;
|
||
|
this.expireYear=5;
|
||
|
}
|
||
|
}
|
||
|
downloadFile(blobContent) {
|
||
|
let blob = new Blob([this.b64toBlob(blobContent, 'application/data:application/vnd.ms-excel', 1024)], {});
|
||
|
saveAs(blob, 'ID Card Print' + '.xls');
|
||
|
}
|
||
|
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.loadingPanel.ShowLoadingPanel = false;
|
||
|
}
|
||
|
}
|