Browse Source

Merge branch 'master' of https://git.2fi-solutions.com/davidhui/TSMS-backend

tags/Baseline_30082024_BACKEND_UAT
MSI\2Fi 1 year ago
parent
commit
cfeb16e920
2 changed files with 41 additions and 22 deletions
  1. +41
    -22
      src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt
  2. BIN
      src/main/resources/templates/report/AR08_Monthly Work Hours Analysis Report.xlsx

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

@@ -682,6 +682,10 @@ open class ReportService(
val monthStyle = workbook.createDataFormat().getFormat("mmm, yyyy") val monthStyle = workbook.createDataFormat().getFormat("mmm, yyyy")
val dateStyle = workbook.createDataFormat().getFormat("dd/mm/yyyy") val dateStyle = workbook.createDataFormat().getFormat("dd/mm/yyyy")


val boldStyle = workbook.createCellStyle()
val boldFont = workbook.createFont()
boldFont.bold = true
boldStyle.setFont(boldFont)
val daysOfMonth = (1..month.lengthOfMonth()).map { day -> val daysOfMonth = (1..month.lengthOfMonth()).map { day ->
val date = month.withDayOfMonth(day) val date = month.withDayOfMonth(day)
val formattedDate = date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) val formattedDate = date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))
@@ -691,8 +695,6 @@ open class ReportService(


val sheet: Sheet = workbook.getSheetAt(0) val sheet: Sheet = workbook.getSheetAt(0)


val boldFont = sheet.workbook.createFont()
boldFont.bold = true
// sheet.forceFormulaRecalculation = true; //Calculate formulas // sheet.forceFormulaRecalculation = true; //Calculate formulas


var rowIndex = 1 // Assuming the location is in (1,2), which is the report date field var rowIndex = 1 // Assuming the location is in (1,2), which is the report date field
@@ -704,22 +706,27 @@ open class ReportService(
var dayInt = 0 var dayInt = 0
var tempCell: Cell var tempCell: Cell


tempCell = sheet.getRow(rowIndex).createCell(columnIndex)
tempCell.setCellValue(FORMATTED_TODAY)
sheet.getRow(rowIndex).createCell(columnIndex).apply {
setCellValue(FORMATTED_TODAY)
}


rowIndex = 2 rowIndex = 2
tempCell = sheet.getRow(rowIndex).createCell(columnIndex)
tempCell.setCellValue(month)
tempCell.cellStyle.dataFormat = monthStyle
sheet.getRow(rowIndex).getCell(columnIndex).apply {
setCellValue(month)
// cellStyle.setFont(boldStyle)

cellStyle.dataFormat = monthStyle
}


rowIndex = 3 rowIndex = 3
tempCell. sheet.getRow(rowIndex).createCell(columnIndex)
tempCell.setCellValue(staff.name)
sheet.getRow(rowIndex).createCell(columnIndex).apply {
setCellValue(staff.name)
}


rowIndex = 4 rowIndex = 4
tempCell.sheet.getRow(rowIndex).createCell(columnIndex)
tempCell.setCellValue(staff.team.name)
sheet.getRow(rowIndex).createCell(columnIndex).apply {
setCellValue(staff.team.name)
}


rowIndex = 5 rowIndex = 5
tempCell = sheet.getRow(rowIndex).createCell(columnIndex) tempCell = sheet.getRow(rowIndex).createCell(columnIndex)
@@ -731,6 +738,7 @@ open class ReportService(


val ThinBorderBottom: MutableMap<String?, Any?> = mutableMapOf() val ThinBorderBottom: MutableMap<String?, Any?> = mutableMapOf()
ThinBorderBottom["borderBottom"] = BorderStyle.THIN ThinBorderBottom["borderBottom"] = BorderStyle.THIN
ThinBorderBottom["wrapText"] = true
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
rowIndex = 7 rowIndex = 7
daysOfMonth.forEach { dayInfo -> daysOfMonth.forEach { dayInfo ->
@@ -738,12 +746,12 @@ open class ReportService(
rowSize++ rowSize++
tempCell = sheet.getRow(rowIndex).createCell(0) tempCell = sheet.getRow(rowIndex).createCell(0)
tempCell.setCellValue(dayInfo.date) tempCell.setCellValue(dayInfo.date)
tempCell.cellStyle = boldStyle
tempCell.cellStyle.dataFormat = dateStyle tempCell.cellStyle.dataFormat = dateStyle
tempCell.cellStyle.setFont(boldFont)
// cellStyle.alignment = HorizontalAlignment.LEFT // cellStyle.alignment = HorizontalAlignment.LEFT
tempCell = sheet.getRow(rowIndex).createCell(1) tempCell = sheet.getRow(rowIndex).createCell(1)
tempCell.setCellValue(dayInfo.weekday) tempCell.setCellValue(dayInfo.weekday)
tempCell.cellStyle.setFont(boldFont)
tempCell.cellStyle = boldStyle
// cellStyle.alignment = HorizontalAlignment.LEFT // cellStyle.alignment = HorizontalAlignment.LEFT
} }


@@ -751,7 +759,7 @@ open class ReportService(
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))
tempCell.setCellValue("Sub-total") tempCell.setCellValue("Sub-total")
tempCell.cellStyle.setFont(boldFont)
tempCell.cellStyle = boldStyle
CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER)
CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom) CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom)
tempCell = sheet.getRow(rowIndex).createCell(1) tempCell = sheet.getRow(rowIndex).createCell(1)
@@ -760,6 +768,7 @@ open class ReportService(
rowIndex += 1 rowIndex += 1
tempCell = sheet.getRow(rowIndex).createCell(0) tempCell = sheet.getRow(rowIndex).createCell(0)
tempCell.setCellValue("Total Normal Hours [A]") tempCell.setCellValue("Total Normal Hours [A]")
tempCell.cellStyle = boldStyle
CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER)


