236 lines
8.9 KiB
TypeScript
236 lines
8.9 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { SearchEmployee } from '../../_models/Employee/searchEmployee';
|
|
import { LeaveYear } from '../../_models/Leave/leaveYear';
|
|
import { LeaveService } from '../../_services/leave/leave.service';
|
|
import { MultipleEmployeeLeaveBalance } from '../../_models/report/multipleEmployeeLeaveBalance';
|
|
import { Leave } from '../../_models/Leave/leave';
|
|
import { EnumStatus } from '../../_models/enums';
|
|
import { HRMNotificationService } from '../../app.notification.service';
|
|
import { loadingPanelService } from '../../hrm-loding panel/loding.panel.service';
|
|
import { ApiService } from '../../app.api.service';
|
|
import { ReportServices } from 'src/app/_services/reports/report.service';
|
|
import { saveAs } from 'file-saver';
|
|
import { Router } from '@angular/router';
|
|
|
|
@Component({
|
|
selector: 'app-multiple-emp-leave-balance',
|
|
templateUrl: './multiple-emp-leave-balance.component.html',
|
|
styleUrls: ['./multiple-emp-leave-balance.component.css']
|
|
})
|
|
export class MultipleEmpLeaveBalanceComponent implements OnInit {
|
|
selectedEmployees: SearchEmployee[] = [];
|
|
leaveYearList: LeaveYear[] = [];
|
|
leaveList: Leave[] = [];
|
|
empIds = '';
|
|
leaveYearId = undefined;
|
|
data: any[] = [];
|
|
employeeLeaveBalance: MultipleEmployeeLeaveBalance[] = [];
|
|
temp = 'Header boss';
|
|
cols: { colfiled: string, colName: string, width: string, color: string }[];
|
|
|
|
reportType: any;
|
|
PDFTitle = 'Employee Leave Balance';
|
|
showPopUp = false;
|
|
src: any;
|
|
base64Data: any;
|
|
|
|
constructor(public leaveService: LeaveService, public notificationService: HRMNotificationService,
|
|
public loadingPanel: loadingPanelService, public apiService: ApiService,
|
|
public reportService: ReportServices,
|
|
public router: Router) {
|
|
this.reportType = this.router.url.split('/').pop();
|
|
debugger
|
|
if(this.reportType == 'multiple-emp-leave-balance')
|
|
this.apiService.selectedMenuName = 'Multiple Employee Leave Balance';
|
|
else if(this.reportType == 'multiple-emp-leave-report')
|
|
this.apiService.selectedMenuName = 'Employee Leave Report';
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.loadLeaveYear();
|
|
}
|
|
|
|
loadLeaveYear() {
|
|
this.leaveService.getAllLeaveYear().subscribe(
|
|
(resp) => {
|
|
this.leaveYearList = resp;
|
|
},
|
|
(err) => {
|
|
console.log(err);
|
|
},
|
|
() => {
|
|
}
|
|
);
|
|
this.leaveService.getAllLeave(EnumStatus.Active, '', '').subscribe(
|
|
(resp) => {
|
|
this.leaveList = resp;
|
|
},
|
|
(err) => {
|
|
console.log(err);
|
|
},
|
|
() => {
|
|
this.leaveList.forEach(x => {
|
|
x.code = x.code.toLowerCase() + x.id;
|
|
});
|
|
console.log(this.leaveList);
|
|
},
|
|
);
|
|
}
|
|
|
|
public GetSelectedEmployee(childData) {
|
|
this.selectedEmployees = childData;
|
|
}
|
|
|
|
// preview() {
|
|
// /*this.selectedEmployees.forEach(x => {
|
|
// if (this.empIds.length !== 0) {
|
|
// this.empIds += ',';
|
|
// }
|
|
// this.empIds += x.employeeID;
|
|
// });*/
|
|
// this.loadingPanel.ShowLoadingPanel = true;
|
|
// if (this.selectedEmployees == undefined || this.selectedEmployees.length == 0) {
|
|
// this.notificationService.showError('Select employees for the report');
|
|
// this.loadingPanel.ShowLoadingPanel = false;
|
|
// return;
|
|
// }
|
|
// this.selectedEmployees[0].departmentID = this.leaveYearId;
|
|
// // this.leaveService.getMultipleEmployeeLeaveBalance(this.selectedEmployees, ).subscribe(
|
|
// this.leaveService.getMultipleEmployeeLeaveBalance(this.leaveYearId, this.selectedEmployees).subscribe(
|
|
// (resp) => {
|
|
// debugger;
|
|
// this.data = resp;
|
|
// },
|
|
// (err) => {
|
|
// this.notificationService.showError(err.error);
|
|
// this.loadingPanel.ShowLoadingPanel = false;
|
|
|
|
// },
|
|
// () => {
|
|
// this.loadingPanel.ShowLoadingPanel = false;
|
|
// if (this.data.length > 0) {
|
|
// this.cols = [];
|
|
// for (var i = 0; i < Object.keys(this.data[0]).length; i++) {
|
|
// if (i == 0) {
|
|
// this.cols.push({
|
|
// 'colfiled': Object.keys(this.data[0])[i], 'colName': this.capitalizeFirstLetter(Object.keys(this.data[0])[i]) == 'EmpNo' ? 'Emp Id' :this.capitalizeFirstLetter(Object.keys(this.data[0])[i]) ,
|
|
// 'width': '80', 'color': 'transparent'
|
|
// });
|
|
// } else if (i == 1) {
|
|
// this.cols.push({
|
|
// 'colfiled': Object.keys(this.data[0])[i], 'colName': this.capitalizeFirstLetter(Object.keys(this.data[0])[i]),
|
|
// 'width': '100', 'color': 'transparent'
|
|
// });
|
|
// } else {
|
|
// this.cols.push({
|
|
// 'colfiled': Object.keys(this.data[0])[i], 'colName': this.replaceUnderscoresWithSpaces(Object.keys(this.data[0])[i].toUpperCase()),
|
|
// 'width': '65', 'color': 'transparent'
|
|
// });
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
// );
|
|
// }
|
|
public capitalizeFirstLetter(inputString: string): string {
|
|
debugger;
|
|
if (inputString.length === 0) {
|
|
return inputString; // Return an empty string if input is empty
|
|
}
|
|
return inputString.charAt(0).toUpperCase() + inputString.slice(1);
|
|
}
|
|
public replaceUnderscoresWithSpaces(str: string): string {
|
|
if (!str) return str;
|
|
return str.replace(/_/g, ' ');
|
|
}
|
|
preview(reportType: string) {
|
|
|
|
if (this.selectedEmployees == undefined || this.selectedEmployees.length == 0) {
|
|
this.notificationService.showWarning('Select employees for the report');
|
|
return;
|
|
}
|
|
if (this.leaveYearId == undefined || this.leaveYearId == null) {
|
|
this.notificationService.showWarning('Select Leave Year');
|
|
return;
|
|
}
|
|
debugger
|
|
|
|
this.selectedEmployees.forEach(x => {
|
|
if (this.empIds !== '') {
|
|
this.empIds += ',';
|
|
}
|
|
this.empIds += x.employeeID;
|
|
});
|
|
|
|
let reportid
|
|
if(this.reportType == 'multiple-emp-leave-balance')
|
|
reportid = 725;
|
|
else if(this.reportType == 'multiple-emp-leave-report')
|
|
reportid = 726;
|
|
|
|
const data = {
|
|
reportid: reportid,
|
|
itemid: this.leaveYearId,
|
|
empIds: this.empIds,
|
|
reportType: reportType,
|
|
};
|
|
|
|
this.loadingPanel.ShowLoadingPanel = true;
|
|
if (reportType === 'PDF')
|
|
this.showPopUp = true;
|
|
this.reportService.getCommonReportData(data).subscribe(
|
|
(resp: any) => {
|
|
debugger;
|
|
if (reportType === 'PDF') {
|
|
this.src = URL.createObjectURL(this.b64toBlob(resp, 'application/pdf', 1024));
|
|
var element = <HTMLIFrameElement>(document.getElementById("pdf-viewer-report"));
|
|
element.src = this.src;
|
|
} else if (reportType === 'EXCEL') {
|
|
this.downloadFile(resp);
|
|
}
|
|
},
|
|
(err) => {
|
|
console.log(err);
|
|
this.notificationService.showError(err.error);
|
|
this.loadingPanel.ShowLoadingPanel = false;
|
|
this.showPopUp = 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;
|
|
}
|
|
}
|