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 93b913d..56d7976 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 @@ -1801,4 +1801,73 @@ open class ReportService( return workbook } + fun getCostAndExpense(status: String): List>{ + val sql = StringBuilder( + " with cte_timesheet as ( " + + " Select p.code, s.name as staff, IFNULL(t.normalConsumed, 0) as normalConsumed, IFNULL(t.otConsumed , 0) as otConsumed, s2.salaryPoint, s2.hourlyRate, t.staffId," + + " t.recordDate" + + " from timesheet t" + + " left join project_task pt on pt.id = t.projectTaskId" + + " left join project p ON p.id = pt.project_id" + + " left join staff s on s.id = t.staffId" + + " left join salary s2 on s.salaryId = s2.salaryPoint" + + " left join team t2 on t2.id = s.teamId" + + " )" + + " select p.code, p.description, c.name as client, concat(t.code, \' - \', t.name) as teamLead, p.expectedTotalFee," + + " SUM(IFNULL(cte_ts.normalConsumed, 0)) as normalConsumed," + + " SUM(IFNULL(cte_ts.otConsumed, 0)) as otConsumed," + + " IFNULL(cte_ts.hourlyRate, 0) as hourlyRate" + + " from project p" + + " left join cte_timesheet cte_ts on p.code = cte_ts.code" + + " left join customer c on c.id = p.customerId" + + " left join tsmsdb.team t on t.teamLead = p.teamLead" + + " left join staff s on s.id = cte_ts.staffId" + + " left join grade g on g.id = s.gradeId" + + " left join team t2 on t2.id = s.teamId" + + " where ISNULL(p.code) = False" + ) + if(status != "All"){ + sql.append( + " and p.status = :status" + ) + } + sql.append( + " group by p.code, p.description , c.name, teamLead, p.expectedTotalFee , hourlyRate" + " order by p.code" + ) + + val args = mapOf( + "status" to status + ) + + val otFactor = BigDecimal(1).toDouble() + val queryList = jdbcDao.queryForList(sql.toString(), args) + val costAndExpenseList = mutableListOf>() + + for(item in queryList){ + val hourlyRate = (item.getValue("hourlyRate") as BigDecimal).toDouble() + if(item["code"] !in costAndExpenseList){ + costAndExpenseList.add( + mapOf( + "code" to item["code"], + "description" to item["description"], + "client" to item["client"], + "teamLead" to item["teamLead"], + "budget" to item["expectedTotalFee"], + "totalManhours" to item["normalConsumed"] as Double + item["otConsumed"] as Double, + "manhourExpenditure" to (hourlyRate * item["normalConsumed"] as Double ) + + (hourlyRate * item["otConsumed"]as Double * otFactor) + ) + ) + }else{ + val existingMap = costAndExpenseList.find { it.containsValue(item["code"]) }!! + costAndExpenseList[costAndExpenseList.indexOf(existingMap)] = existingMap.toMutableMap().apply { + put("totalManhours", get("manhours") as Double + (item["normalConsumed"] as Double + item["otConsumed"] as Double)) + put("manhourExpenditure", get("manhourExpenditure") as Double + ((hourlyRate * item["normalConsumed"] as Double ) + + (hourlyRate * item["otConsumed"]as Double * otFactor))) + } + } + } + + return costAndExpenseList + } } 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 a336018..8c8e045 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 @@ -225,4 +225,9 @@ fun downloadLateStartReport(@RequestBody @Valid request: LateStartReportRequest) .body(ByteArrayResource(reportResult)) } + @GetMapping("/costNExpenses/{status}") + fun getManhoursSpent(@PathVariable status: String): List> { + return excelReportService.getCostAndExpense("All") + } + } \ No newline at end of file