diff --git a/Areas/OTcalculate/Controllers/HrDashboardController.cs b/Areas/OTcalculate/Controllers/HrDashboardController.cs index fccffca..af97c1f 100644 --- a/Areas/OTcalculate/Controllers/HrDashboardController.cs +++ b/Areas/OTcalculate/Controllers/HrDashboardController.cs @@ -28,11 +28,6 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Controllers return View(); } - public IActionResult OtApproval() - { - return View(); - } - public IActionResult Settings() { return View(); diff --git a/Areas/OTcalculate/Services/OvertimeExcel.cs b/Areas/OTcalculate/Services/OvertimeExcel.cs index da9a93e..90d5db4 100644 --- a/Areas/OTcalculate/Services/OvertimeExcel.cs +++ b/Areas/OTcalculate/Services/OvertimeExcel.cs @@ -5,7 +5,7 @@ using System.Linq; using Microsoft.EntityFrameworkCore; using ClosedXML.Excel; using ClosedXML.Excel.Drawings; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using PSTW_CentralSystem.Areas.OTcalculate.Models; using PSTW_CentralSystem.Models; @@ -17,12 +17,12 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services public class OvertimeExcel { private readonly CentralSystemContext _centralDbContext; - private readonly IWebHostEnvironment _env; + private readonly IWebHostEnvironment _env; - public OvertimeExcel(CentralSystemContext centralDbContext, IWebHostEnvironment env) + public OvertimeExcel(CentralSystemContext centralDbContext, IWebHostEnvironment env) { _centralDbContext = centralDbContext; - _env = env; + _env = env; } public MemoryStream GenerateOvertimeExcel( @@ -31,6 +31,8 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services decimal userRate, DateTime? selectedMonth = null, bool isHoU = false, + bool isHoD = false, + bool isManager = false, string? flexiHour = null, byte[]? logoImage = null, bool isSimplifiedExport = false, @@ -90,7 +92,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services worksheet.Cell(currentRow, 1).Style.Font.SetBold(); currentRow++; - currentRow++; + currentRow++; if (isSimplifiedExport) { @@ -98,19 +100,18 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services } else { - - if (isHoU) + if (isHoU || isHoD || isManager) // If HoU, HoD, or Manager, hide salary details { if (showStationColumn) { - AddHoUPSTWAirHeaders(worksheet, ref currentRow); + AddHoUPSTWAirHeaders(worksheet, ref currentRow); // This already excludes salary info } else { - AddHoUNonPSTWAirHeaders(worksheet, ref currentRow); + AddHoUNonPSTWAirHeaders(worksheet, ref currentRow); // This already excludes salary info } } - else + else // For other users (who are not HoU, HoD, or Manager) { if (showStationColumn) { @@ -236,7 +237,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services descriptionCell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; } - else + else // Not simplified export { var dayType = GetDayType(date, userSetting?.State?.WeekendId, publicHolidayDates); var classified = ClassifyOt(record, hrp, publicHolidayDates, userSetting?.State?.WeekendId); @@ -259,7 +260,15 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services decimal currentRowTotalRd = currentRdUnder4 + currentRd4to8 + currentRdAfter; decimal currentRowTotalPh = currentPhUnder8 + currentPhAfter; - var otAmt = CalculateOtAmount(record, hrp, publicHolidayDates, userSetting?.State?.WeekendId); + decimal otAmtValParsed = 0; + string otAmt = ""; + + if (!isHoU && !isHoD && !isManager) // Only calculate and show OT amount if not HoU, HoD, or Manager + { + otAmt = CalculateOtAmount(record, hrp, publicHolidayDates, userSetting?.State?.WeekendId); + otAmtValParsed = decimal.TryParse(otAmt, out decimal val) ? val : 0; + } + totalOfficeBreak += (decimal)record.OfficeBreak.GetValueOrDefault(0); totalAfterBreak += (decimal)record.AfterBreak.GetValueOrDefault(0); @@ -280,9 +289,9 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services grandTotalNdOd += currentRowTotalNdOd; grandTotalRd += currentRowTotalRd; grandTotalPh += currentRowTotalPh; - grandTotalOtAmount += decimal.TryParse(otAmt, out decimal otAmtVal) ? otAmtVal : 0; + grandTotalOtAmount += otAmtValParsed; // Only add if it was calculated - if (!isHoU) + if (!isHoU && !isHoD && !isManager) // Only show if not HoU, HoD, or Manager { // Basic Salary worksheet.Cell(currentRow, col).Value = !hasPrintedSalaryDetails ? basicSalary.ToString("N2") : ""; @@ -294,7 +303,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services worksheet.Cell(currentRow, col).Value = !hasPrintedSalaryDetails ? hrp.ToString("N2") : ""; worksheet.Cell(currentRow, col++).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; } - hasPrintedSalaryDetails = true; + hasPrintedSalaryDetails = true; // Ensure these are printed only once if visible var dayCell = worksheet.Cell(currentRow, col); var dateCell = worksheet.Cell(currentRow, col + 1); @@ -339,7 +348,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services worksheet.Cell(currentRow, col++).Value = currentRowTotalRd > 0 ? currentRowTotalRd.ToString("N2") : ""; worksheet.Cell(currentRow, col++).Value = currentRowTotalPh > 0 ? currentRowTotalPh.ToString("N2") : ""; - if (!isHoU) + if (!isHoU && !isHoD && !isManager) // Only show if not HoU, HoD, or Manager { worksheet.Cell(currentRow, col++).Value = otAmt == "0.00" ? "" : otAmt; } @@ -406,7 +415,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services int totalLabelStartColumnIndex = 1; int totalLabelEndColumnIndex; - if (!isHoU) + if (!isHoU && !isHoD && !isManager) // If not HoU, HoD, or Manager, include salary columns in merge { totalLabelEndColumnIndex = 3; } @@ -436,7 +445,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services int colTotalPhIndex = 0; int colOtAmtIndex = 0; - if (!isHoU) + if (!isHoU && !isHoD && !isManager) { colOfficeBreakIndex = 8; colAfterBreakIndex = 11; @@ -491,7 +500,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services worksheet.Cell(currentRow, colTotalRdIndex).Value = grandTotalRd.ToString("N2"); worksheet.Cell(currentRow, colTotalPhIndex).Value = grandTotalPh.ToString("N2"); - if (!isHoU) + if (!isHoU && !isHoD && !isManager) { worksheet.Cell(currentRow, colOtAmtIndex).Value = Math.Round(grandTotalOtAmount, MidpointRounding.AwayFromZero).ToString("F2"); } @@ -501,7 +510,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services if (!isSimplifiedExport && otStatus != null) { - currentRow++; + currentRow++; worksheet.Cell(currentRow, 1).Value = "Approval Summary:"; worksheet.Cell(currentRow, 1).Style.Font.SetBold(); @@ -586,16 +595,16 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services int remarksColorStartRow = currentRow - 1; var phColorCell = worksheet.Cell(remarksColorStartRow, remarksStartColumn); - phColorCell.Value = " "; - phColorCell.Style.Fill.BackgroundColor = XLColor.FromHtml("FFC0CB"); + phColorCell.Value = " "; + phColorCell.Style.Fill.BackgroundColor = XLColor.FromHtml("FFC0CB"); phColorCell.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); worksheet.Cell(remarksColorStartRow, remarksStartColumn + 1).Value = " Public Holiday"; worksheet.Cell(remarksColorStartRow, remarksStartColumn + 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; var weekendColorCell = worksheet.Cell(remarksColorStartRow + 1, remarksStartColumn); - weekendColorCell.Value = " "; - weekendColorCell.Style.Fill.BackgroundColor = XLColor.FromHtml("ADD8E6"); + weekendColorCell.Value = " "; + weekendColorCell.Style.Fill.BackgroundColor = XLColor.FromHtml("ADD8E6"); weekendColorCell.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); worksheet.Cell(remarksColorStartRow + 1, remarksStartColumn + 1).Value = " Weekend"; @@ -603,7 +612,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services - int holidayListRow = remarksColorStartRow + 3; + int holidayListRow = remarksColorStartRow + 3; worksheet.Cell(holidayListRow, remarksStartColumn).Value = $"Public Holidays in {displayMonth:MMMM yyyy}:"; worksheet.Cell(holidayListRow, remarksStartColumn).Style.Font.SetBold(); holidayListRow++; @@ -640,7 +649,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services if (hasAnyApprovedSignature) { - int messageRow = holidayListRow + 2; + int messageRow = holidayListRow + 2; int lastContentColumn = worksheet.LastColumnUsed().ColumnNumber(); var messageCellRange = worksheet.Range(messageRow, 1, messageRow, lastContentColumn); @@ -658,7 +667,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services currentRow = Math.Max(currentRow, holidayListRow); } } - else if (isSimplifiedExport) + else if (isSimplifiedExport) { AddRemarksSection(worksheet, ref currentRow, displayMonth, userSetting?.State?.WeekendId, publicHolidays.Select(h => new CalendarModel { HolidayDate = h.HolidayDate, HolidayName = h.HolidayName }).ToList()); } @@ -688,7 +697,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services } else { - if (!isHoU) + if (!isHoU && !isHoD && !isManager) // If not HoU, HoD, or Manager, include salary columns in width adjustment { worksheet.Column(1).Width = 15; // Basic Salary worksheet.Column(2).Width = 10; // ORP @@ -714,7 +723,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services int descColIndex = showStationColumn ? 29 : 28; worksheet.Column(descColIndex).Width = 60; } - else + else // If HoU, HoD, or Manager, adjust columns without salary info { worksheet.Column(1).Width = 10; worksheet.Column(2).Width = 12; @@ -729,12 +738,12 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services worksheet.Column(9).Width = 15; worksheet.Column(10).Width = 18; - for (int i = 11; i <= 23; i++) + for (int i = 11; i <= 23; i++) // Adjust based on new column count { worksheet.Column(i).Width = 12; } - int descColIndex = showStationColumn ? 25 : 24; + int descColIndex = showStationColumn ? 25 : 24; // Adjust based on new column count worksheet.Column(descColIndex).Width = 60; } } @@ -814,7 +823,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services currentCol = 1; - currentCol += 2; + currentCol += 2; var cellOfficeFrom = worksheet.Cell(rowIndex, currentCol++); cellOfficeFrom.Value = "From"; @@ -844,7 +853,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services if (showStationColumn) { - currentCol++; + currentCol++; } currentCol++; @@ -853,7 +862,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services headerRow2Range.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); headerRow2Range.Style.Border.InsideBorder = XLBorderStyleValues.Thin; - rowIndex++; + rowIndex++; } private void ApplyHeaderStyle(IXLCell cell, int styleType) @@ -867,31 +876,31 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services switch (styleType) { - case 1: - cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#78aafa"); - cell.Style.Font.FontColor = XLColor.Black; + case 1: + cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#78aafa"); + cell.Style.Font.FontColor = XLColor.Black; break; - case 2: - cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#DDEBF7"); + case 2: + cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#DDEBF7"); cell.Style.Font.FontColor = XLColor.Black; break; case 3: - cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#C6E0B4"); + cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#C6E0B4"); cell.Style.Font.FontColor = XLColor.Black; break; - case 4: - cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#F8CBAD"); + case 4: + cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#F8CBAD"); cell.Style.Font.FontColor = XLColor.Black; break; - case 5: - cell.Style.Fill.BackgroundColor = XLColor.FromHtml("D8D1F5"); + case 5: + cell.Style.Fill.BackgroundColor = XLColor.FromHtml("D8D1F5"); cell.Style.Font.FontColor = XLColor.Black; break; - case 6: - cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#FF69B4"); - cell.Style.Font.FontColor = XLColor.Black; + case 6: + cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#FF69B4"); + cell.Style.Font.FontColor = XLColor.Black; break; - default: + default: cell.Style.Fill.BackgroundColor = XLColor.FromHtml("#A9D08E"); cell.Style.Font.FontColor = XLColor.Black; break; @@ -908,13 +917,13 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services switch (styleIndex) { - case 18: + case 18: cell.Style.Fill.BackgroundColor = XLColor.FromHtml("FFC0CB"); break; - case 19: + case 19: cell.Style.Fill.BackgroundColor = XLColor.FromHtml("ADD8E6"); break; - default: + default: cell.Style.Fill.BackgroundColor = XLColor.NoColor; break; } @@ -928,32 +937,32 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services currentCol = 1; var cellA = worksheet.Cell(rowIndex, currentCol); cellA.Value = "Basic Salary (RM)"; - ApplyHeaderStyle(cellA, 6); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellA, 6); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellB = worksheet.Cell(rowIndex, currentCol); cellB.Value = "ORP"; - ApplyHeaderStyle(cellB, 6); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellB, 6); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellC = worksheet.Cell(rowIndex, currentCol); cellC.Value = "HRP"; - ApplyHeaderStyle(cellC, 6); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellC, 6); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellD = worksheet.Cell(rowIndex, currentCol); cellD.Value = "Day"; ApplyHeaderStyle(cellD, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellE = worksheet.Cell(rowIndex, currentCol); cellE.Value = "Date"; ApplyHeaderStyle(cellE, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellF = worksheet.Cell(rowIndex, currentCol); @@ -967,7 +976,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellI = worksheet.Cell(rowIndex, currentCol); cellI.Value = "After Office Hour"; ApplyHeaderStyle(cellI, 2); - var mergedRangeI = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeI = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeI.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeI.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -975,25 +984,25 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellL = worksheet.Cell(rowIndex, currentCol); cellL.Value = "OT Hrs (Office Hour)"; ApplyHeaderStyle(cellL, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellM = worksheet.Cell(rowIndex, currentCol); cellM.Value = "OT Hrs (After Office Hour)"; ApplyHeaderStyle(cellM, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellN = worksheet.Cell(rowIndex, currentCol); cellN.Value = "Normal Day (After Office)"; - ApplyHeaderStyle(cellN, 2); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellN, 2); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellO = worksheet.Cell(rowIndex, currentCol); cellO.Value = "Off Day"; ApplyHeaderStyle(cellO, 2); - var mergedRangeO = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeO = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeO.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeO.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -1009,7 +1018,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellU = worksheet.Cell(rowIndex, currentCol); cellU.Value = "Public Holiday"; ApplyHeaderStyle(cellU, 2); - var mergedRangeU = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 1).Merge(); + var mergedRangeU = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 1).Merge(); mergedRangeU.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeU.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 2; @@ -1017,43 +1026,43 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellW = worksheet.Cell(rowIndex, currentCol); cellW.Value = "Total OT"; ApplyHeaderStyle(cellW, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellX = worksheet.Cell(rowIndex, currentCol); cellX.Value = "Total ND & OD"; ApplyHeaderStyle(cellX, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellY = worksheet.Cell(rowIndex, currentCol); cellY.Value = "Total RD"; ApplyHeaderStyle(cellY, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellZ = worksheet.Cell(rowIndex, currentCol); cellZ.Value = "Total PH"; ApplyHeaderStyle(cellZ, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellAA = worksheet.Cell(rowIndex, currentCol); cellAA.Value = "OT Amt (RM)"; - ApplyHeaderStyle(cellAA, 6); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellAA, 6); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellAB = worksheet.Cell(rowIndex, currentCol); cellAB.Value = "Station"; ApplyHeaderStyle(cellAB, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellAC = worksheet.Cell(rowIndex, currentCol); cellAC.Value = "Description"; ApplyHeaderStyle(cellAC, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var headerRow1Range = worksheet.Range(startRowIndex, 1, startRowIndex, worksheet.LastColumnUsed().ColumnNumber()); @@ -1065,7 +1074,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services currentCol = 1; - currentCol += 5; + currentCol += 5; var cellF_sub = worksheet.Cell(rowIndex, currentCol++); cellF_sub.Value = "From"; @@ -1091,7 +1100,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services cellK_sub.Value = "Break"; ApplyHeaderStyle(cellK_sub, 3); - currentCol += 2; + currentCol += 2; var cellN_sub = worksheet.Cell(rowIndex, currentCol++); cellN_sub.Value = "ND OT"; @@ -1135,7 +1144,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services headerRow2Range.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); headerRow2Range.Style.Border.InsideBorder = XLBorderStyleValues.Thin; - rowIndex++; + rowIndex++; } private void AddNonHoUNonPSTWAirHeaders(IXLWorksheet worksheet, ref int rowIndex) @@ -1146,32 +1155,32 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services currentCol = 1; var cellA = worksheet.Cell(rowIndex, currentCol); cellA.Value = "Basic Salary (RM)"; - ApplyHeaderStyle(cellA, 6); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellA, 6); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellB = worksheet.Cell(rowIndex, currentCol); cellB.Value = "ORP"; - ApplyHeaderStyle(cellB, 6); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellB, 6); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellC = worksheet.Cell(rowIndex, currentCol); cellC.Value = "HRP"; - ApplyHeaderStyle(cellC, 6); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellC, 6); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellD = worksheet.Cell(rowIndex, currentCol); cellD.Value = "Day"; ApplyHeaderStyle(cellD, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellE = worksheet.Cell(rowIndex, currentCol); cellE.Value = "Date"; ApplyHeaderStyle(cellE, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellF = worksheet.Cell(rowIndex, currentCol); @@ -1185,7 +1194,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellI = worksheet.Cell(rowIndex, currentCol); cellI.Value = "After Office Hour"; ApplyHeaderStyle(cellI, 2); - var mergedRangeI = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeI = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeI.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeI.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -1193,24 +1202,24 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellL = worksheet.Cell(rowIndex, currentCol); cellL.Value = "OT Hrs (Office Hour)"; ApplyHeaderStyle(cellL, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellM = worksheet.Cell(rowIndex, currentCol); cellM.Value = "OT Hrs (After Office Hour)"; ApplyHeaderStyle(cellM, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellN = worksheet.Cell(rowIndex, currentCol); cellN.Value = "Normal Day (After Office)"; ApplyHeaderStyle(cellN, 2); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellO = worksheet.Cell(rowIndex, currentCol); cellO.Value = "Off Day"; - ApplyHeaderStyle(cellO, 2); + ApplyHeaderStyle(cellO, 2); var mergedRangeO = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeO.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeO.Style.Border.InsideBorder = XLBorderStyleValues.Thin; @@ -1219,7 +1228,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellR = worksheet.Cell(rowIndex, currentCol); cellR.Value = "Rest Day"; ApplyHeaderStyle(cellR, 2); - var mergedRangeR = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeR = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeR.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeR.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -1227,7 +1236,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellU = worksheet.Cell(rowIndex, currentCol); cellU.Value = "Public Holiday"; ApplyHeaderStyle(cellU, 2); - var mergedRangeU = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 1).Merge(); + var mergedRangeU = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 1).Merge(); mergedRangeU.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeU.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 2; @@ -1235,47 +1244,47 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellW = worksheet.Cell(rowIndex, currentCol); cellW.Value = "Total OT"; ApplyHeaderStyle(cellW, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellX = worksheet.Cell(rowIndex, currentCol); cellX.Value = "Total ND & OD"; ApplyHeaderStyle(cellX, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellY = worksheet.Cell(rowIndex, currentCol); cellY.Value = "Total RD"; ApplyHeaderStyle(cellY, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellZ = worksheet.Cell(rowIndex, currentCol); cellZ.Value = "Total PH"; ApplyHeaderStyle(cellZ, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellAA = worksheet.Cell(rowIndex, currentCol); cellAA.Value = "OT Amt (RM)"; - ApplyHeaderStyle(cellAA, 6); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellAA, 6); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellAB = worksheet.Cell(rowIndex, currentCol); - cellAB.Value = "Description"; + cellAB.Value = "Description"; ApplyHeaderStyle(cellAB, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var headerRow1Range = worksheet.Range(startRowIndex, 1, startRowIndex, worksheet.LastColumnUsed().ColumnNumber()); headerRow1Range.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); headerRow1Range.Style.Border.InsideBorder = XLBorderStyleValues.Thin; - rowIndex++; + rowIndex++; currentCol = 1; - currentCol += 5; + currentCol += 5; var cellF_sub = worksheet.Cell(rowIndex, currentCol++); cellF_sub.Value = "From"; @@ -1301,7 +1310,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services cellK_sub.Value = "Break"; ApplyHeaderStyle(cellK_sub, 3); - currentCol += 2; + currentCol += 2; var cellN_sub = worksheet.Cell(rowIndex, currentCol++); cellN_sub.Value = "ND OT"; @@ -1339,13 +1348,13 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services cellV_sub.Value = "PH After"; ApplyHeaderStyle(cellV_sub, 3); - currentCol += 6; + currentCol += 6; var headerRow2Range = worksheet.Range(rowIndex, 1, rowIndex, worksheet.LastColumnUsed().ColumnNumber()); headerRow2Range.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); headerRow2Range.Style.Border.InsideBorder = XLBorderStyleValues.Thin; - rowIndex++; + rowIndex++; } private void AddHoUPSTWAirHeaders(IXLWorksheet worksheet, ref int rowIndex) @@ -1357,19 +1366,19 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellA = worksheet.Cell(rowIndex, currentCol); cellA.Value = "Day"; ApplyHeaderStyle(cellA, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellB = worksheet.Cell(rowIndex, currentCol); cellB.Value = "Date"; - ApplyHeaderStyle(cellB, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellB, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellC = worksheet.Cell(rowIndex, currentCol); cellC.Value = "Office Hour"; ApplyHeaderStyle(cellC, 2); - var mergedRangeC = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeC = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeC.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeC.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -1377,33 +1386,33 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellF = worksheet.Cell(rowIndex, currentCol); cellF.Value = "After Office Hour"; ApplyHeaderStyle(cellF, 2); - var mergedRangeF = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeF = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeF.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeF.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; var cellI = worksheet.Cell(rowIndex, currentCol); cellI.Value = "OT Hrs (Office Hour)"; - ApplyHeaderStyle(cellI, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellI, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellJ = worksheet.Cell(rowIndex, currentCol); cellJ.Value = "OT Hrs (After Office Hour)"; - ApplyHeaderStyle(cellJ, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellJ, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellK = worksheet.Cell(rowIndex, currentCol); cellK.Value = "Normal Day (After Office)"; - ApplyHeaderStyle(cellK, 2); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellK, 2); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellL = worksheet.Cell(rowIndex, currentCol); cellL.Value = "Off Day"; - ApplyHeaderStyle(cellL, 2); - var mergedRangeL = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + ApplyHeaderStyle(cellL, 2); + var mergedRangeL = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeL.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeL.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -1411,7 +1420,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellO = worksheet.Cell(rowIndex, currentCol); cellO.Value = "Rest Day"; ApplyHeaderStyle(cellO, 2); - var mergedRangeO = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeO = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeO.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeO.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -1419,55 +1428,55 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellR = worksheet.Cell(rowIndex, currentCol); cellR.Value = "Public Holiday"; ApplyHeaderStyle(cellR, 2); - var mergedRangeR = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 1).Merge(); + var mergedRangeR = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 1).Merge(); mergedRangeR.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeR.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 2; var cellT = worksheet.Cell(rowIndex, currentCol); cellT.Value = "Total OT"; - ApplyHeaderStyle(cellT, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellT, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellU = worksheet.Cell(rowIndex, currentCol); cellU.Value = "Total ND & OD"; - ApplyHeaderStyle(cellU, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellU, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellV = worksheet.Cell(rowIndex, currentCol); cellV.Value = "Total RD"; ApplyHeaderStyle(cellV, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellW = worksheet.Cell(rowIndex, currentCol); cellW.Value = "Total PH"; - ApplyHeaderStyle(cellW, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellW, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellX = worksheet.Cell(rowIndex, currentCol); cellX.Value = "Station"; - ApplyHeaderStyle(cellX, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellX, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellY = worksheet.Cell(rowIndex, currentCol); cellY.Value = "Description"; ApplyHeaderStyle(cellY, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var headerRow1Range = worksheet.Range(startRowIndex, 1, startRowIndex, worksheet.LastColumnUsed().ColumnNumber()); headerRow1Range.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); headerRow1Range.Style.Border.InsideBorder = XLBorderStyleValues.Thin; - rowIndex++; + rowIndex++; currentCol = 1; - currentCol += 2; + currentCol += 2; var cellC_sub = worksheet.Cell(rowIndex, currentCol++); cellC_sub.Value = "From"; @@ -1493,7 +1502,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services cellH_sub.Value = "Break"; ApplyHeaderStyle(cellH_sub, 3); - currentCol += 2; + currentCol += 2; var cellK_sub = worksheet.Cell(rowIndex, currentCol++); cellK_sub.Value = "ND OT"; @@ -1531,13 +1540,13 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services cellS_sub.Value = "PH After"; ApplyHeaderStyle(cellS_sub, 3); - currentCol += 5; + currentCol += 5; var headerRow2Range = worksheet.Range(rowIndex, 1, rowIndex, worksheet.LastColumnUsed().ColumnNumber()); headerRow2Range.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); headerRow2Range.Style.Border.InsideBorder = XLBorderStyleValues.Thin; - rowIndex++; + rowIndex++; } private void AddHoUNonPSTWAirHeaders(IXLWorksheet worksheet, ref int rowIndex) @@ -1548,20 +1557,20 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services currentCol = 1; var cellA = worksheet.Cell(rowIndex, currentCol); cellA.Value = "Day"; - ApplyHeaderStyle(cellA, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellA, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellB = worksheet.Cell(rowIndex, currentCol); cellB.Value = "Date"; - ApplyHeaderStyle(cellB, 1); + ApplyHeaderStyle(cellB, 1); worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellC = worksheet.Cell(rowIndex, currentCol); cellC.Value = "Office Hour"; ApplyHeaderStyle(cellC, 2); - var mergedRangeC = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeC = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeC.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeC.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -1569,33 +1578,33 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellF = worksheet.Cell(rowIndex, currentCol); cellF.Value = "After Office Hour"; ApplyHeaderStyle(cellF, 2); - var mergedRangeF = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeF = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeF.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeF.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; var cellI = worksheet.Cell(rowIndex, currentCol); cellI.Value = "OT Hrs (Office Hour)"; - ApplyHeaderStyle(cellI, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellI, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellJ = worksheet.Cell(rowIndex, currentCol); cellJ.Value = "OT Hrs (After Office Hour)"; - ApplyHeaderStyle(cellJ, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellJ, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellK = worksheet.Cell(rowIndex, currentCol); cellK.Value = "Normal Day (After Office)"; ApplyHeaderStyle(cellK, 2); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellL = worksheet.Cell(rowIndex, currentCol); cellL.Value = "Off Day"; - ApplyHeaderStyle(cellL, 2); - var mergedRangeL = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + ApplyHeaderStyle(cellL, 2); + var mergedRangeL = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeL.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeL.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -1603,7 +1612,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellO = worksheet.Cell(rowIndex, currentCol); cellO.Value = "Rest Day"; ApplyHeaderStyle(cellO, 2); - var mergedRangeO = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); + var mergedRangeO = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 2).Merge(); mergedRangeO.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeO.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 3; @@ -1611,7 +1620,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellR = worksheet.Cell(rowIndex, currentCol); cellR.Value = "Public Holiday"; ApplyHeaderStyle(cellR, 2); - var mergedRangeR = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 1).Merge(); + var mergedRangeR = worksheet.Range(rowIndex, currentCol, rowIndex, currentCol + 1).Merge(); mergedRangeR.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); mergedRangeR.Style.Border.InsideBorder = XLBorderStyleValues.Thin; currentCol += 2; @@ -1619,29 +1628,29 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var cellT = worksheet.Cell(rowIndex, currentCol); cellT.Value = "Total OT"; ApplyHeaderStyle(cellT, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellU = worksheet.Cell(rowIndex, currentCol); cellU.Value = "Total ND & OD"; - ApplyHeaderStyle(cellU, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellU, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellV = worksheet.Cell(rowIndex, currentCol); cellV.Value = "Total RD"; - ApplyHeaderStyle(cellV, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellV, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellW = worksheet.Cell(rowIndex, currentCol); cellW.Value = "Total PH"; - ApplyHeaderStyle(cellW, 1); - worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); + ApplyHeaderStyle(cellW, 1); + worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; var cellX = worksheet.Cell(rowIndex, currentCol); - cellX.Value = "Description"; + cellX.Value = "Description"; ApplyHeaderStyle(cellX, 1); worksheet.Range(rowIndex, currentCol, rowIndex + 1, currentCol).Merge(); currentCol++; @@ -1653,7 +1662,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services rowIndex++; currentCol = 1; - currentCol += 2; + currentCol += 2; var cellC_sub = worksheet.Cell(rowIndex, currentCol++); cellC_sub.Value = "From"; @@ -1679,7 +1688,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services cellH_sub.Value = "Break"; ApplyHeaderStyle(cellH_sub, 3); - currentCol += 2; + currentCol += 2; var cellK_sub = worksheet.Cell(rowIndex, currentCol++); cellK_sub.Value = "ND OT"; @@ -1717,27 +1726,26 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services cellS_sub.Value = "PH After"; ApplyHeaderStyle(cellS_sub, 3); - currentCol += 4; + currentCol += 4; var headerRow2Range = worksheet.Range(rowIndex, 1, rowIndex, worksheet.LastColumnUsed().ColumnNumber()); headerRow2Range.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); headerRow2Range.Style.Border.InsideBorder = XLBorderStyleValues.Thin; - rowIndex++; + rowIndex++; } - private uint GetDayCellColorStyleIndex(DateTime date, int? weekendId, List publicHolidays) { if (publicHolidays.Contains(date.Date)) - return 18; + return 18; DayOfWeek dayOfWeek = date.DayOfWeek; if ((weekendId == 1 && (dayOfWeek == DayOfWeek.Friday || dayOfWeek == DayOfWeek.Saturday)) || (weekendId == 2 && (dayOfWeek == DayOfWeek.Saturday || dayOfWeek == DayOfWeek.Sunday))) return 19; - return 11; + return 11; } private bool IsAdmin(int userId) @@ -1817,7 +1825,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services } int hours = (int)ts.TotalHours; - int minutes = ts.Minutes; + int minutes = ts.Minutes; return $"{hours}:{minutes:D2}"; } @@ -1853,7 +1861,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services totalMinutes += 24 * 60; } - return (decimal)Math.Max(0, totalMinutes); + return (decimal)Math.Max(0, totalMinutes); } private string CalculateOfficeOtHours(OtRegisterModel record) @@ -1994,7 +2002,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services private string CalculateOtAmount(OtRegisterModel record, decimal hrp, List publicHolidays, int? weekendId) { - var orp = CalculateOrp(hrp * 208); + var orp = CalculateOrp(hrp * 208); var dayType = GetDayType(record.OtDate, weekendId, publicHolidays); var officeRaw = CalculateOfficeOtHours(record); @@ -2049,10 +2057,10 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services { int remarksStartColumn = 1; - int remarksRow = currentRow + 1; + int remarksRow = currentRow + 1; var phColorCell = worksheet.Cell(remarksRow, remarksStartColumn); - phColorCell.Value = " "; + phColorCell.Value = " "; phColorCell.Style.Fill.BackgroundColor = XLColor.FromHtml("FFC0CB"); phColorCell.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); @@ -2061,7 +2069,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services remarksRow++; var weekendColorCell = worksheet.Cell(remarksRow, remarksStartColumn); - weekendColorCell.Value = " "; + weekendColorCell.Value = " "; weekendColorCell.Style.Fill.BackgroundColor = XLColor.FromHtml("ADD8E6"); weekendColorCell.Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin); @@ -2069,7 +2077,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services worksheet.Cell(remarksRow, remarksStartColumn + 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; remarksRow++; - remarksRow++; + remarksRow++; worksheet.Cell(remarksRow, remarksStartColumn).Value = $"Public Holidays in {displayMonth:MMMM yyyy}:"; worksheet.Cell(remarksRow, remarksStartColumn).Style.Font.SetBold(); diff --git a/Areas/OTcalculate/Services/OvertimePDF.cs b/Areas/OTcalculate/Services/OvertimePDF.cs index f32e9fa..de0337e 100644 --- a/Areas/OTcalculate/Services/OvertimePDF.cs +++ b/Areas/OTcalculate/Services/OvertimePDF.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using PSTW_CentralSystem.Areas.OTcalculate.Models; -using PSTW_CentralSystem.Models; +using PSTW_CentralSystem.Models; using Microsoft.EntityFrameworkCore; using PSTW_CentralSystem.DBContext; @@ -27,7 +27,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services decimal userRate, DateTime? selectedMonth = null, byte[]? logoImage = null, - bool isHoU = false, + bool isRestrictedUser = false, string? flexiHour = null, List? approvedSignatures = null) { @@ -45,7 +45,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var publicHolidaysForUser = _centralDbContext.Holidays .Where(h => userSetting != null && h.StateId == userSetting.State.StateId && h.HolidayDate.Month == displayMonth.Month && h.HolidayDate.Year == displayMonth.Year) - .OrderBy(h => h.HolidayDate) + .OrderBy(h => h.HolidayDate) .ToList(); records = records.OrderBy(r => r.OtDate).ToList(); @@ -117,7 +117,8 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services column.Item().PaddingVertical(10).LineHorizontal(0.5f).LineColor(Colors.Grey.Lighten2); - column.Item().Element(container => ComposeTable(container, records, user, userRate, showStationColumn, allDatesInMonth, isHoU, publicHolidaysForUser.Select(h => h.HolidayDate.Date).ToList())); + // Pass the new isRestrictedUser flag to ComposeTable + column.Item().Element(container => ComposeTable(container, records, user, userRate, showStationColumn, allDatesInMonth, isRestrictedUser, publicHolidaysForUser.Select(h => h.HolidayDate.Date).ToList())); column.Item().PaddingTop(20).Element(container => { @@ -153,7 +154,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services if (approval.ApprovedDate.HasValue) { individualApprovalColumn.Item().PaddingTop(2) - .Text(approval.ApprovedDate.Value.ToString("dd MMMM yyyy")) + .Text(approval.ApprovedDate.Value.ToString("dd MMMM yyyy")) .FontSize(8).AlignCenter(); } })); @@ -173,8 +174,8 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services { table.ColumnsDefinition(columns => { - columns.RelativeColumn(1); - columns.RelativeColumn(2); + columns.RelativeColumn(1); + columns.RelativeColumn(2); }); table.Header(header => @@ -194,7 +195,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services else { table.Cell().ColumnSpan(2).Border(0.25f).Padding(2) - .Text($"No public holidays found for {userSetting?.State?.StateName ?? "this state"} in {displayMonth:MMMM yyyy}.") + .Text($"No public holidays found for {userSetting?.State?.StateName ?? "this state"} in {displayMonth:MMMM yyyy}.") .FontSize(7).Italic().AlignCenter(); } }); @@ -216,7 +217,8 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services return stream; } - private void ComposeTable(IContainer container, List records, UserModel user, decimal userRate, bool showStationColumn, List allDatesInMonth, bool isHoU, List publicHolidays) + // Update the signature of ComposeTable to accept the new flag + private void ComposeTable(IContainer container, List records, UserModel user, decimal userRate, bool showStationColumn, List allDatesInMonth, bool hideSalaryDetails, List publicHolidays) { var recordsGroupedByDate = records .GroupBy(r => r.OtDate.Date) @@ -230,7 +232,8 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services { table.ColumnsDefinition(columns => { - if (!isHoU) + // Conditionally add salary columns based on hideSalaryDetails + if (!hideSalaryDetails) { columns.RelativeColumn(0.25f); // Basic Salary columns.RelativeColumn(0.2f); // ORP @@ -259,7 +262,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services columns.RelativeColumn(0.3f); columns.RelativeColumn(0.2f); columns.RelativeColumn(0.2f); - if (!isHoU) + if (!hideSalaryDetails) // Conditionally add Total Amt column { columns.RelativeColumn(0.25f); } @@ -274,7 +277,8 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services table.Header(header => { - if (!isHoU) + // Conditionally add salary headers based on hideSalaryDetails + if (!hideSalaryDetails) { header.Cell().RowSpan(2).Background("#fce5cd").Border(0.25f).Padding(3).Text("Basic Salary\n(RM)").FontSize(6).Bold().AlignCenter(); header.Cell().RowSpan(2).Background("#fce5cd").Border(0.25f).Padding(3).Text("ORP").FontSize(6).Bold().AlignCenter(); @@ -299,7 +303,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services header.Cell().RowSpan(2).Background("#fdebd0").Border(0.25f).Padding(3).Text("Total\nRD").FontSize(6).Bold().AlignCenter(); header.Cell().RowSpan(2).Background("#fdebd0").Border(0.25f).Padding(3).Text("Total\nPH").FontSize(6).Bold().AlignCenter(); - if (!isHoU) + if (!hideSalaryDetails) // Conditionally add Total Amt header { header.Cell().RowSpan(2).Background("#fce5cd").Border(0.25f).Padding(3).Text("OT Amt\n(RM)").FontSize(6).Bold().AlignCenter(); } @@ -413,14 +417,15 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services if (center) text.AlignCenter(); } - if (!isHoU) + // Conditionally render salary details + if (!hideSalaryDetails) { // Display the calculated values here AddCell(!hasPrintedSalaryDetails ? $"{basicSalary:F2}" : ""); AddCell(!hasPrintedSalaryDetails ? $"{orp:F2}" : ""); AddCell(!hasPrintedSalaryDetails ? $"{hrp:F2}" : ""); } - hasPrintedSalaryDetails = true; + hasPrintedSalaryDetails = true; if (date.Date != previousDate?.Date) { @@ -455,7 +460,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services AddCell(totalNdOd); AddCell(totalRd); AddCell(totalPh); - if (!isHoU) + if (!hideSalaryDetails) // Conditionally render Total Amt column { AddCell(otAmt == "0.00" ? "" : otAmt); } @@ -473,7 +478,8 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services } } - if (!isHoU) + // Adjust column span for the TOTAL row based on visibility + if (!hideSalaryDetails) { table.Cell().ColumnSpan(5).Background("#d8d1f5").Border(0.80f).Padding(3) .Text("TOTAL").Bold().FontSize(6).AlignCenter(); @@ -540,10 +546,10 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services table.Cell().Background("#d8d1f5").Border(0.80f).Padding(3) .Text($"{grandTotalPh:N2}").Bold().FontSize(6).AlignCenter(); - if (!isHoU) + if (!hideSalaryDetails) // Conditionally render Total Amt in footer { table.Cell().Background("#d8d1f5").Border(0.80f).Padding(3) - .Text($"{Math.Round(grandTotalOtAmount, MidpointRounding.AwayFromZero):F2}").Bold().FontSize(6).AlignCenter(); + .Text($"{Math.Round(grandTotalOtAmount, MidpointRounding.AwayFromZero):F2}").Bold().FontSize(6).AlignCenter(); } if (showStationColumn) @@ -556,7 +562,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services public MemoryStream GenerateSimpleOvertimeTablePdf( List records, - UserModel user, + UserModel user, decimal userRate, DateTime? selectedMonth = null, byte[]? logoImage = null, @@ -576,8 +582,8 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var publicHolidaysForUser = _centralDbContext.Holidays .Where(h => userSetting != null && h.StateId == userSetting.State.StateId && h.HolidayDate.Month == displayMonth.Month && h.HolidayDate.Year == displayMonth.Year) - .OrderBy(h => h.HolidayDate) - .ToList(); + .OrderBy(h => h.HolidayDate) + .ToList(); records = records.OrderBy(r => r.OtDate).ToList(); var stream = new MemoryStream(); @@ -666,8 +672,8 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services { table.ColumnsDefinition(columns => { - columns.RelativeColumn(1); - columns.RelativeColumn(2); + columns.RelativeColumn(1); + columns.RelativeColumn(2); }); table.Header(header => @@ -687,7 +693,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services else { table.Cell().ColumnSpan(2).Border(0.25f).Padding(2) - .Text($"No public holidays found for {userSetting?.State?.StateName ?? "this state"} in {displayMonth:MMMM yyyy}.") // Changed format + .Text($"No public holidays found for {userSetting?.State?.StateName ?? "this state"} in {displayMonth:MMMM yyyy}.") .FontSize(7).Italic().AlignCenter(); } }); @@ -788,7 +794,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services decimal totalHours = 0; decimal totalBreak = 0; bool alternate = false; - DateTime? previousDate = null; + DateTime? previousDate = null; foreach (var date in allDatesInMonth) { @@ -821,7 +827,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services AddCell("", true, backgroundColor); AddCell("", true, backgroundColor); } - previousDate = date; + previousDate = date; var officeHours = CalculateOfficeOtHours(record); var afterHours = CalculateAfterOfficeOtHours(record); @@ -845,7 +851,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services AddCell(FormatAsHourMinute(totalTime, isMinutes: false)); AddCell(FormatAsHourMinute(breakTime, isMinutes: true)); - // Station + // Station if (showStationColumn) { AddCell(record.Stations?.StationName ?? ""); @@ -902,7 +908,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services var lastDate = records.Last().OtDate; if (firstDate.Month == lastDate.Month && firstDate.Year == lastDate.Year) - return firstDate.ToString("MMMM yyyy"); + return firstDate.ToString("MMMM yyyy"); return $"{firstDate:MMM yyyy} - {lastDate:MMM yyyy}"; } @@ -941,14 +947,14 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services DayOfWeek dayOfWeek = date.DayOfWeek; - if ((weekendId == 1 && dayOfWeek == DayOfWeek.Saturday) || - (weekendId == 2 && dayOfWeek == DayOfWeek.Sunday)) + if ((weekendId == 1 && dayOfWeek == DayOfWeek.Saturday) || + (weekendId == 2 && dayOfWeek == DayOfWeek.Sunday)) { return "Rest Day"; } - if ((weekendId == 1 && dayOfWeek == DayOfWeek.Friday) || - (weekendId == 2 && dayOfWeek == DayOfWeek.Saturday)) + if ((weekendId == 1 && dayOfWeek == DayOfWeek.Friday) || + (weekendId == 2 && dayOfWeek == DayOfWeek.Saturday)) { return "Off Day"; } @@ -992,11 +998,11 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services if (totalMinutes < 0) { - totalMinutes += 24 * 60; + totalMinutes += 24 * 60; } - totalMinutes -= (record.OfficeBreak ?? 0); - totalMinutes = Math.Max(0, totalMinutes); + totalMinutes -= (record.OfficeBreak ?? 0); + totalMinutes = Math.Max(0, totalMinutes); int hours = (int)(totalMinutes / 60); int minutes = (int)(totalMinutes % 60); @@ -1015,11 +1021,11 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services if (totalMinutes < 0) { - totalMinutes += 24 * 60; + totalMinutes += 24 * 60; } - totalMinutes -= (record.AfterBreak ?? 0); - totalMinutes = Math.Max(0, totalMinutes); + totalMinutes -= (record.AfterBreak ?? 0); + totalMinutes = Math.Max(0, totalMinutes); int hours = (int)(totalMinutes / 60); int minutes = (int)(totalMinutes % 60); @@ -1055,7 +1061,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services switch (dayType) { case "Normal Day": - result["ndAfter"] = toFixedOrEmpty(afterHrs); + result["ndAfter"] = toFixedOrEmpty(afterHrs); break; case "Off Day": @@ -1105,7 +1111,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services { result["phUnder8"] = toFixedOrEmpty(officeHrs); // Assign all to 'under 8' } - else // If total office hours are more than 8 + else { result["phAfter"] = toFixedOrEmpty(officeHrs); // Assign all to 'PH After' (for office hours beyond 8) } @@ -1170,7 +1176,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services private string CalculateOtAmount(OtRegisterModel record, decimal hrp, List publicHolidays, int? weekendId) { - decimal orp = hrp * 8m; + decimal orp = hrp * 8m; var dayType = GetDayType(record.OtDate, weekendId, publicHolidays); @@ -1238,7 +1244,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Services if ((weekendId == 1 && (dayOfWeek == DayOfWeek.Friday || dayOfWeek == DayOfWeek.Saturday)) || (weekendId == 2 && (dayOfWeek == DayOfWeek.Saturday || dayOfWeek == DayOfWeek.Sunday))) - return "#add8e6"; + return "#add8e6"; return "#ffffff"; } diff --git a/Areas/OTcalculate/Views/ApprovalDashboard/OtReview.cshtml b/Areas/OTcalculate/Views/ApprovalDashboard/OtReview.cshtml index aaa4162..ee7449c 100644 --- a/Areas/OTcalculate/Views/ApprovalDashboard/OtReview.cshtml +++ b/Areas/OTcalculate/Views/ApprovalDashboard/OtReview.cshtml @@ -86,9 +86,9 @@ - - - + + + @@ -102,7 +102,7 @@ - + @@ -127,7 +127,7 @@ -
Basic Salary
(RM)
ORPHRPBasic Salary
(RM)
ORPHRP Date Office Hour After Office HourTotal OT Hrs
ND & OD
Total OT Hrs
RD
Total OT Hrs
PH
OT Amt (RM)OT Amt (RM) Station Description Action