| @@ -704,7 +704,9 @@ open class DashboardService( | |||||
| + " coalesce(sum(i.issueAmount),0) as totalInvoiced," | + " coalesce(sum(i.issueAmount),0) as totalInvoiced," | ||||
| + " coalesce(pj.totalFee,0) - coalesce(sum(i.issueAmount),0) as unInvoiced," | + " coalesce(pj.totalFee,0) - coalesce(sum(i.issueAmount),0) as unInvoiced," | ||||
| + " coalesce(sum(i.paidAmount),0) as totalReceived," | + " coalesce(sum(i.paidAmount),0) as totalReceived," | ||||
| + " round(expenditure.cumulativeExpenditure,2) as cumulativeExpenditure," | |||||
| + " round(expenditure.cumulativeExpenditure + projectExpense.amount,2) as totalExpenditure," | |||||
| + " round(expenditure.cumulativeExpenditure,2) as manhoursExpenditure," | |||||
| + " round(projectExpense.amount,2) as projectExpense," | |||||
| + " case" | + " case" | ||||
| + " when coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),3),0) >= 1 then 'Positive'" | + " when coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),3),0) >= 1 then 'Positive'" | ||||
| + " when coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),3),0) < 1 then 'Negative'" | + " when coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),3),0) < 1 then 'Negative'" | ||||
| @@ -780,6 +782,16 @@ open class DashboardService( | |||||
| + " ) as r" | + " ) as r" | ||||
| + " group by r.teamId" | + " group by r.teamId" | ||||
| + " ) as expenditure on expenditure.teamId = t.id" | + " ) as expenditure on expenditure.teamId = t.id" | ||||
| + " left join (" | |||||
| + " select" | |||||
| + " t4.id as teamId," | |||||
| + " sum(pe.amount) as amount" | |||||
| + " from team t4" | |||||
| + " left join project p4 on t4.teamLead = p4.teamLead" | |||||
| + " left join project_expense pe on pe.projectId = p4.id" | |||||
| + " where p4.status = 'On-going'" | |||||
| + " group by t4.id" | |||||
| + " ) as projectExpense on projectExpense.teamId = t.id" | |||||
| + " where t.deleted = 0" | + " where t.deleted = 0" | ||||
| + " and pj.projectNo is not null" | + " and pj.projectNo is not null" | ||||
| ) | ) | ||||
| @@ -851,7 +863,9 @@ open class DashboardService( | |||||
| + " count(p.code) as projectNo," | + " count(p.code) as projectNo," | ||||
| + " sum(p.expectedTotalFee) as totalFee," | + " sum(p.expectedTotalFee) as totalFee," | ||||
| + " round((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0))) * 0.8,2) as totalBudget," | + " round((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0))) * 0.8,2) as totalBudget," | ||||
| + " round(expenditure.cumulativeExpenditure,2) as cumulativeExpenditure," | |||||
| + " round(expenditure.cumulativeExpenditure + projectExpense.amount,2) as totalExpenditure," | |||||
| + " round(expenditure.cumulativeExpenditure,2) as manhoursExpenditure," | |||||
| + " round(projectExpense.amount,2) as projectExpense," | |||||
| + " sum(i.issueAmount) as totalInvoiced," | + " sum(i.issueAmount) as totalInvoiced," | ||||
| + " sum(p.expectedTotalFee) - sum(i.issueAmount) as unInvoiced," | + " sum(p.expectedTotalFee) - sum(i.issueAmount) as unInvoiced," | ||||
| + " sum(i.paidAmount) as totalReceived," | + " sum(i.paidAmount) as totalReceived," | ||||
| @@ -913,8 +927,17 @@ open class DashboardService( | |||||
| + " group by t3.id, se.hourlyRate" | + " group by t3.id, se.hourlyRate" | ||||
| + " ) as r" | + " ) as r" | ||||
| + " ) as expenditure on 1=1." | + " ) as expenditure on 1=1." | ||||
| + " left join (" | |||||
| + " select" | |||||
| + " p4.id as pid," | |||||
| + " sum(pe.amount) as amount" | |||||
| + " from project p4" | |||||
| + " left join project_expense pe on pe.projectId = p4.id" | |||||
| + " where p4.status = 'On-going'" | |||||
| + " group by p4.id" | |||||
| + " ) as projectExpense on 1 = 1" | |||||
| + " where p.status = 'On-going'" | + " where p.status = 'On-going'" | ||||
| + " group by expenditure.cumulativeExpenditure" | |||||
| + " group by expenditure.cumulativeExpenditure,projectExpense.amount" | |||||
| ) | ) | ||||
| return jdbcDao.queryForList(sql.toString(), args) | return jdbcDao.queryForList(sql.toString(), args) | ||||
| @@ -979,7 +1002,9 @@ open class DashboardService( | |||||
| + " p.projectNo as projectNo," | + " p.projectNo as projectNo," | ||||
| + " p.totalFee as totalFee," | + " p.totalFee as totalFee," | ||||
| + " p.totalBudget as totalBudget," | + " p.totalBudget as totalBudget," | ||||
| + " COALESCE(round(expenditure.cumulativeExpenditure,2),0) as cumulativeExpenditure," | |||||
| + " COALESCE(round(expenditure.cumulativeExpenditure + projectExpense.amount,2),0) as totalExpenditure," | |||||
| + " COALESCE(round(expenditure.cumulativeExpenditure,2),0) as manhoursExpenditure," | |||||
| + " COALESCE(round(projectExpense.amount,2),0) as projectExpense," | |||||
| + " coalesce(sum(i.issueAmount),0) as totalInvoiced," | + " coalesce(sum(i.issueAmount),0) as totalInvoiced," | ||||
| + " coalesce(sum(i.paidAmount),0) as totalReceived," | + " coalesce(sum(i.paidAmount),0) as totalReceived," | ||||
| + " case" | + " case" | ||||
| @@ -1128,6 +1153,21 @@ open class DashboardService( | |||||
| + " ) as r" | + " ) as r" | ||||
| + " group by r.teamId, r.customerId" | + " group by r.teamId, r.customerId" | ||||
| + " ) as expenditure on expenditure.teamId = t.id and expenditure.customerId = i.cid" | + " ) as expenditure on expenditure.teamId = t.id and expenditure.customerId = i.cid" | ||||
| + " left join (" | |||||
| + " select" | |||||
| + " t4.id as teamId," | |||||
| + " sum(pe.amount) as amount" | |||||
| + " from team t4" | |||||
| + " left join project p4 on t4.teamLead = p4.teamLead" | |||||
| + " left join project_expense pe on pe.projectId = p4.id" | |||||
| + " where p4.status = 'On-going'") | |||||
| if (args != null) { | |||||
| if (args.containsKey("teamId")) | |||||
| sql.append(" AND t4.id = :teamId"); | |||||
| } | |||||
| sql.append( | |||||
| " group by t4.id" | |||||
| + " ) as projectExpense on projectExpense.teamId = t.id" | |||||
| + " where t.deleted = 0" | + " where t.deleted = 0" | ||||
| + " and i.cid is not null" | + " and i.cid is not null" | ||||
| ) | ) | ||||
| @@ -1212,7 +1252,9 @@ open class DashboardService( | |||||
| + " s3.name as subsidiaryName," | + " s3.name as subsidiaryName," | ||||
| + " p.expectedTotalFee as totalFee," | + " p.expectedTotalFee as totalFee," | ||||
| + " round((p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8,2) as totalBudget," | + " round((p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8,2) as totalBudget," | ||||
| + " COALESCE(round(expenditure.cumulativeExpenditure,2),0) as cumulativeExpenditure," | |||||
| + " COALESCE(round(expenditure.cumulativeExpenditure + projectExpense.amount,2),0) as totalExpenditure," | |||||
| + " COALESCE(round(expenditure.cumulativeExpenditure,2),0) as manhoursExpenditure," | |||||
| + " COALESCE(round(projectExpense.amount,2),0) as projectExpense," | |||||
| + " coalesce(sum(i.issueAmount),0) as totalInvoiced," | + " coalesce(sum(i.issueAmount),0) as totalInvoiced," | ||||
| + " coalesce(sum(i.paidAmount),0) as totalReceived," | + " coalesce(sum(i.paidAmount),0) as totalReceived," | ||||
| + " case" | + " case" | ||||
| @@ -1282,6 +1324,16 @@ open class DashboardService( | |||||
| + " ) as r" | + " ) as r" | ||||
| + " group by r.teamId, r.customerId, r.projectId" | + " group by r.teamId, r.customerId, r.projectId" | ||||
| + " ) as expenditure on expenditure.teamId = t.id and expenditure.customerId = c.id and expenditure.projectId = p.id" | + " ) as expenditure on expenditure.teamId = t.id and expenditure.customerId = c.id and expenditure.projectId = p.id" | ||||
| + " left join (" | |||||
| + " select" | |||||
| + " t4.id as teamId," | |||||
| + " sum(pe.amount) as amount" | |||||
| + " from team t4" | |||||
| + " left join project p4 on t4.teamLead = p4.teamLead" | |||||
| + " left join project_expense pe on pe.projectId = p4.id" | |||||
| + " where p4.status = 'On-going'" | |||||
| + " group by t4.id" | |||||
| + " ) as projectExpense on projectExpense.teamId = t.id" | |||||
| + " where t.deleted = 0" | + " where t.deleted = 0" | ||||
| + " and p.status = 'On-going'" | + " and p.status = 'On-going'" | ||||
| ) | ) | ||||