瀏覽代碼

[For David] - Financial Summary Report

tags/Baseline_30082024_BACKEND_UAT
MSI\2Fi 1 年之前
父節點
當前提交
a2be2c9659
共有 2 個文件被更改,包括 87 次插入0 次删除
  1. +82
    -0
      src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt
  2. +5
    -0
      src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt

+ 82
- 0
src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt 查看文件

@@ -10,6 +10,7 @@ import com.ffii.tsms.modules.data.web.models.SaveCustomerResponse
import com.ffii.tsms.modules.project.web.models.SaveCustomerRequest
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service
import java.math.BigDecimal
import java.util.Optional

@Service
@@ -140,6 +141,87 @@ open class DashboardService(

return jdbcDao.queryForList(sql.toString(), args)
}

open fun getFinancialStatus(): 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"
+ " ),"
+ " 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.teamLead = 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"
+ " left join staff s on s.id = t.staffId"
+ " left join salary s2 on s.salaryId = s2.salaryPoint"
+ " 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\' "
)

sql.append(" order by p.code")

return jdbcDao.queryForList(sql.toString())
}

fun searchFinancialSummary(): List<Map<String, Any>> {
val financialStatus: List<Map<String, Any>> = getFinancialStatus()

val otFactor = BigDecimal(1)

val tempList = mutableListOf<Map<String, Any>>()

for (item in financialStatus) {
val normalConsumed = item.getValue("normalConsumed") as Double
val hourlyRate = item.getValue("hourlyRate") as BigDecimal
// println("normalConsumed------------- $normalConsumed")
// println("hourlyRate------------- $hourlyRate")
val manHourRate = normalConsumed.toBigDecimal().multiply(hourlyRate)
// println("manHourRate------------ $manHourRate")

val otConsumed = item.getValue("otConsumed") as Double
val manOtHourRate = otConsumed.toBigDecimal().multiply(hourlyRate).multiply(otFactor)

if (!tempList.any { it.containsValue(item.getValue("code")) }) {

tempList.add(
mapOf(
"code" to item.getValue("code"),
"description" to item.getValue("description"),
"client" to item.getValue("client"),
"teamLead" to item.getValue("teamLead"),
"planStart" to item.getValue("planStart"),
"planEnd" to item.getValue("planEnd"),
"expectedTotalFee" to item.getValue("expectedTotalFee"),
"normalConsumed" to manHourRate,
"otConsumed" to manOtHourRate,
"issuedAmount" to item.getValue("sumIssuedAmount"),
"paidAmount" to item.getValue("sumPaidAmount"),
)
)
} else {
// Find the existing Map in the tempList that has the same "code" value
val existingMap = tempList.find { it.containsValue(item.getValue("code")) }!!

// Update the existing Map with the new manHourRate and manOtHourRate values
tempList[tempList.indexOf(existingMap)] = existingMap.toMutableMap().apply {
put("normalConsumed", (get("normalConsumed") as BigDecimal).add(manHourRate))
put("otConsumed", (get("otConsumed") as BigDecimal).add(manOtHourRate))
}
}
}
return tempList
}
}



+ 5
- 0
src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt 查看文件

@@ -69,4 +69,9 @@ class DashboardController(
}
return result
}

@GetMapping("/searchFinancialSummary")
fun searchFinancialSummary(): List<Map<String, Any>>{
return dashboardService.searchFinancialSummary()
}
}

Loading…
取消
儲存