From 056f7aaedcd5a43ec8bee3ea47fd37f84aa3e8e6 Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Sat, 8 Nov 2025 19:37:43 +0800 Subject: [PATCH] Fix Dashboard --- .../modules/data/service/DashboardService.kt | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 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 da4559c..e36173b 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 @@ -1580,7 +1580,7 @@ open class DashboardService( + " from(" + " select" + " se.recordMonth as recordMonth," - + " (coalesce(sum(t3.normalConsumed),0) * se.hourlyRate) + (coalesce(sum(t3.otConsumed),0) * se.hourlyRate * 1.0) as cumulativeExpenditure" + + " (coalesce(sum(ifNull(t3.normalConsumed, 0)),0) * ifNull(se.hourlyRate, 0)) + (coalesce(sum(ifNull(t3.otConsumed, 0)),0) * ifNull(se.hourlyRate, 0) * 1.0) as cumulativeExpenditure" + " from(" + " select" + " month(t.recordDate) as recordMonth," @@ -1588,20 +1588,21 @@ open class DashboardService( + " t.recordDate as timesheet_record_date," + " s.id as staff_id," + " se.id as salary_effective_id," - + " se.salaryId," - + " se.startdate as salary_effective_start_date," + + " coalesce(se.salaryId, s.salaryId) as salaryId," + + " coalesce(se.startdate, s.joinDate) as salary_effective_start_date," + " coalesce(se.enddate,now()) as salary_effective_end_date," - + " s2.hourlyRate as hourlyRate" + + " coalesce(s2.hourlyRate, staffS.hourlyRate, 0) as hourlyRate" + " from project p" + " left join project_task pt on p.id = pt.project_id" + " left join timesheet t on pt.id = t.projectTaskId" + " left join staff s on t.staffId = s.id" + " left join salary_effective se on t.recordDate >= se.`date` and s.id = se.staffId" + " left join salary s2 on se.salaryId = s2.salaryPoint" + + " left join salary staffS on staffS.salaryPoint = s.salaryId" + " where t.id is not null" + " and p.id in (:projectIds)" + " and year(t.recordDate) = :year" - + " group by t.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate" + + " group by t.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate, staffS.hourlyRate" + " ) as se" + " left join timesheet t3 on se.tid = t3.id" + " where t3.recordDate >= se.salary_effective_start_date and t3.recordDate <= se.salary_effective_end_date" @@ -1617,7 +1618,7 @@ open class DashboardService( fun BeforeCurrentYearCashFlowMonthlyCumulativeExpenditure(args: Map): List> { val sql = StringBuilder( " select" - + " coalesce (sum(result.expenditure),0) as beforeCurrentYearCumulativeExpenditure" + + " coalesce (sum(ifNull(result.expenditure, 0)),0) as beforeCurrentYearCumulativeExpenditure" + " from(" + " select" + " r.recordYearMonth as recordYearMonth," @@ -1639,20 +1640,21 @@ open class DashboardService( + " t.recordDate as timesheet_record_date," + " s.id as staff_id," + " se.id as salary_effective_id," - + " se.salaryId," - + " se.startdate as salary_effective_start_date," + + " coalesce(se.salaryId, s.salaryId) as salaryId," + + " coalesce(se.startdate, s.joinDate) as salary_effective_start_date," + " coalesce(se.enddate,now()) as salary_effective_end_date," - + " s2.hourlyRate as hourlyRate" + + " coalesce(s2.hourlyRate, staffS.hourlyRate, 0) as hourlyRate" + " from project p" + " left join project_task pt on p.id = pt.project_id" + " left join timesheet t on pt.id = t.projectTaskId" + " left join staff s on t.staffId = s.id" + " left join salary_effective se on t.recordDate >= se.`date` and s.id = se.staffId" + " left join salary s2 on se.salaryId = s2.salaryPoint" + + " left join salary staffS on s.salaryId = staffS.salaryPoint" + " where t.id is not null" + " and p.id in (:projectIds)" + " and year(t.recordDate) < :year" - + " group by t.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate" + + " group by t.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate, staffS.hourlyRate" + " ) as se" + " left join timesheet t3 on se.tid = t3.id" + " where t3.recordDate >= se.salary_effective_start_date and t3.recordDate <= se.salary_effective_end_date" @@ -1765,30 +1767,31 @@ open class DashboardService( + " ) as i on i.pid = p.id" + " left join(" + " select" - + " sum(r.expenditure) as expenditure" + + " sum(coalesce(r.expenditure, 0)) as expenditure" + " from(" + " select" + " t3.id," - + " (coalesce(sum(t3.normalConsumed),0) * se.hourlyRate) + (coalesce(sum(t3.otConsumed),0) * se.hourlyRate * 1.0) as expenditure" + + " (coalesce(sum(coalesce(t3.normalConsumed, 0)),0) * se.hourlyRate) + (coalesce(sum(coalesce(t3.otConsumed, 0)),0) * se.hourlyRate * 1.0) as expenditure" + " from (" + " select" + " t2.id as tid," + " t2.recordDate as timesheet_record_date," + " s.id as staff_id," + " se.id as salary_effective_id," - + " se.salaryId," - + " se.startdate as salary_effective_start_date," + + " coalesce(se.salaryId, s.salaryId) as salaryId," + + " coalesce(se.startdate, s.joinDate) as salary_effective_start_date," + " coalesce(se.enddate,now()) as salary_effective_end_date," - + " s2.hourlyRate as hourlyRate" + + " coalesce(s2.hourlyRate, staffS.hourlyRate, 0) as hourlyRate" + " from project p" + " left join project_task pt on p.id = pt.project_id" + " left join timesheet t2 on pt.id = t2.projectTaskId" + " left join staff s on t2.staffId = s.id" + " left join salary_effective se on t2.recordDate >= se.`date` and s.id = se.staffId" + " left join salary s2 on se.salaryId = s2.salaryPoint" + + " left join salary staffS on s.salaryId = staffS.salaryPoint" + " where t2.id is not null" + " and p.id in (:projectIds)" - + " group by t2.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate" + + " group by t2.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate, staffS.hourlyRate" + " ) as se" + " left join timesheet t3 on se.tid = t3.id" + " where t3.recordDate >= se.salary_effective_start_date and t3.recordDate <= se.salary_effective_end_date" @@ -1991,20 +1994,21 @@ open class DashboardService( + " t2.recordDate as timesheet_record_date, " + " s.id as staff_id, " + " se.id as salary_effective_id, " - + " se.salaryId, " - + " se.startdate as salary_effective_start_date, " + + " coalesce(se.salaryId, s.salaryId) as salaryId, " + + " coalesce(se.startdate, s.joinDate) as salary_effective_start_date, " + " coalesce(se.enddate,NOW()) as salary_effective_end_date, " - + " s2.hourlyRate as hourlyRate " + + " coalesce(s2.hourlyRate, staffS.hourlyRate, 0) as hourlyRate " + " from project p2 " + " left join project_task pt ON p2.id = pt.project_id " + " left join timesheet t2 on pt.id = t2.projectTaskId " + " left join staff s on t2.staffId = s.id " + " left join salary_effective se on t2.recordDate >= se.`date` and s.id = se.staffId " + " left join salary s2 on se.salaryId = s2.salaryPoint " + + " left join salary staffS on s.salaryId = staffS.salaryPoint " + " where p2.status = 'On-going' " + " and t2.id is not null " + " AND p2.id IN (:projectIds) " - + " group by t2.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate " + + " group by t2.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate, staffS.hourlyRate " + " ) as se " + " left join timesheet t3 on se.tid = t3.id " + " where t3.recordDate >= se.salary_effective_start_date and t3.recordDate <= se.salary_effective_end_date " @@ -2769,7 +2773,7 @@ open class DashboardService( continue } System.out.println("-----------------------------------") - System.out.println("Staff Name: ${curr.name}") + System.out.println("Staff Name: ${curr.name} | Team: ${thisTeam.team.code}") var dateListSize = dateList.size var publicHolidayListSize = publicHolidayList.size var companyHolidaySize = companyHoliday.size @@ -2786,12 +2790,16 @@ open class DashboardService( result.add( mapOf( "id" to curr.id!!, + "staffId" to curr.staffId, "name" to curr.name, + "teamCode" to thisTeam.team.code, "teamId" to thisTeam.team.id, "UnsubmittedCount" to unsubmittedCount, )) } - return result + + val filteredResult = result.filter { it["staffId"] != "A003" && it["staffId"] != "A004" && it["staffId"] != "B011" }.filter{ it["teamCode"] != "HO"} + return filteredResult } fun getMonthlyUnsubmittedTimesheet(args: Map): List> { val today = LocalDate.now() @@ -2826,7 +2834,7 @@ open class DashboardService( continue } System.out.println("-----------------------------------") - System.out.println("Staff Name: ${curr.name}") + System.out.println("Staff Name: ${curr.name} | Team: ${thisTeam.team.code}") var dateListSize = dateList.size var publicHolidayListSize = publicHolidayList.size var companyHolidaySize = companyHoliday.size @@ -2843,12 +2851,15 @@ open class DashboardService( result.add( mapOf( "id" to curr.id!!, + "staffId" to curr.staffId, "name" to curr.name, + "teamCode" to thisTeam.team.code, "teamId" to thisTeam.team.id, "UnsubmittedCount" to unsubmittedCount, )) } - return result + val filteredResult = result.filter { it["staffId"] != "A003" && it["staffId"] != "A004" && it["staffId"] != "B011" }.filter{ it["teamCode"] != "HO"} + return filteredResult } fun weeklyUnsubmittedTimeSheet(args: Map): List> { val sql = StringBuilder(