From 99337662e34cc12c0cf82c41b5e6de1e3e67496a Mon Sep 17 00:00:00 2001 From: "Mac\\David" Date: Wed, 29 May 2024 23:47:09 +0800 Subject: [PATCH] bug fix --- .../modules/data/service/DashboardService.kt | 79 ++++++++++++++++--- .../modules/data/web/DashboardController.kt | 20 +++++ 2 files changed, 89 insertions(+), 10 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 28cca86..91a963c 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 @@ -110,8 +110,8 @@ open class DashboardService( + " s.name as teamLead," + " tg.name as expectedStage," + " p.totalManhour as budgetedManhour," - + " sum(t.normalConsumed) + sum(t.otConsumed) as spentManhour," - + " p.totalManhour - sum(t.normalConsumed) - sum(t.otConsumed) as remainedManhour," + + " COALESCE (sum(t.normalConsumed) + sum(t.otConsumed),0) as spentManhour," + + " COALESCE (p.totalManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) as remainedManhour," + " coalesce (round(((sum(t.normalConsumed) - sum(t.otConsumed))/p.totalManhour)*100,2),0) as manhourConsumptionPercentage," + " DATE_FORMAT(milestonePayment.comingPaymentMilestone, '%Y-%m-%d') as comingPaymentMilestone" + " from project p" @@ -254,8 +254,8 @@ open class DashboardService( + " s.name as teamLead," + " tg.name as expectedStage," + " p.totalManhour as budgetedManhour," - + " sum(t.normalConsumed) + sum(t.otConsumed) as spentManhour," - + " p.totalManhour - sum(t.normalConsumed) - sum(t.otConsumed) as remainedManhour," + + " COALESCE (sum(t.normalConsumed) + sum(t.otConsumed),0) as spentManhour," + + " COALESCE (p.totalManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) as remainedManhour," + " coalesce (round(((sum(t.normalConsumed) - sum(t.otConsumed))/p.totalManhour)*100,2),0) as manhourConsumptionPercentage," + " DATE_FORMAT(milestonePayment.comingPaymentMilestone, '%Y-%m-%d') as comingPaymentMilestone" + " from project p" @@ -301,7 +301,18 @@ open class DashboardService( + " coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2),0) as cpi" + " from team t" + " left join project p on t.teamLead = p.teamLead" - + " left join invoice i on p.code = i.projectCode" + + " left join (" + + " select" + + " t3.id as tid," + + " sum(i3.issueAmount) as issueAmount," + + " sum(i3.paidAmount) as paidAmount" + + " from team t3" + + " left join project p3 on t3.teamLead = p3.teamLead" + + " left join invoice i3 on p3.code = i3.projectCode" + + " where t3.deleted = 0" + + " and p3.status = 'On-going'" + + " group by t3.id" + + " ) as i on i.tid = t.id" + " left join (" + " select" + " r.teamId as teamId," @@ -347,7 +358,17 @@ open class DashboardService( + " end as cashFlowStatus," + " round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2) as cpi" + " from project p" - + " left join invoice i on p.code = i.projectCode" + + " left join (" + + " select" + + " p3.id as pid," + + " sum(i3.issueAmount) as issueAmount," + + " sum(i3.paidAmount) as paidAmount" + + " from project p3" + + " left join invoice i3 on p3.code = i3.projectCode" + + " where p3.deleted = 0" + + " and p3.status = 'On-going'" + + " group by p3.id" + + " ) as i on i.pid = p.id" + " left join (" + " select" + " sum(r.cumulativeExpenditure) as cumulativeExpenditure" @@ -399,6 +420,7 @@ open class DashboardService( + " left join customer c on p.customerId = c.id" + " left join (" + " select" + + " t3.id as tid," + " c3.id as cid," + " sum(i3.issueAmount) as issueAmount," + " sum(i3.paidAmount) as paidAmount" @@ -415,8 +437,8 @@ open class DashboardService( if (args.containsKey("teamId")) sql.append(" AND t3.id = :teamId"); } - sql.append( " group by c3.id" - + " ) as i on i.cid = c.id" + sql.append( " group by c3.id, t3.id" + + " ) as i on i.cid = c.id and i.tid = t.id" + " left join (" + " select" + " r.teamId as teamId," @@ -657,7 +679,17 @@ open class DashboardService( + " coalesce (expenditure.expenditure,0) as totalExpenditure," + " coalesce (sum(p.expectedTotalFee)*0.8 - expenditure.expenditure,0) as expenditureReceivable" + " from project p" - + " left join invoice i on p.code = i.projectCode" + + " left join (" + + " select" + + " p3.id as pid," + + " sum(i3.issueAmount) as issueAmount," + + " sum(i3.paidAmount) as paidAmount" + + " from project p3" + + " left join invoice i3 on p3.code = i3.projectCode" + + " where p3.deleted = 0" + + " and p3.status = 'On-going'" + + " group by p3.id" + + " ) as i on i.pid = p.id" + " left join(" + " select" + " sum(r.expenditure) as expenditure" @@ -933,9 +965,12 @@ open class DashboardService( + " p.id as id," + " p.code as projectCode," + " p.name as projectName," - + " concat(c.code,'-',c.name) as customerCodeAndName" + + " concat(c.code,'-',c.name) as customerCodeAndName," + + " concat(c.code,'-',c.name) as customerCodeAndName," + + " concat(s.code,'-',s.name) as subsidiaryCodeAndName" + " from project p" + " left join customer c on p.customerId = c.id" + + " left join subsidiary s on p.customerSubsidiaryId = s.id" + " where p.status = 'On-going'" + " and p.deleted = 0" ) @@ -1033,7 +1068,31 @@ open class DashboardService( return jdbcDao.queryForList(sql.toString(), args) } + fun monthlyActualTeamTotalManhoursSpent(args: Map): List> { + val sql = StringBuilder( + " WITH RECURSIVE date_series AS (" + + " SELECT DATE_FORMAT(:startdate, '%Y-%m-01') AS month" + + " UNION ALL" + + " SELECT DATE_FORMAT(DATE_ADD(month, INTERVAL 1 MONTH), '%Y-%m-01')" + + " FROM date_series" + + " WHERE month < DATE_FORMAT(:enddate, '%Y-%m-01')" + + " )" + + " SELECT" + + " ds.month AS yearMonth," + + " IFNULL(SUM(IFNULL(ts.normalConsumed, 0) + IFNULL(ts.otConsumed, 0)), 0) AS 'TotalManhourConsumed'," + + " :teamId AS teamId" + + " FROM date_series ds" + + " LEFT JOIN staff st" + + " on st.teamId = :teamId" + + " LEFT JOIN timesheet ts" + + " ON DATE_FORMAT(ts.recordDate, '%Y-%m') = DATE_FORMAT(ds.month, '%Y-%m') and ts.staffID = st.id" + + " WHERE ds.month BETWEEN DATE_FORMAT(:startdate, '%Y-%m-01') AND DATE_FORMAT(:enddate, '%Y-%m-01')" + + " GROUP BY ds.month, st.teamId" + + " ORDER BY ds.month" + ) + return jdbcDao.queryForList(sql.toString(), args) + } } 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 a69305d..70c2162 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 @@ -232,4 +232,24 @@ class DashboardController( result["summarySubStage"] = summarySubStage return listOf(result) } + @GetMapping("/searchMonthlyActualTeamTotalManhoursSpent") + fun searchMonthlyActualTeamTotalManhoursSpent(request: HttpServletRequest?): List> { + val args = mutableMapOf() + val teamId = request?.getParameter("teamId") + val startdate = request?.getParameter("startdate") + val enddate = request?.getParameter("enddate") + if (teamId != null) { + args["teamId"] = teamId + } + if (startdate != null) { + args["startdate"] = startdate + } + if (enddate != null) { + args["enddate"] = enddate + } + val result = mutableMapOf() + val monthlyActualTeamTotalManhoursSpent = dashboardService.monthlyActualTeamTotalManhoursSpent(args) + result["monthlyActualTeamTotalManhoursSpent"] = monthlyActualTeamTotalManhoursSpent + return listOf(result) + } } \ No newline at end of file