EchoTex_Payroll/HRM.UI/ClientApp/src/app/payroll/emp-confirmation-duration/emp-confirmation-duration.component.ts

223 lines
7.5 KiB
TypeScript
Raw Normal View History

2024-10-14 10:01:49 +06:00
import {Component, OnInit} from '@angular/core';
import {ApiService} from '../../app.api.service';
import {HRMNotificationService} from '../../app.notification.service';
import {loadingPanelService} from '../../hrm-loding panel/loding.panel.service';
import { PayrollType } from '../../_models/Authentication/payrollType';
import {EnumStatus} from '../../_models/enums';
import { EmployeeConfirmation } from '../../_models/Payroll/EmployeeConfirmation';
import { AuthService } from '../../_services/auth/auth.service';
import { EmployeeServices } from '../../_services/employee/employee.service';
import {LeaveService} from '../../_services/leave/leave.service';
import {PmpService} from '../../_services/pmp/pmp.service';
import { ReportServices } from '../../_services/reports/report.service';
@Component({
selector: 'app-emp-confirmation-duration',
templateUrl: './emp-confirmation-duration.component.html',
styleUrls: ['./emp-confirmation-duration.component.css']
})
export class EmpConfirmationDurationComponent implements OnInit {
fromDate = new Date();
toDate = new Date();
isDisplay = false;
payrolltype: PayrollType;
confirmationMonth = new Date();
PDFTitle = ''
showPopUp = false;
src: any;
employeeConfirmation: EmployeeConfirmation;
employeeConfirmationList: EmployeeConfirmation[] = [];
empupcomingConfirmations: any;
constructor(public _apiService: ApiService, public empService: EmployeeServices,
public notificationService: HRMNotificationService,
public loadingPanel: loadingPanelService, public authService: AuthService, public reportService: ReportServices,) {
this.employeeConfirmation = new EmployeeConfirmation();
this._apiService.selectedMenuName = 'Employee Confirmation Duration';
this.PDFTitle = 'Employee Confirmation Duration';
}
refresh() {
this.loadData();
}
ngOnInit() {
this.loadingPanel.ShowLoadingPanel = true;
this.authService.GetPayrollTypeByLoginID().subscribe(
(x) => {
this.payrolltype = x;
},
(x) => {
// console.log(x);
this.loadingPanel.ShowLoadingPanel = false;
},
() => {
this.fromDate = new Date(this.payrolltype.nextPayProcessDate);
this.toDate = new Date(this.payrolltype.nextPayProcessDate);
this.loadingPanel.ShowLoadingPanel = false;
this.loadData();
});
}
loadData() {
this.loadingPanel.ShowLoadingPanel = true;
this.empService.getupcomingConfirmation(this.payrolltype.nextPayProcessDate).subscribe(
(resp) => {
this.empupcomingConfirmations = resp;
//console.log(this.empupcomingConfirmations);
},
(x) => {
console.log(x.message);
this.loadingPanel.ShowLoadingPanel = false;
},
() => {
this.loadingPanel.ShowLoadingPanel = false;
}
);
}
add() {
this.isDisplay = true;
this.employeeConfirmation = new EmployeeConfirmation();
}
removeHandler({ dataItem }) {
if (!confirm('Are you sure to delete the Item')) {
return;
}
const item = dataItem as EmployeeConfirmation;
this.loadingPanel.ShowLoadingPanel = true;
this.empService.deleteEmployeeConfirmationData(item).subscribe(
() => {
},
(x) => {
console.log(x);
this.loadingPanel.ShowLoadingPanel = false;
},
() => {
this.notificationService.showSuccess('Deleted Successfully');
this.loadData();
this.loadingPanel.ShowLoadingPanel = false;
}
);
}
cancel() {
this.isDisplay = false;
}
onUpdate() {
this.isDisplay = false;
}
editHandler(rowIndex: any) {
this.employeeConfirmation = this.employeeConfirmationList[rowIndex];
this.isDisplay = true;
}
saveHandler(dataItem:any) {
if (dataItem.month == undefined || dataItem.month == 0 ) {
this.notificationService.showError("Extended must be greater Zero");
return;
}
if (!confirm('Are you sure to extend ' + dataItem.month + ' Months more.')) {
return;
}
//if (dataItem.month < dataItem.duration) {
// this.notificationService.showError("Extended must be greater service length");
// return;
//}
const item: EmployeeConfirmation = new EmployeeConfirmation();
if (dataItem.empconfirmid != undefined) {
item.id = dataItem.empconfirmid;
}
item.employeeID = dataItem.employeeid;
item.joiningDate = dataItem.joiningdate;
item.gradeConfirmDuration = dataItem.confirmMonthDuration;
item.month = dataItem.month + dataItem.prvExteded ;
this.loadingPanel.ShowLoadingPanel = true;
this.empService.saveEmployeeConfirmationData(item).subscribe(
() => {
},
(x) => {
console.log(x);
this.notificationService.showError(x);
this.loadingPanel.ShowLoadingPanel = false;
},
() => {
this.notificationService.showSuccess('Data Saved');
this.loadData();
this.loadingPanel.ShowLoadingPanel = false;
},
);
this.isDisplay = false;
this.loadData();
this.employeeConfirmation = new EmployeeConfirmation();
}
closeForm(): void {
this.showPopUp = false;
}
upcomingConfirmation() {
debugger
const data = {
confirmationDate: this.confirmationMonth.toDateString()
};
this.showPopUp = true;
this.loadingPanel.ShowLoadingPanel = true;
this.reportService.getEmployeeConfirmationData(data).subscribe(
(resp: any) => {
// this.src = URL.createObjectURL(this.b64toBlob(resp, 'data:application/pdf;base64', 1024));
// this.showPopUp = true;
this.src = URL.createObjectURL(this.b64toBlob(resp, 'application/pdf', 1024));
var element = <HTMLIFrameElement>(document.getElementById("pdf-viewer-report-pcomming-confirmation"));
element.src = this.src;
},
(err) => {
console.log(err);
this.notificationService.showError(err.error);
this.loadingPanel.ShowLoadingPanel = false;
},
() => {
this.loadingPanel.ShowLoadingPanel = false;
// this.loadGrid();
}
);
}
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);
}
const blob = new Blob(byteArrays, { type: contentType });
return blob;
}
public onCancel(e): void {
this.closeForm();
}
}