Ver a proveniência

update monthly report

tags/Baseline_30082024_BACKEND_UAT
MSI\derek há 1 ano
ascendente
cometimento
fdb70d15ec
3 ficheiros alterados com 60 adições e 8 eliminações
  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 Ver ficheiro

@@ -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<String>,
staff: Staff,
timesheets: List<Map<String, Any>>,
leaves: List<Map<String, Any>>,
@@ -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<String>,
staff: Staff,
timesheets: List<Map<String, Any>>,
leaves: List<Map<String, Any>>,
@@ -1195,18 +1199,42 @@ open class ReportService(
ThinBorderBottom["wrapText"] = true
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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 ->
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


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

@@ -134,8 +134,10 @@ class ReportController(
@Throws(ServletRequestBindingException::class, IOException::class)
fun StaffMonthlyWorkHourAnalysisReport(@RequestBody @Valid request: StaffMonthlyWorkHourAnalysisReportRequest): ResponseEntity<Resource> {
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<String, Any> = 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)


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

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

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

data class LateStartReportRequest (


Carregando…
Cancelar
Guardar