浏览代码

With, client and team fiter

tags/Baseline_30082024_BACKEND_UAT
MSI\2Fi 1年前
父节点
当前提交
b5e9d286db
共有 3 个文件被更改,包括 54 次插入15 次删除
  1. +49
    -10
      src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt
  2. +3
    -3
      src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt
  3. +2
    -2
      src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt

+ 49
- 10
src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt 查看文件

@@ -8,6 +8,7 @@ import com.ffii.tsms.modules.data.entity.Team
import com.ffii.tsms.modules.project.entity.Invoice
import com.ffii.tsms.modules.project.entity.Milestone
import com.ffii.tsms.modules.project.entity.Project
import com.ffii.tsms.modules.report.web.model.costAndExpenseRequest
import com.ffii.tsms.modules.timesheet.entity.Leave
import com.ffii.tsms.modules.timesheet.entity.Timesheet
import com.ffii.tsms.modules.timesheet.entity.projections.MonthlyLeave
@@ -32,6 +33,7 @@ import java.time.LocalDate
import java.time.YearMonth
import java.time.format.DateTimeFormatter
import java.util.*
import kotlin.jvm.optionals.getOrElse


data class DayInfo(val date: String?, val weekday: String?)
@@ -1933,7 +1935,7 @@ open class ReportService(

val gradeCell = row.getCell(1) ?: row.createCell(1)
gradeCell.apply {
setCellValue("G${staff.getValue("grade")}")
setCellValue("${staff.getValue("grade")}")
}
CellUtil.setAlignment(gradeCell, HorizontalAlignment.CENTER);

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

fun getCostAndExpense(status: String): List<Map<String,Any?>>{
fun getCostAndExpense(clientId: Long?, teamId: Long?): List<Map<String,Any?>>{
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,"
@@ -2131,17 +2133,25 @@ open class ReportService(
+ " left join team t2 on t2.id = s.teamId"
+ " where ISNULL(p.code) = False"
)
if(status != "All"){
if(clientId != null){
sql.append(
" and p.status = :status"
" and c.id = :clientId "
)
}

if(teamId != null){
sql.append(
" and p.teamLead = :teamId "
)
}

sql.append(
" group by p.code, p.description , c.name, teamLead, p.expectedTotalFee , hourlyRate" + " order by p.code"
)

val args = mapOf(
"status" to status
"clientId" to clientId,
"teamId" to teamId
)

val otFactor = BigDecimal(1).toDouble()
@@ -2179,6 +2189,8 @@ open class ReportService(
fun createCostAndExpenseWorkbook(
templatePath: String,
costAndExpenseList: List<Map<String, Any?>>,
teamId: Long?,
clientId: Long?
): Workbook{
val resource = ClassPathResource(templatePath)
val templateInputStream = resource.inputStream
@@ -2188,9 +2200,35 @@ open class ReportService(
var rowNum = 0
rowNum = 1
val row1: Row = sheet.getRow(rowNum)
val row1Cell = row1.getCell(1)
val row1Cell = row1.getCell(2)
row1Cell.setCellValue(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd")).toString())

rowNum = 2
val row2: Row = sheet.getRow(rowNum)
val row2Cell = row2.getCell(2)
if(teamId == null){
row2Cell.setCellValue("All")
}else{
val sql = StringBuilder(
" select t.id, t.code, t.name, concat(t.code, \" - \" ,t.name) as teamLead from team t where t.id = :teamId "
)
val team = jdbcDao.queryForMap(sql.toString(), mapOf("teamId" to teamId)).get()
row2Cell.setCellValue(team["teamLead"] as String)
}

rowNum = 3
val row3: Row = sheet.getRow(rowNum)
val row3Cell = row3.getCell(2)
if(clientId == null){
row3Cell.setCellValue("All")
}else{
val sql = StringBuilder(
" select c.id, c.name from customer c where c.id = :clientId "
)
val client = jdbcDao.queryForMap(sql.toString(), mapOf("clientId" to clientId)).get()
row3Cell.setCellValue(client["name"] as String)
}

rowNum = 6
for(item in costAndExpenseList){
val index = costAndExpenseList.indexOf(item)
@@ -2239,7 +2277,7 @@ open class ReportService(

val cell8 = row.getCell(8) ?: row.createCell(8)
cell8.apply {
cellFormula = "H${rowNum+1}/G${rowNum+1}"
cellFormula = "H${rowNum+1}/F${rowNum+1}"
}
sheet.setRowBreak(rowNum++);
}
@@ -2247,10 +2285,11 @@ open class ReportService(
return workbook
}

fun genCostAndExpenseReport(): ByteArray{
val costAndExpenseList = getCostAndExpense("All")
fun genCostAndExpenseReport(request: costAndExpenseRequest): ByteArray{

val costAndExpenseList = getCostAndExpense(request.clientId, request.teamId)

val workbook: Workbook = createCostAndExpenseWorkbook(COSTANDEXPENSE_REPORT, costAndExpenseList)
val workbook: Workbook = createCostAndExpenseWorkbook(COSTANDEXPENSE_REPORT, costAndExpenseList, request.clientId, request.teamId)

val outputStream: ByteArrayOutputStream = ByteArrayOutputStream()
workbook.write(outputStream)


+ 3
- 3
src/main/java/com/ffii/tsms/modules/report/web/ReportController.kt 查看文件

@@ -277,15 +277,15 @@ fun downloadLateStartReport(@RequestBody @Valid request: LateStartReportRequest)
}

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

@PostMapping("/costandexpenseReport")
@Throws(ServletRequestBindingException::class, IOException::class)
fun getCostAndExpenseReport(@RequestBody @Valid request: costAndExpenseRequest): ResponseEntity<Resource> {
println(request)
val reportResult: ByteArray = excelReportService.genCostAndExpenseReport()
val reportResult: ByteArray = excelReportService.genCostAndExpenseReport(request)

return ResponseEntity.ok()
.header("filename", "Cost and Expense Report - " + LocalDate.now() + ".xlsx")


+ 2
- 2
src/main/java/com/ffii/tsms/modules/report/web/model/ReportRequest.kt 查看文件

@@ -14,8 +14,8 @@ data class PandLReportRequest (
)

data class costAndExpenseRequest (
val teamId: Long,
val clientId: String,
val teamId: Long?,
val clientId: Long?,
val budgetPercentage: String,
)



正在加载...
取消
保存