2024-10-14 10:01:49 +06:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2025-10-07 12:46:18 +06:00
|
|
|
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';
|
2025-10-05 18:00:58 +06:00
|
|
|
import { GlobalfunctionExtension } from 'src/app/_models/globalFunctions';
|
2025-10-07 12:46:18 +06:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { EmployeeServices } from 'src/app/_services/employee/employee.service';
|
|
|
|
import { AuthorizedPerson } from 'src/app/adhoc-feature/authorized-persons/authorizedPerson';
|
2024-10-14 10:01:49 +06:00
|
|
|
|
|
|
|
@Component({
|
2025-10-07 12:46:18 +06:00
|
|
|
selector: 'app-emp-leave-balance',
|
|
|
|
templateUrl: './emp-leave-balance.component.html',
|
|
|
|
styleUrls: ['./emp-leave-balance.component.scss']
|
2024-10-14 10:01:49 +06:00
|
|
|
})
|
|
|
|
export class EmpLeaveBalanceComponent implements OnInit {
|
|
|
|
selectedEmployee: SearchEmployee;
|
|
|
|
leaveYearList: LeaveYear[] = [];
|
|
|
|
leaveList: Leave[] = [];
|
|
|
|
leaveYearId: number;
|
2025-10-07 12:46:18 +06:00
|
|
|
PDFTitle = null;
|
2024-10-14 10:01:49 +06:00
|
|
|
showPopUp = false;
|
|
|
|
data: Array<Object>;
|
|
|
|
src: any;
|
|
|
|
base64Data: any;
|
|
|
|
leaveId: number;
|
2025-10-05 18:00:58 +06:00
|
|
|
fromDate: Date = GlobalfunctionExtension.getFirstDateofYear(new Date());
|
|
|
|
toDate: Date = GlobalfunctionExtension.getLastDateOfYear(new Date());
|
2024-10-14 10:01:49 +06:00
|
|
|
|
2025-10-07 12:46:18 +06:00
|
|
|
authPersons: AuthorizedPerson[];
|
|
|
|
personID: number;
|
|
|
|
reportRoute: any;
|
|
|
|
reportID: number;
|
2024-10-14 10:01:49 +06:00
|
|
|
|
|
|
|
constructor(public leaveService: LeaveService,
|
2025-10-07 12:46:18 +06:00
|
|
|
public notificationService: HRMNotificationService,
|
|
|
|
public reportService: ReportServices,
|
|
|
|
public loadingPanel: loadingPanelService,
|
|
|
|
public apiService: ApiService,
|
|
|
|
public router: Router,
|
|
|
|
public employeeService: EmployeeServices) {
|
|
|
|
this.reportRoute = this.router.url.split('/').pop();
|
|
|
|
debugger
|
|
|
|
if (this.reportRoute == 'emp-leave-balance') {
|
|
|
|
this.apiService.selectedMenuName = 'Employee Leave Balance';
|
|
|
|
this.PDFTitle = 'Employee Leave Balance';
|
|
|
|
this.reportID = 724;
|
|
|
|
}
|
|
|
|
else if (this.reportRoute == 'leave-register') {
|
|
|
|
this.apiService.selectedMenuName = 'Leave Register Report';
|
|
|
|
this.PDFTitle = 'Leave Register Bangla';
|
|
|
|
this.reportID = 727;
|
|
|
|
}
|
2024-10-14 10:01:49 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.loadLeaveYear();
|
2025-10-07 12:46:18 +06:00
|
|
|
this.loadAuthPersons();
|
2024-10-14 10:01:49 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
public GetSelectedEmployee(childData) {
|
|
|
|
this.selectedEmployee = childData;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadLeaveYear() {
|
|
|
|
this.leaveService.getAllLeaveYear().subscribe(
|
|
|
|
(resp) => {
|
|
|
|
this.leaveYearList = resp;
|
|
|
|
},
|
|
|
|
(err) => {
|
2025-10-05 18:00:58 +06:00
|
|
|
this.notificationService.showError(err.error);
|
2025-10-07 12:46:18 +06:00
|
|
|
this.loadingPanel.ShowLoadingPanel = false;
|
2024-10-14 10:01:49 +06:00
|
|
|
},
|
|
|
|
() => {
|
2025-10-05 18:00:58 +06:00
|
|
|
// console.log(this.leaveYearList);
|
2024-10-14 10:01:49 +06:00
|
|
|
}
|
|
|
|
);
|
|
|
|
this.leaveService.getAllLeave(EnumStatus.Active, '', '').subscribe(
|
|
|
|
(resp) => {
|
|
|
|
this.leaveList = resp;
|
|
|
|
},
|
|
|
|
(err) => {
|
2025-10-05 18:00:58 +06:00
|
|
|
this.notificationService.showError(err.error);
|
2025-10-07 12:46:18 +06:00
|
|
|
this.loadingPanel.ShowLoadingPanel = false;
|
2024-10-14 10:01:49 +06:00
|
|
|
},
|
|
|
|
() => {
|
2025-10-05 18:00:58 +06:00
|
|
|
// console.log(this.leaveList);
|
2024-10-14 10:01:49 +06:00
|
|
|
/*this.leaveList.forEach(x => {
|
|
|
|
x.code = x.code.toLowerCase() + x.id;
|
|
|
|
});*/
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2025-10-07 12:46:18 +06:00
|
|
|
loadAuthPersons() {
|
|
|
|
this.employeeService.getAuthorizedPerson().subscribe(
|
|
|
|
(resp) => {
|
|
|
|
this.authPersons = resp;
|
|
|
|
debugger;
|
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
this.notificationService.showError(err.error);
|
|
|
|
this.loadingPanel.ShowLoadingPanel = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2024-10-14 10:01:49 +06:00
|
|
|
|
2025-10-07 12:46:18 +06:00
|
|
|
preview(reportType: string) {
|
2025-10-05 18:00:58 +06:00
|
|
|
// const leave = this.leaveYearList.find(l => l.id === this.leaveYearId);
|
|
|
|
// if (leave === null) {
|
|
|
|
// this.notificationService.showError('Please select leave year!');
|
|
|
|
// return;
|
|
|
|
// }
|
2025-10-07 12:46:18 +06:00
|
|
|
let data;
|
|
|
|
if (this.reportID == 724)
|
|
|
|
data = {
|
|
|
|
reportid: this.reportID,
|
|
|
|
itemid: this.leaveId,
|
|
|
|
bankId: null,
|
|
|
|
empIds: this.selectedEmployee.employeeID.toString(),
|
|
|
|
reportType: reportType,
|
|
|
|
fromDate: this.fromDate,
|
|
|
|
toDate: this.toDate
|
|
|
|
};
|
|
|
|
else if (this.reportID == 727)
|
|
|
|
data = {
|
|
|
|
reportid: this.reportID,
|
|
|
|
itemid: this.personID,
|
|
|
|
empIds: this.selectedEmployee.employeeID.toString(),
|
|
|
|
reportType: reportType,
|
|
|
|
};
|
2024-10-14 10:01:49 +06:00
|
|
|
|
|
|
|
this.loadingPanel.ShowLoadingPanel = true;
|
2025-10-07 12:46:18 +06:00
|
|
|
if (reportType === 'PDF')
|
|
|
|
this.showPopUp = true;
|
2024-10-14 10:01:49 +06:00
|
|
|
this.reportService.getCommonReportData(data).subscribe(
|
|
|
|
(resp: any) => {
|
2025-10-07 12:46:18 +06:00
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
|
|
|
|
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') {
|
2024-10-14 10:01:49 +06:00
|
|
|
this.downloadFile(resp);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
console.log(err);
|
|
|
|
this.notificationService.showError(err.error);
|
|
|
|
this.loadingPanel.ShowLoadingPanel = false;
|
2025-10-07 12:46:18 +06:00
|
|
|
this.showPopUp = false;
|
2024-10-14 10:01:49 +06:00
|
|
|
},
|
|
|
|
() => {
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2025-10-07 12:46:18 +06:00
|
|
|
const blob = new Blob(byteArrays, { type: contentType });
|
2024-10-14 10:01:49 +06:00
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeForm(): void {
|
|
|
|
this.showPopUp = false;
|
|
|
|
}
|
|
|
|
}
|