import { Component, ChangeDetectionStrategy, ViewChild } from '@angular/core'; import { DatePipe } from '@angular/common'; 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 { VirtualGridLoadedEvent } from 'src/app/_models/common/virtual-grid'; /** * Discontinue Employee Details: employees discontinued inside a date range, with the same columns as * Employee Details (/reports/report-viewer/empDetailInfo) plus the Discontinue Date. * * The grid is the common (server grid "discontinue-employee", * HRM.DA/Service/VirtualGrid/Definitions/DiscontinueEmployeeVirtualGrid.cs); this screen only owns its filters. */ @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 { @ViewChild('grid') grid: VirtualGridComponent; fromDate: Date = new Date(new Date().getFullYear(), new Date().getMonth(), 1); toDate: Date = new Date(); dateFormat = 'dd-MMM-yyyy'; constructor(public apiService: ApiService, public notificationService: HRMNotificationService, private datePipe: DatePipe) { this.apiService.selectedMenuName = 'Discontinue Employee Details'; } 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.datePipe.transform(this.fromDate, 'yyyy-MM-dd'), toDate: this.datePipe.transform(this.toDate, 'yyyy-MM-dd'), }); } onLoaded(event: VirtualGridLoadedEvent): void { if (event.firstLoad && event.total === 0) { this.notificationService.showWarning('No employee was discontinued in the selected date range.', 'Warning'); } } }