diff --git a/HRM.BO/Employee/Employee.cs b/HRM.BO/Employee/Employee.cs index 4ddf416..25e8573 100644 --- a/HRM.BO/Employee/Employee.cs +++ b/HRM.BO/Employee/Employee.cs @@ -522,6 +522,7 @@ namespace HRM.BO List GetAllEmps(); void UpdateLM2(List emps); List GetWithDiscontinue(int payrollTypeID); + List GetDiscontinuedInRange(DateTime fromDate, DateTime toDate, int payrollTypeID); List GetSubordinates(int employeeID); //List GetAllSubordinates(int nodeID); List GetByDeptShiftGFType(string deptIDs, int shiftID, string GFType, int payrollTypeID); diff --git a/HRM.DA/DA/Employee/EmployeeDA.cs b/HRM.DA/DA/Employee/EmployeeDA.cs index 6adbd52..27d205e 100644 --- a/HRM.DA/DA/Employee/EmployeeDA.cs +++ b/HRM.DA/DA/Employee/EmployeeDA.cs @@ -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 diff --git a/HRM.DA/Service/Employee/EmployeeService.cs b/HRM.DA/Service/Employee/EmployeeService.cs index f0d72a9..5b368ad 100644 --- a/HRM.DA/Service/Employee/EmployeeService.cs +++ b/HRM.DA/Service/Employee/EmployeeService.cs @@ -1482,6 +1482,37 @@ namespace HRM.DA return employees; } + public List GetDiscontinuedInRange(DateTime fromDate, DateTime toDate, int payrollTypeID) + { + List employees = new List(); + + TransactionContext tc = null; + try + { + tc = TransactionContext.Begin(); + + DataReader dr = new DataReader(EmployeeDA.GetDiscontinuedInRange(tc, fromDate, toDate, payrollTypeID)); + employees = this.CreateObjects(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 GetWithDiscontinue(int payrollTypeID) { List employees = new List(); diff --git a/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts b/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts index 87e80c1..6eb58a8 100644 --- a/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts +++ b/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts @@ -326,6 +326,12 @@ export class EmployeeServices { return this.apiService.httpPost('/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('/Employee/getDiscontinueEmpDetailInfo', { fromDate: fromDate, toDate: toDate }); + } + getCurrentHeadCount(departmentId: number, designationId: number, gradeId: number) { return this.apiService.httpGet('/Employee/getCurrentHeadCount' + '/' + departmentId + '/' + designationId + '/' + gradeId); } diff --git a/HRM.UI/ClientApp/src/app/reports/discontinue-employee-details/discontinue-employee-details.component.html b/HRM.UI/ClientApp/src/app/reports/discontinue-employee-details/discontinue-employee-details.component.html new file mode 100644 index 0000000..fe546dc --- /dev/null +++ b/HRM.UI/ClientApp/src/app/reports/discontinue-employee-details/discontinue-employee-details.component.html @@ -0,0 +1,44 @@ + +
+Search Criteria +
+
+ + +
+
+ + +
+
+ +
+
+
+ +@if (showGrid) { +
+ + + + + + + + + @for (column of columns; track column.field) { + + + } + + +
+} diff --git a/HRM.UI/ClientApp/src/app/reports/discontinue-employee-details/discontinue-employee-details.component.scss b/HRM.UI/ClientApp/src/app/reports/discontinue-employee-details/discontinue-employee-details.component.scss new file mode 100644 index 0000000..778804b --- /dev/null +++ b/HRM.UI/ClientApp/src/app/reports/discontinue-employee-details/discontinue-employee-details.component.scss @@ -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; + } +} diff --git a/HRM.UI/ClientApp/src/app/reports/discontinue-employee-details/discontinue-employee-details.component.ts b/HRM.UI/ClientApp/src/app/reports/discontinue-employee-details/discontinue-employee-details.component.ts new file mode 100644 index 0000000..8472e09 --- /dev/null +++ b/HRM.UI/ClientApp/src/app/reports/discontinue-employee-details/discontinue-employee-details.component.ts @@ -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; + } +} diff --git a/HRM.UI/ClientApp/src/app/reports/reports-routing.module.ts b/HRM.UI/ClientApp/src/app/reports/reports-routing.module.ts index b4244e2..5b884a3 100644 --- a/HRM.UI/ClientApp/src/app/reports/reports-routing.module.ts +++ b/HRM.UI/ClientApp/src/app/reports/reports-routing.module.ts @@ -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] }, diff --git a/HRM.UI/ClientApp/src/app/reports/reports.module.ts b/HRM.UI/ClientApp/src/app/reports/reports.module.ts index d593a5b..5101ad7 100644 --- a/HRM.UI/ClientApp/src/app/reports/reports.module.ts +++ b/HRM.UI/ClientApp/src/app/reports/reports.module.ts @@ -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, diff --git a/HRM.UI/Controllers/Employee/EmployeeController.cs b/HRM.UI/Controllers/Employee/EmployeeController.cs index 9dd96d8..fe3b1a4 100644 --- a/HRM.UI/Controllers/Employee/EmployeeController.cs +++ b/HRM.UI/Controllers/Employee/EmployeeController.cs @@ -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 + } + + /// + /// 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. + /// + [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 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()); + + // Built here rather than with Employee.getSearchEmp, which casts DepartmentID for + // LocationID/GradeID and throws when an employee has no department. + List 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 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(); + 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]