Browse Source

update monthly report

tags/Baseline_30082024_BACKEND_UAT
MSI\derek 1 year ago
parent
commit
fdb70d15ec
3 changed files with 60 additions and 8 deletions
  1. +52
    -5
      src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt
  2. +6
    -2
      src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt
  3. +2
    -1
      src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt

+ 52
- 5
src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt View File

@@ -21,6 +21,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.apache.poi.ss.usermodel.FormulaEvaluator import org.apache.poi.ss.usermodel.FormulaEvaluator
import org.apache.poi.ss.util.CellReference import org.apache.poi.ss.util.CellReference
import org.apache.poi.ss.util.RegionUtil import org.apache.poi.ss.util.RegionUtil
import org.apache.poi.xssf.usermodel.XSSFCellStyle
import org.springframework.core.io.ClassPathResource import org.springframework.core.io.ClassPathResource
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
@@ -92,7 +93,7 @@ open class ReportService(
.createCell(columnIndex + keyIndex + 1) .createCell(columnIndex + keyIndex + 1)
when (obj[key]) { when (obj[key]) {
is Double -> tempCell.setCellValue(obj[key] as Double) is Double -> tempCell.setCellValue(obj[key] as Double)
else -> tempCell.setCellValue(obj[key] as String)
else -> tempCell.setCellValue(obj[key].toString())
} }
} }
rowIndex++ rowIndex++
@@ -210,6 +211,7 @@ open class ReportService(
@Throws(IOException::class) @Throws(IOException::class)
fun generateStaffMonthlyWorkHourAnalysisReport( fun generateStaffMonthlyWorkHourAnalysisReport(
month: LocalDate, month: LocalDate,
holidays: List<String>,
staff: Staff, staff: Staff,
timesheets: List<Map<String, Any>>, timesheets: List<Map<String, Any>>,
leaves: List<Map<String, Any>>, leaves: List<Map<String, Any>>,
@@ -217,6 +219,7 @@ open class ReportService(
// Generate the Excel report with query results // Generate the Excel report with query results
val workbook: Workbook = createStaffMonthlyWorkHourAnalysisReport( val workbook: Workbook = createStaffMonthlyWorkHourAnalysisReport(
month, month,
holidays,
staff, staff,
timesheets, timesheets,
leaves, leaves,
@@ -1095,6 +1098,7 @@ open class ReportService(
@Throws(IOException::class) @Throws(IOException::class)
private fun createStaffMonthlyWorkHourAnalysisReport( private fun createStaffMonthlyWorkHourAnalysisReport(
month: LocalDate, month: LocalDate,
holidays: List<String>,
staff: Staff, staff: Staff,
timesheets: List<Map<String, Any>>, timesheets: List<Map<String, Any>>,
leaves: List<Map<String, Any>>, leaves: List<Map<String, Any>>,
@@ -1195,18 +1199,42 @@ open class ReportService(
ThinBorderBottom["wrapText"] = true ThinBorderBottom["wrapText"] = true
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
rowIndex = 7 rowIndex = 7
print(daysOfMonth)
val holidayIndexList = mutableListOf<Int>()
println(daysOfMonth.get(0))

val fillOrange = workbook.createCellStyle()
fillOrange.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.index);
fillOrange.setFillPattern(FillPatternType.SOLID_FOREGROUND)

daysOfMonth.forEach { dayInfo -> daysOfMonth.forEach { dayInfo ->
rowIndex++ rowIndex++
rowSize++ 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 = sheet.getRow(rowIndex).createCell(0)
tempCell.setCellValue(dayInfo.date) 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.cellStyle.dataFormat = dateStyle
tempCell = sheet.getRow(rowIndex).createCell(1) tempCell = sheet.getRow(rowIndex).createCell(1)
tempCell.setCellValue(dayInfo.weekday) tempCell.setCellValue(dayInfo.weekday)
tempCell.cellStyle = boldStyle
if (isHoliday) {
tempCell.cellStyle = fillOrange
tempCell.cellStyle.setFont(boldFont)
} else {
tempCell.cellStyle = boldStyle
}
} }

println(holidayIndexList)
rowIndex += 1 rowIndex += 1
tempCell = sheet.getRow(rowIndex).createCell(0) tempCell = sheet.getRow(rowIndex).createCell(0)
sheet.addMergedRegion(CellRangeAddress(rowIndex, rowIndex, 0, 1)) sheet.addMergedRegion(CellRangeAddress(rowIndex, rowIndex, 0, 1))
@@ -1300,11 +1328,14 @@ open class ReportService(
println(columnSize) println(columnSize)
/////////////////////////////////////////////////////////////// main data ////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// main data //////////////////////////////////////////////////////////////
if (timesheets.isNotEmpty()) { if (timesheets.isNotEmpty()) {
// val accountingStyle = workbook.createDataFormat().getFormat("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)")
projectList.forEachIndexed { index, _ -> projectList.forEachIndexed { index, _ ->
for (i in 0 until rowSize) { for (i in 0 until rowSize) {
tempCell = sheet.getRow(8 + i).createCell(columnIndex + index) tempCell = sheet.getRow(8 + i).createCell(columnIndex + index)
tempCell.setCellValue(0.0) tempCell.setCellValue(0.0)
if ( 8+i in holidayIndexList) {
tempCell.cellStyle = fillOrange
}
tempCell.cellStyle.dataFormat = accountingStyle tempCell.cellStyle.dataFormat = accountingStyle
} }
} }
@@ -1314,6 +1345,10 @@ open class ReportService(
dayInt = temp[index]["date"].toString().toInt() dayInt = temp[index]["date"].toString().toInt()
tempCell = sheet.getRow(dayInt.plus(7)).createCell(columnIndex) tempCell = sheet.getRow(dayInt.plus(7)).createCell(columnIndex)
tempCell.setCellValue((temp[index]["normalConsumed"] as Double) + (temp[index]["otConsumed"] as Double)) 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++ columnIndex++
} }
@@ -1322,6 +1357,10 @@ open class ReportService(
for (i in 0 until rowSize) { for (i in 0 until rowSize) {
tempCell = sheet.getRow(8 + i).createCell(columnIndex) tempCell = sheet.getRow(8 + i).createCell(columnIndex)
tempCell.setCellValue(0.0) tempCell.setCellValue(0.0)
if ( 8+i in holidayIndexList) {
tempCell.cellStyle = fillOrange

}
tempCell.cellStyle.dataFormat = accountingStyle tempCell.cellStyle.dataFormat = accountingStyle
} }
if (leaves.isNotEmpty()) { if (leaves.isNotEmpty()) {
@@ -1329,6 +1368,10 @@ open class ReportService(
dayInt = leave["recordDate"].toString().toInt() dayInt = leave["recordDate"].toString().toInt()
tempCell = sheet.getRow(dayInt.plus(7)).createCell(columnIndex) tempCell = sheet.getRow(dayInt.plus(7)).createCell(columnIndex)
tempCell.setCellValue(leave["leaveHours"] as Double) tempCell.setCellValue(leave["leaveHours"] as Double)
if ( dayInt.plus(7) in holidayIndexList) {
tempCell.cellStyle = fillOrange

}
} }
} }
///////////////////////////////////////////////////////// Leave Hours title //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// Leave Hours title ////////////////////////////////////////////////////////////////////
@@ -1357,6 +1400,10 @@ open class ReportService(
tempCell = sheet.getRow(rowIndex).createCell(columnIndex) tempCell = sheet.getRow(rowIndex).createCell(columnIndex)
tempCell.cellFormula = tempCell.cellFormula =
"SUM(${getColumnAlphabet(2)}${rowIndex + 1}:${getColumnAlphabet(columnIndex - 2)}${rowIndex + 1})" // should columnIndex - 2 "SUM(${getColumnAlphabet(2)}${rowIndex + 1}:${getColumnAlphabet(columnIndex - 2)}${rowIndex + 1})" // should columnIndex - 2
if ( rowIndex in holidayIndexList) {
tempCell.cellStyle = fillOrange

}
rowIndex++ rowIndex++
} }
// cal subtotal // cal subtotal


+ 6
- 2
src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt View File

@@ -134,8 +134,10 @@ class ReportController(
@Throws(ServletRequestBindingException::class, IOException::class) @Throws(ServletRequestBindingException::class, IOException::class)
fun StaffMonthlyWorkHourAnalysisReport(@RequestBody @Valid request: StaffMonthlyWorkHourAnalysisReportRequest): ResponseEntity<Resource> { fun StaffMonthlyWorkHourAnalysisReport(@RequestBody @Valid request: StaffMonthlyWorkHourAnalysisReportRequest): ResponseEntity<Resource> {
val thisMonth = request.yearMonth.atDay(1) val thisMonth = request.yearMonth.atDay(1)
val holidays = request.holidays
val nextMonth = request.yearMonth.plusMonths(1).atDay(1) val nextMonth = request.yearMonth.plusMonths(1).atDay(1)

print(thisMonth)
print(nextMonth)
val staff = staffRepository.findById(request.id).orElseThrow() val staff = staffRepository.findById(request.id).orElseThrow()
val args: Map<String, Any> = mutableMapOf( val args: Map<String, Any> = mutableMapOf(
"staffId" to request.id, "staffId" to request.id,
@@ -145,7 +147,9 @@ class ReportController(
val timesheets = excelReportService.getTimesheet(args) val timesheets = excelReportService.getTimesheet(args)
val leaves = excelReportService.getLeaves(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") // val mediaType: MediaType = MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
return ResponseEntity.ok() return ResponseEntity.ok()
// .contentType(mediaType) // .contentType(mediaType)


+ 2
- 1
src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt View File

@@ -35,7 +35,8 @@ data class ProjectPotentialDelayReportRequest (


data class StaffMonthlyWorkHourAnalysisReportRequest ( data class StaffMonthlyWorkHourAnalysisReportRequest (
val id: Long, val id: Long,
val yearMonth: YearMonth
val yearMonth: YearMonth,
val holidays: List<String>
) )


data class LateStartReportRequest ( data class LateStartReportRequest (


Loading…
Cancel
Save