diff --git a/src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt b/src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt index 580c3aa..7ec148e 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt @@ -162,4 +162,14 @@ open class TeamService( ) return jdbcDao.queryForList(sql.toString(), args) } + + open fun combo2(): List> { + val sql = StringBuilder("select" + + " t.id as id," + + " t.name, t.code " + + " from team t" + + " where t.deleted = false " + ) + return jdbcDao.queryForList(sql.toString()) + } } \ No newline at end of file diff --git a/src/main/java/com/ffii/tsms/modules/data/web/TeamController.kt b/src/main/java/com/ffii/tsms/modules/data/web/TeamController.kt index 871c268..bb00181 100644 --- a/src/main/java/com/ffii/tsms/modules/data/web/TeamController.kt +++ b/src/main/java/com/ffii/tsms/modules/data/web/TeamController.kt @@ -53,4 +53,10 @@ class TeamController(private val teamService: TeamService) { ) ) } + + @GetMapping("/combo2") + @Throws(ServletRequestBindingException::class) + fun combo2(): List> { + return teamService.combo2() + } } \ No newline at end of file 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 1194886..9e19cb4 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 @@ -42,9 +42,9 @@ open class ReportService( // ==============================|| GENERATE REPORT ||============================== // - fun genFinancialStatusReport(projectId: Long): ByteArray { + fun genFinancialStatusReport(teamLeadId: Long): ByteArray { - val financialStatus: List> = getFinancialStatus(projectId) + val financialStatus: List> = getFinancialStatus(teamLeadId) val otFactor = BigDecimal(1) @@ -53,10 +53,10 @@ open class ReportService( for (item in financialStatus){ val normalConsumed = item.getValue("normalConsumed") as Double val hourlyRate = item.getValue("hourlyRate") as BigDecimal - println("normalConsumed------------- $normalConsumed") - println("hourlyRate------------- $hourlyRate") +// println("normalConsumed------------- $normalConsumed") +// println("hourlyRate------------- $hourlyRate") val manHourRate = normalConsumed.toBigDecimal().multiply(hourlyRate) - println("manHourRate------------ $manHourRate") +// println("manHourRate------------ $manHourRate") val otConsumed = item.getValue("otConsumed") as Double val manOtHourRate = otConsumed.toBigDecimal().multiply(hourlyRate).multiply(otFactor) @@ -88,9 +88,9 @@ open class ReportService( } } - println("tempList---------------------- $tempList") +// println("tempList---------------------- $tempList") - val workbook: Workbook = createFinancialStatusReport(FINANCIAL_STATUS_REPORT, tempList) + val workbook: Workbook = createFinancialStatusReport(FINANCIAL_STATUS_REPORT, tempList, teamLeadId) val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() workbook.write(outputStream) @@ -170,6 +170,7 @@ open class ReportService( private fun createFinancialStatusReport( templatePath: String, projects: List>, + teamLeadId: Long ) : Workbook { val resource = ClassPathResource(templatePath) @@ -369,8 +370,20 @@ open class ReportService( genDateCell.setCellValue(LocalDate.now().toString()) rowNum = 2 + val row2: Row = sheet.getRow(rowNum) + val row2Cell = row2.createCell(2) + if (teamLeadId < 0) { + row2Cell.setCellValue("All") + }else{ + row2Cell.apply { + cellFormula = "D15" + } + } rowNum = 4 + val row4: Row = sheet.getRow(rowNum) + val row4Cell = row4.createCell(2) + row4Cell.setCellValue(projects.size.toString()) rowNum = 5 val row5: Row = sheet.getRow(rowNum) @@ -1037,16 +1050,21 @@ open class ReportService( return workbook } - open fun getFinancialStatus(projectId: Long?): List> { + open fun getFinancialStatus(teamLeadId: Long?): List> { val sql = StringBuilder( " with cte_invoice as (select p.code, sum(i.issueAmount) as sumIssuedAmount , sum(i.paidAmount) as sumPaidAmount" + " from invoice i" + " left join project p on p.code = i.projectCode" + " group by p.code" - + ")" - + " Select p.code, p.description, c.name, t2.name, p.planStart , p.planEnd , p.expectedTotalFee ," - + " s.name , IFNULL(t.normalConsumed, 0) as normalConsumed, IFNULL(t.otConsumed , 0) as otConsumed, s2.hourlyRate," - + " cte_i.sumIssuedAmount, cte_i.sumPaidAmount" + + " )," + + " cte_teamLead as (" + + " select p.teamLead, p.code, t.name as teamName , t.code as teamCode" + + " from project p" + + " left join team t on t.id = p.teamLead" + + " )" + + " Select p.code, p.description, c.name as client, concat(cte_t.teamCode, \' - \', cte_t.teamName) as teamLead, p.planStart , p.planEnd , p.expectedTotalFee ," + + " s.name as staff , IFNULL(t.normalConsumed, 0) as normalConsumed, IFNULL(t.otConsumed , 0) as otConsumed, s2.hourlyRate," + + " IFNULL(cte_i.sumIssuedAmount, 0) as sumIssuedAmount , IFNULL(cte_i.sumPaidAmount, 0) as sumPaidAmount " + " from timesheet t" + " left join project_task pt on pt.id = t.projectTaskId" + " left join project p ON p.id = pt.project_id" @@ -1055,13 +1073,15 @@ open class ReportService( + " left join customer c on c.id = p.customerId" + " left join team t2 on t2.id = s.teamId" + " left join cte_invoice cte_i on cte_i.code = p.code" + + " left join cte_teamLead cte_t on cte_t.code = p.code" + + " where p.status = \'On-going\' " ) - if (projectId!! > 0) { - sql.append(" where p.id = :projectId ") + if (teamLeadId!! > 0) { + sql.append(" and p.teamLead = :teamLeadId ") } sql.append(" order by p.code") - val args = mapOf("projectId" to projectId) + val args = mapOf("teamLeadId" to teamLeadId) return jdbcDao.queryForList(sql.toString(), args) } diff --git a/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt b/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt index 4534b57..0dd06f1 100644 --- a/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt +++ b/src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt @@ -46,7 +46,7 @@ class ReportController( fun getFinancialStatusReport(@RequestBody @Valid request: FinancialStatusReportRequest): ResponseEntity { - val reportResult: ByteArray = excelReportService.genFinancialStatusReport(request.projectId) + val reportResult: ByteArray = excelReportService.genFinancialStatusReport(request.teamLeadId) return ResponseEntity.ok() .header("filename", "Financial Status Report - " + LocalDate.now() + ".xlsx") @@ -114,7 +114,7 @@ class ReportController( @GetMapping("/financialReport/{id}") fun getFinancialReport(@PathVariable id: Long): List> { - println(excelReportService.genFinancialStatusReport(id)) +// println(excelReportService.genFinancialStatusReport(id)) return excelReportService.getFinancialStatus(id) } diff --git a/src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt b/src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt index 94158bc..4d002cb 100644 --- a/src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt +++ b/src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt @@ -3,7 +3,7 @@ package com.ffii.tsms.modules.report.web.model import java.time.YearMonth data class FinancialStatusReportRequest ( - val projectId: Long + val teamLeadId: Long ) data class ProjectCashFlowReportRequest ( val projectId: Long