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 748735a..cb678cb 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 @@ -2339,7 +2339,7 @@ open class ReportService( return workbook } - fun getCostAndExpense(clientId: Long?, teamId: Long?): List>{ + fun getCostAndExpense(clientId: Long?, teamId: Long?, type: 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," @@ -2351,13 +2351,15 @@ open class ReportService( + " 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," + + " select p.code, p.description, c.name as client, IFNULL(s2.name, \'NA\') as subsidiary, 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 customer_subsidiary cs on cs.id = p.customerSubsidiaryId" + + " left join subsidiary s2 on s2.id = cs.subsidiaryId " + " 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" @@ -2365,9 +2367,16 @@ open class ReportService( + " where ISNULL(p.code) = False" ) if(clientId != null){ - sql.append( - " and c.id = :clientId " - ) + if(type == "client"){ + sql.append( + " and c.id = :clientId " + ) + } + if(type == "subsidiary"){ + sql.append( + " and s2.id = :clientId " + ) + } } if(teamId != null){ @@ -2377,7 +2386,7 @@ open class ReportService( } sql.append( - " group by p.code, p.description , c.name, teamLead, p.expectedTotalFee , hourlyRate" + " order by p.code" + " group by p.code, p.description , c.name, teamLead, p.expectedTotalFee , hourlyRate, s2.name " + " order by p.code" ) val args = mapOf( @@ -2397,6 +2406,7 @@ open class ReportService( "code" to item["code"], "description" to item["description"], "client" to item["client"], + "subsidiary" to item["subsidiary"], "teamLead" to item["teamLead"], "budget" to item["expectedTotalFee"], "totalManhours" to item["normalConsumed"] as Double + item["otConsumed"] as Double, @@ -2431,7 +2441,8 @@ open class ReportService( costAndExpenseList: List>, teamId: Long?, clientId: Long?, - budgetPercentage: Double? + budgetPercentage: Double?, + type: String ): Workbook{ val resource = ClassPathResource(templatePath) val templateInputStream = resource.inputStream @@ -2466,9 +2477,17 @@ open class ReportService( if(clientId == null){ row3Cell.setCellValue("All") }else{ - val sql = StringBuilder( - " select c.id, c.name from customer c where c.id = :clientId " - ) + val sql= StringBuilder() + if(type == "client"){ + sql.append( + " select c.id, c.name from customer c where c.id = :clientId " + ) + } + if(type == "subsidiary"){ + sql.append( + " select s.id, s.name from subsidiary s where s.id = :clientId " + ) + } val client = jdbcDao.queryForMap(sql.toString(), mapOf("clientId" to clientId)).get() row3Cell.setCellValue(client["name"] as String) } @@ -2476,7 +2495,7 @@ open class ReportService( val filterList: List> if(budgetPercentage != null){ - filterList = costAndExpenseList.filter { ((it["budgetPercentage"] as? Double) ?: 0.0) > budgetPercentage } + filterList = costAndExpenseList.filter { ((it["budgetPercentage"] as? Double) ?: 0.0) <= budgetPercentage } }else{ filterList = costAndExpenseList } @@ -2512,31 +2531,36 @@ open class ReportService( } val cell5 = row.getCell(5) ?: row.createCell(5) - val budget = item["budget"] as Double * 0.8 cell5.apply { - setCellValue(budget) -// cellStyle.dataFormat = accountingStyle + setCellValue(item["subsidiary"].toString()) } - CellUtil.setCellStyleProperty(cell5, "dataFormat", accountingStyle) val cell6 = row.getCell(6) ?: row.createCell(6) - val manHoutsSpentCost = item["manhourExpenditure"] as Double + val budget = item["budget"] as Double * 0.8 cell6.apply { - setCellValue(manHoutsSpentCost) + setCellValue(budget) +// cellStyle.dataFormat = accountingStyle } - CellUtil.setCellStyleProperty(cell6, "dataFormat", accountingStyle) + CellUtil.setCellStyleProperty(cell5, "dataFormat", accountingStyle) val cell7 = row.getCell(7) ?: row.createCell(7) + val manHoutsSpentCost = item["manhourExpenditure"] as Double cell7.apply { - cellFormula = "F${rowNum+1}-G${rowNum+1}" + setCellValue(manHoutsSpentCost) } CellUtil.setCellStyleProperty(cell7, "dataFormat", accountingStyle) val cell8 = row.getCell(8) ?: row.createCell(8) cell8.apply { - cellFormula = "H${rowNum+1}/F${rowNum+1}" + cellFormula = "G${rowNum+1}-H${rowNum+1}" + } + CellUtil.setCellStyleProperty(cell8, "dataFormat", accountingStyle) + + val cell9 = row.getCell(9) ?: row.createCell(9) + cell9.apply { + cellFormula = "I${rowNum+1}/G${rowNum+1}" } - CellUtil.setCellStyleProperty(cell8, "dataFormat", percentStyle) + CellUtil.setCellStyleProperty(cell9, "dataFormat", percentStyle) sheet.setRowBreak(rowNum++); } @@ -2546,9 +2570,9 @@ open class ReportService( fun genCostAndExpenseReport(request: costAndExpenseRequest): ByteArray{ - val costAndExpenseList = getCostAndExpense(request.clientId, request.teamId) + val costAndExpenseList = getCostAndExpense(request.clientId, request.teamId, request.type) - val workbook: Workbook = createCostAndExpenseWorkbook(COSTANDEXPENSE_REPORT, costAndExpenseList, request.teamId, request.clientId, request.budgetPercentage) + val workbook: Workbook = createCostAndExpenseWorkbook(COSTANDEXPENSE_REPORT, costAndExpenseList, request.teamId, request.clientId, request.budgetPercentage, request.type) val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() workbook.write(outputStream) 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 563801f..f84307e 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 @@ -286,7 +286,7 @@ class ReportController( @GetMapping("/costNExpenses/{status}") fun getManhoursSpent(@RequestBody @Valid request: costAndExpenseRequest): List> { - return excelReportService.getCostAndExpense(request.clientId, request.teamId) + return excelReportService.getCostAndExpense(request.clientId, request.teamId, request.type) } @PostMapping("/costandexpenseReport") 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 c56925d..1233753 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 @@ -17,6 +17,7 @@ data class costAndExpenseRequest ( val teamId: Long?, val clientId: Long?, val budgetPercentage: Double?, + val type: String, ) data class ProjectCashFlowReportRequest ( diff --git a/src/main/resources/templates/report/AR04_Cost and Expense Report v02.xlsx b/src/main/resources/templates/report/AR04_Cost and Expense Report v02.xlsx index a8aeceb..8f971d5 100644 Binary files a/src/main/resources/templates/report/AR04_Cost and Expense Report v02.xlsx and b/src/main/resources/templates/report/AR04_Cost and Expense Report v02.xlsx differ