diff --git a/HRM.DA/DA/Bonus/BonusProcessDA.cs b/HRM.DA/DA/Bonus/BonusProcessDA.cs index 80e542b..c2bb757 100644 --- a/HRM.DA/DA/Bonus/BonusProcessDA.cs +++ b/HRM.DA/DA/Bonus/BonusProcessDA.cs @@ -658,6 +658,19 @@ AND BP.PayrollTypeID=%n", emps, FromDate, ToDate, payrollTypeID); return approved; } + + /// + /// Bonus Process screen: how many BONUSPROCESS headers this bonus already has in this month (whole month) + /// for this payroll type. Used to stop the same bonus type being processed twice in one month. + /// + internal static int CountProcessInMonth(TransactionContext tc, int payrolltypeid, int bonusid, DateTime bonusMonth) + { + object count = tc.ExecuteScalar( + "SELECT COUNT(*) FROM BONUSPROCESS WHERE PAYROLLTYPEID = %n AND BONUSID = %n AND BONUSMONTH BETWEEN %d AND %d", + payrolltypeid, bonusid, PayrollGlobalFunctions.PayrollFirstDateOfMonth(bonusMonth), + PayrollGlobalFunctions.PayrollLastDateOfMonth(bonusMonth)); + return (count == null || count == DBNull.Value) ? 0 : Convert.ToInt32(count); + } #endregion internal static DataSet GetMontlyProdBonus(TransactionContext tc, DateTime dBonusMonth) diff --git a/HRM.DA/Service/Bonus/BonusProcessService.cs b/HRM.DA/Service/Bonus/BonusProcessService.cs index b26b15e..2d68419 100644 --- a/HRM.DA/Service/Bonus/BonusProcessService.cs +++ b/HRM.DA/Service/Bonus/BonusProcessService.cs @@ -934,6 +934,7 @@ namespace HRM.DA // 1. checks if (this.IsApproved(request.BonusID, bonusMonth, payrolltypeid)) throw new ServiceException("selected Bonus is already process and Approved"); + this.CheckAlreadyProcessedInMonth(request.BonusID, bonusMonth, payrolltypeid); BonusProcessAndSaveResult result = new BonusProcessAndSaveResult(); HashSet alreadyProcessed = new HashSet( @@ -1008,6 +1009,7 @@ namespace HRM.DA // 1. checks if (this.IsApproved(request.BonusID, bonusMonth, payrolltypeid)) throw new ServiceException("selected Bonus is already process and Approved"); + this.CheckAlreadyProcessedInMonth(request.BonusID, bonusMonth, payrolltypeid); List problems = new List(); var otherPayroll = uploadedRows.Where(x => x.Employee != null && x.Employee.PayrollTypeID != payrolltypeid) @@ -1842,6 +1844,36 @@ namespace HRM.DA return isApproved; } + /// + /// Bonus Process screen (Process and Upload): the same bonus type may be processed only once in a month. + /// Throws when this bonus already has a process in this month for this payroll type. + /// + public void CheckAlreadyProcessedInMonth(int bonusID, DateTime bonusMonth, int payrolltypeid) + { + TransactionContext tc = null; + int count = 0; + try + { + tc = TransactionContext.Begin(); + count = BonusProcessDA.CountProcessInMonth(tc, payrolltypeid, bonusID, bonusMonth); + tc.End(); + } + catch (Exception e) + { + #region Handle Exception + + if (tc != null) + tc.HandleError(); + ExceptionLog.Write(e); + throw new ServiceException(e.Message, e); + + #endregion + } + if (count > 0) + throw new ServiceException("This bonus type is already processed for " + bonusMonth.ToString("MMMM yyyy") + + ". The same bonus type cannot be processed twice in the same month."); + } + public DataTable GetUnApprovedBonuses(DateTime dMonthDate, int payrollTypeID) {