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 279a397..551df9e 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 @@ -629,13 +629,14 @@ open class DashboardService( } fun CashFlowReceivableAndExpenditure(args: Map): List> { val sql = StringBuilder("select" - + "coalesce (round(sum(i.paidAmount)/sum(i.issueAmount)*100,0)) as receivedPercentage," - + "coalesce (round(expenditure.expenditure/(sum(p.expectedTotalFee)*0.8)*100,0)) as expenditurePercentage," + + " coalesce (round(sum(i.paidAmount)/sum(i.issueAmount)*100,0),0) as receivedPercentage," + + " coalesce (round(expenditure.expenditure/(sum(p.expectedTotalFee)*0.8)*100,0),0) as expenditurePercentage," + " coalesce (sum(i.issueAmount),0) as totalInvoiced," + " coalesce (sum(i.paidAmount),0) as totalReceived," + " coalesce (sum(i.issueAmount) - sum(i.paidAmount),0) as receivable," + " coalesce (round(sum(p.expectedTotalFee)*0.8,2),0) as totalBudget," - + " coalesce (expenditure.expenditure) as totalExpenditure" + + " coalesce (expenditure.expenditure) 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(" @@ -697,7 +698,8 @@ open class DashboardService( + " from project p" + " left join milestone m on p.id = m.projectId" + " left join milestone_payment mp on m.id = mp.milestoneId" - + " where p.id in (:projecIds)" + + " where p.id in (:projectIds)" + + " and year(mp.date) = :year" + " group by month(mp.date)" + " ) as anticipateIncome on months.month = anticipateIncome.anticipateIncomeDate" ) @@ -706,17 +708,26 @@ open class DashboardService( } fun CashFlowAnticipateExpenditure(args: Map): List> { val sql = StringBuilder("select" - + " p.id, p.name," - + " date_format(p.planStart, '%Y-%m') as planStart," - + " date_format(p.planEnd, '%Y-%m') as planEnd," - + " month(p.planStart) as startMonth," - + " PERIOD_DIFF(DATE_FORMAT(p.planEnd, '%Y%m'), DATE_FORMAT(p.planStart, '%Y%m'))+1 AS 'Duration'," - + " ROUND(p.totalManhour / (PERIOD_DIFF(DATE_FORMAT(p.planEnd, '%Y%m'), DATE_FORMAT(p.planStart, '%Y%m'))+1), 2) AS 'Average Manhours'," - + " p.teamLead, p.totalManhour" - + " FROM project p" - + " WHERE p.status = 'On-going'" - + " and p.id in (:productIds)" - + " order by teamLead, planStart" + + " p.id, p.name," + + " date_format(p.planStart, '%Y-%m') as planStart," + + " date_format(p.planEnd, '%Y-%m') as planEnd," + + " case" + + " when year(p.planStart) < :year then 1" + + " when year(p.planStart) = :year then month(p.planStart)" + + " end as startMonth," + + " case" + + " when year(p.planStart) < :year and year(p.planEnd) > :year then 12" + + " when year(p.planStart) < :year and year(p.planEnd) = :year then month(p.planEnd)" + + " 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'," + + " 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 (year(p.planStart) <= :year and year(p.planEnd) >= :year)" + + " order by teamLead, planStart" ) 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 dcd5b35..7e6f150 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 @@ -150,5 +150,58 @@ class DashboardController( result["expenditureList"] = cashFlowMonthlyExpenditure return listOf(result) } - + @GetMapping("/searchCashFlowReceivableAndExpenditure") + fun searchCashFlowReceivableAndExpenditure(request: HttpServletRequest?): List> { + val args = mutableMapOf() + val projectIdList = request?.getParameter("projectIdList") + val projectIds = projectIdList?.split(",")?.map { it.toInt() }?.toList() + if (projectIds != null) { + args["projectIds"] = projectIds + } + return dashboardService.CashFlowReceivableAndExpenditure(args) + } + @GetMapping("/searchCashFlowAnticipate") + fun searchCashFlowAnticipate(request: HttpServletRequest?): List> { + val args = mutableMapOf() + val projectIdList = request?.getParameter("projectIdList") + val year = request?.getParameter("year") + val projectIds = projectIdList?.split(",")?.map { it.toInt() }?.toList() + if (projectIds != null) { + args["projectIds"] = projectIds + } + if (year != null) { + args["year"] = year + } + val result = mutableMapOf() + val cashFlowAnticipateIncome = dashboardService.CashFlowAnticipateIncome(args) + val cashFlowAnticipateExpenditure = dashboardService.CashFlowAnticipateExpenditure(args) + result["anticipateIncomeList"] = cashFlowAnticipateIncome + result["anticipateExpenditureList"] = cashFlowAnticipateExpenditure + return listOf(result) + } + @GetMapping("/searchCashFlowLedger") + fun searchCashFlowLedger(request: HttpServletRequest?): List> { + val args = mutableMapOf() + val projectIdList = request?.getParameter("projectIdList") + val projectIds = projectIdList?.split(",")?.map { it.toInt() }?.toList() + if (projectIds != null) { + args["projectIds"] = projectIds + } + return dashboardService.CashFlowLedger(args) + } + @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 result = mutableMapOf() + val teamCashFlowIncome = dashboardService.TeamCashFlowIncome(args) + val teamCashFlowExpenditure = dashboardService.TeamCashFlowExpenditure(args) + result["teamCashFlowIncome"] = teamCashFlowIncome + result["teamCashFlowExpenditure"] = teamCashFlowExpenditure + return listOf(result) + } } \ No newline at end of file