| @@ -4,6 +4,7 @@ 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 | |||
| @@ -21,7 +22,9 @@ import org.springframework.stereotype.Service | |||
| import java.io.ByteArrayOutputStream | |||
| import java.io.IOException | |||
| import java.math.BigDecimal | |||
| import java.time.DayOfWeek | |||
| import java.time.LocalDate | |||
| import java.time.YearMonth | |||
| import java.time.format.DateTimeFormatter | |||
| @Service | |||
| @@ -41,6 +44,7 @@ open class DashboardService( | |||
| private val salaryEffectiveService: SalaryEffectiveService, | |||
| private val projectExpenseRepository: ProjectExpenseRepository, | |||
| private val teamRepository: TeamRepository, | |||
| private val companyHolidayService: CompanyHolidayService, | |||
| private val jdbcDao: JdbcDao | |||
| ) { | |||
| private val DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd") | |||
| @@ -2648,6 +2652,166 @@ open class DashboardService( | |||
| return jdbcDao.queryForList(sql.toString(), args) | |||
| } | |||
| fun monthlySubmittedTimesheet(args: Map<String, Any>): List<Map<String, Any>> { | |||
| val unsubmittedSQL = StringBuilder( | |||
| " with team_cte as ( " | |||
| + " select " | |||
| + " * " | |||
| + " from team_log tl " | |||
| + " where :startdate >= tl.`from` and (:startdate < tl.`to` or tl.`to` is null) " | |||
| + " ) " | |||
| + " select " | |||
| + " result.recordDate, result.staffId, sum(result.marked) as marked " | |||
| + " from ( " | |||
| + " select " | |||
| + " t.recordDate, " | |||
| + " t.staffId, " | |||
| + " (coalesce(t.normalConsumed, 0) + coalesce(t.otConsumed, 0)) as marked " | |||
| + " from timesheet t " | |||
| + " 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 " | |||
| + " select " | |||
| + " recordDate, " | |||
| + " staffId, " | |||
| + " (leaveHours) as marked " | |||
| + " from `leave` l " | |||
| + " where l.deleted = false " | |||
| + " and l.recordDate >= :startdate and l.recorddate < DATE_ADD(:startdate, INTERVAL 1 MONTH) " | |||
| + " ) result " | |||
| + " group by recordDate, staffId " | |||
| + " having marked >= 8 " | |||
| + " and staffId = :staffId; " | |||
| ) | |||
| return jdbcDao.queryForList(unsubmittedSQL.toString(), args) | |||
| } | |||
| fun weeklySubmittedTimesheet(args: Map<String, Any>): List<Map<String, Any>> { | |||
| // departDate | |||
| val submittedSQL = StringBuilder( | |||
| " with team_cte as ( " | |||
| + " select " | |||
| + " * " | |||
| + " from team_log tl " | |||
| + " where :startdate >= tl.`from` and (:startdate < tl.`to` or tl.`to` is null) " | |||
| + " ) " | |||
| + " select " | |||
| + " result.recordDate, result.staffId, sum(result.marked) as marked " | |||
| + " from ( " | |||
| + " select " | |||
| + " t.recordDate, " | |||
| + " t.staffId, " | |||
| + " (coalesce(t.normalConsumed, 0) + coalesce(t.otConsumed, 0)) as marked " | |||
| + " from timesheet t " | |||
| + " 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 " | |||
| + " select " | |||
| + " recordDate, " | |||
| + " staffId, " | |||
| + " (leaveHours) as marked " | |||
| + " from `leave` l " | |||
| + " where l.deleted = false " | |||
| + " and l.recordDate >= :startdate and l.recorddate < DATE_ADD(:startdate, INTERVAL 7 DAY) " | |||
| + " ) result " | |||
| + " group by recordDate, staffId " | |||
| + " having marked >= 8 " | |||
| + " and staffId = :staffId; " | |||
| ) | |||
| return jdbcDao.queryForList(submittedSQL.toString(), args) | |||
| } | |||
| fun getWeeklyUnsubmittedTimesheet(args: Map<String, Any>): List<Map<String, Any>> { | |||
| val result = mutableListOf<Map<String, Any>>() | |||
| val teamId = args["teamId"] as Long | |||
| val staffs = staffsService.findAll().orElseThrow() | |||
| val startDate = args["startdate"] as LocalDate | |||
| val year = startDate.year | |||
| val month = startDate.month | |||
| val day = startDate.dayOfMonth | |||
| 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 | |||
| } | |||
| }.toMutableList() | |||
| val publicHolidayList = (args["publicHolidayList"] as List<LocalDate>).filter { it.year == startDate.year && it.month == startDate.month } | |||
| 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) } | |||
| } | |||
| thisArgs["staffId"] = curr.id!! | |||
| val submittedMonth = monthlySubmittedTimesheet(thisArgs) | |||
| val UnsubmittedCount = dateList.size - publicHolidayList.size - companyHoliday.size - submittedMonth.size | |||
| result.add( | |||
| mapOf( | |||
| "id" to curr.id!!, | |||
| "name" to curr.name, | |||
| "teamId" to thisTeam.team.id, | |||
| "UnsubmittedCount" to UnsubmittedCount, | |||
| )) | |||
| } | |||
| return result | |||
| } | |||
| fun getMonthlyUnsubmittedTimesheet(args: Map<String, Any>): List<Map<String, Any>> { | |||
| val result = mutableListOf<Map<String, Any>>() | |||
| val teamId = args["teamId"] as Long | |||
| val staffs = staffsService.findAll().orElseThrow() | |||
| val startDate = args["startdate"] as LocalDate | |||
| 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 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 | |||
| } else { | |||
| null | |||
| } | |||
| }.toMutableList() | |||
| val publicHolidayList = (args["publicHolidayList"] as List<LocalDate>).filter { it.year == startDate.year && it.month == startDate.month } | |||
| 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) } | |||
| } | |||
| thisArgs["staffId"] = curr.id!! | |||
| val submittedMonth = monthlySubmittedTimesheet(thisArgs) | |||
| val UnsubmittedCount = dateList.size - publicHolidayList.size - companyHoliday.size - submittedMonth.size | |||
| result.add( | |||
| mapOf( | |||
| "id" to curr.id!!, | |||
| "name" to curr.name, | |||
| "teamId" to thisTeam.team.id, | |||
| "UnsubmittedCount" to UnsubmittedCount, | |||
| )) | |||
| } | |||
| return result | |||
| } | |||
| fun weeklyUnsubmittedTimeSheet(args: Map<String, Any>): List<Map<String, Any>> { | |||
| val sql = StringBuilder( | |||
| "SELECT" | |||