From fdb70d15eca7583fc329de2b9d27b5dddb67d845 Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Wed, 10 Jul 2024 17:11:06 +0800 Subject: [PATCH] update monthly report --- .../modules/report/service/ReportService.kt | 57 +++++++++++++++++-- .../modules/report/web/ReportController.kt | 8 ++- .../modules/report/web/model/ReportRequest.kt | 3 +- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt index 35b968c..86a957c 100644 --- a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt +++ b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt @@ -21,6 +21,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook import org.apache.poi.ss.usermodel.FormulaEvaluator import org.apache.poi.ss.util.CellReference import org.apache.poi.ss.util.RegionUtil +import org.apache.poi.xssf.usermodel.XSSFCellStyle import org.springframework.core.io.ClassPathResource import org.springframework.stereotype.Service import java.io.ByteArrayOutputStream @@ -92,7 +93,7 @@ open class ReportService( .createCell(columnIndex + keyIndex + 1) when (obj[key]) { is Double -> tempCell.setCellValue(obj[key] as Double) - else -> tempCell.setCellValue(obj[key] as String) + else -> tempCell.setCellValue(obj[key].toString()) } } rowIndex++ @@ -210,6 +211,7 @@ open class ReportService( @Throws(IOException::class) fun generateStaffMonthlyWorkHourAnalysisReport( month: LocalDate, + holidays: List, staff: Staff, timesheets: List>, leaves: List>, @@ -217,6 +219,7 @@ open class ReportService( // Generate the Excel report with query results val workbook: Workbook = createStaffMonthlyWorkHourAnalysisReport( month, + holidays, staff, timesheets, leaves, @@ -1095,6 +1098,7 @@ open class ReportService( @Throws(IOException::class) private fun createStaffMonthlyWorkHourAnalysisReport( month: LocalDate, + holidays: List, staff: Staff, timesheets: List>, leaves: List>, @@ -1195,18 +1199,42 @@ open class ReportService( ThinBorderBottom["wrapText"] = true ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// rowIndex = 7 + print(daysOfMonth) + val holidayIndexList = mutableListOf() + println(daysOfMonth.get(0)) + + val fillOrange = workbook.createCellStyle() + fillOrange.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.index); + fillOrange.setFillPattern(FillPatternType.SOLID_FOREGROUND) + daysOfMonth.forEach { dayInfo -> rowIndex++ rowSize++ + var isHoliday = false + println(dayInfo.weekday) + if (dayInfo.date in holidays || dayInfo.weekday.equals("Sun") || dayInfo.weekday.equals("Sat")) { + holidayIndexList.add(rowIndex) + isHoliday = true + } tempCell = sheet.getRow(rowIndex).createCell(0) tempCell.setCellValue(dayInfo.date) - tempCell.cellStyle = boldStyle + if (isHoliday) { + tempCell.cellStyle = fillOrange + tempCell.cellStyle.setFont(boldFont) + } else { + tempCell.cellStyle = boldStyle + } tempCell.cellStyle.dataFormat = dateStyle tempCell = sheet.getRow(rowIndex).createCell(1) tempCell.setCellValue(dayInfo.weekday) - tempCell.cellStyle = boldStyle + if (isHoliday) { + tempCell.cellStyle = fillOrange + tempCell.cellStyle.setFont(boldFont) + } else { + tempCell.cellStyle = boldStyle + } } - + println(holidayIndexList) rowIndex += 1 tempCell = sheet.getRow(rowIndex).createCell(0) sheet.addMergedRegion(CellRangeAddress(rowIndex, rowIndex, 0, 1)) @@ -1300,11 +1328,14 @@ open class ReportService( println(columnSize) /////////////////////////////////////////////////////////////// main data ////////////////////////////////////////////////////////////// if (timesheets.isNotEmpty()) { - +// val accountingStyle = workbook.createDataFormat().getFormat("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)") projectList.forEachIndexed { index, _ -> for (i in 0 until rowSize) { tempCell = sheet.getRow(8 + i).createCell(columnIndex + index) tempCell.setCellValue(0.0) + if ( 8+i in holidayIndexList) { + tempCell.cellStyle = fillOrange + } tempCell.cellStyle.dataFormat = accountingStyle } } @@ -1314,6 +1345,10 @@ open class ReportService( dayInt = temp[index]["date"].toString().toInt() tempCell = sheet.getRow(dayInt.plus(7)).createCell(columnIndex) tempCell.setCellValue((temp[index]["normalConsumed"] as Double) + (temp[index]["otConsumed"] as Double)) + if ( dayInt.plus(7) in holidayIndexList) { + tempCell.cellStyle = fillOrange + tempCell.cellStyle.dataFormat = accountingStyle + } } columnIndex++ } @@ -1322,6 +1357,10 @@ open class ReportService( for (i in 0 until rowSize) { tempCell = sheet.getRow(8 + i).createCell(columnIndex) tempCell.setCellValue(0.0) + if ( 8+i in holidayIndexList) { + tempCell.cellStyle = fillOrange + + } tempCell.cellStyle.dataFormat = accountingStyle } if (leaves.isNotEmpty()) { @@ -1329,6 +1368,10 @@ open class ReportService( dayInt = leave["recordDate"].toString().toInt() tempCell = sheet.getRow(dayInt.plus(7)).createCell(columnIndex) tempCell.setCellValue(leave["leaveHours"] as Double) + if ( dayInt.plus(7) in holidayIndexList) { + tempCell.cellStyle = fillOrange + + } } } ///////////////////////////////////////////////////////// Leave Hours title //////////////////////////////////////////////////////////////////// @@ -1357,6 +1400,10 @@ open class ReportService( tempCell = sheet.getRow(rowIndex).createCell(columnIndex) tempCell.cellFormula = "SUM(${getColumnAlphabet(2)}${rowIndex + 1}:${getColumnAlphabet(columnIndex - 2)}${rowIndex + 1})" // should columnIndex - 2 + if ( rowIndex in holidayIndexList) { + tempCell.cellStyle = fillOrange + + } rowIndex++ } // cal subtotal diff --git a/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt b/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt index 93e7643..1e10b4b 100644 --- a/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt +++ b/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt @@ -134,8 +134,10 @@ class ReportController( @Throws(ServletRequestBindingException::class, IOException::class) fun StaffMonthlyWorkHourAnalysisReport(@RequestBody @Valid request: StaffMonthlyWorkHourAnalysisReportRequest): ResponseEntity { val thisMonth = request.yearMonth.atDay(1) + val holidays = request.holidays val nextMonth = request.yearMonth.plusMonths(1).atDay(1) - + print(thisMonth) + print(nextMonth) val staff = staffRepository.findById(request.id).orElseThrow() val args: Map = mutableMapOf( "staffId" to request.id, @@ -145,7 +147,9 @@ class ReportController( val timesheets = excelReportService.getTimesheet(args) val leaves = excelReportService.getLeaves(args) - val reportResult: ByteArray = excelReportService.generateStaffMonthlyWorkHourAnalysisReport(thisMonth, staff, timesheets, leaves) + print(timesheets) + print(leaves) + val reportResult: ByteArray = excelReportService.generateStaffMonthlyWorkHourAnalysisReport(thisMonth, holidays, staff, timesheets, leaves) // val mediaType: MediaType = MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") return ResponseEntity.ok() // .contentType(mediaType) diff --git a/src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt b/src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt index 1c8b509..b66e46a 100644 --- a/src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt +++ b/src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt @@ -35,7 +35,8 @@ data class ProjectPotentialDelayReportRequest ( data class StaffMonthlyWorkHourAnalysisReportRequest ( val id: Long, - val yearMonth: YearMonth + val yearMonth: YearMonth, + val holidays: List ) data class LateStartReportRequest (