465 lines
17 KiB
TypeScript
465 lines
17 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
import { HrEmployee } from '../../../_models/HREmployee/hrEmployee';
|
|
import { SearchEmployee } from '../../../_models/Employee/searchEmployee';
|
|
import { EmployeeServices } from '../../../_services/employee/employee.service';
|
|
import { AttendanceServices } from '../../../_services/attendance/attendance.service';
|
|
import { ApiService } from '../../../app.api.service';
|
|
import { HRMNotificationService } from '../../../app.notification.service';
|
|
import { DataTransferService } from '../../../data.transfer.service';
|
|
import { AppWindowPopUp } from '../../../app.windowPopup.service';
|
|
import { UntilityHandlerService } from '../../../utility.hanldler.service';
|
|
import { Employee } from '../../../_models/Employee/employee';
|
|
import { EnumExtension, EnumGender, EnumMaritalStatus, EnumPaymentMode, EnumPersonType, EnumStatus } from '../../../_models/enums';
|
|
import { BasicService } from '../../../_services/Basic/basic.service';
|
|
import { Category } from '../../../_models/Basic/category';
|
|
import { Religion } from '../../../_models/HRBasic/religion';
|
|
import { loadingPanelService } from '../../../hrm-loding panel/loding.panel.service';
|
|
import { PayrollType } from 'src/app/_models/Authentication/payrollType';
|
|
import { JwtHelperService } from '@auth0/angular-jwt';
|
|
import { AuthService } from '../../../_services/auth/auth.service';
|
|
|
|
@Component({
|
|
selector: 'app-employee-payroll-profile',
|
|
templateUrl: './employee-payroll-profile.component.html',
|
|
styleUrls: ['./employee-payroll-profile.component.css']
|
|
})
|
|
export class EmployeePayrollProfileComponent implements OnInit {
|
|
|
|
employeeForm: FormGroup;
|
|
hrEmployeeProfile: HrEmployee;
|
|
selectedEmployee: SearchEmployee;
|
|
employee: Employee;
|
|
ddlcategories: Category[];
|
|
ddlreligions: Religion[];
|
|
public empLineManager: SearchEmployee;
|
|
lineManager: Employee;
|
|
ddlgender: any = EnumExtension.getNamesAndValues(EnumGender);
|
|
ddlmaritalStatus: any = EnumExtension.getNamesAndValues(EnumMaritalStatus);
|
|
ddlpaymentMode: any = EnumExtension.getNamesAndValues(EnumPaymentMode);
|
|
newEmployee: boolean;
|
|
ddlpersonType: any = EnumExtension.getNamesAndValues(EnumPersonType);
|
|
selectedCategoryid: number;
|
|
selectedReligionID: number;
|
|
selectedGender: number;
|
|
salaryProcessDate: Date;
|
|
selectedMaritalStatus: number;
|
|
chkEndofContactDate: boolean = false;
|
|
showBankAccount: boolean = false;
|
|
isBankAccountActive: boolean = true;
|
|
payrolltype: PayrollType;
|
|
|
|
payrollTypes: PayrollType[];
|
|
selectedPayrollTypeID: number;
|
|
nextPayProcessDate: Date;
|
|
|
|
constructor(public employeeService: EmployeeServices,
|
|
public basicService: BasicService,
|
|
public attendanceServices: AttendanceServices,
|
|
public apiService: ApiService,
|
|
public notificationService: HRMNotificationService,
|
|
public dataTransferService: DataTransferService,
|
|
public WindowPopUp: AppWindowPopUp,
|
|
public loadingPanelService: loadingPanelService, public authService: AuthService) {
|
|
this.empLineManager = undefined;
|
|
this.employee = new Employee();
|
|
this.newEmployee = false;
|
|
this.apiService.selectedMenuName = 'Employee Profile';
|
|
|
|
this.ddlpaymentMode.sort((a, b) => {
|
|
const ddlpaymentModeA = a.name.toLowerCase();
|
|
const ddlpaymentModeB = b.name.toLowerCase();
|
|
if (ddlpaymentModeA < ddlpaymentModeB) {
|
|
return -1;
|
|
}
|
|
if (ddlpaymentModeA > ddlpaymentModeB) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
|
|
this.ddlmaritalStatus.sort((a, b) => {
|
|
const ddlmaritalStatusA = a.name.toLowerCase();
|
|
const ddlmaritalStatusB = b.name.toLowerCase();
|
|
if (ddlmaritalStatusA < ddlmaritalStatusB) {
|
|
return -1;
|
|
}
|
|
if (ddlmaritalStatusA > ddlmaritalStatusB) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
|
|
this.ddlpersonType.sort((a, b) => {
|
|
const ddlpersonTypeA = a.name.toLowerCase();
|
|
const ddlpersonTypeB = b.name.toLowerCase();
|
|
if (ddlpersonTypeA < ddlpersonTypeB) {
|
|
return -1;
|
|
}
|
|
if (ddlpersonTypeA > ddlpersonTypeB) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.createForm();
|
|
this.loadDropDown();
|
|
|
|
this.ddlgender.sort((a, b) => {
|
|
const genderA = a.name.toLowerCase();
|
|
const genderB = b.name.toLowerCase();
|
|
if (genderA < genderB) {
|
|
return -1;
|
|
}
|
|
if (genderA > genderB) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
|
|
}
|
|
|
|
checkValue(value: any) {
|
|
if (value === true) {
|
|
this.employee = new Employee();
|
|
this.empLineManager = new SearchEmployee();
|
|
this.selectedEmployee = undefined;
|
|
this.selectedReligionID = undefined;
|
|
this.selectedGender = undefined;
|
|
this.selectedMaritalStatus = undefined;
|
|
this.selectedCategoryid = undefined;
|
|
this.isBankAccountActive = true;
|
|
|
|
this.lastSalaryProcessDate();
|
|
|
|
// this.loadingPanelService.ShowLoadingPanel = true;
|
|
// this.employeeService.generateEmployeeNo().subscribe(
|
|
// (resp) => {
|
|
// this.employee.employeeNo = resp as string;
|
|
// },
|
|
// (err) => {
|
|
// this.notificationService.showError(err);
|
|
// this.loadingPanelService.ShowLoadingPanel = false;
|
|
// },
|
|
// () => {
|
|
// this.loadingPanelService.ShowLoadingPanel = false;
|
|
// }
|
|
// );
|
|
}
|
|
else {
|
|
this.employee.employeeNo = undefined;
|
|
}
|
|
}
|
|
|
|
lastSalaryProcessDate() {
|
|
// const jwtHelper = new JwtHelperService();
|
|
// const user = jwtHelper.decodeToken(localStorage.getItem('token'));
|
|
// this.nextPayProcessDate = new Date(user.nextPayProcessDate);
|
|
|
|
// const sp = new PayrollType();
|
|
// this.nextPayProcessDate = sp.getFirstDateofNextPayProcessDate(this.nextPayProcessDate);
|
|
// this.employee.joiningDate = this.nextPayProcessDate;
|
|
|
|
// console.log('Next Pay Process Date : '+this.nextPayProcessDate);
|
|
|
|
this.authService.GetPayrollTypeByLoginID().subscribe(
|
|
(x) => {
|
|
this.payrolltype = x;
|
|
},
|
|
(x) => {
|
|
this.notificationService.showError(x.error);
|
|
},
|
|
() => {
|
|
var ptype: PayrollType = new PayrollType();
|
|
this.employee.joiningDate = new Date(ptype.getFirstDateofMonth(this.payrolltype.nextPayProcessDate));
|
|
this.employee.joiningDate = new Date();
|
|
});
|
|
}
|
|
|
|
loadDropDown() {
|
|
this.basicService.getAllCategory(EnumStatus.Active).subscribe(
|
|
(resp) => {
|
|
this.ddlcategories = resp;
|
|
},
|
|
(x) => {
|
|
console.log(x);
|
|
},
|
|
() => {
|
|
this.ddlcategories.sort((a, b) => {
|
|
const categoriesA = a.name.toLowerCase();
|
|
const categoriesB = b.name.toLowerCase();
|
|
if (categoriesA < categoriesB) {
|
|
return -1;
|
|
}
|
|
if (categoriesA > categoriesB) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
},
|
|
);
|
|
this.basicService.getAllReligion().subscribe(
|
|
(resp) => {
|
|
this.ddlreligions = resp;
|
|
},
|
|
(x) => {
|
|
console.log(x);
|
|
},
|
|
() => {
|
|
this.ddlreligions.sort((a, b) => {
|
|
const religionA = a.name.toLowerCase();
|
|
const religionB = b.name.toLowerCase();
|
|
if (religionA < religionB) {
|
|
return -1;
|
|
}
|
|
if (religionA > religionB) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
},
|
|
);
|
|
}
|
|
|
|
createForm() {
|
|
this.employeeForm = new FormBuilder().group({
|
|
isNew: ['', Validators.required],
|
|
// employeeId: ['', Validators.required],
|
|
employeeId: [''],
|
|
name: ['', Validators.required],
|
|
mobileNo: [''],
|
|
emailAddress: [''],
|
|
dateOfBirth: ['', Validators.required],
|
|
religion: ['', Validators.required],
|
|
gender: ['', Validators.required],
|
|
category: ['', Validators.required],
|
|
dateOfJoining: ['', Validators.required],
|
|
lastSalaryCalculationDay: [''],
|
|
chkEndofContactDate: [''],
|
|
maritalStatus: ['', Validators.required],
|
|
personType: [''],
|
|
isOTEligible: [''],
|
|
IsFixedLocation: [''],
|
|
paymentMode: [''],
|
|
successFactorId: [''],
|
|
oneViewId: [''],
|
|
isShownInTaxSheet: [''],
|
|
isConfirmed: [''],
|
|
foreignExpatriate: [''],
|
|
fatherName: [''],
|
|
tinNo: [''],
|
|
endOfContractDate: [''],
|
|
});
|
|
}
|
|
|
|
public GetSelectedEmployee(childData: any) {
|
|
if (childData === undefined) {
|
|
this.employee = new Employee();
|
|
this.selectedCategoryid = undefined;
|
|
this.selectedReligionID = undefined;
|
|
this.selectedGender = undefined;
|
|
this.selectedMaritalStatus = undefined;
|
|
this.isBankAccountActive = true;
|
|
return;
|
|
}
|
|
debugger;
|
|
this.selectedEmployee = childData;
|
|
this.isBankAccountActive = false;
|
|
this.employeeService.getEmployeeByID(this.selectedEmployee.employeeID).subscribe(
|
|
(resp: any) => {
|
|
this.employee = resp;
|
|
this.employee.birthDate = new Date(this.employee.birthDate);
|
|
this.employee.joiningDate = new Date(this.employee.joiningDate);
|
|
},
|
|
(err: any) => {
|
|
this.notificationService.showError(err.error);
|
|
},
|
|
() => {
|
|
debugger;
|
|
this.empLineManager = undefined;
|
|
this.selectedCategoryid = this.employee.categoryID;
|
|
this.selectedReligionID = this.employee.religionID;
|
|
this.selectedGender = this.employee.gender;
|
|
this.selectedMaritalStatus = this.employee.maritalStatus;
|
|
this.employee.birthDate = new Date(this.employee.birthDate);
|
|
this.employee.joiningDate = new Date(this.employee.joiningDate);
|
|
this.employee.inclusionDate = new Date(this.employee.inclusionDate);
|
|
if (this.employee.endOfContractDate != undefined)
|
|
this.employee.endOfContractDate = new Date(this.employee.endOfContractDate);
|
|
this.chkEndofContactDate = this.employee.endOfContractDate == undefined ? false : true;
|
|
if (this.employee.lineManagerID !== undefined && this.employee.lineManagerID !== null) {
|
|
this.employeeService.getEmployeeByID(this.employee.lineManagerID).subscribe(
|
|
(resp: any) => {
|
|
this.lineManager = resp;
|
|
|
|
},
|
|
(err: any) => {
|
|
// console.log(err);
|
|
this.notificationService.showError(err.error);
|
|
},
|
|
() => {
|
|
this.empLineManager = new SearchEmployee();
|
|
this.empLineManager.employeeNo = this.lineManager.employeeNo;
|
|
this.empLineManager.name = this.lineManager.name;
|
|
this.empLineManager.employeeID = this.lineManager.id;
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|
|
);
|
|
}
|
|
|
|
searchEmployee() {
|
|
const data = {
|
|
employeeNo: this.employeeForm.value.employeeCode
|
|
};
|
|
|
|
}
|
|
LastSalarycheckValue() {
|
|
if (this.chkEndofContactDate == false) {
|
|
this.employee.endOfContractDate = undefined;
|
|
}
|
|
}
|
|
public LineManagerSelected(childData) {
|
|
if (childData !== undefined) {
|
|
const emp: SearchEmployee = childData;
|
|
this.empLineManager = emp;
|
|
this.employee.lineManagerID = emp.employeeID;
|
|
}
|
|
|
|
}
|
|
// public saveGeneratedEmployee() {
|
|
|
|
// debugger;
|
|
// if (this.newEmployee === true) {
|
|
// this.loadingPanelService.ShowLoadingPanel = true;
|
|
// this.employeeService.generateEmployeeNo().subscribe(
|
|
// (resp) => {
|
|
// this.employee.employeeNo = resp as string;
|
|
// },
|
|
// (err) => {
|
|
// this.notificationService.showError(err);
|
|
// this.loadingPanelService.ShowLoadingPanel = false;
|
|
// },
|
|
// () => {
|
|
// this.loadingPanelService.ShowLoadingPanel = false;
|
|
// setTimeout(() => {
|
|
// this.saveEmployee();
|
|
// }, 1000);
|
|
// }
|
|
// );
|
|
|
|
// }
|
|
// else {
|
|
// this.saveEmployee();
|
|
// }
|
|
// }
|
|
|
|
saveEmployee() {
|
|
|
|
if (!this.employeeForm.valid) {
|
|
this.notificationService.showError('Required Fields can\'t be empty');
|
|
return;
|
|
}
|
|
|
|
if (this.chkEndofContactDate == true && this.employee.endOfContractDate == undefined) {
|
|
this.notificationService.showError('Please select Last Salary Date');
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
if (this.employee.birthDate.getFullYear() < 10) {
|
|
this.notificationService.showError('select a valid data of birth');
|
|
return;
|
|
}
|
|
|
|
this.employee.maritalStatus = this.selectedMaritalStatus;
|
|
this.employee.gender = this.selectedGender;
|
|
|
|
if (this.employee.maritalStatus == EnumMaritalStatus.None) {
|
|
this.notificationService.showError('please select a marital status.');
|
|
return;
|
|
}
|
|
|
|
if (this.employee.gender == EnumGender.Regardless) {
|
|
this.notificationService.showError('please select employee Gender.');
|
|
return;
|
|
}
|
|
|
|
this.employee.categoryID = this.selectedCategoryid;
|
|
this.employee.religionID = this.selectedReligionID;
|
|
this.employee.nationalityID = null;
|
|
this.loadingPanelService.ShowLoadingPanel = true;
|
|
//console.log(this.employee);
|
|
//return;
|
|
this.employeeService.saveEmployee(this.employee).subscribe(
|
|
(resp) => {
|
|
this.employee = resp;
|
|
},
|
|
(ex) => {
|
|
this.notificationService.showError(ex.error);
|
|
this.loadingPanelService.ShowLoadingPanel = false;
|
|
},
|
|
() => {
|
|
this.loadingPanelService.ShowLoadingPanel = false;
|
|
this.notificationService.showSuccess('Data Save successfully');
|
|
if (this.employee !== null && this.newEmployee == true && this.employee.id > 0) {
|
|
this.selectedEmployee = new SearchEmployee();
|
|
this.selectedEmployee.employeeID = this.employee.id;
|
|
this.selectedEmployee.categoryID = this.employee.categoryID;
|
|
this.selectedEmployee.name = this.employee.name;
|
|
this.selectedEmployee.employeeNo = this.employee.employeeNo;
|
|
this.showBankAccount = true;
|
|
|
|
} else {
|
|
this.employee = new Employee();
|
|
this.selectedMaritalStatus = undefined;
|
|
this.selectedGender = undefined;
|
|
this.selectedCategoryid = undefined;
|
|
this.selectedReligionID = undefined;
|
|
this.selectedEmployee = undefined;
|
|
}
|
|
|
|
},
|
|
);
|
|
}
|
|
|
|
onCancel() {
|
|
this.employee = new Employee();
|
|
}
|
|
|
|
viewBankAccount() {
|
|
debugger;
|
|
this.dataTransferService.setData(this.selectedEmployee);
|
|
this.showBankAccount = true;
|
|
}
|
|
onClose() {
|
|
this.showBankAccount = false;
|
|
this.dataTransferService.setData(undefined);
|
|
}
|
|
saveCompleted($event: any) {
|
|
debugger
|
|
if ($event === true) {
|
|
this.employee = new Employee();
|
|
this.selectedMaritalStatus = undefined;
|
|
this.selectedGender = undefined;
|
|
this.selectedCategoryid = undefined;
|
|
this.selectedReligionID = undefined;
|
|
this.selectedEmployee = undefined;
|
|
|
|
this.showBankAccount = false;
|
|
this.isBankAccountActive = true;
|
|
}
|
|
else {
|
|
this.showBankAccount = false;
|
|
}
|
|
}
|
|
}
|