143 lines
4.6 KiB
TypeScript
143 lines
4.6 KiB
TypeScript
|
import { Component, OnInit } from '@angular/core';
|
||
|
import {SearchEmployee} from '../../_models/Employee/searchEmployee';
|
||
|
import {LeaveYear} from '../../_models/Leave/leaveYear';
|
||
|
import {Leave} from '../../_models/Leave/leave';
|
||
|
import {LeaveService} from '../../_services/leave/leave.service';
|
||
|
import {HRMNotificationService} from '../../app.notification.service';
|
||
|
import {loadingPanelService} from '../../hrm-loding panel/loding.panel.service';
|
||
|
import {ApiService} from '../../app.api.service';
|
||
|
import {EnumStatus} from '../../_models/enums';
|
||
|
import {saveAs} from 'file-saver';
|
||
|
import {ReportServices} from '../../_services/reports/report.service';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-emp-leave-balance',
|
||
|
templateUrl: './emp-leave-balance.component.html',
|
||
|
styleUrls: ['./emp-leave-balance.component.scss']
|
||
|
})
|
||
|
export class EmpLeaveBalanceComponent implements OnInit {
|
||
|
selectedEmployee: SearchEmployee;
|
||
|
leaveYearList: LeaveYear[] = [];
|
||
|
leaveList: Leave[] = [];
|
||
|
leaveYearId: number;
|
||
|
PDFTitle = 'Employee Leave Balance';
|
||
|
showPopUp = false;
|
||
|
data: Array<Object>;
|
||
|
src: any;
|
||
|
base64Data: any;
|
||
|
leaveId: number;
|
||
|
|
||
|
|
||
|
constructor(public leaveService: LeaveService,
|
||
|
public notificationService: HRMNotificationService,
|
||
|
public reportService: ReportServices,
|
||
|
public loadingPanel: loadingPanelService,
|
||
|
public apiService: ApiService) {
|
||
|
this.apiService.selectedMenuName = 'Employee Leave Balance';
|
||
|
}
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
this.loadLeaveYear();
|
||
|
}
|
||
|
|
||
|
public GetSelectedEmployee(childData) {
|
||
|
this.selectedEmployee = childData;
|
||
|
}
|
||
|
|
||
|
loadLeaveYear() {
|
||
|
this.leaveService.getAllLeaveYear().subscribe(
|
||
|
(resp) => {
|
||
|
this.leaveYearList = resp;
|
||
|
},
|
||
|
(err) => {
|
||
|
console.log(err);
|
||
|
},
|
||
|
() => {
|
||
|
console.log(this.leaveYearList);
|
||
|
}
|
||
|
);
|
||
|
this.leaveService.getAllLeave(EnumStatus.Active, '', '').subscribe(
|
||
|
(resp) => {
|
||
|
this.leaveList = resp;
|
||
|
},
|
||
|
(err) => {
|
||
|
console.log(err);
|
||
|
},
|
||
|
() => {
|
||
|
console.log(this.leaveList);
|
||
|
/*this.leaveList.forEach(x => {
|
||
|
x.code = x.code.toLowerCase() + x.id;
|
||
|
});*/
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
|
||
|
preview() {
|
||
|
const leave = this.leaveYearList.find(l => l.id === this.leaveYearId);
|
||
|
if (leave === null) {
|
||
|
this.notificationService.showError('Please select leave year!');
|
||
|
return;
|
||
|
}
|
||
|
const data = {
|
||
|
reportid: 97,
|
||
|
itemid: this.leaveId,
|
||
|
bankId: null,
|
||
|
empIds: this.selectedEmployee.employeeID.toString(),
|
||
|
reportType: 'PDF',
|
||
|
fromDate: leave.startDate,
|
||
|
toDate: leave.endDate
|
||
|
};
|
||
|
|
||
|
this.loadingPanel.ShowLoadingPanel = true;
|
||
|
this.reportService.getCommonReportData(data).subscribe(
|
||
|
(resp: any) => {
|
||
|
if (data.reportType === 'PDF') {
|
||
|
this.src = URL.createObjectURL(this.b64toBlob(resp, 'data:application/pdf;base64', 1024));
|
||
|
this.showPopUp = true;
|
||
|
} else if (data.reportType === 'EXCEL') {
|
||
|
this.downloadFile(resp);
|
||
|
}
|
||
|
},
|
||
|
(err) => {
|
||
|
console.log(err);
|
||
|
this.notificationService.showError(err.error);
|
||
|
this.loadingPanel.ShowLoadingPanel = false;
|
||
|
},
|
||
|
() => {
|
||
|
|
||
|
this.loadingPanel.ShowLoadingPanel = false;
|
||
|
// this.loadGrid();
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
downloadFile(blobContent) {
|
||
|
const blob = new Blob([this.b64toBlob(blobContent, 'application/data:application/vnd.ms-excel', 1024)], {});
|
||
|
saveAs(blob, this.PDFTitle + '.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;
|
||
|
}
|
||
|
}
|