var normalConsumed = 0.0 var normalConsumed = 0.0
@@ -780,8 +789,8 @@ open class ReportService(
rowIndex += 1 rowIndex += 1
tempCell = sheet.getRow(rowIndex).createCell(0) tempCell = sheet.getRow(rowIndex).createCell(0)
tempCell.setCellValue("Total Other Hours [B]") tempCell.setCellValue("Total Other Hours [B]")
tempCell.cellStyle = boldStyle
CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER)
tempCell.cellStyle.setFont(boldFont)
tempCell = sheet.getRow(rowIndex).createCell(2) tempCell = sheet.getRow(rowIndex).createCell(2)
tempCell.setCellValue(otConsumed) tempCell.setCellValue(otConsumed)
tempCell.cellStyle.dataFormat = accountingStyle tempCell.cellStyle.dataFormat = accountingStyle
@@ -793,6 +802,7 @@ open class ReportService(
rowIndex += 1 rowIndex += 1
tempCell = sheet.getRow(rowIndex).createCell(0) tempCell = sheet.getRow(rowIndex).createCell(0)
tempCell.setCellValue("Total Leave Hours") tempCell.setCellValue("Total Leave Hours")
tempCell.cellStyle = boldStyle
CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER)
sheet.addMergedRegion(CellRangeAddress(rowIndex,rowIndex , 0, 1)) sheet.addMergedRegion(CellRangeAddress(rowIndex,rowIndex , 0, 1))
if (leaves.isNotEmpty()) { if (leaves.isNotEmpty()) {
@@ -808,7 +818,7 @@ open class ReportService(
rowIndex += 1 rowIndex += 1
tempCell = sheet.getRow(rowIndex).createCell(0) tempCell = sheet.getRow(rowIndex).createCell(0)
tempCell.setCellValue("Total Spent Manhours [A+B]") tempCell.setCellValue("Total Spent Manhours [A+B]")
tempCell.cellStyle.setFont(boldFont)
tempCell.cellStyle = boldStyle
CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER) CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER)
CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom) CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom)
tempCell = sheet.getRow(rowIndex).createCell(1) tempCell = sheet.getRow(rowIndex).createCell(1)
@@ -827,9 +837,13 @@ open class ReportService(
projectList.forEachIndexed { index, title -> projectList.forEachIndexed { index, title ->
tempCell = sheet.getRow(7).createCell(columnIndex + index) tempCell = sheet.getRow(7).createCell(columnIndex + index)
tempCell.setCellValue(title) tempCell.setCellValue(title)
CellUtil.setAlignment(tempCell, HorizontalAlignment.RIGHT)
tempCell.cellStyle = boldStyle
CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER)
CellUtil.setVerticalAlignment(tempCell, VerticalAlignment.CENTER)
CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom) CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom)
columnSize++
} }
println(columnSize)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (timesheets.isNotEmpty()) { if (timesheets.isNotEmpty()) {
projectList.forEach { _ -> projectList.forEach { _ ->
@@ -865,11 +879,16 @@ open class ReportService(
///////////////////////////////////////////////////////// Leave Hours //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// Leave Hours ////////////////////////////////////////////////////////////////////
tempCell = sheet.getRow(rowIndex).createCell(columnIndex) tempCell = sheet.getRow(rowIndex).createCell(columnIndex)
tempCell.setCellValue("Leave Hours") tempCell.setCellValue("Leave Hours")
tempCell.cellStyle = boldStyle
CellUtil.setVerticalAlignment(tempCell, VerticalAlignment.CENTER)
CellUtil.setAlignment(tempCell, HorizontalAlignment.CENTER)
CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom) CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom)


columnIndex += 1 columnIndex += 1
tempCell = sheet.getRow(rowIndex).createCell(columnIndex) tempCell = sheet.getRow(rowIndex).createCell(columnIndex)
tempCell.setCellValue("Daily Manhour Spent\n(Excluding Leave Hours)") tempCell.setCellValue("Daily Manhour Spent\n(Excluding Leave Hours)")
tempCell.cellStyle = boldStyle
CellUtil.setAlignment(tempCell, HorizontalAlignment.LEFT)
CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom) CellUtil.setCellStyleProperties(tempCell, ThinBorderBottom)


sheet.addMergedRegion(CellRangeAddress(6,6 , 2, columnIndex)) sheet.addMergedRegion(CellRangeAddress(6,6 , 2, columnIndex))
@@ -884,18 +903,18 @@ open class ReportService(
} }
// cal subtotal // cal subtotal
println(rowIndex) println(rowIndex)
for (i in 0 until columnSize - 2) { // minus last col
tempCell = sheet.getRow(rowIndex).createCell(2 + i)
for (i in 0 ..columnSize ) { // minus last col
println(sheet.getRow(rowIndex).getCell(2 + i))
tempCell = sheet.getRow(rowIndex).getCell(2 + i) ?: sheet.getRow(rowIndex).createCell(2 + i)
tempCell.cellFormula = "SUM(${getColumnAlphabet(2 + i)}9:${getColumnAlphabet(2 + i)}${rowIndex})" tempCell.cellFormula = "SUM(${getColumnAlphabet(2 + i)}9:${getColumnAlphabet(2 + i)}${rowIndex})"
tempCell.cellStyle = boldStyle
tempCell.cellStyle.dataFormat = accountingStyle tempCell.cellStyle.dataFormat = accountingStyle
tempCell.cellStyle.setFont(boldFont)
CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom) CellUtil.setCellStyleProperties(tempCell, DoubleBorderBottom)
} }
} }
return workbook return workbook
} }



@Throws(IOException::class) @Throws(IOException::class)
private fun createSalaryList( private fun createSalaryList(
salarys: List<Salary>, salarys: List<Salary>,


BIN
src/main/resources/templates/report/AR08_Monthly Work Hours Analysis Report.xlsx View File


Loading…
Cancel
Save