From 8fb91756bac8a13cc64b1c41896aa2918f4f16b1 Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Thu, 9 Jan 2025 17:46:32 +0800 Subject: [PATCH] update unsubmitted timesheet departDate & leave check --- .../modules/data/service/DashboardService.kt | 61 ++++++++++--------- .../modules/data/web/DashboardController.kt | 11 ++-- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt b/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt index f7600e4..98b916c 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt @@ -4,12 +4,10 @@ import com.ffii.core.support.JdbcDao import com.ffii.core.utils.CheckingUtils import com.ffii.tsms.modules.data.entity.CustomerRepository 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.web.models.FinancialSummaryByClient import com.ffii.tsms.modules.data.web.models.FinancialSummaryByProject 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.ProjectExpenseService import com.ffii.tsms.modules.timesheet.entity.TimesheetRepository @@ -29,21 +27,13 @@ import java.time.format.DateTimeFormatter @Service 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 timesheetsService: TimesheetsService, - private val invoiceService: InvoiceService, - private val projectExpenseService: ProjectExpenseService, private val timesheetRepository: TimesheetRepository, private val invoiceRepository: InvoiceRepository, private val staffsService: StaffsService, private val teamLogService: TeamLogService, private val salaryEffectiveService: SalaryEffectiveService, private val projectExpenseRepository: ProjectExpenseRepository, - private val teamRepository: TeamRepository, private val companyHolidayService: CompanyHolidayService, private val jdbcDao: JdbcDao ) { @@ -2672,7 +2662,7 @@ open class DashboardService( + " left join team_cte tc on tc.staffId = t.staffId " + " left join staff s on s.id = t.staffId " + " where t.recordDate >= :startdate and t.recordDate < DATE_ADD(:startdate, INTERVAL 1 MONTH) " - + " union " + + " union all" + " select " + " recordDate, " + " staffId, " @@ -2708,7 +2698,7 @@ open class DashboardService( + " left join team_cte tc on tc.staffId = t.staffId " + " left join staff s on s.id = t.staffId " + " where t.recordDate >= :startdate and t.recordDate < DATE_ADD(:startdate, INTERVAL 7 DAY) " - + " union " + + " union all " + " select " + " recordDate, " + " staffId, " @@ -2722,9 +2712,12 @@ open class DashboardService( + " and staffId = :staffId; " ) return jdbcDao.queryForList(submittedSQL.toString(), args) + // change to for int, count(marked) } fun getWeeklyUnsubmittedTimesheet(args: Map): List> { + val today = LocalDate.now() + val today2 = LocalDate.now() val result = mutableListOf>() val teamId = args["teamId"] as Long val staffs = staffsService.findAll().orElseThrow() @@ -2732,44 +2725,45 @@ open class DashboardService( val year = startDate.year val month = startDate.month val day = startDate.dayOfMonth - + val dayInWeek = today.dayOfWeek.value % 7 +// println(today.dayOfWeek.value % 7) val yearMonth = YearMonth.of(year, month) 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() - val publicHolidayList = (args["publicHolidayList"] as List).filter { it.year == startDate.year && it.month == startDate.month } + val publicHolidayList = (args["publicHolidayList"] as List).filter {it >= dateList.first() && it <= dateList.last() } val companyHoliday = companyHolidayService.allCompanyHolidays().filter { it.date.month == month } val thisArgs = args.toMutableMap() for (curr in staffs) { val thisTeam = teamLogService.getStaffTeamLog(curr.id!!, startDate) - println(thisTeam) if (thisTeam == null || thisTeam.team.id != teamId) { continue } if (curr.departDate != null) { dateList.filter { it.isBefore(curr.departDate) } + publicHolidayList.filter { it.isBefore(curr.departDate) } + companyHoliday.filter { it.date.isBefore(curr.departDate) } } 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( mapOf( "id" to curr.id!!, "name" to curr.name, "teamId" to thisTeam.team.id, - "UnsubmittedCount" to UnsubmittedCount, + "UnsubmittedCount" to unsubmittedCount, )) } return result } fun getMonthlyUnsubmittedTimesheet(args: Map): List> { + val today = LocalDate.now() val result = mutableListOf>() val teamId = args["teamId"] as Long val staffs = staffsService.findAll().orElseThrow() @@ -2777,8 +2771,12 @@ open class DashboardService( val year = startDate.year val month = startDate.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) if (date.dayOfWeek != DayOfWeek.SATURDAY && date.dayOfWeek != DayOfWeek.SUNDAY) { date // Include the date if it's not Saturday or Sunday @@ -2792,22 +2790,25 @@ open class DashboardService( for (curr in staffs) { val thisTeam = teamLogService.getStaffTeamLog(curr.id!!, startDate) - println(thisTeam) +// println(thisTeam) if (thisTeam == null || thisTeam.team.id != teamId) { continue } if (curr.departDate != null) { dateList.filter { it.isBefore(curr.departDate) } + publicHolidayList.filter { it.isBefore(curr.departDate) } + companyHoliday.filter { it.date.isBefore(curr.departDate) } } thisArgs["staffId"] = curr.id!! 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( mapOf( "id" to curr.id!!, "name" to curr.name, "teamId" to thisTeam.team.id, - "UnsubmittedCount" to UnsubmittedCount, + "UnsubmittedCount" to unsubmittedCount, )) } return result diff --git a/src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt b/src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt index fc17dac..468482c 100644 --- a/src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt +++ b/src/main/java/com/ffii/tsms/modules/data/web/DashboardController.kt @@ -350,20 +350,21 @@ class DashboardController( val publicHolidayListParam = request?.getParameter("publicHolidayList") println(enddate) if (teamId != null) { - args["teamId"] = teamId + args["teamId"] = teamId.toLong() } if (startdate != null) { - args["startdate"] = startdate + args["startdate"] = LocalDate.parse(startdate) } if (enddate != null) { - args["enddate"] = enddate + args["enddate"] = LocalDate.parse(enddate) } if (publicHolidayListParam != null) { - val publicHolidayList = publicHolidayListParam.split(",").map { it.trim() } + val publicHolidayList = publicHolidayListParam.split(",").map { LocalDate.parse(it.trim()) } args["publicHolidayList"] = publicHolidayList } println(args) - return dashboardService.weeklyUnsubmittedTimeSheet(args) + return dashboardService.getWeeklyUnsubmittedTimesheet(args) +// return dashboardService.weeklyUnsubmittedTimeSheet(args) } @GetMapping("/searchMonthlyUnsubmittedTimeSheet") fun searchMonthlyUnsubmittedTimeSheet(request: HttpServletRequest?): List> {