Browse Source

costandexpense Report: Add subsidiary for searching

tags/Baseline_30082024_BACKEND_UAT
MSI\2Fi 1 year ago
parent
commit
d980a5df9c
4 changed files with 49 additions and 24 deletions
  1. +47
    -23
      src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt
  2. +1
    -1
      src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt
  3. +1
    -0
      src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt
  4. BIN
      src/main/resources/templates/report/AR04_Cost and Expense Report v02.xlsx

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

@@ -2339,7 +2339,7 @@ open class ReportService(
return workbook return workbook
} }


fun getCostAndExpense(clientId: Long?, teamId: Long?): List<Map<String,Any?>>{
fun getCostAndExpense(clientId: Long?, teamId: Long?, type: String): List<Map<String,Any?>>{
val sql = StringBuilder( val sql = StringBuilder(
" with cte_timesheet as ( " " 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," + " 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 salary s2 on s.salaryId = s2.salaryPoint"
+ " left join team t2 on t2.id = s.teamId" + " 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.normalConsumed, 0)) as normalConsumed,"
+ " SUM(IFNULL(cte_ts.otConsumed, 0)) as otConsumed," + " SUM(IFNULL(cte_ts.otConsumed, 0)) as otConsumed,"
+ " IFNULL(cte_ts.hourlyRate, 0) as hourlyRate" + " IFNULL(cte_ts.hourlyRate, 0) as hourlyRate"
+ " from project p" + " from project p"
+ " left join cte_timesheet cte_ts on p.code = cte_ts.code" + " left join cte_timesheet cte_ts on p.code = cte_ts.code"
+ " left join customer c on c.id = p.customerId" + " 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 tsmsdb.team t on t.teamLead = p.teamLead"
+ " left join staff s on s.id = cte_ts.staffId" + " left join staff s on s.id = cte_ts.staffId"
+ " left join grade g on g.id = s.gradeId" + " left join grade g on g.id = s.gradeId"
@@ -2365,9 +2367,16 @@ open class ReportService(
+ " where ISNULL(p.code) = False" + " where ISNULL(p.code) = False"
) )
if(clientId != null){ 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){ if(teamId != null){
@@ -2377,7 +2386,7 @@ open class ReportService(
} }


sql.append( 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( val args = mapOf(
@@ -2397,6 +2406,7 @@ open class ReportService(
"code" to item["code"], "code" to item["code"],
"description" to item["description"], "description" to item["description"],
"client" to item["client"], "client" to item["client"],
"subsidiary" to item["subsidiary"],
"teamLead" to item["teamLead"], "teamLead" to item["teamLead"],
"budget" to item["expectedTotalFee"], "budget" to item["expectedTotalFee"],
"totalManhours" to item["normalConsumed"] as Double + item["otConsumed"] as Double, "totalManhours" to item["normalConsumed"] as Double + item["otConsumed"] as Double,
@@ -2431,7 +2441,8 @@ open class ReportService(
costAndExpenseList: List<Map<String, Any?>>, costAndExpenseList: List<Map<String, Any?>>,
teamId: Long?, teamId: Long?,
clientId: Long?, clientId: Long?,
budgetPercentage: Double?
budgetPercentage: Double?,
type: String
): Workbook{ ): Workbook{
val resource = ClassPathResource(templatePath) val resource = ClassPathResource(templatePath)
val templateInputStream = resource.inputStream val templateInputStream = resource.inputStream
@@ -2466,9 +2477,17 @@ open class ReportService(
if(clientId == null){ if(clientId == null){
row3Cell.setCellValue("All") row3Cell.setCellValue("All")
}else{ }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() val client = jdbcDao.queryForMap(sql.toString(), mapOf("clientId" to clientId)).get()
row3Cell.setCellValue(client["name"] as String) row3Cell.setCellValue(client["name"] as String)
} }
@@ -2476,7 +2495,7 @@ open class ReportService(


val filterList: List<Map<String, Any?>> val filterList: List<Map<String, Any?>>
if(budgetPercentage != null){ if(budgetPercentage != null){
filterList = costAndExpenseList.filter { ((it["budgetPercentage"] as? Double) ?: 0.0) > budgetPercentage }
filterList = costAndExpenseList.filter { ((it["budgetPercentage"] as? Double) ?: 0.0) <= budgetPercentage }
}else{ }else{
filterList = costAndExpenseList filterList = costAndExpenseList
} }
@@ -2512,31 +2531,36 @@ open class ReportService(
} }


val cell5 = row.getCell(5) ?: row.createCell(5) val cell5 = row.getCell(5) ?: row.createCell(5)
val budget = item["budget"] as Double * 0.8
cell5.apply { 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 cell6 = row.getCell(6) ?: row.createCell(6)
val manHoutsSpentCost = item["manhourExpenditure"] as Double
val budget = item["budget"] as Double * 0.8
cell6.apply { 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 cell7 = row.getCell(7) ?: row.createCell(7)
val manHoutsSpentCost = item["manhourExpenditure"] as Double
cell7.apply { cell7.apply {
cellFormula = "F${rowNum+1}-G${rowNum+1}"
setCellValue(manHoutsSpentCost)
} }
CellUtil.setCellStyleProperty(cell7, "dataFormat", accountingStyle) CellUtil.setCellStyleProperty(cell7, "dataFormat", accountingStyle)


val cell8 = row.getCell(8) ?: row.createCell(8) val cell8 = row.getCell(8) ?: row.createCell(8)
cell8.apply { 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++); sheet.setRowBreak(rowNum++);
} }
@@ -2546,9 +2570,9 @@ open class ReportService(


fun genCostAndExpenseReport(request: costAndExpenseRequest): ByteArray{ 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() val outputStream: ByteArrayOutputStream = ByteArrayOutputStream()
workbook.write(outputStream) workbook.write(outputStream)


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

@@ -286,7 +286,7 @@ class ReportController(


@GetMapping("/costNExpenses/{status}") @GetMapping("/costNExpenses/{status}")
fun getManhoursSpent(@RequestBody @Valid request: costAndExpenseRequest): List<Map<String, Any?>> { fun getManhoursSpent(@RequestBody @Valid request: costAndExpenseRequest): List<Map<String, Any?>> {
return excelReportService.getCostAndExpense(request.clientId, request.teamId)
return excelReportService.getCostAndExpense(request.clientId, request.teamId, request.type)
} }


@PostMapping("/costandexpenseReport") @PostMapping("/costandexpenseReport")


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

@@ -17,6 +17,7 @@ data class costAndExpenseRequest (
val teamId: Long?, val teamId: Long?,
val clientId: Long?, val clientId: Long?,
val budgetPercentage: Double?, val budgetPercentage: Double?,
val type: String,
) )


data class ProjectCashFlowReportRequest ( data class ProjectCashFlowReportRequest (


BIN
src/main/resources/templates/report/AR04_Cost and Expense Report v02.xlsx View File


Loading…
Cancel
Save