133 lines
5.2 KiB
TypeScript
133 lines
5.2 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';
|
||
|
|
||
|
@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 }[];
|
||
|
|
||
|
constructor(public leaveService: LeaveService, public notificationService: HRMNotificationService,
|
||
|
public loadingPanel: loadingPanelService, public apiService: ApiService) {
|
||
|
this.apiService.selectedMenuName = 'Employee Leave Balance';
|
||
|
}
|
||
|
|
||
|
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, ' ');
|
||
|
}
|
||
|
}
|