This commit is contained in:
Mohaimen Hasan 2026-11-12 15:57:00 +06:00
parent e6931518df
commit 4eb1990286
2 changed files with 45 additions and 0 deletions

View File

@ -658,6 +658,19 @@ AND BP.PayrollTypeID=%n", emps, FromDate, ToDate, payrollTypeID);
return approved;
}
/// <summary>
/// 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.
/// </summary>
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)

View File

@ -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<int> alreadyProcessed = new HashSet<int>(
@ -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<string> problems = new List<string>();
var otherPayroll = uploadedRows.Where(x => x.Employee != null && x.Employee.PayrollTypeID != payrolltypeid)
@ -1842,6 +1844,36 @@ namespace HRM.DA
return isApproved;
}
/// <summary>
/// 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.
/// </summary>
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)
{