From 16f6a635fd7417b412b87ed60c75b8a5fd8c07fd Mon Sep 17 00:00:00 2001 From: Mohaimen Hasan Date: Sun, 29 Nov 2026 18:51:10 +0600 Subject: [PATCH] Category Wise Salary Process --- HRM.BO/Salary/SalaryProcess.cs | 1 + HRM.BO/Tax/IncomeTax.cs | 46 +++++++++------- HRM.DA/DA/Salary/SalaryProcessDA.cs | 14 +++++ HRM.DA/Service/Salary/SalaryProcessService.cs | 29 ++++++++++ .../app/_services/payroll/salary.service.ts | 5 ++ .../bonus-approve.component.html | 2 + .../salary-process.component.html | 26 ++++++++- .../salary-process.component.ts | 54 +++++++++++++++++-- .../Controllers/Payroll/SalaryController.cs | 19 +++++++ 9 files changed, 173 insertions(+), 23 deletions(-) diff --git a/HRM.BO/Salary/SalaryProcess.cs b/HRM.BO/Salary/SalaryProcess.cs index ace1bbc..917a92c 100644 --- a/HRM.BO/Salary/SalaryProcess.cs +++ b/HRM.BO/Salary/SalaryProcess.cs @@ -462,6 +462,7 @@ namespace HRM.BO bool GetBySMonth(DateTime sMonth, int payrollTypeID); List SalaryProcess(SalaryProcess item, List employees); + List GetCategoryEmployeeIDs(int categoryID, int payrollTypeID, DateTime salaryMonth); int Save(SalaryProcess item); void Delete(int id); diff --git a/HRM.BO/Tax/IncomeTax.cs b/HRM.BO/Tax/IncomeTax.cs index 2c8871b..d771352 100644 --- a/HRM.BO/Tax/IncomeTax.cs +++ b/HRM.BO/Tax/IncomeTax.cs @@ -89,28 +89,38 @@ namespace HRM.BO public EnumIncomeTaxItemGroup ItemGroup { get; set; } public EnumIncomeTaxSide Side { get; set; } - //#region Service Factory IIncomeTaxService : IIncomeTaxService + //#region Service Factory IIncomeTaxService : IIncomeTaxService - //internal static IIncomeTaxService Service - //{ - // get { return Services.Factory.CreateService(typeof(IIncomeTaxService)); } - //} + //internal static IIncomeTaxService Service + //{ + // get { return Services.Factory.CreateService(typeof(IIncomeTaxService)); } + //} - //#endregion + //#endregion - #endregion - public string getEmpID(List items) + #endregion + + //public string getEmpID(List items) + //{ + // string str = ""; + // items.ForEach(x => + // { + // if (x != null) + // str = str + x.EmployeeID + ","; + // }); + + // if (str.Length > 0) str = str.Substring(0, str.Length - 1); + + // return str; + //} + + + // Comma-separated employee IDs of the rows, for "employeeID IN (...)". + // Each employee once: income-tax data has many rows per employee, and building the string by + // repeated concatenation made Bonus Approve take minutes on a large payroll. + public string getEmpID(List items) { - string str = ""; - items.ForEach(x => - { - if (x != null) - str = str + x.EmployeeID + ","; - }); - - if (str.Length > 0) str = str.Substring(0, str.Length - 1); - - return str; + return string.Join(",", items.Where(x => x != null).Select(x => x.EmployeeID).Distinct()); } diff --git a/HRM.DA/DA/Salary/SalaryProcessDA.cs b/HRM.DA/DA/Salary/SalaryProcessDA.cs index e3e65ac..edbc5d8 100644 --- a/HRM.DA/DA/Salary/SalaryProcessDA.cs +++ b/HRM.DA/DA/Salary/SalaryProcessDA.cs @@ -21,6 +21,20 @@ namespace HRM.DA #endregion + #region Category employees (Salary Process screen, no employee selected) + + // Live employees of the payroll type in the category whose salary of the month is not processed yet + internal static IDataReader GetCategoryEmployeeIDs(TransactionContext tc, int categoryID, int payrollTypeID, DateTime salaryMonth) + { + return tc.ExecuteReader( + "SELECT e.EmployeeID FROM Employee e WHERE e.Status=%n AND e.PayrollTypeID=%n AND e.CategoryID=%n" + + " AND NOT EXISTS (SELECT 1 FROM SalaryMonthly sm WHERE sm.EmployeeID = e.EmployeeID AND sm.SalaryMonth=%d AND sm.PayrollTypeID=%n)" + + " ORDER BY e.EmployeeNo", + (int)EnumEmployeeStatus.Live, payrollTypeID, categoryID, salaryMonth, payrollTypeID); + } + + #endregion + #region Insert function internal static void Insert(TransactionContext tc, SalaryProcess item) diff --git a/HRM.DA/Service/Salary/SalaryProcessService.cs b/HRM.DA/Service/Salary/SalaryProcessService.cs index 8aebcac..e737f3a 100644 --- a/HRM.DA/Service/Salary/SalaryProcessService.cs +++ b/HRM.DA/Service/Salary/SalaryProcessService.cs @@ -339,6 +339,35 @@ namespace HRM.DA } return errorList; } + // Salary Process screen, no employee selected but a Category: the Live employees of the payroll type in + // that category whose salary of the month is not processed yet (the employee picker leaves those out too) + public List GetCategoryEmployeeIDs(int categoryID, int payrollTypeID, DateTime salaryMonth) + { + List employeeIDs = new List(); + TransactionContext tc = null; + try + { + tc = TransactionContext.Begin(); + DataReader dr = new DataReader(SalaryProcessDA.GetCategoryEmployeeIDs(tc, categoryID, payrollTypeID, salaryMonth)); + while (dr.Read()) + { + employeeIDs.Add(dr.GetInt32("EmployeeID").Value); + } + 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 employeeIDs; + } + public List SalaryProcess(SalaryProcess item, List employees) { try diff --git a/HRM.UI/ClientApp/src/app/_services/payroll/salary.service.ts b/HRM.UI/ClientApp/src/app/_services/payroll/salary.service.ts index 650106b..cf10d81 100644 --- a/HRM.UI/ClientApp/src/app/_services/payroll/salary.service.ts +++ b/HRM.UI/ClientApp/src/app/_services/payroll/salary.service.ts @@ -207,6 +207,11 @@ export class SalaryService { return this.apiService.httpPost('/salary/salaryValidation', params); } + // Salary Process screen: employees of a category (payroll type wise, Live, salary not processed yet) + getCategoryEmployeeIDsForSalary(categoryID: number) { + return this.apiService.httpGet('/salary/getCategoryEmployeeIDsForSalary/' + categoryID); + } + salaryProcess(params: any) { return this.apiService.httpPost('/salary/SalaryProcess', params); } diff --git a/HRM.UI/ClientApp/src/app/payroll-ot/bonus-approve/bonus-approve.component.html b/HRM.UI/ClientApp/src/app/payroll-ot/bonus-approve/bonus-approve.component.html index 079a00d..a0cefa7 100644 --- a/HRM.UI/ClientApp/src/app/payroll-ot/bonus-approve/bonus-approve.component.html +++ b/HRM.UI/ClientApp/src/app/payroll-ot/bonus-approve/bonus-approve.component.html @@ -1,3 +1,5 @@ + +
diff --git a/HRM.UI/ClientApp/src/app/payroll/salary/salary-process/salary-process.component.html b/HRM.UI/ClientApp/src/app/payroll/salary/salary-process/salary-process.component.html index 9fe035e..abc08e8 100644 --- a/HRM.UI/ClientApp/src/app/payroll/salary/salary-process/salary-process.component.html +++ b/HRM.UI/ClientApp/src/app/payroll/salary/salary-process/salary-process.component.html @@ -33,6 +33,7 @@
+ +
+
+ +
+
+ + + +
+
@@ -143,7 +162,12 @@
- + + diff --git a/HRM.UI/ClientApp/src/app/payroll/salary/salary-process/salary-process.component.ts b/HRM.UI/ClientApp/src/app/payroll/salary/salary-process/salary-process.component.ts index 6008f96..f88dc33 100644 --- a/HRM.UI/ClientApp/src/app/payroll/salary/salary-process/salary-process.component.ts +++ b/HRM.UI/ClientApp/src/app/payroll/salary/salary-process/salary-process.component.ts @@ -6,6 +6,8 @@ import {DataTransferService} from '../../../data.transfer.service'; import {loadingPanelService} from '../../../hrm-loding panel/loding.panel.service'; import {PayrollType} from '../../../_models/Authentication/payrollType'; import {SearchEmployee} from '../../../_models/Employee/searchEmployee'; +import {Category} from '../../../_models/Basic/category'; +import {EnumStatus} from '../../../_models/enums'; import {SalaryProcessStatus, SalaryProcessSummaryItem} from '../../../_models/Payroll/salaryProcess'; import {AuthService} from '../../../_services/auth/auth.service'; import {BasicService} from '../../../_services/Basic/basic.service'; @@ -42,6 +44,9 @@ export class SalaryProcessComponent implements OnInit { returnMessage: string = ''; processRequest: { paymentDate: Date, remarks: string, empid: number, euroRate: number }[]; euroRate = 0; + // Category: when no employee is selected, the salary of this category's employees is processed + categories: Category[] = []; + selectedCategoryID: number = null; // Salary summary panel (collapsed by default, loaded on first expand per salary month) showSummary: boolean = false; @@ -75,6 +80,15 @@ export class SalaryProcessComponent implements OnInit { this.pbuttonEnalble = true; this.createFrom(); + // categories of the current payroll type (the API filters by the login's payroll type) + this.basicDataService.getAllCategory(EnumStatus.Active).subscribe( + (resp: Category[]) => { + this.categories = resp || []; + }, + (err: any) => { + this.notificationService.showError(err.error); + }); + this.authservice.GetPayrollTypeByLoginID().subscribe( (resp: any) => { this.payrollType = resp; @@ -170,6 +184,7 @@ export class SalaryProcessComponent implements OnInit { salaryMonth: ['', Validators.required], processDate: ['', Validators.required], euroRate: [0, Validators.required], + category: [null], }); } @@ -182,16 +197,47 @@ export class SalaryProcessComponent implements OnInit { } process() { - if (this.selectedEmps == undefined || this.selectedEmps.length == 0) { - this.notificationService.showWarning('Please select employee for the proces'); + if (this.selectedEmps != undefined && this.selectedEmps.length > 0) { + // employees selected: processed exactly as before (the Category is not used) + this.runSalaryProcess(this.selectedEmps.map(x => x.employeeID)); + return; + } + if (this.selectedCategoryID == undefined || this.selectedCategoryID == null || this.selectedCategoryID <= 0) { + this.notificationService.showWarning('Please select employee or category for the proces'); return; } + // no employee selected: the Live employees of the category (current payroll type) whose salary of + // this month is not processed yet, then the same process as for selected employees + let empIDs: number[] = []; + this.loadingPanelService.ShowLoadingPanel = true; + this.salaryservice.getCategoryEmployeeIDsForSalary(this.selectedCategoryID).subscribe( + (resp: number[]) => { + empIDs = resp || []; + }, + (err: any) => { + this.loadingPanelService.ShowLoadingPanel = false; + this.notificationService.showError(err.error); + this.returnMessage = err.error; + }, + () => { + this.loadingPanelService.ShowLoadingPanel = false; + if (empIDs.length == 0) { + this.notificationService.showWarning('Employee not found of this category.'); + this.returnMessage = 'Employee not found of this category.'; + return; + } + this.runSalaryProcess(empIDs); + }); + } + + // the salary process itself, unchanged: one request item per employee + private runSalaryProcess(empIDs: number[]) { this.loadingPanelService.ShowLoadingPanel = true; var returnID: number; this.processRequest = []; - this.selectedEmps.forEach(x => { - this.processRequest.push({ 'paymentDate': this.paymentdate, 'remarks': this.remarks, 'empid': x.employeeID, 'euroRate': this.euroRate }); + empIDs.forEach(empID => { + this.processRequest.push({ 'paymentDate': this.paymentdate, 'remarks': this.remarks, 'empid': empID, 'euroRate': this.euroRate }); }); this.errorOrSucessList = []; this.salaryservice.salaryProcess(this.processRequest).subscribe( diff --git a/HRM.UI/Controllers/Payroll/SalaryController.cs b/HRM.UI/Controllers/Payroll/SalaryController.cs index ecd9cb6..63ab486 100644 --- a/HRM.UI/Controllers/Payroll/SalaryController.cs +++ b/HRM.UI/Controllers/Payroll/SalaryController.cs @@ -1197,6 +1197,25 @@ namespace HRM.UI.Controllers.Payroll } + // Salary Process screen: no employee selected but a Category -> the employees to process + [HttpGet("getCategoryEmployeeIDsForSalary/{categoryID}")] + public ActionResult GetCategoryEmployeeIDsForSalary(int categoryID) + { + CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); + List employeeIDs = new List(); + try + { + employeeIDs = _salaryProcessService.GetCategoryEmployeeIDs(categoryID, (int)currentUser.PayrollTypeID, + (DateTime)currentUser.NextPayProcessDate); + } + catch (Exception e) + { + return StatusCode(StatusCodes.Status500InternalServerError, e.Message); + } + + return Ok(employeeIDs); + } + [HttpPost] [Route("undoSalaryProcessById")] public ActionResult UndoSalaryProcessById(SalaryProcess item)