import { Component, OnInit, ViewEncapsulation } from '@angular/core'; 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 { EmployeeWorkPlanSetup } from '../../_models/Attendance/employeeWorkPlanSetup'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { HrEmployee } from '../../_models/HREmployee/hrEmployee'; import { SearchEmployee } from '../../_models/Employee/searchEmployee'; import { EnumWorkPlanGroup, HolidayDayOfWeek, EnumStatus, HolidayType, EnumWorkPlanDayType, EnumDayOfWeek } from '../../_models/enums'; import { Shift } from '../../_models/Attendance/shift'; import { WorkPlanGroup } from '../../_models/Attendance/workPlanGroup'; import { Employee } from '../../_models/Employee/employee'; import { WorkPlanSetup } from '../../core-hr/employee-profile/workPlanSetup'; import { loadingPanelService } from '../../hrm-loding panel/loding.panel.service'; import { Router } from '@angular/router'; import { DateTimePickerComponent } from '@progress/kendo-angular-dateinputs'; @Component({ selector: 'app-echotex-roster-assignment', templateUrl: './echotex-roster-assignment.component.html', styleUrls: ['./echotex-roster-assignment.component.css'] }) export class EchotexRosterAssignmentComponent implements OnInit { rosterAssignmentForm: FormGroup; empWorkPlanSetupList: EmployeeWorkPlanSetup[] = []; shifts: Shift[]; workPlanGroupName = ''; workPlanGroupInitialShift = ''; workPlanGroupList: WorkPlanGroup[]; selectedEmployees: SearchEmployee[]; employees: Employee[]; empIds: number[] = []; exportExcelFileName: string = ''; selectedWorkPlanID: number; fixedWorkPlan: boolean = true; startDate: Date; holidayDayOfWeekArray = Object.values(HolidayDayOfWeek); constructor(public employeeService: EmployeeServices, public attendanceServices: AttendanceServices, public apiService: ApiService, public notificationService: HRMNotificationService, public dataTransferService: DataTransferService, public WindowPopUp: AppWindowPopUp, public utilityHandlerService: UntilityHandlerService, public loadingPanel: loadingPanelService, private router: Router) { this.apiService.selectedMenuName = 'Roster Assignment'; this.exportExcelFileName = 'RosterAssignment.xlsx'; this.attendanceServices.getShifts(EnumStatus.Regardless).subscribe( (resp) => { this.shifts = resp; }, () => { }, () => { } ); this.loadingPanel.ShowLoadingPanel = true; this.attendanceServices.getWorkPlanGroupList(EnumStatus.Regardless).subscribe( (resp) => { this.workPlanGroupList = resp; }, (x) => { this.loadingPanel.ShowLoadingPanel = false; }, () => { this.loadingPanel.ShowLoadingPanel = false; } ); } ngOnInit() { this.createForm(); // this.loadData(); this.workPlanGroupInitialShift = 'Select a Roster to view detail'; } createForm() { this.rosterAssignmentForm = new FormBuilder().group({ group: ['', Validators.required], startDate: [''], }); } //loadData() { // this.attendanceServices.getEmployeeWorkPlanSetupList().subscribe( // (resp) => { // this.empWorkPlanSetupList = resp; // }, // () => { // }, // () => { // }, // ); //} public GetSelectedEmployee(childData) { this.selectedEmployees = childData; } UploadEmployeeRoster() { this.router.navigateByUrl('/common-interface/data-upload/52'); } public AddtotheList() { if (this.selectedWorkPlanID == undefined || this.selectedWorkPlanID == null) { this.notificationService.showWarning('Please select an work-plan/Roster group'); return; } if (this.selectedEmployees == undefined || this.selectedEmployees.length == 0) { this.notificationService.showWarning('Please select employee'); return; } if (this.selectedEmployees != undefined) { this.selectedEmployees.forEach(x => { if (this.empWorkPlanSetupList.findIndex(i => i.employeeID == x.employeeID) == -1) { var ewpList: EmployeeWorkPlanSetup = new EmployeeWorkPlanSetup(); ewpList.employeeID = x.employeeID; ewpList.employeeNoView = x.employeeNo; ewpList.employeeNameView = x.name; ewpList.workPlanGroupID = this.selectedWorkPlanID; var wp = this.workPlanGroupList.find(w => w.id == this.selectedWorkPlanID); ewpList.workPlanGroupNameView = wp.name; debugger; if (!this.fixedWorkPlan) { ewpList.startDate = this.startDate; // ewpList.weekEndOn = this.getDayOfWeekEnum(ewpList.startDate); ewpList.weekEndOn = ewpList.startDate.getDay(); } var wplan = this.workPlanGroupList.find(x => x.id == this.selectedWorkPlanID); ewpList.workPlanGroupType = wplan.type; this.empWorkPlanSetupList.push(ewpList); } }); var oldList: EmployeeWorkPlanSetup[]; this.attendanceServices.IsEmpExistInWorkplan(this.selectedEmployees).subscribe( (resp: any) => { oldList = resp; }, (x) => { this.notificationService.showWarning(x.error); }, () => { let str = ''; if (oldList != undefined) { oldList.forEach(x => { var item = this.empWorkPlanSetupList.find(e => e.employeeID == x.employeeID && e.workPlanGroupID != x.workPlanGroupID); if (item != undefined) { item.oldWorkPlanGroupID = x.workPlanGroupID; item.oldWorkPlanGroupName = x.workPlanGroupNameView; str = str + x.employeeNameView + '(' + x.employeeNoView + '),'; } }); } if (str.length > 0) { str = str.substring(0, str.length - 1); str = 'Employee already in another Group:' + str; alert(str); } } ); } } populateEmpWorkPlanByWorkGroup(selectedwrokPlan: any) { if (selectedwrokPlan == undefined) { return; } //this.attendanceServices.getEmployeeWorkPlanSetupByWPGroupID(selectedwrokPlan).subscribe( // (resp: any) => { // this.empWorkPlanSetupList = resp; // }, // (x) => { // }, // () => { // } //); var wplan = this.workPlanGroupList.find(x => x.id == selectedwrokPlan); this.loadGroupTypeAndInitialShift(wplan); } loadGroupTypeAndInitialShift(workPlanGroup: WorkPlanGroup) { this.loadingPanel.ShowLoadingPanel = true; this.empWorkPlanSetupList = []; debugger; if (workPlanGroup.type != EnumWorkPlanGroup.Fixed && (workPlanGroup.type != undefined || workPlanGroup.type != null)) { this.fixedWorkPlan = false; this.startDate = new Date(); } else { this.fixedWorkPlan = true; } this.attendanceServices.getEmployeeWorkPlanSetupByWPGroupID(workPlanGroup.id).subscribe( (resp) => { this.empWorkPlanSetupList = resp; }, () => { this.loadingPanel.ShowLoadingPanel = false; }, () => { //console.log(this.empWorkPlanSetupList); debugger; // if (this.empWorkPlanSetupList.length > 0) { // if (this.empWorkPlanSetupList[0].workPlanGroupType != EnumWorkPlanGroup.Fixed && // (this.empWorkPlanSetupList[0].workPlanGroupType != undefined || this.empWorkPlanSetupList[0].workPlanGroupType != null)) { // this.fixedWorkPlan = false; // this.startDate = new Date(); // } // else { // this.fixedWorkPlan = true; // } // } // else { // this.fixedWorkPlan = true; // } this.loadingPanel.ShowLoadingPanel = false; }, ); this.workPlanGroupName = ''; this.workPlanGroupName = workPlanGroup.name; if (workPlanGroup.type === EnumWorkPlanGroup.Fixed) { this.workPlanGroupInitialShift = ''; let tempShift = this.shifts.find(x => x.id === workPlanGroup.saturdayShiftID); this.workPlanGroupInitialShift += '[' + 'Sat: ' + (tempShift !== undefined ? tempShift.shortName : '❌') + '], '; tempShift = this.shifts.find(x => x.id === workPlanGroup.sundayShiftID); this.workPlanGroupInitialShift += '[' + 'Sun: ' + (tempShift !== undefined ? tempShift.shortName : '❌') + '], '; tempShift = this.shifts.find(x => x.id === workPlanGroup.mondayShiftID); this.workPlanGroupInitialShift += '[' + 'Mon: ' + (tempShift !== undefined ? tempShift.shortName : '❌') + '], '; tempShift = this.shifts.find(x => x.id === workPlanGroup.tuesdayShiftID); this.workPlanGroupInitialShift += '[' + 'Tue: ' + (tempShift !== undefined ? tempShift.shortName : '❌') + '], '; tempShift = this.shifts.find(x => x.id === workPlanGroup.wednesdayShiftID); this.workPlanGroupInitialShift += '[' + 'Wed: ' + (tempShift !== undefined ? tempShift.shortName : '❌') + '], '; tempShift = this.shifts.find(x => x.id === workPlanGroup.thursdayShiftID); this.workPlanGroupInitialShift += '[' + 'Thu: ' + (tempShift !== undefined ? tempShift.shortName : '❌') + '], '; tempShift = this.shifts.find(x => x.id === workPlanGroup.fridayShiftID); this.workPlanGroupInitialShift += '[' + 'Fri: ' + (tempShift !== undefined ? tempShift.shortName : '❌') + '], '; tempShift = this.shifts.find(x => x.id === workPlanGroup.saturdayShiftID); this.workPlanGroupInitialShift += '[' + 'Sat: ' + (tempShift !== undefined ? tempShift.shortName : '❌') + '], '; this.workPlanGroupInitialShift += '[' + 'Holiday 1: ' + HolidayDayOfWeek[workPlanGroup.holidayOne] + '], '; this.workPlanGroupInitialShift += '[' + 'Holiday 2: ' + HolidayDayOfWeek[workPlanGroup.holidayTwo] + '], '; } else { this.workPlanGroupInitialShift = ''; const tempShift = this.shifts.find(x => x.id === workPlanGroup.saturdayShiftID); this.workPlanGroupInitialShift += ' [' + (tempShift !== undefined ? tempShift.shortName : '❌') + '], '; this.workPlanGroupInitialShift += '[' + 'Holiday 1: ' + HolidayDayOfWeek[workPlanGroup.holidayOne] + '], '; this.workPlanGroupInitialShift += '[' + 'Holiday 2: ' + HolidayDayOfWeek[workPlanGroup.holidayTwo] + '], '; } } saveEmpWorkPlan() { this.empWorkPlanSetupList.forEach(x => { var wplan: WorkPlanGroup = this.workPlanGroupList.find(y => x.workPlanGroupID == x.workPlanGroupID); x.saturdayShiftID = wplan.saturdayShiftID; x.sundayShiftID = wplan.sundayShiftID; x.mondayShiftID = wplan.mondayShiftID; x.tuesdayShiftID = wplan.tuesdayShiftID; x.wednesdayShiftID = wplan.wednesdayShiftID; x.thursdayShiftID = wplan.thursdayShiftID; x.fridayShiftID = wplan.fridayShiftID; x.employee = null; }); this.loadingPanel.ShowLoadingPanel = true; this.attendanceServices.saveEmployeeWorkPlanSetupList(this.empWorkPlanSetupList).subscribe( () => { }, (x) => { this.loadingPanel.ShowLoadingPanel = false; console.log(x); this.notificationService.showError(x.error); }, () => { this.loadingPanel.ShowLoadingPanel = false; this.notificationService.showSuccess('Saved Data successfully.'); } ); } public removeHandler(item: EmployeeWorkPlanSetup) { if (!confirm('Are you sure to delete the item?')) { return; } this.attendanceServices.deleteEmployeeWorkPlanSetupById(item).subscribe( () => { }, (x) => { this.notificationService.showError(x.error); }, () => { let indexOfTheItem = this.empWorkPlanSetupList.indexOf(item); if (indexOfTheItem > -1) { this.empWorkPlanSetupList.splice(indexOfTheItem, 1); } this.notificationService.showSuccess('Data Removed successfully.'); } ); } public getHolidayDayOfWeek( day: number): string { debugger; day = day + 1; switch (day) { case HolidayDayOfWeek.Sunday: return 'Sunday'; case HolidayDayOfWeek.Monday: return 'Monday'; case HolidayDayOfWeek.Tuesday: return 'Tuesday'; case HolidayDayOfWeek.Wednesday: return 'Wednesday'; case HolidayDayOfWeek.Thursday: return 'Thursday'; case HolidayDayOfWeek.Friday: return 'Friday'; case HolidayDayOfWeek.Saturday: return 'Saturday'; default: return ''; } } // getDayOfWeek(date: Date): string { // const daysOfWeek: string[] = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; // const dayIndex: number = date.getDay(); // return daysOfWeek[dayIndex]; // } // getDayOfWeekEnum(date: Date): EnumDayOfWeek { // console.log(date.getDay()); // const dayIndex: number = date.getDay(); // return dayIndex as EnumDayOfWeek; // } }