Discontinue Employee Reports

This commit is contained in:
Mohaimen Hasan 2026-11-09 11:59:10 +06:00
parent ad77279acf
commit b11141a57c
10 changed files with 396 additions and 1 deletions

View File

@ -522,6 +522,7 @@ namespace HRM.BO
List<Employee> GetAllEmps();
void UpdateLM2(List<Employee> emps);
List<Employee> GetWithDiscontinue(int payrollTypeID);
List<Employee> GetDiscontinuedInRange(DateTime fromDate, DateTime toDate, int payrollTypeID);
List<Employee> GetSubordinates(int employeeID);
//List<Employee> GetAllSubordinates(int nodeID);
List<Employee> GetByDeptShiftGFType(string deptIDs, int shiftID, string GFType, int payrollTypeID);

View File

@ -663,6 +663,18 @@ namespace HRM.DA
return tc.ExecuteReader(sql);
}
// Discontinue Employee Details report: employees discontinued (Status = Discontinued)
// whose discontinue date (ENDOFCONTRACTDATE) falls inside the date range.
internal static IDataReader GetDiscontinuedInRange(TransactionContext tc, DateTime fromDate, DateTime toDate,
int payrollTypeID)
{
string sql = SQLParser.MakeSQL(
"SELECT * FROM Employee WHERE STATUS = %n AND ENDOFCONTRACTDATE IS NOT NULL "
+ "AND CAST(ENDOFCONTRACTDATE AS DATE) BETWEEN %d AND %d AND PAYROLLTYPEID = %n order by EmployeeNo",
(int)EnumEmployeeStatus.Discontinued, fromDate, toDate, payrollTypeID);
return tc.ExecuteReader(sql);
}
internal static IDataReader GetAllSubordinatesNew(TransactionContext tc, int employeeID)
{
//For Oracle

View File

@ -1482,6 +1482,37 @@ namespace HRM.DA
return employees;
}
public List<Employee> GetDiscontinuedInRange(DateTime fromDate, DateTime toDate, int payrollTypeID)
{
List<Employee> employees = new List<Employee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeDA.GetDiscontinuedInRange(tc, fromDate, toDate, payrollTypeID));
employees = this.CreateObjects<Employee>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return employees;
}
public List<Employee> GetWithDiscontinue(int payrollTypeID)
{
List<Employee> employees = new List<Employee>();

View File

@ -326,6 +326,12 @@ export class EmployeeServices {
return this.apiService.httpPost<EmployeeDetailInfo[]>('/Employee/getEmpDetailInfo', emps);
}
// Discontinue Employee Details report: same rows as getEmpDetailInfo plus discontinueDate,
// for employees discontinued between fromDate and toDate (both 'yyyy-MM-dd').
getDiscontinueEmpDetailInfo(fromDate: string, toDate: string) {
return this.apiService.httpPost<any[]>('/Employee/getDiscontinueEmpDetailInfo', { fromDate: fromDate, toDate: toDate });
}
getCurrentHeadCount(departmentId: number, designationId: number, gradeId: number) {
return this.apiService.httpGet<number>('/Employee/getCurrentHeadCount' + '/' + departmentId + '/' + designationId + '/' + gradeId);
}

View File

@ -0,0 +1,44 @@
<app-loading-panel></app-loading-panel>
<fieldset class="filter-box">
<legend>Search Criteria</legend>
<div class="filter-bar">
<div class="filter-field">
<label>From Date</label>
<kendo-datepicker [(ngModel)]="fromDate" [format]="dateFormat"></kendo-datepicker>
</div>
<div class="filter-field">
<label>To Date</label>
<kendo-datepicker [(ngModel)]="toDate" [format]="dateFormat"></kendo-datepicker>
</div>
<div class="filter-action">
<button kendoButton themeColor="primary" [svgIcon]="apiService.KendoSVGIcon['filePdf']"
(click)="preview()">Preview</button>
</div>
</div>
</fieldset>
@if (showGrid) {
<div class="col-12">
<kendo-grid [kendoGridBinding]="filteredData" [sortable]="true" [resizable]="true" [pageable]="false"
[style.height]="'500px'">
<ng-template kendoGridToolbarTemplate>
<kendo-textbox class="grid-search" placeholder="Search in all columns..." [clearButton]="true"
[(ngModel)]="searchText" (valueChange)="onSearch($event)">
</kendo-textbox>
<label class="grid-count">
Total: {{ filteredData.length }}@if (searchText) { <span> of {{ data.length }}</span> }
</label>
<kendo-grid-spacer></kendo-grid-spacer>
<button type="button" kendoGridExcelCommand [svgIcon]="apiService.KendoSVGIcon['fileExcel']"
[disabled]="filteredData.length === 0">
Export to Excel
</button>
</ng-template>
@for (column of columns; track column.field) {
<kendo-grid-column [field]="column.field" [title]="column.title" [width]="column.width">
</kendo-grid-column>
}
<kendo-grid-excel [fileName]="excelFileName"></kendo-grid-excel>
</kendo-grid>
</div>
}

View File

@ -0,0 +1,60 @@
// Bordered box around the search criteria.
.filter-box {
border: 1px solid #d0d5dd;
border-radius: 6px;
padding: 4px 16px 16px;
margin: 0 0.5rem 14px;
legend {
padding: 0 6px;
font-weight: 600;
width: auto;
}
}
// Labels sit above their date pickers; the Preview button lines up with the pickers' bottom edge.
.filter-bar {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 12px 24px;
}
.filter-field {
display: flex;
flex-direction: column;
gap: 4px;
width: 280px;
label {
font-weight: 600;
}
kendo-datepicker {
width: 100%;
}
}
.filter-action {
margin-left: auto;
}
.grid-search {
width: 280px;
}
.grid-count {
margin-left: 12px;
white-space: nowrap;
}
@media (max-width: 600px) {
.filter-field,
.grid-search {
width: 100%;
}
.filter-action {
margin-left: 0;
}
}

View File

@ -0,0 +1,168 @@
import { Component, OnInit, ChangeDetectionStrategy } 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 { loadingPanelService } from 'src/app/hrm-loding panel/loding.panel.service';
import { EmployeeServices } from 'src/app/_services/employee/employee.service';
import { SystemConfigurationService } from 'src/app/_services/common/systemconfiguration.service';
import { SystemConfigaration } from 'src/app/_models/common/SystemConfigaration';
import { EnumConfigurationType } from 'src/app/_models/enums';
interface GridColumn {
field: string;
title: string;
width: number;
}
/**
* Discontinue Employee Details: the same columns as Employee Details
* (/reports/report-viewer/empDetailInfo), but only for the employees discontinued
* inside a date range, plus their Discontinue Date. Export to Excel from the grid.
*/
@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 {
fromDate: Date = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
toDate: Date = new Date();
dateFormat = 'dd-MMM-yyyy';
data: any[] = [];
filteredData: any[] = [];
searchText = '';
showGrid = false;
columns: GridColumn[] = [];
excelFileName = 'DiscontinueEmployeeDetails.xlsx';
constructor(public apiService: ApiService,
public notificationService: HRMNotificationService,
public loadingPanel: loadingPanelService,
private employeeService: EmployeeServices,
private systemConfigService: SystemConfigurationService,
private datePipe: DatePipe) {
this.apiService.selectedMenuName = 'Discontinue Employee Details';
}
ngOnInit(): void {
this.buildColumns([]);
this.systemConfigService.GetAllChildrenByParentNode(EnumConfigurationType.Logic, 'department').subscribe(
(configs: SystemConfigaration[]) => this.buildColumns(configs || []),
() => this.buildColumns([])
);
}
/** Same columns, in the same order, as the Employee Details report, plus Discontinue Date. */
private buildColumns(departmentConfigs: SystemConfigaration[]): void {
const cols: GridColumn[] = [
{ 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 },
{ field: 'joiningDate', title: 'Joining Date', width: 120 },
{ field: 'discontinueDate', title: 'Discontinue Date', width: 130 },
{ 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 },
];
// Department tier headings come from the Logic configuration, exactly as in Employee Details.
const tierFields = ['deptireOne', 'deptireTwo', 'deptireThree', 'deptireFour', 'deptireFive'];
let ind = 0;
departmentConfigs.forEach(c => {
if (c.node && c.node.toLocaleLowerCase() === 'text') {
if (ind < tierFields.length) {
cols.push({ field: tierFields[ind], title: c.value, width: 150 });
}
ind++;
}
});
cols.push(
{ 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 },
{ field: 'basicSalary', title: 'Basic Salary', width: 120 },
{ field: 'grossSalary', title: 'Gross Salary', width: 120 },
{ 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 },
);
this.columns = cols;
}
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;
}
const from = this.datePipe.transform(this.fromDate, 'yyyy-MM-dd');
const to = this.datePipe.transform(this.toDate, 'yyyy-MM-dd');
this.excelFileName = 'DiscontinueEmployeeDetails_' + from + '_to_' + to + '.xlsx';
this.loadingPanel.ShowLoadingPanel = true;
this.showGrid = false;
this.searchText = '';
this.employeeService.getDiscontinueEmpDetailInfo(from, to).subscribe(
(resp: any[]) => {
this.data = (resp || []).map(row => this.formatRow(row));
this.filteredData = this.data;
},
(err) => {
this.loadingPanel.ShowLoadingPanel = false;
this.notificationService.showError(err && err.error ? err.error : 'Failed to load discontinued employees.');
},
() => {
this.loadingPanel.ShowLoadingPanel = false;
this.showGrid = true;
if (this.data.length === 0) {
this.notificationService.showWarning('No employee was discontinued in the selected date range.', 'Warning');
}
}
);
}
/** Keeps the rows where any shown column contains the search text (case-insensitive). */
onSearch(value: string): void {
const term = (value || '').trim().toLowerCase();
if (!term) {
this.filteredData = this.data;
return;
}
const fields = this.columns.map(c => c.field);
this.filteredData = this.data.filter(row =>
fields.some(f => row[f] != null && String(row[f]).toLowerCase().includes(term)));
}
/** Same display formatting as Employee Details: dates as 'dd MMM yyyy', salaries with 2 decimals. */
private formatRow(row: any): any {
['birthDate', 'joiningDate', 'dateOfConfirmation', 'discontinueDate'].forEach(f => {
row[f] = row[f] != null ? this.datePipe.transform(row[f], 'dd MMM yyyy') : '';
});
const money = new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
['basicSalary', 'grossSalary'].forEach(f => {
row[f] = row[f] != null ? money.format(row[f]) : '0.00';
});
return row;
}
}

