From f3ff0cd16a36e589f529bdcac1a880a960cdc512 Mon Sep 17 00:00:00 2001 From: Mohaimen Hasan Date: Sun, 29 Nov 2026 18:15:43 +0600 Subject: [PATCH] Bonus Process by Religion Done --- HRM.BO/Bonus/Bonus.cs | 1 + HRM.DA/DA/Bonus/BonusDA.cs | 9 ++++++ HRM.DA/DA/Bonus/BonusProcessDA.cs | 4 ++- HRM.DA/Service/Bonus/BonusProcessService.cs | 21 ++++++++++++-- HRM.DA/Service/Bonus/BonusService.cs | 28 +++++++++++++++++++ .../bonus-process/bonus-process.component.ts | 19 +++++++++++-- .../bonus-undo/bonus-undo.component.html | 3 ++ 7 files changed, 78 insertions(+), 7 deletions(-) diff --git a/HRM.BO/Bonus/Bonus.cs b/HRM.BO/Bonus/Bonus.cs index a89938b..11a50d9 100644 --- a/HRM.BO/Bonus/Bonus.cs +++ b/HRM.BO/Bonus/Bonus.cs @@ -211,6 +211,7 @@ namespace HRM.BO DataSet GetCCWiseBonusSummary(DateTime bMonthDate, string bonus); DataSet GetCCWiseBonus(DateTime bMonthDate, string bonus); List GetReligions(int bonusID); + List GetReligionEmployeeIDs(int bonusID, int payrollTypeID); } #endregion diff --git a/HRM.DA/DA/Bonus/BonusDA.cs b/HRM.DA/DA/Bonus/BonusDA.cs index c731dd3..6e859d1 100644 --- a/HRM.DA/DA/Bonus/BonusDA.cs +++ b/HRM.DA/DA/Bonus/BonusDA.cs @@ -141,6 +141,15 @@ namespace HRM.DA " WHERE br.BonusID=%n ORDER BY r.SequenceNo, r.Name", bonusID); } + // Live employees of the payroll type whose religion is one of the bonus's religions + internal static IDataReader GetReligionEmployeeIDs(TransactionContext tc, int bonusID, int payrollTypeID) + { + return tc.ExecuteReader( + "SELECT e.EmployeeID FROM Employee e WHERE e.Status=%n AND e.PayrollTypeID=%n" + + " AND e.ReligionID IN (SELECT br.ReligionID FROM BonusReligion br WHERE br.BonusID=%n) ORDER BY e.EmployeeNo", + (int)EnumEmployeeStatus.Live, payrollTypeID, bonusID); + } + internal static IDataReader GetReligionsByPayrollType(TransactionContext tc, int payrollTypeID) { return tc.ExecuteReader( diff --git a/HRM.DA/DA/Bonus/BonusProcessDA.cs b/HRM.DA/DA/Bonus/BonusProcessDA.cs index c2bb757..b7db8a8 100644 --- a/HRM.DA/DA/Bonus/BonusProcessDA.cs +++ b/HRM.DA/DA/Bonus/BonusProcessDA.cs @@ -716,7 +716,9 @@ AND BP.PayrollTypeID=%n", emps, FromDate, ToDate, payrollTypeID); internal static DataTable GetUnApprovedBonuses(TransactionContext tc, DateTime dMonthDate, int payrollTypeID) { return tc.ExecuteDataTable("SELECT *, b.name, (SELECT Count(*) FROM bonusProcessDetail bdetail WHERE bdetail.bonusProcessid = bp.bonusProcessid) Count, " + - "(CASE WHEN EXISTS (SELECT 1 FROM SalaryApprovalAttachment saa WHERE saa.ReferenceID = bp.bonusProcessid) THEN 1 ELSE 0 END) IsAttachment " + + "(CASE WHEN EXISTS (SELECT 1 FROM SalaryApprovalAttachment saa WHERE saa.ReferenceID = bp.bonusProcessid) THEN 1 ELSE 0 END) IsAttachment, " + + "(SELECT STRING_AGG(r.Name, ', ') WITHIN GROUP (ORDER BY r.SequenceNo, r.Name) FROM BonusReligion br " + + "INNER JOIN Religion r ON r.ReligionID = br.ReligionID WHERE br.BonusID = bp.bonusid) ReligionNames " + "FROM bonusProcess bp, bonus b WHERE b.bonusid = bp.bonusid AND bp.IsApprove = %b AND bp.BonusMonth = %d AND bp.PayrollTypeID = %n", false, dMonthDate, payrollTypeID); } diff --git a/HRM.DA/Service/Bonus/BonusProcessService.cs b/HRM.DA/Service/Bonus/BonusProcessService.cs index 2d68419..4434756 100644 --- a/HRM.DA/Service/Bonus/BonusProcessService.cs +++ b/HRM.DA/Service/Bonus/BonusProcessService.cs @@ -921,11 +921,24 @@ namespace HRM.DA throw new ServiceException("Nothing to process."); if (request.BonusID <= 0) throw new ServiceException("Please select a bonus."); - if (request.EmployeeIDs == null || request.EmployeeIDs.Count == 0) - throw new ServiceException("Please select employee for the proces"); if (request.CurrProcess <= 0) throw new ServiceException("Currently Process For Basic must be greater than zero."); + // No employee selected: a bonus with Religion(s) set (Bonus master) is processed for every Live + // employee of the current payroll type with one of those religions; without a Religion the + // employees must be selected, as before. + bool byReligion = false; + if (request.EmployeeIDs == null || request.EmployeeIDs.Count == 0) + { + BonusService bonusService = new BonusService(); + if (bonusService.GetReligions(request.BonusID).Count == 0) + throw new ServiceException("Please select employee for the process"); + request.EmployeeIDs = bonusService.GetReligionEmployeeIDs(request.BonusID, payrolltypeid); + if (request.EmployeeIDs.Count == 0) + throw new ServiceException("Employee not found of this bonus's religion(s)."); + byReligion = true; + } + PayrollType payrollType = new PayrollTypeService().Get(payrolltypeid); if (payrollType == null) throw new ServiceException("Payroll type not found."); @@ -947,7 +960,9 @@ namespace HRM.DA else empIDs.Add(id); } if (empIDs.Count == 0) - throw new ServiceException("The selected bonus is already processed for all the selected employees."); + throw new ServiceException(byReligion + ? "The selected bonus is already processed for all the employees of its religion(s)." + : "The selected bonus is already processed for all the selected employees."); List employees = new EmployeeService().GetByEmpIDList(empIDs, payrolltypeid); if (employees.Count == 0) diff --git a/HRM.DA/Service/Bonus/BonusService.cs b/HRM.DA/Service/Bonus/BonusService.cs index 860d1eb..f50dac6 100644 --- a/HRM.DA/Service/Bonus/BonusService.cs +++ b/HRM.DA/Service/Bonus/BonusService.cs @@ -402,6 +402,34 @@ namespace HRM.DA return religions; } + // Live employees of the payroll type whose religion is set on the bonus (BonusReligion) + public List GetReligionEmployeeIDs(int bonusID, int payrollTypeID) + { + List employeeIDs = new List(); + TransactionContext tc = null; + try + { + tc = TransactionContext.Begin(); + DataReader dr = new DataReader(BonusDA.GetReligionEmployeeIDs(tc, bonusID, payrollTypeID)); + 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 DataSet GetCCWiseBonusSummary(DateTime bMonthDate, string bonus) { DataSet obonus = new DataSet(); 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 2d9af1f..e1bf388 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 @@ -235,7 +235,16 @@ export class BonusProcessComponent implements OnInit { search() { } process() { - if (this.bonusProcess == undefined || this.bonusProcess.bonusProcessDetails.length == 0) { + if (this.selectedbonusID == undefined || this.selectedbonusID == null || this.selectedbonusID <= 0) { + this.notificationService.showWarning('Please select a Bonus Type first.'); + return; + } + const hasEmployees = this.bonusProcess != undefined && this.bonusProcess.bonusProcessDetails != undefined + && this.bonusProcess.bonusProcessDetails.length > 0; + // no employee selected: allowed only when the bonus has Religion(s) set — the server then processes + // every live employee of the current payroll type with one of those religions + const byReligion = !hasEmployees && this.bonusReligions != undefined && this.bonusReligions.length > 0; + if (!hasEmployees && !byReligion) { this.notificationService.showWarning('Please select employee for the proces'); return; } @@ -244,7 +253,10 @@ export class BonusProcessComponent implements OnInit { const option = this.disburseWithSalary ? 'with Disburse With Salary' : this.isTaxProcess ? 'with Calculate Tax' : 'without Disburse With Salary and Calculate Tax'; - this.notificationService.showActiveConfirm('Confirmation', 'Are you sure you want to process the bonus ' + option + '?').then((isConfirmed) => { + const whom = byReligion + ? ' for all live employees of ' + this.bonusReligions.map(r => r.name).join(', ') + : ''; + this.notificationService.showActiveConfirm('Confirmation', 'Are you sure you want to process the bonus' + whom + ' ' + option + '?').then((isConfirmed) => { if (isConfirmed) { this.processConfirmed(); @@ -281,7 +293,8 @@ export class BonusProcessComponent implements OnInit { currProcess: this.processFor, isDisburseWithSalary: this.disburseWithSalary, isTaxProcess: this.isTaxProcess, - employeeIDs: this.bonusProcess.bonusProcessDetails.map(x => x.employeeID), + // empty = no employee selected: the server takes the bonus's religion employees + employeeIDs: (this.bonusProcess?.bonusProcessDetails ?? []).map(x => x.employeeID), }; var result: BonusProcessAndSaveResult; this.errorOrSucessList = []; diff --git a/HRM.UI/ClientApp/src/app/payroll-ot/bonus-undo/bonus-undo.component.html b/HRM.UI/ClientApp/src/app/payroll-ot/bonus-undo/bonus-undo.component.html index 63800b3..3ba88d5 100644 --- a/HRM.UI/ClientApp/src/app/payroll-ot/bonus-undo/bonus-undo.component.html +++ b/HRM.UI/ClientApp/src/app/payroll-ot/bonus-undo/bonus-undo.component.html @@ -25,6 +25,9 @@ + + +