diff --git a/HRM.BO/Bonus/BonusProcess.cs b/HRM.BO/Bonus/BonusProcess.cs index 5e0ccd4..bd11189 100644 --- a/HRM.BO/Bonus/BonusProcess.cs +++ b/HRM.BO/Bonus/BonusProcess.cs @@ -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 employees, int bonusid, DateTime dBasicMonth, DateTime dPayDate, DateTime dCuttOfDate, double CurrProcess, bool IsDisburseWithSalary, bool IsTaxProcess); List CalculateBonusTax(List bonusDetails, diff --git a/HRM.DA/DA/Bonus/BonusProcessDA.cs b/HRM.DA/DA/Bonus/BonusProcessDA.cs index c2bb757..6f6092c 100644 --- a/HRM.DA/DA/Bonus/BonusProcessDA.cs +++ b/HRM.DA/DA/Bonus/BonusProcessDA.cs @@ -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) { diff --git a/HRM.DA/Service/Bonus/BonusProcessService.cs b/HRM.DA/Service/Bonus/BonusProcessService.cs index 2d68419..2716785 100644 --- a/HRM.DA/Service/Bonus/BonusProcessService.cs +++ b/HRM.DA/Service/Bonus/BonusProcessService.cs @@ -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(); diff --git a/HRM.Report/Class/PaySlip.cs b/HRM.Report/Class/PaySlip.cs index 0013101..7b0b1fa 100644 --- a/HRM.Report/Class/PaySlip.cs +++ b/HRM.Report/Class/PaySlip.cs @@ -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. /// - 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 } /// - /// 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. /// - 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() : 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> columns = new List>(); // 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(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(bonus.Key, bonus.OrderBy(b => b.Month).Last().Name)); + } if (heads.Any(h => h.Group == unauthGroup)) columns.Add(new KeyValuePair(unauthKey, "Unauthorized Leave")); columns.Add(new KeyValuePair(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(bonusTaxKey, "Bonus Tax")); + bonusTaxAdded = true; + } columns.Add(new KeyValuePair(head.Key, head.Description)); } + if (!bonusTaxAdded) + columns.Add(new KeyValuePair(bonusTaxKey, "Bonus Tax")); columns.Add(new KeyValuePair(totalDeductionKey, "Total Deduction")); columns.Add(new KeyValuePair(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 salaryRows = salaryMonths.ContainsKey(rowKey) ? salaryMonths[rowKey] : new List(); + 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 amounts = new Dictionary(); 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; diff --git a/HRM.Report/RDLC/DateRangeWiseSalarySheet.rdlc b/HRM.Report/RDLC/DateRangeWiseSalarySheet.rdlc index 169f08a..ac7da41 100644 --- a/HRM.Report/RDLC/DateRangeWiseSalarySheet.rdlc +++ b/HRM.Report/RDLC/DateRangeWiseSalarySheet.rdlc @@ -94,7 +94,7 @@ 0in 0.25in - 13.6in + 16.14in @@ -964,7 +964,7 @@ 1.52083in 0.25in - 12.08in + 14.62in 1 - 8.5in - 14in - 8.5in - 14in + 11.69in + 16.54in + 11.69in + 16.54in 0.2in 0.2in 0.3in diff --git a/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.html b/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.html index 2c54ef9..3f56be9 100644 --- a/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.html +++ b/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.html @@ -50,6 +50,15 @@ } + @if (hiddenIncludeBonus==true) { +
+ +
+
+ +
+ } + @if (hiddenItemDDL==true) {
diff --git a/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.ts b/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.ts index 7e8376b..9fd761f 100644 --- a/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.ts +++ b/HRM.UI/ClientApp/src/app/reports/report-viewer/report-viewer.component.ts @@ -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; diff --git a/HRM.UI/Controllers/Report/ReportController.cs b/HRM.UI/Controllers/Report/ReportController.cs index 0945e14..91aa154 100644 --- a/HRM.UI/Controllers/Report/ReportController.cs +++ b/HRM.UI/Controllers/Report/ReportController.cs @@ -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(); + bytes = new PaySlip().ShowReportDateRange((int)currentUser.PayrollTypeID, fromDate, toDate, sEmpIDs, reportType, includeBonus); break; case EnumReportType.Envelop: break;