View File

@ -33,6 +33,7 @@ import { CcwiseNewPfMemberWithAmountComponent } from './ccwise-new-pf-member-wit
import { TrainingReportsComponent } from './training-reports/training-reports.component';
import { EssTaxCertificateComponent } from './ess-tax-certificate/ess-tax-certificate.component';
import { JvReportComponent } from './jv-report/jv-report.component';
import { DiscontinueEmployeeDetailsComponent } from './discontinue-employee-details/discontinue-employee-details.component';
export const routes: Routes = [
{ path: 'report-viewer/36', component: ReportViewerComponent, canActivate: [AuthGuard] },
@ -82,6 +83,7 @@ export const routes: Routes = [
{ path: 'date-wise-job-card-new', component: DateWiseJobCardNewComponent, canActivate: [AuthGuard] },
{ path: 'date-wise-attn-records', component: DateWiseAttnRecordsComponent, canActivate: [AuthGuard] },
{ path: 'monthly-exception-report', component: MonthlyExceptionReportComponent, canActivate: [AuthGuard] },
{ path: 'discontinue-employee-details', component: DiscontinueEmployeeDetailsComponent, canActivate: [AuthGuard] },
{ path: 'report-viewer/34', component: ReportViewerComponent, canActivate: [AuthGuard] },
{ path: 'report-viewer/170', component: ReportViewerComponent, canActivate: [AuthGuard] },
{ path: 'report-viewer/169', component: ReportViewerComponent, canActivate: [AuthGuard] },

View File

@ -56,6 +56,7 @@ import { TabViewCompatModule } from 'src/app/custom-components/tab-view-compat/t
import { EssTaxCertificateComponent } from './ess-tax-certificate/ess-tax-certificate.component';
import { EmpCommonInformationModule } from '../ess/emp-common-information/EmpCommonInformationModule';
import { JvReportComponent } from './jv-report/jv-report.component';
import { DiscontinueEmployeeDetailsComponent } from './discontinue-employee-details/discontinue-employee-details.component';
@NgModule({
declarations: [
@ -86,7 +87,8 @@ import { JvReportComponent } from './jv-report/jv-report.component';
TrainingReportsComponent,
CareerHistoryReportComponent,
EssTaxCertificateComponent,
JvReportComponent
JvReportComponent,
DiscontinueEmployeeDetailsComponent
],
imports: [
TextBoxModule,

View File

@ -2213,6 +2213,75 @@ namespace HRM.UI.Controllers
return Ok(items);
}
public class DiscontinueEmpDetailRequest
{
public string FromDate { get; set; } // yyyy-MM-dd
public string ToDate { get; set; } // yyyy-MM-dd
}
/// <summary>
/// Discontinue Employee Details report: the same columns as Employee Details (getEmpDetailInfo),
/// but only for employees discontinued between FromDate and ToDate (by discontinue date),
/// in the current payroll type, plus their Discontinue Date. Reuses GetEmpDetailInfo unchanged.
/// </summary>
[HttpPost("getDiscontinueEmpDetailInfo")]
public ActionResult GetDiscontinueEmpDetailInfo(DiscontinueEmpDetailRequest request)
{
DateTime fromDate, toDate;
if (request == null
|| !DateTime.TryParseExact(request.FromDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.None, out fromDate)
|| !DateTime.TryParseExact(request.ToDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.None, out toDate))
return BadRequest("Please select a valid From Date and To Date.");
if (fromDate > toDate)
return BadRequest("From Date cannot be after To Date.");
List<Employee> discontinued;
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
discontinued = _EmployeeService.GetDiscontinuedInRange(fromDate, toDate, (int)currentUser.PayrollTypeID);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
if (discontinued.Count == 0)
return Ok(new List<Newtonsoft.Json.Linq.JObject>());
// Built here rather than with Employee.getSearchEmp, which casts DepartmentID for
// LocationID/GradeID and throws when an employee has no department.
List<SearchEmployee> selected = discontinued
.Select(x => new SearchEmployee { ID = x.ID, EmployeeID = x.ID, EmployeeNo = x.EmployeeNo, Name = x.Name })
.ToList();
ActionResult detailResult = GetEmpDetailInfo(selected);
if (!(detailResult is OkObjectResult ok) || !(ok.Value is List<EmployeeDetailInfo> details))
return detailResult;
var serializer = JsonSerializer.Create(new JsonSerializerSettings
{
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
});
var discontinueDates = discontinued
.GroupBy(x => x.EmployeeNo)
.ToDictionary(g => g.Key, g => g.First().EndOfContractDate);
var rows = new List<Newtonsoft.Json.Linq.JObject>();
foreach (EmployeeDetailInfo item in details)
{
var row = Newtonsoft.Json.Linq.JObject.FromObject(item, serializer);
DateTime? discontinueDate = null;
if (item.EmployeeNo != null && discontinueDates.TryGetValue(item.EmployeeNo, out DateTime? d))
discontinueDate = d;
row["discontinueDate"] = discontinueDate;
rows.Add(row);
}
return Ok(rows);
}
//[HttpPost("getEmpApiResponse")]
//[AllowAnonymous]