Browse Source

Update Gen Financial Status Report from filter project to Team

tags/Baseline_30082024_BACKEND_UAT
MSI\2Fi 1 year ago
parent
commit
d94c06e90b
5 changed files with 54 additions and 18 deletions
  1. +10
    -0
      src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt
  2. +6
    -0
      src/main/java/com/ffii/tsms/modules/data/web/TeamController.kt
  3. +35
    -15
      src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt
  4. +2
    -2
      src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt
  5. +1
    -1
      src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt

+ 10
- 0
src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt View File

@@ -162,4 +162,14 @@ open class TeamService(
)
return jdbcDao.queryForList(sql.toString(), args)
}

open fun combo2(): List<Map<String, Any>> {
val sql = StringBuilder("select"
+ " t.id as id,"
+ " t.name, t.code "
+ " from team t"
+ " where t.deleted = false "
)
return jdbcDao.queryForList(sql.toString())
}
}

+ 6
- 0
src/main/java/com/ffii/tsms/modules/data/web/TeamController.kt View File

@@ -53,4 +53,10 @@ class TeamController(private val teamService: TeamService) {
)
)
}

@GetMapping("/combo2")
@Throws(ServletRequestBindingException::class)
fun combo2(): List<Map<String, Any>> {
return teamService.combo2()
}
}

+ 35
- 15
src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt View File

@@ -42,9 +42,9 @@ open class ReportService(

// ==============================|| GENERATE REPORT ||============================== //

fun genFinancialStatusReport(projectId: Long): ByteArray {
fun genFinancialStatusReport(teamLeadId: Long): ByteArray {

val financialStatus: List<Map<String, Any>> = getFinancialStatus(projectId)
val financialStatus: List<Map<String, Any>> = 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<Map<String, Any>>,
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<Map<String, Any>> {
open fun getFinancialStatus(teamLeadId: Long?): List<Map<String, Any>> {
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)
}


+ 2
- 2
src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt View File

@@ -46,7 +46,7 @@ class ReportController(
fun getFinancialStatusReport(@RequestBody @Valid request: FinancialStatusReportRequest): ResponseEntity<Resource> {


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<Map<String, Any>> {
println(excelReportService.genFinancialStatusReport(id))
// println(excelReportService.genFinancialStatusReport(id))
return excelReportService.getFinancialStatus(id)
}


+ 1
- 1
src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt View File

@@ -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


Loading…
Cancel
Save