From 9944262dd1ec4fb13e6bbbdb4b527f5be0cf1bad Mon Sep 17 00:00:00 2001 From: Mohaimen Hasan Date: Wed, 11 Nov 2026 13:15:14 +0600 Subject: [PATCH] Bonus Process Employee Loading --- HRM.BO/Employee/Employee.cs | 1 + HRM.BO/Employee/EmployeeLite.cs | 17 +++++++ HRM.DA/DA/Employee/EmployeeDA.cs | 28 ++++++++++++ HRM.DA/Service/Employee/EmployeeService.cs | 45 +++++++++++++++++++ .../src/app/_models/Employee/employeeLite.ts | 7 +++ .../_services/employee/employee.service.ts | 6 +++ .../bonus-process.component.html | 7 ++- .../bonus-process/bonus-process.component.ts | 29 ++++++------ .../app/picker/employee-picker.component.html | 2 +- .../Employee/EmployeeController.cs | 21 +++++++++ 10 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 HRM.BO/Employee/EmployeeLite.cs create mode 100644 HRM.UI/ClientApp/src/app/_models/Employee/employeeLite.ts diff --git a/HRM.BO/Employee/Employee.cs b/HRM.BO/Employee/Employee.cs index 10219f7..42c8ba6 100644 --- a/HRM.BO/Employee/Employee.cs +++ b/HRM.BO/Employee/Employee.cs @@ -563,6 +563,7 @@ namespace HRM.BO //void SaveBasicInfo(Employee item); List GetByEmpIDs(string empIDs, int payrollTypeID); List GetByEmpIDs(string empIDs); + List GetLiteByEmpIDs(List empIDs); List GetFssEmp(string empIDs, int payrollTypeID); List GetEmpsWithDiscontinue(string empIDs, int payrollTypeID); DataSet GetEmpJoining4Novartis(DateTime dEffectDate, int payrollTypeID); diff --git a/HRM.BO/Employee/EmployeeLite.cs b/HRM.BO/Employee/EmployeeLite.cs new file mode 100644 index 0000000..b340694 --- /dev/null +++ b/HRM.BO/Employee/EmployeeLite.cs @@ -0,0 +1,17 @@ +using System; + +namespace HRM.BO +{ + /// + /// A light Employee: only the few columns that screens working on thousands of employees at once need + /// (Bonus Process today). Loading the whole Employee row for 10k+ employees never reached the browser. + /// To add a field: add the property here, the column in EmployeeDA.GetLiteByEmpIDs, and the read in + /// EmployeeService.GetLiteByEmpIDs (and in ClientApp _models/Employee/employeeLite.ts). + /// + public class EmployeeLite + { + public int EmployeeID { get; set; } + public bool IsConfirmed { get; set; } + public DateTime? JoiningDate { get; set; } + } +} diff --git a/HRM.DA/DA/Employee/EmployeeDA.cs b/HRM.DA/DA/Employee/EmployeeDA.cs index dab0422..83be850 100644 --- a/HRM.DA/DA/Employee/EmployeeDA.cs +++ b/HRM.DA/DA/Employee/EmployeeDA.cs @@ -798,6 +798,34 @@ namespace HRM.DA return dr; } + /// + /// The EmployeeLite columns only, for any number of employees (10k+ at a time). + /// The IDs go in as ONE varchar(max) parameter and land in a temp table with a primary key, so the + /// SQL text stays small and SQL Server knows how many rows to expect (an inline IN list or + /// STRING_SPLIT in the join is much slower at this size). Needs SQL Server 2016+ (STRING_SPLIT). + /// + internal static IDataReader GetLiteByEmpIDs(TransactionContext tc, List empIDs) + { + const string sql = @"SET NOCOUNT ON; + IF OBJECT_ID('tempdb..#elEmpIds') IS NOT NULL DROP TABLE #elEmpIds; + CREATE TABLE #elEmpIds (ID int NOT NULL PRIMARY KEY); + INSERT INTO #elEmpIds (ID) SELECT DISTINCT CONVERT(int, value) FROM STRING_SPLIT(@empIds, ',') WHERE value <> ''; + SELECT e.EMPLOYEEID AS EmployeeID, e.ISCONFIRMED AS IsConfirmed, e.JOININGDATE AS JoiningDate + FROM Employee e + INNER JOIN #elEmpIds t ON t.ID = e.EMPLOYEEID; + DROP TABLE #elEmpIds;"; + + // ints only (the caller passes List), so the parameter can never carry anything but digits and commas + string ids = string.Join(",", empIDs); + // must be a SqlParameter[]: Ease.Core casts the array to SqlParameter[], and a lone parameter + // passed to "params IDataParameter[]" would arrive as an IDataParameter[] and fail that cast + SqlParameter[] parameters = + { + SqlHelperExtension.CreateInParam("@empIds", SqlDbType.VarChar, ids, -1) // varchar(max) + }; + return tc.ExecuteReader(CommandType.Text, sql, parameters); + } + internal static IDataReader GetFssEmp(TransactionContext tc, string empIDs, int payrollTypeID) { string sTableName; diff --git a/HRM.DA/Service/Employee/EmployeeService.cs b/HRM.DA/Service/Employee/EmployeeService.cs index 295b305..e5b7abb 100644 --- a/HRM.DA/Service/Employee/EmployeeService.cs +++ b/HRM.DA/Service/Employee/EmployeeService.cs @@ -1890,6 +1890,51 @@ namespace HRM.DA return employees; } + + /// + /// A light Employee (EmployeeLite) for each of the given employees — an alternative to GetByEmpIDs + /// for screens that need only a few fields for thousands of employees (Bonus Process). + /// + public List GetLiteByEmpIDs(List empIDs) + { + List items = new List(); + if (empIDs == null || empIDs.Count == 0) + return items; + + TransactionContext tc = null; + try + { + tc = TransactionContext.Begin(); + + DataReader dr = new DataReader(EmployeeDA.GetLiteByEmpIDs(tc, empIDs.Distinct().ToList())); + while (dr.Read()) + { + items.Add(new EmployeeLite + { + EmployeeID = dr.GetInt32("EmployeeID").Value, + IsConfirmed = dr.GetBoolean("IsConfirmed", false), + JoiningDate = dr.GetDateTime("JoiningDate") + }); + } + 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 items; + } public void UpdateBanglaInformation(List employeBanglaInfo) { diff --git a/HRM.UI/ClientApp/src/app/_models/Employee/employeeLite.ts b/HRM.UI/ClientApp/src/app/_models/Employee/employeeLite.ts new file mode 100644 index 0000000..af25426 --- /dev/null +++ b/HRM.UI/ClientApp/src/app/_models/Employee/employeeLite.ts @@ -0,0 +1,7 @@ +// A light Employee: only the few fields screens working on thousands of employees at once need +// (api/Employee/getEmployeeLiteByEmpIDs). Mirrors HRM.BO.EmployeeLite — add a field in both. +export class EmployeeLite { + public employeeID: number; + public isConfirmed: boolean; + public joiningDate: Date; +} 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..e5c2ccf 100644 --- a/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts +++ b/HRM.UI/ClientApp/src/app/_services/employee/employee.service.ts @@ -11,6 +11,7 @@ import {TrainingType} from '../../_models/Basic/trainingType'; import {EducationType} from '../../_models/HRBasic/education-type'; import {NominationPurpose} from '../../_models/HRBasic/nomination-purpose'; import {Employee} from '../../_models/Employee/employee'; +import {EmployeeLite} from '../../_models/Employee/employeeLite'; import {EmployeeBankAccount} from '../../_models/Employee/employeeBankAccount'; import {EmployeeCostCenter} from '../../_models/Employee/employeeCostCenter'; import {Relation} from '../../_models/HRBasic/relation'; @@ -135,6 +136,11 @@ export class EmployeeServices { getEmployeesByEmpIDs(data: any) { return this.apiService.httpPost('/Employee/getEmployeesByEmpIDs', data); } + + // A light Employee (only a few fields) — light enough for 10k+ employees (Bonus Process). + getEmployeeLiteByEmpIDs(empIds: number[]) { + return this.apiService.httpPost('/Employee/getEmployeeLiteByEmpIDs', empIds); + } getEmployeeDetailByEmpIDs(data: any) { return this.apiService.httpPost('/Employee/getEmployeeDetailByEmpIDs', data); } diff --git a/HRM.UI/ClientApp/src/app/payroll-ot/bonus-process/bonus-process.component.html b/HRM.UI/ClientApp/src/app/payroll-ot/bonus-process/bonus-process.component.html index 837695a..7722ef0 100644 --- a/HRM.UI/ClientApp/src/app/payroll-ot/bonus-process/bonus-process.component.html +++ b/HRM.UI/ClientApp/src/app/payroll-ot/bonus-process/bonus-process.component.html @@ -131,7 +131,10 @@
- + + - +
diff --git a/HRM.UI/ClientApp/src/app/payroll-ot/bonus-process/bonus-process.component.ts b/HRM.UI/ClientApp/src/app/payroll-ot/bonus-process/bonus-process.component.ts index a8083be..7807d02 100644 --- a/HRM.UI/ClientApp/src/app/payroll-ot/bonus-process/bonus-process.component.ts +++ b/HRM.UI/ClientApp/src/app/payroll-ot/bonus-process/bonus-process.component.ts @@ -8,6 +8,7 @@ import {loadingPanelService} from '../../hrm-loding panel/loding.panel.service'; import {PayrollType} from '../../_models/Authentication/payrollType'; import {Bonus} from '../../_models/Basic/bonus'; import {Employee} from '../../_models/Employee/employee'; +import {EmployeeLite} from '../../_models/Employee/employeeLite'; import {SearchEmployee} from '../../_models/Employee/searchEmployee'; import {EnumIncomeTaxItemGroup, EnumStatus, EnumTaxMergeType} from '../../_models/enums'; import {BonusProcess, BonusProcessDetail} from '../../_models/Payroll/bonusProcess'; @@ -126,6 +127,7 @@ export class BonusProcessComponent implements OnInit { this.returnMessage = err.error; }, () => { + debugger; this.loadingPanelService.ShowLoadingPanel = false; this.RefreshDefaultGrid(); } @@ -159,6 +161,7 @@ export class BonusProcessComponent implements OnInit { } } }); + this.bonusProcess.bonusProcessDetails = [...this.bonusProcess.bonusProcessDetails]; this.RefreshEmployees(); if (this.alreadyProcessesList.length > 0) { this.showModal = true; @@ -167,37 +170,29 @@ export class BonusProcessComponent implements OnInit { } RefreshEmployees() { if (this.selectedEmps == undefined) return; - var ids = SearchEmployee.getEmpIds(this.selectedEmps); - - const data = { - dataList: ids, - }; - var emps: Employee[]; - + const empIds: number[] = this.selectedEmps.map(e => e.employeeID); + var emps: EmployeeLite[]; this.loadingPanelService.ShowLoadingPanel = true; - this.empService.getEmployeesByEmpIDs(data).subscribe( + this.empService.getEmployeeLiteByEmpIDs(empIds).subscribe( (resp: any) => { emps = resp; }, (err: any) => { this.loadingPanelService.ShowLoadingPanel = false; this.notificationService.showWarning(err.error); - }, () => { this.loadingPanelService.ShowLoadingPanel = false; emps.forEach(x => { - let bindex = this.bonusProcess.bonusProcessDetails.findIndex(b => b.employeeID == x.id); + let bindex = this.bonusProcess.bonusProcessDetails.findIndex(b => b.employeeID == x.employeeID); if (bindex != -1) { this.bonusProcess.bonusProcessDetails[bindex].employee.isConfirmed = x.isConfirmed; this.bonusProcess.bonusProcessDetails[bindex].employee.joiningDate = x.joiningDate; } }); - }); + }); } - checkWithOrTax(from: number, value: boolean) { - debugger; if (from == 1) { if (value == true) { this.isTaxProcess = false; @@ -509,8 +504,16 @@ export class BonusProcessComponent implements OnInit { removefromList(rowIndex: number) { this.bonusProcess.bonusProcessDetails.splice(rowIndex, 1); + // new array reference so the (virtual) grid re-reads it + this.bonusProcess.bonusProcessDetails = [...this.bonusProcess.bonusProcessDetails]; } + // Excel export: every row, not only the rows the virtual grid has on screen + public allBonusRows = (): any => { + const rows = this.bonusProcess?.bonusProcessDetails ?? []; + return { data: rows, total: rows.length }; + }; + removeHandler({dataItem}) { console.log(dataItem); } diff --git a/HRM.UI/ClientApp/src/app/picker/employee-picker.component.html b/HRM.UI/ClientApp/src/app/picker/employee-picker.component.html index 0d64364..79b9c9b 100644 --- a/HRM.UI/ClientApp/src/app/picker/employee-picker.component.html +++ b/HRM.UI/ClientApp/src/app/picker/employee-picker.component.html @@ -316,7 +316,7 @@
diff --git a/HRM.UI/Controllers/Employee/EmployeeController.cs b/HRM.UI/Controllers/Employee/EmployeeController.cs index f362815..c670638 100644 --- a/HRM.UI/Controllers/Employee/EmployeeController.cs +++ b/HRM.UI/Controllers/Employee/EmployeeController.cs @@ -2293,6 +2293,27 @@ namespace HRM.UI.Controllers return Ok(employeeList); } + + /// + /// A light Employee (EmployeeLite) for each posted employee ID (body: [1, 2, 3]). + /// For screens that pick 10k+ employees and need only a few fields (Bonus Process); + /// getEmployeesByEmpIDs returns the whole Employee row and is too heavy for that. + /// + [HttpPost("getEmployeeLiteByEmpIDs")] + public ActionResult GetEmployeeLiteByEmpIDs([FromBody] List empIds) + { + List items = new List(); + try + { + items = _EmployeeService.GetLiteByEmpIDs(empIds); + } + catch (Exception ex) + { + return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); + } + + return Ok(items); + } [HttpPost("updateBanglaInformation")] public ActionResult updateBanglaInformation(dynamic data) {