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 551df9e..eeeceba 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 @@ -721,11 +721,14 @@ open class DashboardService( + " when year(p.planStart) = :year and year(p.planEnd) > :year then 12 - month(p.planStart)" + " else PERIOD_DIFF(DATE_FORMAT(p.planEnd, '%Y%m'), DATE_FORMAT(p.planStart, '%Y%m'))+1" + " end AS 'Duration'," + + " PERIOD_DIFF(DATE_FORMAT(p.planEnd, '%Y%m'), DATE_FORMAT(p.planStart, '%Y%m'))+1 as projectDuration," + + " p.expectedTotalFee*0.8 as totalBudget," + + " (p.expectedTotalFee*0.8) / (PERIOD_DIFF(DATE_FORMAT(p.planEnd, '%Y%m'), DATE_FORMAT(p.planStart, '%Y%m'))+1) as aniticipateExpenditure," + " ROUND(p.totalManhour / (PERIOD_DIFF(DATE_FORMAT(p.planEnd, '%Y%m'), DATE_FORMAT(p.planStart, '%Y%m'))+1), 2) AS 'AverageManhours'," + " p.teamLead, p.totalManhour" + " FROM project p" + " WHERE p.status = 'On-going'" - + " and p.id in (1,2,3,4,5,6)" + + " and p.id in (:projectIds)" + " and (year(p.planStart) <= :year and year(p.planEnd) >= :year)" + " order by teamLead, planStart" ) @@ -734,6 +737,7 @@ open class DashboardService( } fun CashFlowLedger(args: Map): List> { val sql = StringBuilder("select" + + " ROW_NUMBER() OVER (ORDER BY date, income, expenditure) AS id," + " date," + " COALESCE(ROUND(income, 2), 0) AS income," + " COALESCE(ROUND(expenditure, 2), 0) AS expenditure," @@ -830,13 +834,18 @@ open class DashboardService( + " left join team t on p.teamLead = t.teamLead" + " left join invoice i on p.code = i.projectCode" + " where p.status = 'On-going'" - + " and t.id = :teamId" - + " and year(i.receiptDate) = :year" - + " and i.id is not null" - + " group by month(i.receiptDate)" - + " ) as invoice on months.month = invoice.invoiceMonth" + ) + if (args != null) { + if (args.containsKey("teamId")) + sql.append(" AND t.id = :teamId") + } + sql.append(" and year(i.receiptDate) = :year" + + " and i.id is not null" + + " group by month(i.receiptDate)" + + " ) as invoice on months.month = invoice.invoiceMonth") + return jdbcDao.queryForList(sql.toString(), args) } fun TeamCashFlowExpenditure(args: Map): List> { @@ -885,13 +894,16 @@ open class DashboardService( + " left join staff s on t.staffId = s.id" + " left join salary s2 on s.salaryId = s2.salaryPoint" + " where t.id is not null" - + " and t2.id = :teamId" - + " and year(t.recordDate) = :year" - + " group by month(t.recordDate),s2.hourlyRate" - + " ) as r" - + " group by r.recordMonth" - + " ) as expenditure on months.month = expenditure.recordMonth" ) + if (args != null) { + if (args.containsKey("teamId")) + sql.append(" AND t2.id = :teamId") + } + sql.append(" and year(t.recordDate) = :year" + + " group by month(t.recordDate),s2.hourlyRate" + + " ) as r" + + " group by r.recordMonth" + + " ) as expenditure on months.month = expenditure.recordMonth") 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 7e6f150..7167dfe 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 @@ -192,10 +192,13 @@ class DashboardController( @GetMapping("/searchTeamCashFlow") fun searchTeamCashFlow(request: HttpServletRequest?): List> { val args = mutableMapOf() - val teamIdList = request?.getParameter("teamIdList") - val teamIds = teamIdList?.split(",")?.map { it.toInt() }?.toList() - if (teamIds != null) { - args["teamIds"] = teamIds + val teamId = request?.getParameter("teamId") + val year = request?.getParameter("year") + if (teamId != null) { + args["teamId"] = teamId + } + if (year != null) { + args["year"] = year } val result = mutableMapOf() val teamCashFlowIncome = dashboardService.TeamCashFlowIncome(args)