From 089487abde561fd9f816614ff2c92f1bf23edbfd Mon Sep 17 00:00:00 2001 From: "Mac\\David" Date: Thu, 6 Jun 2024 20:40:43 +0800 Subject: [PATCH] fix --- .../modules/data/service/DashboardService.kt | 48 +++++++++++++------ .../modules/data/web/DashboardController.kt | 4 ++ 2 files changed, 38 insertions(+), 14 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 8ef4048..925f851 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 @@ -102,6 +102,7 @@ open class DashboardService( + " ) milestonePayment on 1=1" + " where p.customerId = :customerId" + " and p.customerSubsidiaryId = :subsidiaryId" + + " and (tg.name != '5. Miscellaneous' or tg.name is null)" + " and p.status not in (\"Pending to Start\",\"Completed\",\"Deleted\")" ) @@ -153,6 +154,7 @@ open class DashboardService( + " where p.customerId = :customerId" + " and isNull(p.customerSubsidiaryId)" + " and p.status not in (\"Pending to Start\",\"Completed\",\"Deleted\")" + + " and (tg.name != '5. Miscellaneous' or tg.name is null)" + " group by p.id, p.code, p.name, te.code, s.name, tg.name, p.totalManhour, milestonePayment.comingPaymentMilestone" ) @@ -302,6 +304,7 @@ open class DashboardService( + " ) milestonePayment on 1=1" + " where p.teamLead = :teamLeadId" + " and p.status not in (\"Pending to Start\",\"Completed\",\"Deleted\")" + + " and (tg.name != '5. Miscellaneous' or tg.name is null)" + " group by p.id, p.code, p.name, te.code, s.name, tg.name, p.totalManhour, milestonePayment.comingPaymentMilestone" ) @@ -312,9 +315,9 @@ open class DashboardService( "select" + " t.id as teamId," + " t.name as teamName," - + " count(p.name) as projectNo," - + " coalesce(sum(p.expectedTotalFee),0) as totalFee," - + " coalesce(sum(round(p.expectedTotalFee * 0.8,2)),0) as totalBudget," + + " pj.projectNo as projectNo," + + " coalesce(pj.totalFee,0) as totalFee," + + " coalesce(pj.totalBudget,0) as totalBudget," + " coalesce(sum(i.issueAmount),0) as totalInvoiced," + " coalesce(sum(i.paidAmount),0) as totalReceived," + " round(expenditure.cumulativeExpenditure,2) as cumulativeExpenditure," @@ -324,7 +327,17 @@ open class DashboardService( + " end as cashFlowStatus," + " 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 (" + + " select" + + " t2.id as tid," + + " count(p.id) as projectNo," + + " sum(p.expectedTotalFee) as totalFee," + + " sum(round(p.expectedTotalFee * 0.8,2)) as totalBudget" + + " from team t2" + + " left join project p on t2.teamLead = p.teamLead" + + " where p.status = 'On-going'" + + " group by t2.id" + + " ) as pj on pj.tid = t.id" + " left join (" + " select" + " t3.id as tid," @@ -361,7 +374,7 @@ open class DashboardService( + " group by r.teamId" + " ) as expenditure on expenditure.teamId = t.id" + " where t.deleted = 0" - + " and p.status = 'On-going'" + + " and pj.projectNo is not null" ) if (viewDashboardAuthority() == "self") { @@ -835,7 +848,7 @@ open class DashboardService( + " COALESCE(ROUND(expenditure, 2), 0) AS expenditure," + " ROUND(SUM(COALESCE(income, 0) - COALESCE(expenditure, 0)) OVER (ORDER BY parsed_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), 2) AS balance," + " CASE" - + " WHEN income > 0 THEN paymentMilestone" + + " WHEN income > 0 THEN concat('Invoice Receipt: ',invoiceNo)" + " ELSE 'Monthly Manpower Expenditure'" + " END AS remarks" + " FROM (" @@ -844,7 +857,7 @@ open class DashboardService( + " DATE_FORMAT(i.receiptDate, '%m/%y') AS formatted_date," + " SUM(i.paidAmount) AS income," + " NULL AS expenditure," - + " i.paymentMilestone AS paymentMilestone" + + " i.invoiceNo AS invoiceNo" + " FROM" + " project p" + " LEFT JOIN invoice i ON p.code = i.projectCode" @@ -854,7 +867,7 @@ open class DashboardService( + " GROUP BY" + " parsed_date," + " formatted_date," - + " i.paymentMilestone" + + " i.invoiceNo" + " UNION" + " SELECT" + " DATE_FORMAT(r.date, '%Y-%m') AS parsed_date," @@ -1428,8 +1441,10 @@ open class DashboardService( + " coalesce (sum(t.normalConsumed)+sum(t.otConsumed),0) as manhours" + " from grade g" + " left join staff s on g.id = s.gradeId" + + " left join team t2 on s.teamId = t2.id" + " left join timesheet t on s.id = t.staffId" + " where g.deleted = 0" + + " and t2.id = :teamId" + " and t.recordDate >= :startdate" + " and t.recordDate < DATE_FORMAT(:enddate, '%Y-%m-%d 23:59:59')" @@ -1437,9 +1452,9 @@ open class DashboardService( if (viewDashboardAuthority() == "self") { val teamId = staffsService.currentStaff()?.team?.id - if (teamId != null) { - sql.append(" and s.teamId = $teamId") - } +// if (teamId != null) { +// sql.append(" and s.teamId = $teamId") +// } } sql.append(" group by g.id" @@ -1471,16 +1486,18 @@ open class DashboardService( + " from grade g" + " left join grade_allocation ga on g.id = ga.gradeId" + " left join project p on ga.projectId = p.id" + + " left join team t on p.teamLead = t.teamLead" + " where p.status = 'On-going'" + + " and t.id = :teamId" + " and p.planEnd > :startdate" + " and p.planStart < :enddate" ) if (viewDashboardAuthority() == "self") { val teamLeadId = staffsService.currentStaff()?.id - if (teamLeadId != null) { - sql.append(" and p.teamLead = $teamLeadId") - } +// if (teamLeadId != null) { +// sql.append(" and p.teamLead = $teamLeadId") +// } } sql.append(" order by g.id") @@ -1491,6 +1508,7 @@ open class DashboardService( val sql = StringBuilder( "select" + " p2.id as id," + + " p2.code as projectNo," + " p2.name as projectName," + " coalesce (result.manhours,0) as manhours," + " coalesce (round((result.manhours/ sum(result.manhours))*100,2),0) as percentage" @@ -1521,6 +1539,7 @@ open class DashboardService( val sql = StringBuilder( "select" + " p2.id as id," + + " p2.code as projectNo," + " p2.name as projectName," + " coalesce (result.manhours,0) as manhours," + " coalesce (round((result.manhours/ sum(result.manhours))*100,2),0) as percentage" @@ -1551,6 +1570,7 @@ open class DashboardService( val sql = StringBuilder( "select" + " p2.id as id," + + " p2.code as projectNo," + " p2.name as projectName," + " coalesce (result.manhours,0) as manhours," + " coalesce (round((result.manhours/ sum(result.manhours))*100,2),0) as percentage" 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 3d068a5..6cb4910 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 @@ -329,12 +329,16 @@ class DashboardController( val args = mutableMapOf() val startdate = request?.getParameter("startdate") val enddate = request?.getParameter("enddate") + val teamId = request?.getParameter("teamId") if (startdate != null) { args["startdate"] = startdate } if (enddate != null) { args["enddate"] = enddate } + if (teamId != null) { + args["teamId"] = teamId + } val result = mutableMapOf() val staffGradeTotalManhours = dashboardService.staffGradeTotalManhours(args) val staffGradeTotalPlannedManhours = dashboardService.staffGradeTotalPlannedManhours(args)