Include bonus option in date range wise salary

This commit is contained in:
chapal 2026-12-01 10:30:12 +06:00
parent 01e548fc23
commit 5ab15e9b34
8 changed files with 176 additions and 34 deletions

View File

@ -922,6 +922,7 @@ namespace HRM.BO
public interface IBonusProcessService
{
DataTable GetBonusItemsForESSBonusPayslip(int EmployeeID);
DataSet GetEmpBonusDateRange(DateTime fromSalaryMonth, DateTime toSalaryMonth, string sEmpID);
BonusProcess CalculateBonus(int payrolltypeid, List<Employee> employees, int bonusid, DateTime dBasicMonth,
DateTime dPayDate, DateTime dCuttOfDate, double CurrProcess, bool IsDisburseWithSalary, bool IsTaxProcess);
List<BonusProcess.BonusProcessDetail> CalculateBonusTax(List<BonusProcess.BonusProcessDetail> bonusDetails,

View File

@ -430,6 +430,31 @@ AND BP.PayrollTypeID=%n", emps, FromDate, ToDate, payrollTypeID);
//{
// return tc.ExecuteReader("SELECT * FROM BonusEmpCostCenter WHERE BonusProcessID=%n", nID);
//}
// Date Range Wise Salary Sheet (Include Bonus): every bonus of the employees whose bonus month OR
// disburse date falls between the first day of fromSalaryMonth and the end of toSalaryMonth.
// A bonus disbursed with salary (ISDISBURSEWITHSALARY = 1) is left out: it is already a salary item
// (SalaryMonthlyDetail, ItemCode -107), so taking it again would count it twice.
// Amount / tax are ChangeBonusAmount / ChangeTaxAmount, the figures the bonus register shows.
internal static DataSet GetEmpBonusDateRange(TransactionContext tc, DateTime fromSalaryMonth, DateTime toSalaryMonth, string sEmpID)
{
DateTime fromDate = new DateTime(fromSalaryMonth.Year, fromSalaryMonth.Month, 1);
DateTime toDateExclusive = new DateTime(toSalaryMonth.Year, toSalaryMonth.Month, 1).AddMonths(1);
string sql = SQLParser.MakeSQL(@"SELECT E.EMPLOYEENO, E.NAME Name, G.DESCRIPTION GName, D.DESCRIPTION Department, E.JOININGDATE,
BPD.BasicSalary, BP.BonusProcessID, BP.BonusID, B.NAME BonusName, BP.BonusMonth, BP.DisburseDate,
BPD.ChangeBonusAmount, BPD.ChangeTaxAmount
FROM BONUSPROCESS BP
inner join BONUSPROCESSDETAIL BPD on BPD.BonusProcessID = BP.BonusProcessID
inner join BONUS B on B.BONUSID = BP.BONUSID
inner join EMPLOYEE E on E.EMPLOYEEID = BPD.EmployeeID
left outer join GRADES G on G.GRADEID = E.GRADEID
left outer join DEPARTMENT D on D.DEPARTMENTID = E.DEPARTMENTID
WHERE BPD.EmployeeID IN(%q) AND ISNULL(BP.ISDISBURSEWITHSALARY, 0) = 0
AND ((BP.BonusMonth >= %d AND BP.BonusMonth < %d))
ORDER BY E.EMPLOYEENO, BP.BonusMonth, BP.BonusID",
sEmpID, fromDate, toDateExclusive);
return tc.ExecuteDataSet(sql);
}
internal static DataSet GetBonusRegister(TransactionContext tc, int BonusID, DateTime dBonusMonth,
string sEmpID, int payrolltypeid)
{

View File

@ -716,6 +716,32 @@ namespace HRM.DA
// return bonusProcessAdjustItems;
//}
public DataSet GetEmpBonusDateRange(DateTime fromSalaryMonth, DateTime toSalaryMonth, string sEmpID)
{
DataSet oBonuses = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oBonuses = BonusProcessDA.GetEmpBonusDateRange(tc, fromSalaryMonth, toSalaryMonth, sEmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oBonuses;
}
public DataSet GetBonusRegister(int bonusID, DateTime dBonusMonth, string sEmpID, int payrolltypeid)
{
DataSet oBonusRegisters = new DataSet();

View File

@ -723,9 +723,11 @@ namespace HRM.Report
/// employee between fromMonth and toMonth - one row per employee per salary month, one column per
/// salary head (the columns come from the data, they are not fixed), then Total Gross, the
/// deduction heads, Total Deduction and Net Pay, with a grand total at the bottom.
/// With includeBonus, every bonus whose bonus month or disburse date falls in the range is added
/// too: one column per bonus and a Bonus Tax column next to Income Tax (see BonusProcessDA.GetEmpBonusDateRange).
/// Rendered from the embedded RDLC DateRangeWiseSalarySheet.rdlc, the way the salary sheet (report 54) is.
/// </summary>
public byte[] ShowReportDateRange(int payrollTypeID, DateTime fromMonth, DateTime toMonth, string sEmpID, string reportType)
public byte[] ShowReportDateRange(int payrollTypeID, DateTime fromMonth, DateTime toMonth, string sEmpID, string reportType, bool includeBonus)
{
DateTime fromSalaryMonth = GlobalFunctions.LastDateOfMonth(fromMonth);
DateTime toSalaryMonth = GlobalFunctions.LastDateOfMonth(toMonth);
@ -735,12 +737,15 @@ namespace HRM.Report
}
DataTable oItems = new SalaryMonthlyService().GetEmpPaySlipDateRangeMonthWise(fromSalaryMonth, toSalaryMonth, sEmpID).Tables[0];
if (oItems.Rows.Count <= 0)
DataTable oBonuses = includeBonus
? new BonusProcessService().GetEmpBonusDateRange(fromSalaryMonth, toSalaryMonth, sEmpID).Tables[0]
: null;
if (oItems.Rows.Count <= 0 && (oBonuses == null || oBonuses.Rows.Count <= 0))
{
return null;
}
DataTable dtSalarySheet = this.GetDateRangeSalarySheetTable(oItems);
DataTable dtSalarySheet = this.GetDateRangeSalarySheetTable(oItems, oBonuses, fromSalaryMonth, toSalaryMonth);
dtSalarySheet.TableName = "DateRangeSalarySheet";
DataSet resultDataSet = new DataSet();
resultDataSet.Tables.Add(dtSalarySheet);
@ -756,20 +761,24 @@ namespace HRM.Report
}
/// <summary>
/// Turns the item rows of GetEmpPaySlipDateRangeMonthWise into the matrix rows: for every employee
/// and salary month, one row per column (0 where that month has no such head). Columns are keyed by
/// ItemGroup|ItemCode|ItemID, not by description, because an arrear and an unauthorized-leave row
/// carry the same description as the gross head ("Basic").
/// Total Gross = gross + arrear - unauthorized leave; Total Deduction = deductions; Net Pay is the
/// processed Net Payable (5 / -132) - the same figures the salary sheet shows.
/// Turns the item rows of GetEmpPaySlipDateRangeMonthWise (and, when given, the bonus rows of
/// GetEmpBonusDateRange) into the matrix rows: for every employee and month, one row per column
/// (0 where that month has no such head). Salary columns are keyed by ItemGroup|ItemCode|ItemID,
/// not by description, because an arrear and an unauthorized-leave row carry the same description
/// as the gross head ("Basic"); bonus columns are keyed by BonusID.
/// Total Gross = gross + arrear - unauthorized leave + bonus; Total Deduction = deductions + bonus tax;
/// Net Pay = the processed Net Payable (5 / -132) + bonus - bonus tax.
/// A bonus goes on the row of its bonus month when that month is in the range, otherwise on the row
/// of its disburse month.
/// </summary>
private DataTable GetDateRangeSalarySheetTable(DataTable oItems)
private DataTable GetDateRangeSalarySheetTable(DataTable oItems, DataTable oBonuses, DateTime fromSalaryMonth, DateTime toSalaryMonth)
{
int grossGroup = (int)EnumSalaryGroup.Gross;
int unauthGroup = (int)EnumSalaryGroup.UnauthLeave;
int deductGroup = (int)EnumSalaryGroup.Deductions;
int arrearGroup = (int)EnumSalaryGroup.Arrear;
const string unauthKey = "UNAUTHLEAVE", totalGrossKey = "TOTALGROSS", totalDeductionKey = "TOTALDEDUCTION", netPayKey = "NETPAY";
const string bonusKeyPrefix = "BONUS|", bonusTaxKey = "BONUSTAX";
DataTable dt = new DataTable();
dt.Columns.Add("EmpNo", typeof(string));
@ -802,6 +811,27 @@ namespace HRM.Report
.Where(h => h.HasAmount)
.ToList();
// bonus rows with the salary month (row) each one belongs to
DateTime fromDate = new DateTime(fromSalaryMonth.Year, fromSalaryMonth.Month, 1);
var bonuses = (oBonuses == null ? new List<DataRow>() : oBonuses.AsEnumerable().ToList())
.Select(r =>
{
DateTime bonusMonth = Convert.ToDateTime(r["BonusMonth"]);
bool bonusMonthInRange = bonusMonth >= fromDate && bonusMonth <= toSalaryMonth.AddDays(1).AddTicks(-1);
return new
{
Row = r,
EmpNo = Convert.ToString(r["EMPLOYEENO"]),
Month = GlobalFunctions.LastDateOfMonth(bonusMonthInRange ? bonusMonth : Convert.ToDateTime(r["DisburseDate"])),
Key = bonusKeyPrefix + Convert.ToInt32(r["BonusID"]),
Name = Convert.ToString(r["BonusName"]),
Amount = r["ChangeBonusAmount"] == DBNull.Value ? 0 : Convert.ToDouble(r["ChangeBonusAmount"]),
Tax = r["ChangeTaxAmount"] == DBNull.Value ? 0 : Convert.ToDouble(r["ChangeTaxAmount"])
};
})
.Where(b => b.Amount != 0 || b.Tax != 0)
.ToList();
#region Column order
List<KeyValuePair<string, string>> columns = new List<KeyValuePair<string, string>>();
// earnings: Basic first, then the salary position; each head's arrear right after it
@ -820,29 +850,61 @@ namespace HRM.Report
{
columns.Add(new KeyValuePair<string, string>(arrear.Key, GetArrearColumnName(arrear.Description)));
}
// one column per bonus, in the order they were paid
foreach (var bonus in bonuses.GroupBy(b => b.Key).OrderBy(g => g.Min(b => b.Month)).ThenBy(g => g.Key))
{
columns.Add(new KeyValuePair<string, string>(bonus.Key, bonus.OrderBy(b => b.Month).Last().Name));
}
if (heads.Any(h => h.Group == unauthGroup))
columns.Add(new KeyValuePair<string, string>(unauthKey, "Unauthorized Leave"));
columns.Add(new KeyValuePair<string, string>(totalGrossKey, "Total Gross"));
// deductions: Income Tax, PF, then the salary position
// deductions: Income Tax (then Bonus Tax), PF, then the salary position
bool bonusTaxAdded = bonuses.Count == 0;
foreach (var head in heads.Where(h => h.Group == deductGroup)
.OrderBy(h => h.Code == (int)EnumSalaryItemCode.Inc_Tax_Deduction ? 0 : h.Code == (int)EnumSalaryItemCode.PF_Contribution ? 1 : 2)
.ThenBy(h => h.Position).ThenBy(h => h.Description))
{
if (!bonusTaxAdded && head.Code != (int)EnumSalaryItemCode.Inc_Tax_Deduction)
{
columns.Add(new KeyValuePair<string, string>(bonusTaxKey, "Bonus Tax"));
bonusTaxAdded = true;
}
columns.Add(new KeyValuePair<string, string>(head.Key, head.Description));
}
if (!bonusTaxAdded)
columns.Add(new KeyValuePair<string, string>(bonusTaxKey, "Bonus Tax"));
columns.Add(new KeyValuePair<string, string>(totalDeductionKey, "Total Deduction"));
columns.Add(new KeyValuePair<string, string>(netPayKey, "Net Pay"));
#endregion
foreach (var salaryMonth in oItems.AsEnumerable()
.GroupBy(r => new { EmpNo = Convert.ToString(r["EMPLOYEENO"]), Month = Convert.ToDateTime(r["SalaryMonth"]) }))
var salaryMonths = oItems.AsEnumerable()
.GroupBy(r => new { EmpNo = Convert.ToString(r["EMPLOYEENO"]), Month = Convert.ToDateTime(r["SalaryMonth"]) })
.ToDictionary(g => g.Key, g => g.ToList());
// a bonus can fall in a month with no salary: that month still gets its row
var rowKeys = salaryMonths.Keys
.Union(bonuses.Select(b => new { b.EmpNo, b.Month }))
.ToList();
foreach (var rowKey in rowKeys)
{
DataRow info = salaryMonth.First();
List<DataRow> salaryRows = salaryMonths.ContainsKey(rowKey) ? salaryMonths[rowKey] : new List<DataRow>();
var monthBonuses = bonuses.Where(b => b.EmpNo == rowKey.EmpNo && b.Month == rowKey.Month).ToList();
// employee information: this month's salary row, else the employee's latest salary row in the
// range, else the bonus row (employee master)
DataRow info = salaryRows.FirstOrDefault()
?? oItems.AsEnumerable().Where(r => Convert.ToString(r["EMPLOYEENO"]) == rowKey.EmpNo)
.OrderBy(r => Convert.ToDateTime(r["SalaryMonth"])).LastOrDefault()
?? monthBonuses.First().Row;
double actualBasic = salaryRows.Count > 0
? (salaryRows[0]["ActualBasic"] == DBNull.Value ? 0 : Convert.ToDouble(salaryRows[0]["ActualBasic"]))
: (monthBonuses[0].Row["BasicSalary"] == DBNull.Value ? 0 : Convert.ToDouble(monthBonuses[0].Row["BasicSalary"]));
Dictionary<string, double> amounts = new Dictionary<string, double>();
double totalGross = 0, totalDeduction = 0, unauthLeave = 0;
double? netPay = null;
foreach (DataRow r in salaryMonth.Where(r => r["ITEMGROUP"] != DBNull.Value))
foreach (DataRow r in salaryRows.Where(r => r["ITEMGROUP"] != DBNull.Value))
{
int group = Convert.ToInt32(r["ITEMGROUP"]);
int code = Convert.ToInt32(r["ItemCode"]);
@ -864,21 +926,32 @@ namespace HRM.Report
if (group != unauthGroup)
amounts[key] = (amounts.ContainsKey(key) ? amounts[key] : 0) + amount;
}
double salaryNetPay = netPay ?? (totalGross - totalDeduction);
double bonusAmount = 0, bonusTax = 0;
foreach (var bonus in monthBonuses)
{
amounts[bonus.Key] = (amounts.ContainsKey(bonus.Key) ? amounts[bonus.Key] : 0) + bonus.Amount;
bonusAmount += bonus.Amount;
bonusTax += bonus.Tax;
}
amounts[unauthKey] = unauthLeave;
amounts[totalGrossKey] = totalGross;
amounts[totalDeductionKey] = totalDeduction;
amounts[netPayKey] = netPay ?? (totalGross - totalDeduction);
amounts[bonusTaxKey] = bonusTax;
amounts[totalGrossKey] = totalGross + bonusAmount;
amounts[totalDeductionKey] = totalDeduction + bonusTax;
amounts[netPayKey] = salaryNetPay + bonusAmount - bonusTax;
for (int i = 0; i < columns.Count; i++)
{
DataRow oRow = dt.NewRow();
oRow["EmpNo"] = salaryMonth.Key.EmpNo;
oRow["EmpNo"] = rowKey.EmpNo;
oRow["EmpName"] = info["Name"];
oRow["Grade"] = info["GName"];
oRow["Department"] = info["Department"];
oRow["SalaryMonth"] = salaryMonth.Key.Month;
oRow["SalaryMonth"] = rowKey.Month;
oRow["JoiningDate"] = info["JOININGDATE"];
oRow["ActualBasic"] = info["ActualBasic"] == DBNull.Value ? 0 : Convert.ToDouble(info["ActualBasic"]);
oRow["ActualBasic"] = actualBasic;
oRow["ColumnKey"] = columns[i].Key;
oRow["ColumnName"] = columns[i].Value;
oRow["ColumnSequence"] = i + 1;

View File

@ -94,7 +94,7 @@
</Paragraphs>
<Left>0in</Left>
<Height>0.25in</Height>
<Width>13.6in</Width>
<Width>16.14in</Width>
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
@ -925,7 +925,7 @@
<Height>1.3in</Height>
<Style />
</Body>
<Width>13.6in</Width>
<Width>16.14in</Width>
<Page>
<PageHeader>
<Height>0.72396in</Height>
@ -935,7 +935,7 @@
<Line Name="line2">
<Top>0.68125in</Top>
<Height>0in</Height>
<Width>13.6in</Width>
<Width>16.14in</Width>
<Style>
<Border>
<Style>Solid</Style>
@ -964,7 +964,7 @@
</Paragraphs>
<Left>1.52083in</Left>
<Height>0.25in</Height>
<Width>12.08in</Width>
<Width>14.62in</Width>
<ZIndex>1</ZIndex>
<Style>
<Border>
@ -1010,7 +1010,7 @@
<Top>0.375in</Top>
<Left>1.52083in</Left>
<Height>0.2in</Height>
<Width>12.08in</Width>
<Width>14.62in</Width>
<ZIndex>3</ZIndex>
<Style>
<PaddingLeft>2pt</PaddingLeft>
@ -1038,7 +1038,7 @@
<Top>0.2in</Top>
<Left>1.52083in</Left>
<Height>0.2in</Height>
<Width>12.08in</Width>
<Width>14.62in</Width>
<ZIndex>4</ZIndex>
<Style>
<PaddingLeft>2pt</PaddingLeft>
@ -1106,7 +1106,7 @@
</Paragraph>
</Paragraphs>
<Top>0.04in</Top>
<Left>11.6in</Left>
<Left>14.14in</Left>
<Height>0.22in</Height>
<Width>2in</Width>
<ZIndex>1</ZIndex>
@ -1124,10 +1124,10 @@
</Border>
</Style>
</PageFooter>
<PageHeight>8.5in</PageHeight>
<PageWidth>14in</PageWidth>
<InteractiveHeight>8.5in</InteractiveHeight>
<InteractiveWidth>14in</InteractiveWidth>
<PageHeight>11.69in</PageHeight>
<PageWidth>16.54in</PageWidth>
<InteractiveHeight>11.69in</InteractiveHeight>
<InteractiveWidth>16.54in</InteractiveWidth>
<LeftMargin>0.2in</LeftMargin>
<RightMargin>0.2in</RightMargin>
<TopMargin>0.3in</TopMargin>

View File

@ -50,6 +50,15 @@
</div>
}
@if (hiddenIncludeBonus==true) {
<div class="col-4 md:col-2">
<label for="includeBonus">Include Bonus</label>
</div>
<div class="col-8 md:col-4">
<input type="checkbox" kendoCheckBox id="includeBonus" [(ngModel)]="includeBonus" />
</div>
}
@if (hiddenItemDDL==true) {
<div class="col-4 md:col-2">
<label>{{itemName}}</label>

View File

@ -150,6 +150,9 @@ export class ReportViewerComponent implements OnInit {
hiddenSendMail = false;
hiddenSelectReport = false;
hiddenAllSearch = false;
/** Date Range Wise Salary Sheet (4101) only: shows the "Include Bonus" check box. */
hiddenIncludeBonus = false;
includeBonus = false;
itemName = 'Item';
reportDropdownDefaultName = 'Select Item...';
public gridView: GridDataResult;
@ -431,6 +434,8 @@ export class ReportViewerComponent implements OnInit {
this.topview = "decade";
this.apiService.selectedMenuName = 'Date Range Wise Salary Sheet';
this.hiddenExport = true;
this.hiddenIncludeBonus = true;
this.includeBonus = false;
} else if (this.reportType === '263' || this.reportType === '709') {
// debugger;
this.SearchFrom = EnumSearchFrom.Salary;
@ -2020,7 +2025,9 @@ export class ReportViewerComponent implements OnInit {
reportType: reportType,
fromDate: this.fromDate != undefined ? this.fromDate.toDateString() : undefined,
toDate: this.toDate != undefined ? this.toDate.toDateString() : undefined,
locationIds: locationIds
locationIds: locationIds,
// Date Range Wise Salary Sheet only (ReportController reads it for that report alone)
...(this.hiddenIncludeBonus ? { includeBonus: this.includeBonus } : {})
};
this.loadingPanel.ShowLoadingPanel = true;

View File

@ -245,7 +245,8 @@ namespace HRM.UI.Controllers.Report
}
break;
case EnumReportType.DateRangeWiseSalarySheet:
bytes = new PaySlip().ShowReportDateRange((int)currentUser.PayrollTypeID, fromDate, toDate, sEmpIDs, reportType);
bool includeBonus = items["includeBonus"] != null && (bool)items["includeBonus"].ToObject<bool>();
bytes = new PaySlip().ShowReportDateRange((int)currentUser.PayrollTypeID, fromDate, toDate, sEmpIDs, reportType, includeBonus);
break;
case EnumReportType.Envelop:
break;