import { Component, ChangeDetectionStrategy, OnInit, ViewChild } from '@angular/core'; import { ApiService } from 'src/app/app.api.service'; import { HRMNotificationService } from 'src/app/app.notification.service'; import { VirtualGridComponent } from 'src/app/custom-components/virtual-grid/virtual-grid.component'; import { VirtualGridColumn, VirtualGridLoadedEvent } from 'src/app/_models/common/virtual-grid'; import { SystemConfigurationService } from 'src/app/_services/common/systemconfiguration.service'; import { SystemConfigaration } from 'src/app/_models/common/SystemConfigaration'; import { EnumConfigurationType } from 'src/app/_models/enums'; /** * Discontinue Employee Details: employees discontinued inside a date range, with the same columns as * Employee Details (/reports/report-viewer/empDetailInfo) plus the Discontinue Date. * * Data: EmployeeController.GetDiscontinueEmployeePage → EmployeeService.GetDiscontinuedEmployeeDetails. * The common does virtual scrolling, search, sort, total and Excel. */ @Component({ selector: 'app-discontinue-employee-details', templateUrl: './discontinue-employee-details.component.html', styleUrls: ['./discontinue-employee-details.component.scss'], changeDetection: ChangeDetectionStrategy.Eager, standalone: false, }) export class DiscontinueEmployeeDetailsComponent implements OnInit { @ViewChild('grid') grid: VirtualGridComponent; fromDate: Date = new Date(new Date().getFullYear(), new Date().getMonth(), 1); toDate: Date = new Date(); dateFormat = 'dd-MMM-yyyy'; /** Grid columns. field = property of DiscontinueEmployeeDetailInfo (camelCase). */ columns: VirtualGridColumn[] = []; constructor(public apiService: ApiService, public notificationService: HRMNotificationService, private systemConfigService: SystemConfigurationService) { this.apiService.selectedMenuName = 'Discontinue Employee Details'; } ngOnInit(): void { // Department tier headings come from the Logic configuration, as in Employee Details. this.systemConfigService.GetAllChildrenByParentNode(EnumConfigurationType.Logic, 'department').subscribe( (configs: SystemConfigaration[]) => this.columns = this.buildColumns(configs || []), () => this.columns = this.buildColumns([]) ); } preview(): void { if (!this.fromDate || !this.toDate) { this.notificationService.showWarning('Please select From Date and To Date.', 'Warning'); return; } if (this.fromDate > this.toDate) { this.notificationService.showWarning('From Date cannot be after To Date.', 'Warning'); return; } this.grid.load({ fromDate: this.fromDate, toDate: this.toDate }); } onLoaded(event: VirtualGridLoadedEvent): void { if (event.firstLoad && event.total === 0) { this.notificationService.showWarning('No employee was discontinued in the selected date range.', 'Warning'); } } private buildColumns(configs: SystemConfigaration[]): VirtualGridColumn[] { const tierFields = ['deptireOne', 'deptireTwo', 'deptireThree', 'deptireFour', 'deptireFive']; const tierColumns: VirtualGridColumn[] = configs .filter(c => (c.node || '').toLowerCase() === 'text') .slice(0, tierFields.length) .map((c, i) => ({ field: tierFields[i], title: c.value, width: 150 })); return [ { field: 'employeeNo', title: 'Employee No', width: 110 }, { field: 'name', title: 'Employee Name', width: 220 }, { field: 'gender', title: 'Gender', width: 100 }, { field: 'birthDate', title: 'Birth Date', width: 120, type: 'date' }, { field: 'joiningDate', title: 'Joining Date', width: 120, type: 'date' }, { field: 'discontinueDate', title: 'Discontinue Date', width: 140, type: 'date' }, { field: 'mobileNo', title: 'Mobile No', width: 130 }, { field: 'emailAddress', title: 'Email Address', width: 200 }, { field: 'designation', title: 'Designation', width: 160 }, { field: 'grade', title: 'Grade', width: 120 }, { field: 'category', title: 'Category', width: 120 }, { field: 'status', title: 'Status', width: 120 }, ...tierColumns, { field: 'location', title: 'Location', width: 130 }, { field: 'religion', title: 'Religion', width: 110 }, { field: 'maritalStatus', title: 'Marital Status', width: 120 }, { field: 'dateOfConfirmation', title: 'Confirmation', width: 120, type: 'date' }, { field: 'basicSalary', title: 'Basic Salary', width: 120, type: 'money' }, { field: 'grossSalary', title: 'Gross Salary', width: 120, type: 'money' }, { field: 'passportNo', title: 'Passport No', width: 120 }, { field: 'bloodGroup', title: 'Blood Group', width: 110 }, { field: 'lineManagerNo', title: 'LineManager No', width: 130 }, { field: 'lineManagerName', title: 'LineManager Name', width: 180 }, { field: 'lineManagerEmail', title: 'LineManager Email', width: 200 }, { field: 'empStatus', title: 'Employee Status', width: 130 }, { field: 'bank', title: 'Bank', width: 150 }, { field: 'branch', title: 'Branch', width: 150 }, { field: 'accountNo', title: 'Account No', width: 150 }, { field: 'nationalId', title: 'National ID/NID', width: 150 }, { field: 'tinNo', title: 'TIN', width: 120 }, ]; } }