import {Component, OnInit, ChangeDetectionStrategy} from '@angular/core'; import {FormGroup, FormControl, FormBuilder, Validators} from '@angular/forms'; import {SearchEmployee} from '../../../../_models/Employee/searchEmployee'; import {AdparameterService} from '../../../../_services/payroll/adparameter.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 {ADParameter, ADParameterGrade, ADParameterEmployee} from '../../../../_models/Payroll/adparameter'; import {AllowanceDeduction} from '../../../../_models/HRBasic/allowanceDeduction'; import {Grade} from '../../../../_models/Basic/grade'; import {EnumArrearType, EnumADEmpType, EnumExtension, EnumPeriodicity, EnumGender, EnumEntitleType, EnumAllowOrDeduct, EnumValueType, EnumAuthStatus} from '../../../../_models/enums'; import { AuthService } from '../../../../_services/auth/auth.service'; import { PayrollType } from '../../../../_models/Authentication/payrollType'; import { Router } from '@angular/router'; import { loadingPanelService } from '../../../../hrm-loding panel/loding.panel.service'; import { LoadingPanelComponent } from 'src/app/hrm-loding panel/loading-panel.component'; import { ButtonModule } from '@progress/kendo-angular-buttons'; import { DropDownListModule } from '@progress/kendo-angular-dropdowns'; import { ReactiveFormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms'; import { KENDO_GRID } from '@progress/kendo-angular-grid'; import { DatePickerModule } from '@progress/kendo-angular-dateinputs'; import { NumericTextBoxModule } from '@progress/kendo-angular-inputs'; import { TabViewCompatModule } from 'src/app/custom-components/tab-view-compat/tab-view-compat'; import { EmployeePickerComponent } from 'src/app/picker/employee-picker.component'; @Component({ selector: 'app-allowance-deduction-parameterization-entry', templateUrl: './allowance-deduction-parameterization-entry.component.html', styleUrls: ['./allowance-deduction-parameterization-entry.component.css'], changeDetection: ChangeDetectionStrategy.Eager, standalone: false, }) export class AllowanceDeductionParameterizationEntryComponent implements OnInit { _adPram: ADParameter; _allowDeducts: AllowanceDeduction[]; _grades: Grade[]; _selectedgrades: number[] = []; _periodicity = [ { name: 'Monthly-Grade-Wise', value: 1}, { name: 'Monthly-Employee-Wise', value: 3 }, { name: 'Once-off', value: 2 }, ]; _selectedPeriodicity: number =1; _gender: any = EnumExtension.getNamesAndValues(EnumGender); _selectedPreiodicity: number; _individualAmount: number=0; _individualFromDate: Date; _individualToDate: Date ; _adEmpType: EnumADEmpType; _individualEmplyees: ADParameterEmployee[]; _ischeckException = false; _ischecknotapplicable = false; _ischeckappliedtoInvididual = false; _fromValidator: FormGroup; _detailLevelText: string = ""; _payrollType: PayrollType; _selectedEmps: SearchEmployee[]; prADParameterEmployees: ADParameterEmployee[] = []; _checkedToDate: boolean = false; public _allowDeductType: EnumAllowOrDeduct = EnumAllowOrDeduct.Allowance; constructor(public adparamService: AdparameterService, public apiservice: ApiService, public notificationService: HRMNotificationService, public datatransferservice: DataTransferService, public WindowPopUp: AppWindowPopUp, public loadingpanelService: loadingPanelService, public apiService: ApiService, public authService: AuthService, public router: Router) { const value = this.router.url.split('/').pop(); if (value.trim().toLowerCase() == "deduction") { this._allowDeductType = EnumAllowOrDeduct.Deduction; this.apiService.selectedMenuName = "Deduction Policy Parametarization"; } else { this.apiService.selectedMenuName = "Allowance Policy Parametarization"; } } ngOnInit() { this.loadingpanelService.ShowLoadingPanel = false; this.createWOForm(); this._grades = []; this._adPram = this.datatransferservice.getData(); this._allowDeducts = this.adparamService._allowDeducts; this.authService.GetPayrollTypeByLoginID().subscribe( (x) => { this._payrollType = x; }, (x) => { }, () => { this._individualToDate = new Date(this._payrollType.nextPayProcessDate); this._individualFromDate = new PayrollType().getFirstDateofMonth(this._payrollType.nextPayProcessDate); }); this.refreshControl(); } private refreshControl() { if (this._adPram.id > 0) { this.adparamService.GetParam(this._adPram.id).subscribe( (x) => { this._adPram = x; }, (x) => { this.notificationService.showError(x.error); this.loadingpanelService.ShowLoadingPanel = false; }, () => { this.AllowDeductselectionChange(this._allowDeducts.find(x => x.id == this._adPram.allowDeductID)); if (this._adPram.periodicity == EnumPeriodicity.Monthly && this._adPram.entitleType == EnumEntitleType.Grade) { this._selectedPeriodicity = 1; this.prediocityPopulate(0); } else if (this._adPram.periodicity == EnumPeriodicity.Monthly && this._adPram.entitleType == EnumEntitleType.Individual){ this._selectedPeriodicity = 3; this.prediocityPopulate(2); } else { this._selectedPeriodicity = 2; this.prediocityPopulate(2); } }); } else this.prediocityPopulate(0); } public createWOForm() { this._fromValidator = new FormBuilder().group({ allowOrDeductID: ['', Validators.required], periodicity: ['', Validators.required], isIndividual: '', flatAmount: '', percentOfBasic: '', percentOfGross: '', minAmount: '', maxAmount: '', isForConfirmOnly: '', isDependsOnAttendance: '', isFractionateApplicable: '', gender: '', isTaxable: '', }); } AllowDeductselectionChange(selectedItem: AllowanceDeduction) { let UsedGrades: ADParameterGrade[]; this.adparamService.GetGradesOfAllowDeduct(selectedItem.id).subscribe( (x) => { UsedGrades = x; }, (x) => { this.notificationService.showError(x); }, () => { this.PrepareGradeData(UsedGrades); }); } changepridicity(item:any) { this._ischecknotapplicable = false; this._ischeckException = false; this._ischeckappliedtoInvididual = false; if (item.value == 1) { this._ischecknotapplicable = true; this._ischeckException = true; this._adPram.periodicity = EnumPeriodicity.Monthly; this._adPram.entitleType = EnumEntitleType.Grade; this.prediocityPopulate(0); } else if (item.value == 3) { this._ischecknotapplicable = false; this._ischeckException = false; this._individualToDate = undefined; this._checkedToDate = true; this._adPram.periodicity = EnumPeriodicity.Monthly; this._adPram.entitleType = EnumEntitleType.Individual; this.prediocityPopulate(2); } else { this._ischecknotapplicable = false; this._ischeckException = false; this._adPram.periodicity = EnumPeriodicity.OneOff; this._adPram.entitleType = EnumEntitleType.Individual; this.prediocityPopulate(2); } } IndividualChecked(e) { this.prediocityPopulate(e.index); } sumofIndividualAmount(): number { if (this._individualEmplyees != undefined) return this._individualEmplyees.reduce((accumulator, obj) => { return accumulator + obj.monthlyAmount; }, 0); else return 0; } prediocityPopulate(value: number) { if (value == 0) { this._individualEmplyees = this._adPram.exception; this._adEmpType = EnumADEmpType.Exception; this._ischecknotapplicable = false; this._ischeckException = true; this._detailLevelText ="Enter Employee's exception amount on selected grades" } if (value == 1) { this._individualEmplyees = this._adPram.notApplicable; this._adEmpType = EnumADEmpType.NotApplicable; this._ischeckappliedtoInvididual = false; this._ischeckException = false; this._ischecknotapplicable = true; this._detailLevelText = "Enter not-Applicable Employee on selected grades" } if (value == 2) { this._individualEmplyees = this._adPram.adParameterEmployees; this._individualEmplyees.forEach(x => { x.formDate = new Date(x.formDate); if (x.tillDate != undefined && x.tillDate != null) x.tillDate = new Date(x.tillDate); }); this._adEmpType = EnumADEmpType.AppliedToIndividual; this._ischecknotapplicable = false; this._ischeckException = false; this._ischeckappliedtoInvididual = true; this._adPram.entitleType = EnumEntitleType.Individual; if (this._adPram.periodicity != EnumPeriodicity.OneOff) this._detailLevelText = "Enter employee month wise amount"; else this._detailLevelText = "Enter employee once-off amount"; } if (this._individualEmplyees.length > 0) { this.prADParameterEmployees = []; this._individualEmplyees.forEach(emp => { this.prADParameterEmployees.push({ ...emp }); }); //this.prADParameterEmployees = [...this._individualEmplyees]; } } todateclicked() { if (this._checkedToDate == true) { this._individualToDate = new Date(this._payrollType.nextPayProcessDate); } } RemoveAll() { // if (!confirm("Are you sure to delete all employees allowance entry")) { // return; // } // this._individualEmplyees.splice(0, this._individualEmplyees.length); this.notificationService.showActiveConfirm('Confirmation', "Are you sure to delete all employees allowance entry?").then((isConfirmed) => { if (isConfirmed) { this._individualEmplyees.splice(0, this._individualEmplyees.length); } }); } AddEmployee() { if (this._checkedToDate == true && this._individualToDate == undefined) { this.notificationService.showError('Please select to Date'); return; } if ((this._adEmpType == EnumADEmpType.Exception || this._adEmpType == EnumADEmpType.AppliedToIndividual) && this._individualAmount == 0) { this.notificationService.showWarning("Please enter an Amount"); return; } if (this._selectedEmps == undefined) return; this._selectedEmps.forEach(x => { let newItem: ADParameterEmployee = this._individualEmplyees.find(e => e.employeeID == x.employeeID); if (newItem === undefined) { newItem = new ADParameterEmployee(); newItem.allowDeductID = this._adPram.allowDeductID; newItem.employeeID = x.employeeID; newItem.arreartype = EnumArrearType.NotPresent; newItem.formDate = this._individualFromDate; newItem.periodicity = this._adPram.periodicity; newItem.tillDate = this._individualToDate; newItem.monthlyAmount = this._individualAmount; newItem.employeeName = x.name; newItem.employeeNo = x.employeeNo; newItem.adEmpType = this._adEmpType; newItem.valueType = EnumValueType.Amount; this._individualEmplyees.push(newItem); } else { newItem.formDate = this._individualFromDate; newItem.tillDate = this._individualToDate; newItem.monthlyAmount = this._individualAmount; newItem.adEmpType = this._adEmpType; } }); } public GetSelectedEmployee(searchEmp: SearchEmployee[]) { if (searchEmp != null) { this._selectedEmps = []; searchEmp.forEach(x => { this._selectedEmps.push(x); }); } } PrepareGradeData(usedGrades: ADParameterGrade[]) { this._grades = []; this.adparamService._grades.forEach(x => { if (usedGrades != undefined) { if (usedGrades.find(g => g.gradeID == x.id) == undefined) { this._grades.push(x); } } else { this._grades.push(x); } }); if (this._adPram.id > 0) { this.adparamService._grades.forEach(x => { if (this._adPram.adParameterGrades != undefined) { if (this._adPram.adParameterGrades.find(g => g.gradeID == x.id) != undefined) { this._grades.splice(0, 0, x); this._selectedgrades.push(x.id); } } }); this._selectedgrades = [...this._selectedgrades] ; } } removeHandler({ dataItem }) { let item = dataItem as ADParameterEmployee; if (item.approvalStatus === EnumAuthStatus.New_Not_Yet_Approve) { this._individualEmplyees.splice(this._individualEmplyees.findIndex(x => x.employeeID == item.employeeID), 1); } else { item.approvalStatus = EnumAuthStatus.Deleted_Not_Yet_Approve; } // this._individualEmplyees.findIndex(x => x.employeeID == item.employeeID). //if (this._adEmpType == EnumADEmpType.Exception) { // this._adPram.exception.splice(this._adPram.exception.findIndex(x => x.employeeID == item.employeeID), 1); //} //else if (this._adEmpType == EnumADEmpType.NotApplicable) { // this._adPram.notApplicable.splice(this._adPram.notApplicable.findIndex(x => x.employeeID == item.employeeID), 1); //} //else if (this._adEmpType == EnumADEmpType.AppliedToIndividual) { // this._adPram.adParameterEmployees.splice(this._adPram.adParameterEmployees.findIndex(x => x.employeeID == item.employeeID), 1); //} } public Save() { debugger; if (this._fromValidator.invalid) { return; } if (this._selectedgrades == undefined || this._selectedgrades.length == 0) { this.notificationService.showError('Please select a Grade'); return; } this._adPram.adParameterGrades = []; this._selectedgrades.forEach(x => { let gad: ADParameterGrade = new ADParameterGrade(); gad.gradeID = x; this._adPram.adParameterGrades.push(gad); }); let oItem; this.loadingpanelService.ShowLoadingPanel = true; if (this._adPram.periodicity == EnumPeriodicity.OneOff && this._adPram.adParameterEmployees.length > 0) { this._adPram.adParameterEmployees.forEach(x => { x.formDate = new PayrollType().getFirstDateofMonth(this._payrollType.nextPayProcessDate); x.tillDate = this._payrollType.nextPayProcessDate; }); } if (this._adPram.adParameterEmployees.length > 0) { this._adPram.adParameterEmployees.forEach(x => { debugger; let adParamEmpItem: ADParameterEmployee = this.prADParameterEmployees.find(y => y.id === x.id); let oPayrollType: PayrollType = new PayrollType(); if (adParamEmpItem) { if (adParamEmpItem.monthlyAmount !== x.monthlyAmount || !oPayrollType.ISSameDate(new Date(adParamEmpItem.tillDate), new Date(x.tillDate)) || !oPayrollType.ISSameDate(new Date(adParamEmpItem.formDate), new Date(x.formDate))) { x.approvalStatus = EnumAuthStatus.Edited_Not_Yet_Approve; x.oldAmount = adParamEmpItem.monthlyAmount; x.oldFormDate = adParamEmpItem.formDate; x.oldTillDate = adParamEmpItem.tillDate; } } }); } debugger; this.adparamService.SaveAdParam(this._adPram).subscribe( (x) => { this._adPram.id = x; }, (x) => { this.notificationService.showError(x.error); this.loadingpanelService.ShowLoadingPanel = false; }, () => { this.notificationService.showSuccess('Data saved sucessfully.'); this.loadingpanelService.ShowLoadingPanel = false; if (this._allowDeductType == EnumAllowOrDeduct.Deduction) { this.router.navigateByUrl('/payroll/deduction-parameterization/deduction'); } else { this.router.navigateByUrl('/payroll/allowance-parameterization/allowance'); } }); } statusString(roleStatus: EnumAuthStatus): string { var str = ""; var status: EnumAuthStatus = roleStatus; switch (status) { case EnumAuthStatus.Active: { str = "Active"; break }; case EnumAuthStatus.Approved: { str = "Approved"; break }; case EnumAuthStatus.New_Not_Yet_Approve: { str = "New Not Yet Approve"; break }; case EnumAuthStatus.Edited_Not_Yet_Approve: { str = "Edited Not Yet Approve"; break }; case EnumAuthStatus.Deleted_Not_Yet_Approve: { str = "Deleted Not Yet Approve"; break }; case EnumAuthStatus.Reverted: { str = "Reverted"; break }; case EnumAuthStatus.Rejected: { str = "Rejected"; break }; case EnumAuthStatus.Deleted: { str = "Deleted"; break }; default: str = "In-Active" } return str; } get2FloatingPoint(value: number): number { // var weightedkpiRating = parseFloat((weightages * rating / 90).toFixed(2)); return parseFloat((value).toFixed(2)); } }