From 112ac09282b0f74da4438b7a042b513600a836fd Mon Sep 17 00:00:00 2001 From: "MSI\\User" Date: Thu, 29 Aug 2024 15:01:52 +0800 Subject: [PATCH] update cumulative expenditure --- .../modules/data/service/DashboardService.kt | 50 +++++++++++++++++++ .../modules/data/web/DashboardController.kt | 2 + 2 files changed, 52 insertions(+) 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 6137be4..3c21eca 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 @@ -1494,6 +1494,56 @@ open class DashboardService( return jdbcDao.queryForList(sql.toString(), args) } + + fun BeforeCurrentYearCashFlowMonthlyCumulativeExpenditure(args: Map): List> { + val sql = StringBuilder("" + + " select" + + " coalesce (sum(result.expenditure),0) as beforeCurrentYearCumulativeExpenditure" + + " from(" + + " select" + + " r.recordYearMonth as recordYearMonth," + + " r.recordYear as recordYear," + + " r.recordMonth as recordMonth," + + " sum(r.cumulativeExpenditure) as expenditure" + + " from(" + + " select" + + " se.recordYearMonth as recordYearMonth," + + " se.recordYear as recordYear," + + " se.recordMonth as recordMonth," + + " (coalesce(sum(t3.normalConsumed),0) * se.hourlyRate) + (coalesce(sum(t3.otConsumed),0) * se.hourlyRate * 1.0) as cumulativeExpenditure" + + " from(" + + " select" + + " DATE_FORMAT (t.recordDate, '%Y-%m') as recordYearMonth," + + " year(t.recordDate) as recordYear," + + " month(t.recordDate) as recordMonth," + + " t.id as tid," + + " 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.enddate,now()) as salary_effective_end_date," + + " s2.hourlyRate 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" + + " where t.id is not null" + + " and p.id in (1)" + + " and year(t.recordDate) < :year" + + " group by t.id, s.id, se.id, se.salaryId,se.date, s2.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" + + " group by se.recordYearMonth, se.recordYear,se.recordMonth, se.hourlyRate" + + " ) as r" + + " group by r.recordYearMonth,r.recordMonth,r.recordYear" + + " ) as result" + ) + return jdbcDao.queryForList(sql.toString(), args) + } fun CashFlowReceivableAndExpenditure(args: Map): List> { val sql = StringBuilder( // "select" 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 b08745e..017cb8f 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 @@ -195,8 +195,10 @@ class DashboardController( val result = mutableMapOf() val cashFlowMonthlyIncome = dashboardService.CashFlowMonthlyIncomeByMonth(args) val cashFlowMonthlyExpenditure = dashboardService.CashFlowMonthlyExpenditureByMonth(args) + val beforeCurrentYearExpenditure = dashboardService.BeforeCurrentYearCashFlowMonthlyCumulativeExpenditure(args) result["incomeList"] = cashFlowMonthlyIncome result["expenditureList"] = cashFlowMonthlyExpenditure + result["beforeCurrentYearExpenditure"] = beforeCurrentYearExpenditure return listOf(result) } @GetMapping("/searchCashFlowReceivableAndExpenditure")