HRM-10/HRM.UI/ClientApp/src/app/attendance/access-card-management/access-card-management.component.ts
2026-11-23 11:49:34 +06:00

290 lines
11 KiB
TypeScript

import { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { Router } from '@angular/router';
import { searchIcon } from '@progress/kendo-svg-icons';
import { ApiService } from '../../app.api.service';
import { HRMNotificationService } from '../../app.notification.service';
import { DataTransferService } from '../../data.transfer.service';
import { loadingPanelService } from '../../hrm-loding panel/loding.panel.service';
import { AccessCard } from '../../_models/Attendance/accessCard';
import { CardOperation } from '../../_models/Attendance/cardOperation';
import { Employee } from '../../_models/Employee/employee';
import { SearchEmployee } from '../../_models/Employee/searchEmployee';
import { HrEmployee } from '../../_models/HREmployee/hrEmployee';
import { AttendanceServices } from '../../_services/attendance/attendance.service';
import { BasicService } from '../../_services/Basic/basic.service';
import { EmployeeServices } from '../../_services/employee/employee.service';
import { EnumCardStatus } from 'src/app/_models/enums';
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 { EmployeePickerComponent } from 'src/app/picker/employee-picker.component';
@Component({
selector: 'app-access-card-management',
templateUrl: './access-card-management.component.html',
styleUrls: ['./access-card-management.component.scss']
,changeDetection: ChangeDetectionStrategy.Eager,
standalone: false
})
export class AccessCardManagementComponent implements OnInit {
actionTypes: { id: number, name: string }[] = [];
selectedtypeid: any;
cardNumber: string;
isThreeYear: boolean = false;
isFiveYear: boolean = false;
actionDate: Date = new Date();
expireYears: number = 3;
expireDate: Date;
setExactDate: Date;
actionName: string = "Assign";
comments: string = "";
visibleCardDDL: boolean = false;
visibleemp: boolean = true;
employee: Employee;
accessCard: AccessCard;
pickerSelecteEmp: SearchEmployee;
assignActive: boolean = false;
selectedAction: number = 1;
foundActive: boolean = false;
@Input()
public set SetEmployee(InputObject: SearchEmployee) {
;
this.pickerSelecteEmp = InputObject;
this.GetSelectedEmployee(InputObject);
this.empPickerActive = false;
}
public empPickerActive: boolean = true;
constructor(public apiService: ApiService, public attnService: AttendanceServices, public datatransferservice: DataTransferService,
public loadingPanel: loadingPanelService,
public notificationService: HRMNotificationService, public employeeService: EmployeeServices,
public basicService: BasicService,
public router: Router) {
if (this.apiService.selectedMenuName !== 'Employee Long Profile')
this.apiService.selectedMenuName = 'Access Card Management';
this.actionTypes.push({
'id': 1, 'name': 'Assign'
});
this.actionTypes.push({
'id': 2, 'name': 'Lost'
});
this.actionTypes.push({
'id': 3, 'name': 'Found'
});
this.actionTypes.push({
'id': 4, 'name': 'Detach'
});
}
typevalueChange($event) {
var id = $event;
console.log(id);
if (id == 1) {
this.visibleCardDDL = false;
this.actionName = 'Assign';
this.selectedAction = 1;
this.foundActive = false;
}
else if (id == 2) {
this.visibleCardDDL = true;
this.actionName = 'Lost Date';
this.selectedAction = 2;
this.foundActive = false;
}
else if (id == 3) {
this.actionName = 'Found Date';
this.visibleCardDDL = true;
this.selectedAction = 3;
this.foundActive = true;
}
else if (id == 4) {
this.actionName = 'Detach Date';
this.visibleCardDDL = true;
this.selectedAction = 4;
this.foundActive = false;
}
}
ngOnInit(): void {
;
this.selectedtypeid = 1;
}
GetSelectedEmployee(item: any) {
if (item == undefined) return;
var emp: SearchEmployee = item as SearchEmployee;
this.employeeService.getEmployeeByID(emp.employeeID).subscribe(
(resp) => {
this.employee = resp;
},
() => {
},
() => {
if (this.employee.cardID != undefined &&
this.employee.cardID != 0) {
this.attnService.getAccessCard(this.employee.cardID).subscribe(
(resp) => {
this.accessCard = resp;
this.assignActive = true;
},
() => {
},
() => {
this.cardNumber = this.accessCard.cardNumber;
}
);
} else {
this.notificationService.showWarning("No Access Card Assigned to this employee");
}
}
);
}
SaveItem() {
;
if (this.selectedAction == 1) {
if (this.employee == undefined) {
this.notificationService.showError('Please select an employee');
return;
}
if (this.employee.cardID !== null) {
this.notificationService.showError('A Card is already assinged to employee');
return;
}
if (this.cardNumber === undefined) {
this.notificationService.showError('Enter a card');
return;
}
var cardop: CardOperation = new CardOperation();
cardop.employeeID = this.employee.id;
cardop.cardNumber = this.cardNumber;
cardop.assignDate = this.actionDate;
cardop.expiredDate = this.expireDate;
cardop.comments = this.comments;
// cardop.cardStatus = EnumCardStatus.Attached;
var cardOperations: CardOperation[] = [];
cardOperations.push(cardop);
this.loadingPanel.ShowLoadingPanel = true;
this.attnService.assignCardToEmployee(cardOperations).subscribe(
(resp) => {
},
(err) => {
this.loadingPanel.ShowLoadingPanel = false;
this.notificationService.showError(err.message);
},
() => {
this.loadingPanel.ShowLoadingPanel = false;
this.assignActive = true;
this.notificationService.showSuccess('Card assigned to employee successfully.');
});
}
else if (this.selectedAction == 2) {
if (this.employee == undefined) {
this.notificationService.showError('Please select an employee');
return;
}
if (this.employee.cardID == undefined || this.employee.cardID == 0) {
this.notificationService.showError('There is no card assinged to employee');
return;
}
;
var cardop: CardOperation = new CardOperation();
cardop.employeeID = this.employee.id;
cardop.cardNumber = this.cardNumber;
cardop.assignDate = this.actionDate;
// var cardOperations: CardOperation[] = [];
// cardOperations.push(cardop);
this.loadingPanel.ShowLoadingPanel = true;
this.attnService.lostCardFromEmployee(cardop).subscribe(
(resp) => {
},
(err) => {
this.loadingPanel.ShowLoadingPanel = false;
this.notificationService.showError(err.message);
},
() => {
this.loadingPanel.ShowLoadingPanel = false;
this.cardNumber = '';
this.assignActive = false;
this.notificationService.showSuccess('Card Marked as Lost successfully.');
});
} else if (this.selectedAction == 3) {
if (this.cardNumber === undefined) {
this.notificationService.showError('Enter a card');
return;
}
const data = {
cardNumber: this.cardNumber,
}
this.attnService.foundCard(data).subscribe(() => {
},
() => {
this.notificationService.showError("Could not update the status");
},
() => {
this.cardNumber = '';
this.notificationService.showSuccess("Card status has changed to free");
}
);
} else if (this.selectedAction == 4) {
if (this.employee == undefined) {
this.notificationService.showError('Please select an employee');
return;
}
if (this.employee.cardID == undefined || this.employee.cardID == 0) {
this.notificationService.showError('There is no card assinged to employee');
return;
}
var cardop: CardOperation = new CardOperation();
cardop.employeeID = this.employee.id;
cardop.cardNumber = this.cardNumber;
cardop.assignDate = this.actionDate;
this.loadingPanel.ShowLoadingPanel = true;
this.attnService.detachCardInfoFromEmployee(cardop).subscribe(
(resp) => {
},
(err) => {
this.loadingPanel.ShowLoadingPanel = false;
this.notificationService.showError(err.message);
},
() => {
this.loadingPanel.ShowLoadingPanel = false;
this.assignActive = true;
this.cardNumber = '';
this.notificationService.showSuccess('Card detached from employee successfully.');
});
}
}
changeCheckbox(checkedCheckbox: 'Three' | 'Five') {
;
if (checkedCheckbox === 'Three' && this.isThreeYear) {
this.isFiveYear = false;
this.setExactDate = new Date(this.actionDate);
this.setExactDate.setFullYear(this.setExactDate.getFullYear() + 3);
this.expireDate = new Date(this.setExactDate);
} else if (checkedCheckbox === 'Five' && this.isFiveYear) {
this.isThreeYear = false;
this.setExactDate = new Date(this.actionDate);
this.setExactDate.setFullYear(this.setExactDate.getFullYear() + 5);
this.expireDate = new Date(this.setExactDate);
}
}
}