Browse Source

update unsubmitted timesheet departDate & leave check

pull/3/head
MSI\derek 7 months ago
parent
commit
8fb91756ba
2 changed files with 37 additions and 35 deletions
  1. +31
    -30
      src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt
  2. +6
    -5
      src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt

+ 31
- 30
src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt View File

@@ -4,12 +4,10 @@ import com.ffii.core.support.JdbcDao
import com.ffii.core.utils.CheckingUtils import com.ffii.core.utils.CheckingUtils
import com.ffii.tsms.modules.data.entity.CustomerRepository import com.ffii.tsms.modules.data.entity.CustomerRepository
import com.ffii.tsms.modules.data.entity.CustomerTypeRepository import com.ffii.tsms.modules.data.entity.CustomerTypeRepository
import com.ffii.tsms.modules.data.entity.StaffRepository
import com.ffii.tsms.modules.data.entity.TeamRepository import com.ffii.tsms.modules.data.entity.TeamRepository
import com.ffii.tsms.modules.data.web.models.FinancialSummaryByClient import com.ffii.tsms.modules.data.web.models.FinancialSummaryByClient
import com.ffii.tsms.modules.data.web.models.FinancialSummaryByProject import com.ffii.tsms.modules.data.web.models.FinancialSummaryByProject
import com.ffii.tsms.modules.project.entity.* import com.ffii.tsms.modules.project.entity.*
import com.ffii.tsms.modules.project.entity.projections.DashboardData
import com.ffii.tsms.modules.project.service.InvoiceService import com.ffii.tsms.modules.project.service.InvoiceService
import com.ffii.tsms.modules.project.service.ProjectExpenseService import com.ffii.tsms.modules.project.service.ProjectExpenseService
import com.ffii.tsms.modules.timesheet.entity.TimesheetRepository import com.ffii.tsms.modules.timesheet.entity.TimesheetRepository
@@ -29,21 +27,13 @@ import java.time.format.DateTimeFormatter


