EchoTex_Payroll/HRM.UI/ClientApp/src/app/profile-update-admin/profile-update-admin.component.ts

459 lines
17 KiB
TypeScript
Raw Normal View History

2024-10-14 10:01:49 +06:00
import {Component, OnInit} from '@angular/core';
import {
BloodGroupList,
enumEmpFileUploadType,
EnumExtension,
EnumGender,
EnumMaritalStatus,
EnumPURequestStatus,
EnumPURequestType, EnumStatus
} from '../_models/enums';
import {ProfileUpdateRequest} from '../_models/ess/profile-update-request';
import {District} from '../_models/HRBasic/district';
import {Thana} from '../_models/HRBasic/thana';
import {Occupation} from '../_models/HRBasic/occupation';
import {EducationLevel} from '../_models/HRBasic/education-level';
import {TrainingType} from '../_models/Basic/trainingType';
import {EducationType} from '../_models/HRBasic/education-type';
import {Institution} from '../_models/HRBasic/institution';
import {Discipline} from '../_models/HRBasic/discipline';
import {EmployeeServices} from '../_services/employee/employee.service';
import {ApiService} from '../app.api.service';
import {BasicService} from '../_services/Basic/basic.service';
import {EssService} from '../_services/ess/ess.service';
import {HRMNotificationService} from '../app.notification.service';
import {loadingPanelService} from '../hrm-loding panel/loding.panel.service';
import {Router} from '@angular/router';
import {DatePipe} from '@angular/common';
import {DomSanitizer} from '@angular/platform-browser';
import {forkJoin} from 'rxjs';
import {ResultType} from '../_models/HRBasic/result-type';
import {TrainingService} from '../_services/training/training.service';
import {Training} from '../_models/Training/training';
import {Relation} from '../_models/HRBasic/relation';
import {NominationPurpose} from '../_models/HRBasic/nomination-purpose';
@Component({
selector: 'app-profile-update-admin',
templateUrl: './profile-update-admin.component.html',
styleUrls: ['./profile-update-admin.component.scss']
})
export class ProfileUpdateAdminComponent implements OnInit {
type: any = EnumExtension.getNamesAndValues(EnumPURequestType);
bloodGroup = BloodGroupList;
genderType: any = EnumExtension.getNamesAndValues(EnumGender);
maritalStatus: any = EnumExtension.getNamesAndValues(EnumMaritalStatus);
puRequest: ProfileUpdateRequest;
selectedPuRequestList: ProfileUpdateRequest[] = [];
puRequestList: ProfileUpdateRequest[] = [];
puRequestListFiltered: ProfileUpdateRequest[] = [];
enumPURequestType = EnumPURequestType;
enumPURequestStatus = EnumPURequestStatus;
selectedType: any;
districts: District[] = [];
permanentThanas: Thana[] = [];
presentThanas: Thana[] = [];
uploadSaveUrl = 'saveUrl';
uploadRemoveUrl = 'removeUrl';
userType: string;
occupations: Occupation[] = [];
educationLevels: EducationLevel[] = [];
trainingTypes: TrainingType[] = [];
educationTypes: EducationType[] = [];
allEducationLevels: EducationType[] = [];
institutions: Institution[] = [];
disciplines: Discipline[] = [];
employeePhoto: any;
selectedFiles?: FileList;
currentFile?: File;
isDisplay = false;
resultTypes: ResultType[];
trainings: Training[] = [];
src: any;
fileName = '';
extension = '';
relations: Relation[] = [];
nominationPurposes: NominationPurpose[] = [];
mySelection: number[] = [];
constructor(public employeeService: EmployeeServices,
public apiService: ApiService,
public basicService: BasicService,
public trainingService: TrainingService,
public essService: EssService,
public notificationService: HRMNotificationService,
public loadingService: loadingPanelService,
public router: Router,
public datePipe: DatePipe,
private sanitizer: DomSanitizer) {
this.apiService.selectedMenuName = 'Profile Update';
}
ngOnInit() {
this.puRequest = new ProfileUpdateRequest();
this.getDropDownData1();
this.loadData();
}
getDropDownData1() {
const occupations = this.basicService.getAllOccupation();
const educationLevels = this.basicService.getAllEducationLevel();
const trainingTypes = this.basicService.getAllTrainingType();
const educationTypes = this.basicService.getAllEducationType();
const institutions = this.basicService.getAllInstitutions();
const disciplines = this.basicService.getAllDiscipline();
this.loadingService.ShowLoadingPanel = true;
forkJoin([occupations, educationLevels, trainingTypes, educationTypes, institutions, disciplines]).subscribe(
([res1, res2, res3, res4, res5, res6]) => {
this.occupations = res1;
this.allEducationLevels = res2;
this.trainingTypes = res3;
this.educationTypes = res4;
this.institutions = res5;
this.disciplines = res6;
},
() => {
this.loadingService.ShowLoadingPanel = false;
},
() => {
this.loadingService.ShowLoadingPanel = false;
this.getDropdownData2();
}
);
}
getDropdownData2() {
const getRelations = this.basicService.getAllRelations();
const getNominationPurpose = this.basicService.getAllNominationPurpose();
const results = this.basicService.getAllResultTypesByStatus(EnumStatus.Regardless);
this.loadingService.ShowLoadingPanel = true;
forkJoin([getRelations, getNominationPurpose, results]).subscribe(
([resp1, resp2, res3]) => {
this.relations = resp1;
this.nominationPurposes = resp2;
this.resultTypes = res3;
},
(err) => {
this.loadingService.ShowLoadingPanel = false;
console.log(err);
},
() => {
this.loadingService.ShowLoadingPanel = false;
},
);
}
loadTraining(value: number) {
this.loadingService.ShowLoadingPanel = true;
this.trainingService.GetTrainingybyTypeID(value).subscribe(
(resp) => {
this.trainings = resp;
},
(err: any) => {
this.loadingService.ShowLoadingPanel = false;
console.log(err);
},
() => {
this.loadingService.ShowLoadingPanel = false;
}
);
}
refreshObject(value: number) {
this.puRequest = new ProfileUpdateRequest();
this.mySelection = [];
if (this.selectedType !== undefined && this.selectedType !== null) {
this.puRequestListFiltered = this.puRequestList.filter(x => x.puRequestType === value);
} else {
this.puRequestListFiltered = this.puRequestList;
}
}
loadData() {
debugger
this.loadingService.ShowLoadingPanel = true;
this.essService.getAllPUR().subscribe(
(resp) => {
this.puRequestList = resp;
},
(x) => {
console.log(x);
this.loadingService.ShowLoadingPanel = false;
},
() => {
this.puRequestListFiltered = this.puRequestList;
this.refreshObject(this.selectedType);
this.loadingService.ShowLoadingPanel = false;
}
);
this.basicService.getAllDistricts().subscribe((resp) => {
this.districts = resp;
},
() => {
},
() => {
}
);
}
loadPermanentThana(value: any) {
this.basicService.getAllThanas(value).subscribe((resp) => {
this.permanentThanas = resp;
},
() => {
},
() => {
}
);
}
loadPresentThana(value: any) {
this.basicService.getAllThanas(value).subscribe((resp) => {
this.presentThanas = resp;
},
() => {
},
() => {
}
);
}
editHandler({dataItem}) {
const editPUreq: ProfileUpdateRequest = dataItem as ProfileUpdateRequest;
this.puRequest = editPUreq;
this.puRequest.requestDate = new Date(editPUreq.requestDate);
this.puRequest.approveDate = new Date(editPUreq.approveDate);
this.puRequest.passportIssueDate = new Date(editPUreq.passportIssueDate);
this.puRequest.passportExpiryDate = new Date(editPUreq.passportExpiryDate);
this.puRequest.spouseMarriageDate = new Date(editPUreq.spouseMarriageDate);
this.puRequest.childBirthDate = new Date(editPUreq.childBirthDate);
this.puRequest.childPassportIssueDate = new Date(editPUreq.childPassportIssueDate);
this.puRequest.childPassportExpiryDate = new Date(editPUreq.childPassportExpiryDate);
this.puRequest.nominationDate = new Date(editPUreq.nominationDate);
this.puRequest.nomineeDateOfBirth = new Date(editPUreq.nomineeDateOfBirth);
this.puRequest.trainingFromDate = new Date(editPUreq.trainingFromDate);
this.puRequest.trainingToDate = new Date(editPUreq.trainingToDate);
this.puRequest.experienceFrom = new Date(editPUreq.experienceFrom);
this.puRequest.experienceTo = new Date(editPUreq.experienceTo);
this.selectedType = editPUreq.puRequestType;
this.isDisplay = true;
if (this.selectedType === EnumPURequestType.Picture_Upload) {
this.showEmpImage(this.puRequest.requestEmpID, enumEmpFileUploadType.Profile_Picture);
} else if (this.selectedType === EnumPURequestType.Mobile_Phone_Information) {
this.showEmpImage(this.puRequest.requestEmpID, enumEmpFileUploadType.Mobile);
} else if (this.selectedType === EnumPURequestType.National_ID_Information) {
this.showEmpImage(this.puRequest.requestEmpID, enumEmpFileUploadType.nationalID);
} else if (this.selectedType === EnumPURequestType.Blood_Group_Information) {
this.showEmpImage(this.puRequest.requestEmpID, enumEmpFileUploadType.bloodGroup);
} else if (this.selectedType === EnumPURequestType.TIN_Information) {
this.showEmpImage(this.puRequest.requestEmpID, enumEmpFileUploadType.TIN);
} else if (this.selectedType === EnumPURequestType.Passport_No_Information) {
this.showEmpImage(this.puRequest.requestEmpID, enumEmpFileUploadType.passport);
} else if (this.selectedType === EnumPURequestType.Educational_Information) {
this.showEmpImage(this.puRequest.requestEmpID, enumEmpFileUploadType.Education);
} else if (this.selectedType === EnumPURequestType.Training_Information) {
this.showEmpImage(this.puRequest.requestEmpID, enumEmpFileUploadType.training);
} else if (this.selectedType === EnumPURequestType.Experience_Information) {
this.showEmpImage(this.puRequest.requestEmpID, enumEmpFileUploadType.Experience);
}
}
rejectRequest() {
if (confirm('Are you sure to reject the request') === false) {
return;
}
if (this.puRequest.adminRemarks === '' || this.puRequest.adminRemarks === null) {
this.notificationService.showError('Admin remarks can\'t be empty while rejecting request');
return;
}
this.puRequest.puRequestStatus = EnumPURequestStatus.Rejected;
this.essService.updateStatusToRejected(this.puRequest).subscribe(
() => {
},
() => {
},
() => {
this.notificationService.showSuccess('Request has been rejected');
this.isDisplay = false;
this.loadData();
},
);
}
showEmpImage(empId: number, enumFileType) {
this.extension = '';
this.employeeService.getUploadEmpFileInProfileUpdate(empId, empId, enumFileType).subscribe(
(resp: any) => {
this.employeePhoto = resp;
},
(err: any) => {
this.notificationService.showError(err.error);
},
() => {
this.extension = this.employeePhoto.fileName.split('.').pop();
if (this.extension === 'pdf') {
/*this.fileName = '';
this.fileName = this.employeePhoto.originalFileName;
const str = this.employeePhoto.fileTobase64;
let _type = 'application/pdf';
const byteCharacters = atob(str);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}*/
const str = this.employeePhoto.fileData;
let _type = 'application/pdf';
const byteCharacters = atob(str);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], { type: _type });
const objectUrl: string = URL.createObjectURL(blob);
/*const a: HTMLAnchorElement = document.createElement('a') as HTMLAnchorElement;
a.href = objectUrl;
a.download = this.fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(objectUrl);*/
this.src = objectUrl;
} else {
this.employeePhoto = this.sanitizer.bypassSecurityTrustResourceUrl(`data:image/png;base64, ${this.employeePhoto.fileData}`);
}
}
);
}
submitProfile() {
this.puRequest.puRequestType = this.selectedType;
this.puRequest.puRequestStatus = EnumPURequestStatus.Approved;
this.loadingService.ShowLoadingPanel = true;
this.essService.updateEmployee(this.puRequest).subscribe(
(resp) => {
},
(x) => {
console.log(x);
this.notificationService.showError(x.error);
this.loadingService.ShowLoadingPanel = false;
},
() => {
this.isDisplay = false;
this.loadingService.ShowLoadingPanel = false;
this.notificationService.showSuccess('Data Updated');
this.loadData();
},
);
}
onPopUpClose() {
this.isDisplay = false;
}
onCancel() {
this.isDisplay = false;
}
/*function(ext) {
if (ext !== undefined) {
return this.extToMimes(ext);
}
return undefined;
}
extToMimes(ext) {
let type;
switch (ext) {
case 'jpg':
type = 'image/jpeg';
break;
case 'png':
type = 'image/jpeg';
break;
case 'jpeg':
type = 'image/jpeg';
break;
case 'txt':
type = 'text/plain';
break;
case 'xls':
type = 'application/vnd.ms-excel';
break;
case 'doc':
type = 'application/msword';
break;
case 'xlsx':
type = 'application/vnd.ms-excel';
break;
case 'pdf':
type = 'application/pdf';
break;
default:
}
return type;
}*/
declineAll() {
this.getSelectedPurReqList(EnumPURequestStatus.Rejected);
this.rejectBulk();
}
approveAll() {
this.getSelectedPurReqList(EnumPURequestStatus.Approved);
this.updateBulk();
}
getSelectedPurReqList(status: EnumPURequestStatus) {
this.mySelection.forEach(x => {
const item = this.puRequestList.find(pur => pur.id === x);
item.puRequestStatus = status;
this.selectedPuRequestList.push(item);
});
}
updateBulk() {
this.loadingService.ShowLoadingPanel = true;
this.essService.updateEmployeeRequestBulk(this.selectedPuRequestList).subscribe(
(resp) => {
},
(x) => {
console.log(x);
this.notificationService.showError(x);
this.loadingService.ShowLoadingPanel = false;
},
() => {
this.selectedPuRequestList = [];
this.notificationService.showSuccess('Data Updated');
this.loadingService.ShowLoadingPanel = false;
this.loadData();
},
);
}
private rejectBulk() {
this.loadingService.ShowLoadingPanel = true;
this.essService.rejectEmployeeRequestBulk(this.selectedPuRequestList).subscribe(
(resp) => {
},
(x) => {
console.log(x);
this.loadingService.ShowLoadingPanel = false;
},
() => {
this.loadingService.ShowLoadingPanel = false;
this.notificationService.showSuccess('Rejected Successfully!');
this.selectedPuRequestList = [];
this.loadData();
},
);
}
}