| @@ -2118,10 +2118,18 @@ open class ReportService( | |||||
| // } | // } | ||||
| open fun getProjectResourceOverconsumptionReport(args: Map<String, Any>): List<Map<String, Any>> { | open fun getProjectResourceOverconsumptionReport(args: Map<String, Any>): List<Map<String, Any>> { | ||||
| val sql = StringBuilder( | |||||
| " SELECT " | |||||
| val sql = StringBuilder("with pe_cte as (" | |||||
| + " select" | |||||
| + " pe.projectId," | |||||
| + " sum(coalesce(amount)) as expense" | |||||
| + " from project_expense pe" | |||||
| + " where deleted = false" | |||||
| + " group by pe.projectId" | |||||
| + " )" | |||||
| + " SELECT " | |||||
| + " p.code, p.name, tm.code as team, concat(c.code, ' -',c.name) as client, COALESCE(concat(ss.code, ' -', ss.name), 'N/A') as subsidiary " | + " p.code, p.name, tm.code as team, concat(c.code, ' -',c.name) as client, COALESCE(concat(ss.code, ' -', ss.name), 'N/A') as subsidiary " | ||||
| + " , (p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8 as plannedBudget, sum(t.consumedBudget) as actualConsumedBudget " | |||||
| + " , (p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8 as plannedBudget, sum(t.consumedBudget) + coalesce(pc.expense, 0) as actualConsumedBudget " | |||||
| + " , coalesce(pc.expense, 0) as projectExpense " | |||||
| + " , COALESCE(p.totalManhour, 0) as plannedManhour, sum(t.normalConsumed + COALESCE(t.otConsumed, 0)) as actualConsumedManhour " | + " , COALESCE(p.totalManhour, 0) as plannedManhour, sum(t.normalConsumed + COALESCE(t.otConsumed, 0)) as actualConsumedManhour " | ||||
| + " , sum(t.consumedBudget) / ((p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8) as budgetConsumptionRate " | + " , sum(t.consumedBudget) / ((p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8) as budgetConsumptionRate " | ||||
| + " , sum(t.normalConsumed + COALESCE(t.otConsumed, 0)) / COALESCE(p.totalManhour, 0) as manhourConsumptionRate " | + " , sum(t.normalConsumed + COALESCE(t.otConsumed, 0)) / COALESCE(p.totalManhour, 0) as manhourConsumptionRate " | ||||
| @@ -2140,6 +2148,7 @@ open class ReportService( | |||||
| + " LEFT JOIN salary sal on se.salaryId = sal.salaryPoint " | + " LEFT JOIN salary sal on se.salaryId = sal.salaryPoint " | ||||
| + " ) t " | + " ) t " | ||||
| + " left join project p on p.id = t.projectId " | + " left join project p on p.id = t.projectId " | ||||
| + " left join pe_cte pc on pc.projectId = t.projectId " | |||||
| + " left join team tm on p.teamLead = tm.teamLead " | + " left join team tm on p.teamLead = tm.teamLead " | ||||
| + " left join customer c on c.id = p.customerId " | + " left join customer c on c.id = p.customerId " | ||||
| + " left join subsidiary ss on p.customerSubsidiaryId = ss.id " | + " left join subsidiary ss on p.customerSubsidiaryId = ss.id " | ||||
| @@ -2168,7 +2177,7 @@ open class ReportService( | |||||
| else -> "" | else -> "" | ||||
| } | } | ||||
| } | } | ||||
| sql.append(" group by p.code, p.name, tm.code, c.code, c.name, ss.code, ss.name, p.expectedTotalFee, p.subContractFee, p.totalManhour ") | |||||
| sql.append(" group by p.code, p.name, tm.code, c.code, c.name, ss.code, ss.name, p.expectedTotalFee, p.subContractFee, p.totalManhour, pc.expense ") | |||||
| sql.append(statusFilter) | sql.append(statusFilter) | ||||
| return jdbcDao.queryForList(sql.toString(), args) | return jdbcDao.queryForList(sql.toString(), args) | ||||
| } | } | ||||