@Service @Service
open class DashboardService( open class DashboardService(
private val customerRepository: CustomerRepository,
private val customerTypeRepository: CustomerTypeRepository,
private val customerSubsidiaryService: CustomerSubsidiaryService,
private val customerContactService: CustomerContactService,
private val projectRepository: ProjectRepository, private val projectRepository: ProjectRepository,
private val timesheetsService: TimesheetsService,
private val invoiceService: InvoiceService,
private val projectExpenseService: ProjectExpenseService,
private val timesheetRepository: TimesheetRepository, private val timesheetRepository: TimesheetRepository,
private val invoiceRepository: InvoiceRepository, private val invoiceRepository: InvoiceRepository,
private val staffsService: StaffsService, private val staffsService: StaffsService,
private val teamLogService: TeamLogService, private val teamLogService: TeamLogService,
private val salaryEffectiveService: SalaryEffectiveService, private val salaryEffectiveService: SalaryEffectiveService,
private val projectExpenseRepository: ProjectExpenseRepository, private val projectExpenseRepository: ProjectExpenseRepository,
private val teamRepository: TeamRepository,
private val companyHolidayService: CompanyHolidayService, private val companyHolidayService: CompanyHolidayService,
private val jdbcDao: JdbcDao private val jdbcDao: JdbcDao
) { ) {
@@ -2672,7 +2662,7 @@ open class DashboardService(
+ " left join team_cte tc on tc.staffId = t.staffId " + " left join team_cte tc on tc.staffId = t.staffId "
+ " left join staff s on s.id = t.staffId " + " left join staff s on s.id = t.staffId "
+ " where t.recordDate >= :startdate and t.recordDate < DATE_ADD(:startdate, INTERVAL 1 MONTH) " + " where t.recordDate >= :startdate and t.recordDate < DATE_ADD(:startdate, INTERVAL 1 MONTH) "
+ " union "
+ " union all"
+ " select " + " select "
+ " recordDate, " + " recordDate, "
+ " staffId, " + " staffId, "
@@ -2708,7 +2698,7 @@ open class DashboardService(
+ " left join team_cte tc on tc.staffId = t.staffId " + " left join team_cte tc on tc.staffId = t.staffId "
+ " left join staff s on s.id = t.staffId " + " left join staff s on s.id = t.staffId "
+ " where t.recordDate >= :startdate and t.recordDate < DATE_ADD(:startdate, INTERVAL 7 DAY) " + " where t.recordDate >= :startdate and t.recordDate < DATE_ADD(:startdate, INTERVAL 7 DAY) "
+ " union "
+ " union all "
+ " select " + " select "
+ " recordDate, " + " recordDate, "
+ " staffId, " + " staffId, "
@@ -2722,9 +2712,12 @@ open class DashboardService(
+ " and staffId = :staffId; " + " and staffId = :staffId; "
) )
return jdbcDao.queryForList(submittedSQL.toString(), args) return jdbcDao.queryForList(submittedSQL.toString(), args)
// change to for int, count(marked)
} }


fun getWeeklyUnsubmittedTimesheet(args: Map<String, Any>): List<Map<String, Any>> { fun getWeeklyUnsubmittedTimesheet(args: Map<String, Any>): List<Map<String, Any>> {
val today = LocalDate.now()
val today2 = LocalDate.now()
val result = mutableListOf<Map<String, Any>>() val result = mutableListOf<Map<String, Any>>()
val teamId = args["teamId"] as Long val teamId = args["teamId"] as Long
val staffs = staffsService.findAll().orElseThrow() val staffs = staffsService.findAll().orElseThrow()
@@ -2732,44 +2725,45 @@ open class DashboardService(
val year = startDate.year val year = startDate.year
val month = startDate.month val month = startDate.month
val day = startDate.dayOfMonth val day = startDate.dayOfMonth

val dayInWeek = today.dayOfWeek.value % 7
// println(today.dayOfWeek.value % 7)
val yearMonth = YearMonth.of(year, month) val yearMonth = YearMonth.of(year, month)
val daysInMonth = yearMonth.lengthOfMonth() val daysInMonth = yearMonth.lengthOfMonth()
val dateList = (0..6).mapNotNull {
val date = LocalDate.of(year, month, day + it)
if (date.dayOfWeek != DayOfWeek.SATURDAY && date.dayOfWeek != DayOfWeek.SUNDAY) {
date // Include the date if it's not Saturday or Sunday
} else {
null
}
val dateList = (1..5).map {
val date = LocalDate.of(year, month, day)
val newDate = date.plusDays(it.toLong())
newDate
}.toMutableList() }.toMutableList()
val publicHolidayList = (args["publicHolidayList"] as List<LocalDate>).filter { it.year == startDate.year && it.month == startDate.month }
val publicHolidayList = (args["publicHolidayList"] as List<LocalDate>).filter {it >= dateList.first() && it <= dateList.last() }
val companyHoliday = companyHolidayService.allCompanyHolidays().filter { it.date.month == month } val companyHoliday = companyHolidayService.allCompanyHolidays().filter { it.date.month == month }
val thisArgs = args.toMutableMap() val thisArgs = args.toMutableMap()


for (curr in staffs) { for (curr in staffs) {
val thisTeam = teamLogService.getStaffTeamLog(curr.id!!, startDate) val thisTeam = teamLogService.getStaffTeamLog(curr.id!!, startDate)
println(thisTeam)
if (thisTeam == null || thisTeam.team.id != teamId) { if (thisTeam == null || thisTeam.team.id != teamId) {
continue continue
} }
if (curr.departDate != null) { if (curr.departDate != null) {
dateList.filter { it.isBefore(curr.departDate) } dateList.filter { it.isBefore(curr.departDate) }
publicHolidayList.filter { it.isBefore(curr.departDate) }
companyHoliday.filter { it.date.isBefore(curr.departDate) }
} }
thisArgs["staffId"] = curr.id!! thisArgs["staffId"] = curr.id!!
val submittedMonth = monthlySubmittedTimesheet(thisArgs)
val UnsubmittedCount = dateList.size - publicHolidayList.size - companyHoliday.size - submittedMonth.size
val submittedWeek = weeklySubmittedTimesheet(thisArgs)
val unsubmittedCount = dateList.size - publicHolidayList.size - companyHoliday.size - submittedWeek.size
if (unsubmittedCount <= 0) continue
result.add( result.add(
mapOf( mapOf(
"id" to curr.id!!, "id" to curr.id!!,
"name" to curr.name, "name" to curr.name,
"teamId" to thisTeam.team.id, "teamId" to thisTeam.team.id,
"UnsubmittedCount" to UnsubmittedCount,
"UnsubmittedCount" to unsubmittedCount,
)) ))
} }
return result return result
} }
fun getMonthlyUnsubmittedTimesheet(args: Map<String, Any>): List<Map<String, Any>> { fun getMonthlyUnsubmittedTimesheet(args: Map<String, Any>): List<Map<String, Any>> {
val today = LocalDate.now()
val result = mutableListOf<Map<String, Any>>() val result = mutableListOf<Map<String, Any>>()
val teamId = args["teamId"] as Long val teamId = args["teamId"] as Long
val staffs = staffsService.findAll().orElseThrow() val staffs = staffsService.findAll().orElseThrow()
@@ -2777,8 +2771,12 @@ open class DashboardService(
val year = startDate.year val year = startDate.year
val month = startDate.month val month = startDate.month
val yearMonth = YearMonth.of(year, month) val yearMonth = YearMonth.of(year, month)
val daysInMonth = yearMonth.lengthOfMonth()
val dateList = (1..daysInMonth).mapNotNull { day ->
val dayInMonth = if (today.year == startDate.year && today.month == startDate.month) {
today.dayOfMonth
} else {
yearMonth.lengthOfMonth()
}
val dateList = (1..dayInMonth).mapNotNull { day ->
val date = LocalDate.of(year, month, day) val date = LocalDate.of(year, month, day)
if (date.dayOfWeek != DayOfWeek.SATURDAY && date.dayOfWeek != DayOfWeek.SUNDAY) { if (date.dayOfWeek != DayOfWeek.SATURDAY && date.dayOfWeek != DayOfWeek.SUNDAY) {
date // Include the date if it's not Saturday or Sunday date // Include the date if it's not Saturday or Sunday
@@ -2792,22 +2790,25 @@ open class DashboardService(


for (curr in staffs) { for (curr in staffs) {
val thisTeam = teamLogService.getStaffTeamLog(curr.id!!, startDate) val thisTeam = teamLogService.getStaffTeamLog(curr.id!!, startDate)
println(thisTeam)
// println(thisTeam)
if (thisTeam == null || thisTeam.team.id != teamId) { if (thisTeam == null || thisTeam.team.id != teamId) {
continue continue
} }
if (curr.departDate != null) { if (curr.departDate != null) {
dateList.filter { it.isBefore(curr.departDate) } dateList.filter { it.isBefore(curr.departDate) }
publicHolidayList.filter { it.isBefore(curr.departDate) }
companyHoliday.filter { it.date.isBefore(curr.departDate) }
} }
thisArgs["staffId"] = curr.id!! thisArgs["staffId"] = curr.id!!
val submittedMonth = monthlySubmittedTimesheet(thisArgs) val submittedMonth = monthlySubmittedTimesheet(thisArgs)
val UnsubmittedCount = dateList.size - publicHolidayList.size - companyHoliday.size - submittedMonth.size
val unsubmittedCount = dateList.size - publicHolidayList.size - companyHoliday.size - submittedMonth.size
if (unsubmittedCount <= 0) continue
result.add( result.add(
mapOf( mapOf(
"id" to curr.id!!, "id" to curr.id!!,
"name" to curr.name, "name" to curr.name,
"teamId" to thisTeam.team.id, "teamId" to thisTeam.team.id,
"UnsubmittedCount" to UnsubmittedCount,
"UnsubmittedCount" to unsubmittedCount,
)) ))
} }
return result return result


+ 6
- 5
src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt View File

@@ -350,20 +350,21 @@ class DashboardController(
val publicHolidayListParam = request?.getParameter("publicHolidayList") val publicHolidayListParam = request?.getParameter("publicHolidayList")
println(enddate) println(enddate)
if (teamId != null) { if (teamId != null) {
args["teamId"] = teamId
args["teamId"] = teamId.toLong()
} }
if (startdate != null) { if (startdate != null) {
args["startdate"] = startdate
args["startdate"] = LocalDate.parse(startdate)
} }
if (enddate != null) { if (enddate != null) {
args["enddate"] = enddate
args["enddate"] = LocalDate.parse(enddate)
} }
if (publicHolidayListParam != null) { if (publicHolidayListParam != null) {
val publicHolidayList = publicHolidayListParam.split(",").map { it.trim() }
val publicHolidayList = publicHolidayListParam.split(",").map { LocalDate.parse(it.trim()) }
args["publicHolidayList"] = publicHolidayList args["publicHolidayList"] = publicHolidayList
} }
println(args) println(args)
return dashboardService.weeklyUnsubmittedTimeSheet(args)
return dashboardService.getWeeklyUnsubmittedTimesheet(args)
// return dashboardService.weeklyUnsubmittedTimeSheet(args)
} }
@GetMapping("/searchMonthlyUnsubmittedTimeSheet") @GetMapping("/searchMonthlyUnsubmittedTimeSheet")
fun searchMonthlyUnsubmittedTimeSheet(request: HttpServletRequest?): List<Map<String, Any>> { fun searchMonthlyUnsubmittedTimeSheet(request: HttpServletRequest?): List<Map<String, Any>> {


Loading…
Cancel
Save