| @@ -55,7 +55,8 @@ open class ReportService( | |||
| private val salaryEffectiveRepository: SalaryEffectiveRepository, | |||
| private val salaryRepository: SalaryRepository, | |||
| private val timesheetRepository: TimesheetRepository, | |||
| private val teamLogRepository: TeamLogRepository | |||
| private val teamLogRepository: TeamLogRepository, | |||
| private val teamRepository: TeamRepository | |||
| ) { | |||
| private val logger: Log = LogFactory.getLog(javaClass) | |||
| private val DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd") | |||
| @@ -3712,6 +3713,7 @@ open class ReportService( | |||
| val templateInputStream = resource.inputStream | |||
| val workbook: Workbook = XSSFWorkbook(templateInputStream) | |||
| val sheet: Sheet = workbook.getSheetAt(0) | |||
| val sheet2: Sheet = workbook.getSheetAt(1) | |||
| val accountingStyle = workbook.createDataFormat().getFormat("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)") | |||
| fun getMonthsBetweenToColumn(start: LocalDate, end: LocalDate, startValue: Int): Map<String, Int> { | |||
| // Get the first day of the start month | |||
| @@ -3730,6 +3732,7 @@ open class ReportService( | |||
| } | |||
| val startDate = LocalDate.parse(args["startDate"].toString()) | |||
| val endDate = LocalDate.parse(args["endDate"].toString()) | |||
| val team = teamRepository.findById(args["teamId"].toString().toLong()).orElseThrow().name | |||
| val monthList = getMonthsBetweenToColumn(startDate, endDate, 4) | |||
| if (monthList.isEmpty()) { | |||
| throw IllegalArgumentException("illegal time period") | |||
| @@ -3742,37 +3745,69 @@ open class ReportService( | |||
| "client" to entry.key["client"]) + monthlyConsumption | |||
| } | |||
| .sortedBy { it["projectCode"] as String } | |||
| val result2 = manhourSummary.groupBy { mapOf("staff" to it["staff"], "projectCode" to it["projectCode"], "projectName" to it["projectName"], "client" to it["client"]) } | |||
| .map { entry -> | |||
| val monthlyConsumption = entry.value.associate { it["recordMonth"] to it["consumed"] } | |||
| mapOf( | |||
| "staff" to entry.key["staff"], | |||
| "projectCode" to entry.key["projectCode"], | |||
| "projectName" to entry.key["projectName"], | |||
| "client" to entry.key["client"]) + monthlyConsumption | |||
| } | |||
| //start from col4 | |||
| var rowIndex = 1 | |||
| var columnIndex = 1 | |||
| var tempRow: Row | |||
| var tempRow2: Row | |||
| var tempCell: Cell | |||
| var tempCell2: Cell | |||
| var columnIndex = 1 | |||
| var rowIndex = 1 // generation time | |||
| tempRow = getOrCreateRow(sheet, rowIndex) | |||
| tempRow2 = getOrCreateRow(sheet2, rowIndex) | |||
| tempCell = getOrCreateCell(tempRow, columnIndex) | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| tempCell.setCellValue(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd")).toString()) | |||
| //write months header | |||
| tempCell2.setCellValue(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd")).toString()) | |||
| rowIndex = 2 // Team | |||
| tempRow = getOrCreateRow(sheet, rowIndex) | |||
| tempRow2 = getOrCreateRow(sheet2, rowIndex) | |||
| tempCell = getOrCreateCell(tempRow, columnIndex) | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| tempCell.setCellValue(team) | |||
| tempCell2.setCellValue(team) | |||
| rowIndex = 3 // report period | |||
| tempRow = getOrCreateRow(sheet, rowIndex) | |||
| tempRow2 = getOrCreateRow(sheet2, rowIndex) | |||
| tempCell = getOrCreateCell(tempRow, columnIndex) | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| tempCell.setCellValue("${args["startDate"].toString()} - ${args["endDate"].toString()}") | |||
| tempCell2.setCellValue("${args["startDate"].toString()} - ${args["endDate"].toString()}") | |||
| // write months header | |||
| rowIndex = 5 | |||
| columnIndex = 3 | |||
| tempRow = getOrCreateRow(sheet, rowIndex) | |||
| tempRow2 = getOrCreateRow(sheet2, rowIndex) | |||
| for (curr in monthList) { | |||
| tempCell = getOrCreateCell(tempRow, columnIndex) | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex + 1) | |||
| alignTopCenter(tempCell) | |||
| alignTopCenter(tempCell2) | |||
| tempCell.setCellValue(curr.key) | |||
| tempCell2.setCellValue(curr.key) | |||
| CellUtil.setCellStyleProperties(tempCell, | |||
| cellBorderArgs(0,1,0,0) | |||
| + fontArgs2(sheet, "Times New Roman",false)) | |||
| CellUtil.setCellStyleProperties(tempCell2, | |||
| cellBorderArgs(0,1,0,0) | |||
| + fontArgs2(sheet2, "Times New Roman",false)) | |||
| columnIndex++ | |||
| } | |||
| //write content | |||
| // write content | |||
| // sheet 1 | |||
| rowIndex = 6 | |||
| for ( curr in result) { | |||
| columnIndex = 0 | |||
| for (curr in result) { | |||
| tempRow = getOrCreateRow(sheet, rowIndex) | |||
| // columnIndex = 0 | |||
| // tempCell = getOrCreateCell(tempRow, columnIndex) | |||
| // CellUtil.setCellStyleProperties(tempCell, | |||
| // cellBorderArgs(1,1,1,1) | |||
| // + fontArgs2(sheet, "Times New Roman",false)) | |||
| // tempCell.setCellValue(curr["staff"].toString()) | |||
| columnIndex = 0 | |||
| tempCell = getOrCreateCell(tempRow, columnIndex) | |||
| CellUtil.setCellStyleProperties(tempCell, | |||
| @@ -3793,9 +3828,6 @@ open class ReportService( | |||
| tempCell.setCellValue(curr["client"].toString()) | |||
| for ( month in monthList) { | |||
| var manhour = 0.0 | |||
| // println("curr-rM ${curr["recordMonth"]}") | |||
| // println("curr ${curr}") | |||
| // println("month $month") | |||
| if (curr.containsKey(month.key.toString())) { | |||
| manhour = curr[month.key.toString()] as Double | |||
| } | |||
| @@ -3824,6 +3856,65 @@ open class ReportService( | |||
| + fontArgs2(sheet, "Times New Roman",false)) | |||
| tempCell.cellFormula = "SUM(${columnLetter}7:$columnLetter$rowIndex)" | |||
| } | |||
| // sheet 2 | |||
| rowIndex = 6 | |||
| columnIndex = 0 | |||
| for (curr in result2) { | |||
| tempRow2 = getOrCreateRow(sheet2, rowIndex) | |||
| columnIndex = 0 | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| CellUtil.setCellStyleProperties(tempCell2, | |||
| cellBorderArgs(1,1,1,1) | |||
| + fontArgs2(sheet2, "Times New Roman",false)) | |||
| tempCell2.setCellValue(curr["staff"].toString()) | |||
| columnIndex = 1 | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| CellUtil.setCellStyleProperties(tempCell2, | |||
| cellBorderArgs(1,1,1,1) | |||
| + fontArgs2(sheet2, "Times New Roman",false)) | |||
| tempCell2.setCellValue(curr["projectCode"].toString()) | |||
| columnIndex = 2 | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| CellUtil.setCellStyleProperties(tempCell2, | |||
| cellBorderArgs(1,1,1,1) | |||
| + fontArgs2(sheet2, "Times New Roman",false)) | |||
| tempCell2.setCellValue(curr["projectName"].toString()) | |||
| columnIndex = 3 | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| CellUtil.setCellStyleProperties(tempCell2, | |||
| cellBorderArgs(1,1,1,1) | |||
| + fontArgs2(sheet2, "Times New Roman",false)) | |||
| tempCell2.setCellValue(curr["client"].toString()) | |||
| for ( month in monthList) { | |||
| var manhour = 0.0 | |||
| if (curr.containsKey(month.key.toString())) { | |||
| manhour = curr[month.key.toString()] as Double | |||
| } | |||
| columnIndex = month.value | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| tempCell2.setCellValue(manhour) | |||
| CellUtil.setCellStyleProperties(tempCell2, | |||
| cellBorderArgs(1,1,1,1) | |||
| + fontArgs2(sheet2, "Times New Roman",false)) | |||
| } | |||
| rowIndex++ | |||
| } | |||
| // total | |||
| tempRow2 = getOrCreateRow(sheet2, rowIndex) | |||
| columnIndex = monthList.values.firstNotNullOfOrNull { it }!! - 1 | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| tempCell2.setCellValue("Total:") | |||
| CellUtil.setCellStyleProperties(tempCell2, fontArgs2(sheet2, "Times New Roman",false)) | |||
| setAlignment(tempCell2,"top", "right") | |||
| for (curr in monthList) { | |||
| columnIndex = curr.value | |||
| val columnLetter = CellReference.convertNumToColString(columnIndex) | |||
| tempCell2 = getOrCreateCell(tempRow2, columnIndex) | |||
| CellUtil.setCellStyleProperties(tempCell2, | |||
| cellBorderArgs(1,1,1,1) | |||
| + fontArgs2(sheet2, "Times New Roman",false)) | |||
| tempCell2.cellFormula = "SUM(${columnLetter}7:$columnLetter$rowIndex)" | |||
| } | |||
| return workbook | |||
| } | |||
| private fun generateTeamsInOutMap( | |||