@@ -3,6 +3,7 @@ package com.ffii.tsms.modules.timesheet.web
import com.ffii.core.exception.BadRequestException
import com.ffii.core.exception.BadRequestException
import com.ffii.tsms.modules.timesheet.entity.LeaveType
import com.ffii.tsms.modules.timesheet.entity.LeaveType
import com.ffii.tsms.modules.timesheet.service.LeaveService
import com.ffii.tsms.modules.timesheet.service.LeaveService
import com.ffii.tsms.modules.timesheet.service.MailReminderService
import com.ffii.tsms.modules.timesheet.service.TimesheetsService
import com.ffii.tsms.modules.timesheet.service.TimesheetsService
import com.ffii.tsms.modules.timesheet.web.models.*
import com.ffii.tsms.modules.timesheet.web.models.*
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletRequest
@@ -11,18 +12,16 @@ import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.springframework.http.ResponseEntity
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.ServletRequestBindingException
import org.springframework.web.bind.ServletRequestBindingException
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartHttpServletRequest
import org.springframework.web.multipart.MultipartHttpServletRequest
import java.io.UnsupportedEncodingException
import java.text.ParseException
import java.time.LocalDate
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeFormatter
@RestController
@RestController
@RequestMapping("/timesheets")
@RequestMapping("/timesheets")
class TimesheetsController(private val timesheetsService: TimesheetsService, private val leaveService: LeaveService) {
class TimesheetsController(private val timesheetsService: TimesheetsService, private val leaveService: LeaveService, private val mailReminderService: MailReminderService ) {
@PostMapping("/save")
@PostMapping("/save")
fun newTimesheetEntry(@Valid @RequestBody recordTimesheet: Map<String, List<TimeEntry>>): Map<String, List<TimeEntry>> {
fun newTimesheetEntry(@Valid @RequestBody recordTimesheet: Map<String, List<TimeEntry>>): Map<String, List<TimeEntry>> {
val parsedEntries = kotlin.runCatching {
val parsedEntries = kotlin.runCatching {
@@ -137,6 +136,22 @@ class TimesheetsController(private val timesheetsService: TimesheetsService, pri
return ResponseEntity.ok(timesheetsService.importFile(workbook))
return ResponseEntity.ok(timesheetsService.importFile(workbook))
}
}
@PostMapping("/import-OS")
@Throws(ServletRequestBindingException::class)
fun importOSFile(request: HttpServletRequest): ResponseEntity<*> {
var workbook: Workbook? = null
try {
val multipartFile = (request as MultipartHttpServletRequest).getFile("multipartFileList")
workbook = XSSFWorkbook(multipartFile?.inputStream)
} catch (e: Exception) {
println("Excel Wrong")
println(e)
}
return ResponseEntity.ok(timesheetsService.importOSFile(workbook))
}
@PostMapping("/import-leave")
@PostMapping("/import-leave")
@Throws(ServletRequestBindingException::class)
@Throws(ServletRequestBindingException::class)
fun importLeaveFile(request: HttpServletRequest): ResponseEntity<*> {
fun importLeaveFile(request: HttpServletRequest): ResponseEntity<*> {
@@ -159,4 +174,14 @@ class TimesheetsController(private val timesheetsService: TimesheetsService, pri
return ResponseEntity.ok(timesheetsService.rearrangeTimesheets())
return ResponseEntity.ok(timesheetsService.rearrangeTimesheets())
}
}
// @GetMapping("/testReminder")
// @Throws(
// UnsupportedEncodingException::class,
// ParseException::class,
// ServletRequestBindingException::class
// )
// fun testReminder(request: HttpServletRequest) {
// mailReminderService.sendTimesheetReminder()
// }
}
}