|
|
@@ -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 |
|
|
|