public ActionResult DashboardofSalaryComponents(int?BranchId, int?Year, byte?Month, int?EmployeeId) { BranchId = BranchId == 0 ? BRANCHID : BranchId; Month = Month == 0 ? null : Month; EmployeeId = EmployeeId == 0 ? null : EmployeeId; SalaryComponantReportVm vm = new SalaryComponantReportVm(); vm.SalaryComponantReport = new List <Salarycomponentreport>(); vm.SalaryComponantReportYTD = new List <Salarycomponentreportytd>(); using (var dbCntx = new HrDataContext()) { List <Salarycomponentreportytd> salarycomponentreportytd = new List <Salarycomponentreportytd>(); List <Salarycomponentreport> salarycomponentreport = new List <Salarycomponentreport>(); if (BranchId == -1 || BranchId == null) { var countryList = SelectListItemHelper.ActiveCountryList(); foreach (var item in countryList) { var list = dbCntx.USP_SALARYCOMPONENTREPORTYTD(Convert.ToInt32(item.Value), Year, EmployeeId).ToList(); if (list.Sum(x => x.TotalSalary) > 0) { foreach (var info in list) { Salarycomponentreportytd countryItem = new Salarycomponentreportytd(); countryItem.BranchID = Convert.ToInt32(item.Value); countryItem.BranchName = item.Text; countryItem.YTDMonth = info.YTDMonth; countryItem.TotalSalary = info.TotalSalary; salarycomponentreportytd.Add(countryItem); } } var SalaryComponantReport = dbCntx.USP_SALARYCOMPONENTREPORT(Convert.ToInt32(item.Value), Year, Month, EmployeeId).ToList(); foreach (var info in SalaryComponantReport) { Salarycomponentreport countryItem = new Salarycomponentreport(); countryItem.BranchID = Convert.ToInt32(item.Value); countryItem.BranchName = item.Text; countryItem.ComponentName = info.ComponentName; countryItem.Amount = info.Amount; salarycomponentreport.Add(countryItem); } } vm.SalaryComponantReportYTD = salarycomponentreportytd; vm.SalaryComponantReport = salarycomponentreport.ToList(); } else { var SalaryComponantReport = dbCntx.USP_SALARYCOMPONENTREPORT(BranchId, Year, Month, EmployeeId).ToList(); foreach (var info in SalaryComponantReport) { Salarycomponentreport countryItem = new Salarycomponentreport(); countryItem.BranchID = BranchId.Value; countryItem.ComponentName = info.ComponentName; countryItem.Amount = info.Amount; salarycomponentreport.Add(countryItem); } vm.SalaryComponantReport = salarycomponentreport.ToList(); var list = dbCntx.USP_SALARYCOMPONENTREPORTYTD(BranchId, Year, EmployeeId).ToList(); foreach (var info in list) { Salarycomponentreportytd countryItem = new Salarycomponentreportytd(); countryItem.BranchID = BranchId.Value; countryItem.YTDMonth = info.YTDMonth; countryItem.TotalSalary = info.TotalSalary; salarycomponentreportytd.Add(countryItem); } vm.SalaryComponantReportYTD = salarycomponentreportytd.ToList(); vm.dt = SALARYCOMPONENTEMPLOYEEYTD(BranchId, Year, Convert.ToInt32(Month), EmployeeId); } } vm.BranchID = BranchId == null ? -1 : BranchId; vm.Year = Year; vm.Month = Month; vm.EmployeeID = EmployeeId; ViewData["RoleCode"] = ROLECODE.ToUpper(); if (vm.dt != null && vm.dt.Columns.Count > 0) { DataRow totalsRow = vm.dt.NewRow(); totalsRow["EMPLOYEE NAME"] = "TOTAL"; for (int j = 1; j < vm.dt.Columns.Count; j++) { DataColumn col = vm.dt.Columns[j]; decimal colTotal = 0; for (int i = 0; i < col.Table.Rows.Count; i++) { DataRow row = col.Table.Rows[i]; if (row[col] == null || row[col].ToString() == "") { row[col] = "0.00"; } colTotal += Convert.ToDecimal(row[col]); } //col.Table.Rows[j]. = Color.Red; totalsRow[col.ColumnName] = colTotal; } vm.dt.Rows.Add(totalsRow); } return(View(vm)); }