diff --git a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt index cb03b56..32036db 100644 --- a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt +++ b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt @@ -248,9 +248,10 @@ open class ReportService( } @Throws(IOException::class) fun generateProjectManhourSummaryReport(args: Map): ByteArray { - val manhourSummary = getManhourSummary(args) + val manhourSummary = getManhourSummary(args + mapOf("groupBy" to "project")) + val manhourSummary2 = getManhourSummary(args + mapOf("groupBy" to "staff")) // Generate the Excel report with query results - val workbook: Workbook = createProjectManhourSummaryReport(args, manhourSummary, PROJECT_MANHOUR_SUMMARY) + val workbook: Workbook = createProjectManhourSummaryReport(args, manhourSummary, manhourSummary2, PROJECT_MANHOUR_SUMMARY) // Write the workbook to a ByteArrayOutputStream val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() workbook.write(outputStream) @@ -2242,8 +2243,7 @@ open class ReportService( open fun getManhourSummary(args: Map): List> { val sql = StringBuilder("select" + " DATE_FORMAT(t.recordDate, '%b-%Y') AS recordMonth, " - + " t.staffId, " - + " s.name as staff, " + + (if (args["groupBy"] == "staff") " t.staffId, s.name as staff, " else "" ) + " p.id as projectId, " + " p.code as projectCode, " + " p.name as projectName, " @@ -2267,7 +2267,11 @@ open class ReportService( if (args.containsKey(("teamId"))) { sql.append(" and coalesce(tl.teamId, s.teamId) = :teamId ") } - sql.append(" group by recordMonth, t.staffId, t.projectId, tl.teamId ") + if (args["groupBy"] == "staff") { + sql.append(" group by recordMonth, t.staffId, t.projectId, tl.teamId ") + } else { + sql.append(" group by recordMonth, t.projectId, tl.teamId ") + } return jdbcDao.queryForList(sql.toString(), args) } @@ -3705,6 +3709,7 @@ open class ReportService( private fun createProjectManhourSummaryReport( args: Map, manhourSummary: List>, + manhourSummary2: List>, templatePath: String ) : Workbook { @@ -3746,7 +3751,7 @@ open class ReportService( } .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"]) } + val result2 = manhourSummary2.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(