|
@@ -1,7 +1,7 @@ |
|
|
package com.ffii.tsms.modules.report.web |
|
|
package com.ffii.tsms.modules.report.web |
|
|
|
|
|
|
|
|
import com.ffii.tsms.modules.data.entity.StaffRepository |
|
|
import com.ffii.tsms.modules.data.entity.StaffRepository |
|
|
import com.ffii.tsms.modules.data.entity.projections.FinancialStatusReportInfo |
|
|
|
|
|
|
|
|
//import com.ffii.tsms.modules.data.entity.projections.FinancialStatusReportInfo |
|
|
import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo |
|
|
import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo |
|
|
import com.ffii.tsms.modules.project.entity.* |
|
|
import com.ffii.tsms.modules.project.entity.* |
|
|
import com.ffii.tsms.modules.report.service.ReportService |
|
|
import com.ffii.tsms.modules.report.service.ReportService |
|
@@ -9,6 +9,8 @@ import com.ffii.tsms.modules.project.service.InvoiceService |
|
|
import com.ffii.tsms.modules.report.web.model.FinancialStatusReportRequest |
|
|
import com.ffii.tsms.modules.report.web.model.FinancialStatusReportRequest |
|
|
import com.ffii.tsms.modules.report.web.model.ProjectCashFlowReportRequest |
|
|
import com.ffii.tsms.modules.report.web.model.ProjectCashFlowReportRequest |
|
|
import com.ffii.tsms.modules.report.web.model.StaffMonthlyWorkHourAnalysisReportRequest |
|
|
import com.ffii.tsms.modules.report.web.model.StaffMonthlyWorkHourAnalysisReportRequest |
|
|
|
|
|
import com.ffii.tsms.modules.report.web.model.LateStartReportRequest |
|
|
|
|
|
import com.ffii.tsms.modules.project.entity.ProjectRepository |
|
|
import com.ffii.tsms.modules.timesheet.entity.LeaveRepository |
|
|
import com.ffii.tsms.modules.timesheet.entity.LeaveRepository |
|
|
import com.ffii.tsms.modules.timesheet.entity.TimesheetRepository |
|
|
import com.ffii.tsms.modules.timesheet.entity.TimesheetRepository |
|
|
import jakarta.validation.Valid |
|
|
import jakarta.validation.Valid |
|
@@ -27,6 +29,14 @@ import org.springframework.http.HttpHeaders |
|
|
import org.springframework.http.MediaType |
|
|
import org.springframework.http.MediaType |
|
|
import java.io.IOException |
|
|
import java.io.IOException |
|
|
import java.time.LocalDate |
|
|
import java.time.LocalDate |
|
|
|
|
|
import java.net.URLEncoder |
|
|
|
|
|
import java.time.format.DateTimeFormatter |
|
|
|
|
|
import org.springframework.stereotype.Controller |
|
|
|
|
|
import com.ffii.tsms.modules.data.entity.TeamRepository |
|
|
|
|
|
import com.ffii.tsms.modules.data.entity.CustomerRepository |
|
|
|
|
|
import org.springframework.data.jpa.repository.JpaRepository |
|
|
|
|
|
import com.ffii.tsms.modules.data.entity.Customer |
|
|
|
|
|
import com.ffii.tsms.modules.project.entity.Project |
|
|
|
|
|
|
|
|
@RestController |
|
|
@RestController |
|
|
@RequestMapping("/reports") |
|
|
@RequestMapping("/reports") |
|
@@ -37,6 +47,8 @@ class ReportController( |
|
|
private val projectRepository: ProjectRepository, |
|
|
private val projectRepository: ProjectRepository, |
|
|
private val timesheetRepository: TimesheetRepository, |
|
|
private val timesheetRepository: TimesheetRepository, |
|
|
private val projectTaskRepository: ProjectTaskRepository, |
|
|
private val projectTaskRepository: ProjectTaskRepository, |
|
|
|
|
|
private val teamRepository: TeamRepository, |
|
|
|
|
|
private val customerRepository: CustomerRepository, |
|
|
private val staffRepository: StaffRepository, |
|
|
private val staffRepository: StaffRepository, |
|
|
private val leaveRepository: LeaveRepository, |
|
|
private val leaveRepository: LeaveRepository, |
|
|
private val invoiceService: InvoiceService) { |
|
|
private val invoiceService: InvoiceService) { |
|
@@ -53,7 +65,6 @@ class ReportController( |
|
|
.body(ByteArrayResource(reportResult)) |
|
|
.body(ByteArrayResource(reportResult)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/ProjectCashFlowReport") |
|
|
@PostMapping("/ProjectCashFlowReport") |
|
|
@Throws(ServletRequestBindingException::class, IOException::class) |
|
|
@Throws(ServletRequestBindingException::class, IOException::class) |
|
|
fun getProjectCashFlowReport(@RequestBody @Valid request: ProjectCashFlowReportRequest): ResponseEntity<Resource> { |
|
|
fun getProjectCashFlowReport(@RequestBody @Valid request: ProjectCashFlowReportRequest): ResponseEntity<Resource> { |
|
@@ -100,18 +111,59 @@ class ReportController( |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@PostMapping("/downloadLateStartReport") |
|
|
@PostMapping("/downloadLateStartReport") |
|
|
fun downloadLateStartReport(): ResponseEntity<ByteArrayResource> { |
|
|
|
|
|
val reportBytes = excelReportService.generateLateStartReport(null) |
|
|
|
|
|
|
|
|
@Throws(ServletRequestBindingException::class, IOException::class) |
|
|
|
|
|
// fun downloadLateStartReport(@RequestBody @Valid request: LateStartReportRequest): ResponseEntity<ByteArrayResource> { |
|
|
|
|
|
// //val reportDate = projectRepository.findAllByPlanStartLessThanEqualAndPlanEndGreaterThanEqual().orElseThrow()//to do |
|
|
|
|
|
// val team = teamRepository.findById(request.teamId).orElseThrow() |
|
|
|
|
|
// //val customer = customerRepository.findById(request.clientId).orElseThrow() |
|
|
|
|
|
|
|
|
|
|
|
// val reportResult: ByteArray = excelReportService.generateLateStartReport(team,customer,reportDate) |
|
|
|
|
|
// val headers = HttpHeaders() |
|
|
|
|
|
// val filename = "Late_Start_Report_${LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))}.xlsx" |
|
|
|
|
|
// headers.add("filename", "${URLEncoder.encode(filename, "UTF-8")}") |
|
|
|
|
|
// // Logging the filename to ensure it's correctly formatted |
|
|
|
|
|
// println("Generated filename for download: $filename") |
|
|
|
|
|
|
|
|
|
|
|
// return ResponseEntity.ok() |
|
|
|
|
|
// .headers(headers) |
|
|
|
|
|
// .contentLength(reportResult.size.toLong()) |
|
|
|
|
|
// .contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) |
|
|
|
|
|
// .body(ByteArrayResource(reportResult)) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
fun downloadLateStartReport(@RequestBody @Valid request: LateStartReportRequest): ResponseEntity<ByteArrayResource> { |
|
|
|
|
|
val team = teamRepository.findById(request.teamId).orElseThrow { |
|
|
|
|
|
Exception("Team not found with ID: ${request.teamId}") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val customer = customerRepository.findByName(request.customer).orElseThrow() |
|
|
|
|
|
// ?: throw Exception("Customer not found with name: ${request.customer}") |
|
|
|
|
|
|
|
|
|
|
|
val projects = projectRepository.findAllByDateRange(request.remainedDateFrom, request.remainedDateTo) |
|
|
|
|
|
if (projects.isEmpty()) { |
|
|
|
|
|
throw Exception("No projects found for the given date: ${request.reportDate}") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val reportResult: ByteArray = try { |
|
|
|
|
|
excelReportService.generateLateStartReport(team, customer, projects) |
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
throw Exception("Error generating report", e) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
val headers = HttpHeaders() |
|
|
val headers = HttpHeaders() |
|
|
headers.add("Content-Disposition", "attachment; filename=Late_Start_Report_${LocalDate.now()}.xlsx") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val formattedDate = request.reportDate.format(DateTimeFormatter.ofPattern("yyyyMMdd")) |
|
|
|
|
|
val filename = "Late_Start_Report_$formattedDate.xlsx" |
|
|
|
|
|
headers.add("Content-Disposition", "attachment; filename=${URLEncoder.encode(filename, "UTF-8")}") |
|
|
|
|
|
|
|
|
|
|
|
println("Generated filename for download: $filename") |
|
|
|
|
|
|
|
|
return ResponseEntity.ok() |
|
|
return ResponseEntity.ok() |
|
|
.headers(headers) |
|
|
.headers(headers) |
|
|
.contentLength(reportBytes.size.toLong()) |
|
|
|
|
|
|
|
|
.contentLength(reportResult.size.toLong()) |
|
|
.contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) |
|
|
.contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) |
|
|
.body(ByteArrayResource(reportBytes)) |
|
|
|
|
|
|
|
|
.body(ByteArrayResource(reportResult)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/financialReport/{id}") |
|
|
@GetMapping("/financialReport/{id}") |
|
|
fun getFinancialReport(@PathVariable id: Long): List<Map<String, Any>> { |
|
|
fun getFinancialReport(@PathVariable id: Long): List<Map<String, Any>> { |
|
|
println(excelReportService.genFinancialStatusReport(id)) |
|
|
println(excelReportService.genFinancialStatusReport(id)) |
|
|