sql.append(" group by p.id, p.code, p.name, te.code, s.name, p.totalManhour, milestonePayment.comingPaymentMilestone")
sql.append(" group by p.id, p.code, p.name, te.code, s.name, p.totalManhour, milestonePayment.comingPaymentMilestone")
if (args["tableSorting"] == "ProjectName") {
sql.append(" ORDER BY p.name ASC")
} else if (args["tableSorting"] == "PercentageASC") {
sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/p.totalManhour)*100,2),0) asc")
} else if (args["tableSorting"] == "PercentageDESC") {
sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/p.totalManhour)*100,2),0) desc")
}
return jdbcDao.queryForList(sql.toString(), args)
return jdbcDao.queryForList(sql.toString(), args)
}
}
@@ -162,7 +171,13 @@ open class DashboardService(
// + " and (tg.name != '5. Miscellaneous' or tg.name is null)"
// + " and (tg.name != '5. Miscellaneous' or tg.name is null)"
+ " group by p.id, p.code, p.name, te.code, s.name, p.totalManhour, milestonePayment.comingPaymentMilestone"
+ " group by p.id, p.code, p.name, te.code, s.name, p.totalManhour, milestonePayment.comingPaymentMilestone"
)
)
if (args["tableSorting"] == "ProjectName") {
sql.append(" ORDER BY p.name ASC")
} else if (args["tableSorting"] == "PercentageASC") {
sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/p.totalManhour)*100,2),0) asc")
} else if (args["tableSorting"] == "PercentageDESC") {
sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/p.totalManhour)*100,2),0) desc")
}
return jdbcDao.queryForList(sql.toString(), args)
return jdbcDao.queryForList(sql.toString(), args)
}
}
@@ -315,9 +330,55 @@ open class DashboardService(
// + " and (tg.name != '5. Miscellaneous' or tg.name is null)"
// + " and (tg.name != '5. Miscellaneous' or tg.name is null)"
+ " group by p.id, p.code, p.name, te.code, s.name, p.totalManhour, milestonePayment.comingPaymentMilestone"
+ " group by p.id, p.code, p.name, te.code, s.name, p.totalManhour, milestonePayment.comingPaymentMilestone"
)
)
if (args["tableSorting"] == "ProjectName") {
sql.append(" ORDER BY p.name ASC")
} else if (args["tableSorting"] == "PercentageASC") {
sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/p.totalManhour)*100,2),0) asc")
} else if (args["tableSorting"] == "PercentageDESC") {
sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/p.totalManhour)*100,2),0) desc")
}
return jdbcDao.queryForList(sql.toString(), args)
}
fun searchTeamConsumption(args: Map<String, Any>): List<Map<String, Any>>
{
val sql = StringBuilder(
"select"
+ " ROW_NUMBER() OVER (ORDER BY te.code, s.name, project.budgetedManhour) AS id,"
+ " te.code as team,"
+ " s.name as teamLead,"
+ " project.budgetedManhour as budgetedManhour,"
+ " COALESCE (sum(t.normalConsumed) + sum(t.otConsumed),0) as spentManhour,"
+ " COALESCE (project.budgetedManhour - sum(t.normalConsumed) - sum(t.otConsumed),0) as remainedManhour,"
+ " coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/project.budgetedManhour)*100,2),0) as manhourConsumptionPercentage"
+ " from team te"
+ " left join project p on p.teamLead = te.teamLead"
+ " 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 te.teamLead = s.id"
+ " left join ("
+ " select sum(p2.totalManhour) as budgetedManhour"
+ " from team t2"
+ " left join project p2 on p2.teamLead = t2.teamLead"
+ " where p2.teamLead in (:teamIds)"
+ " ) as project on 1 = 1"
+ " where p.teamLead in (:teamIds)"
+ " and p.status not in ('Pending to Start','Completed','Deleted')"
+ " group by te.code, s.name, project.budgetedManhour"
)
if (args["tableSorting"] == "ProjectName") {
sql.append(" ORDER BY te.code ASC")
} else if (args["tableSorting"] == "PercentageASC") {
sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/project.budgetedManhour)*100,2),0) asc")
} else if (args["tableSorting"] == "PercentageDESC") {
sql.append(" ORDER BY coalesce (round(((sum(t.normalConsumed) + sum(t.otConsumed))/project.budgetedManhour)*100,2),0) desc")
}
return jdbcDao.queryForList(sql.toString(), args)
return jdbcDao.queryForList(sql.toString(), args)
}
}
fun searchFinancialSummaryCard(args: Map<String, Any>): List<Map<String, Any>> {
fun searchFinancialSummaryCard(args: Map<String, Any>): List<Map<String, Any>> {
val sql = StringBuilder(
val sql = StringBuilder(
"select"
"select"
@@ -327,13 +388,19 @@ open class DashboardService(
+ " coalesce(pj.totalFee,0) as totalFee,"
+ " coalesce(pj.totalFee,0) as totalFee,"
+ " coalesce(pj.totalBudget,0) as totalBudget,"
+ " coalesce(pj.totalBudget,0) as totalBudget,"
+ " 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(sum(i.paidAmount),0) as totalReceived,"
+ " coalesce(sum(i.paidAmount),0) as totalReceived,"
+ " round(expenditure.cumulativeExpenditure,2) as cumulativeExpenditure,"
+ " round(expenditure.cumulativeExpenditure,2) as cumulativeExpenditure,"
+ " case"
+ " case"
+ " when coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2),0) >= 1 then 'Positive'"
+ " when coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2),0) >= 1 then 'Positive'"
+ " when coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2),0) < 1 then 'Negative'"
+ " when coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2),0) < 1 then 'Negative'"
+ " end as cashFlowStatus,"
+ " end as cashFlowStatus,"
+ " coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2),0) as cpi"
+ " coalesce(round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2),0) as cpi,"
+ " coalesce(round(coalesce(pj.totalFee,0) / (expenditure.cumulativeExpenditure),2),0) as projectedCpi,"
+ " case"
+ " when coalesce(round(coalesce(pj.totalFee,0) / (expenditure.cumulativeExpenditure),2),0) >= 1 then 'Positive'"
+ " when coalesce(round(coalesce(pj.totalFee,0) / (expenditure.cumulativeExpenditure),2),0) < 1 then 'Negative'"
+ " end as projectedCashFlowStatus"
+ " from team t"
+ " from team t"
+ " left join ("
+ " left join ("
+ " select"
+ " select"
@@ -404,12 +471,18 @@ open class DashboardService(
+ " round(sum(p.expectedTotalFee) * 0.8,2) as totalBudget,"
+ " round(sum(p.expectedTotalFee) * 0.8,2) as totalBudget,"
+ " round(expenditure.cumulativeExpenditure,2) as cumulativeExpenditure,"
+ " round(expenditure.cumulativeExpenditure,2) as cumulativeExpenditure,"
+ " sum(i.issueAmount) as totalInvoiced,"
+ " sum(i.issueAmount) as totalInvoiced,"
+ " sum(p.expectedTotalFee) - sum(i.issueAmount) as unInvoiced,"
+ " sum(i.paidAmount) as totalReceived,"
+ " sum(i.paidAmount) as totalReceived,"
+ " case"
+ " case"
+ " when round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2) >= 1 then 'Positive'"
+ " when round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2) >= 1 then 'Positive'"
+ " when round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2) < 1 then 'Negative'"
+ " when round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2) < 1 then 'Negative'"
+ " end as cashFlowStatus,"
+ " end as cashFlowStatus,"
+ " round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2) as cpi"
+ " round(sum(i.issueAmount) / (expenditure.cumulativeExpenditure),2) as cpi,"
+ " round(sum(p.expectedTotalFee) / (expenditure.cumulativeExpenditure),2) as projectedCpi,"
+ " case"
+ " when round(sum(p.expectedTotalFee) / (expenditure.cumulativeExpenditure),2) >= 1 then 'Positive'"
+ " when round(sum(p.expectedTotalFee) / (expenditure.cumulativeExpenditure),2) < 1 then 'Negative'"
+ " end as projectedCashFlowStatus"
+ " from project p"
+ " from project p"
+ " left join ("
+ " left join ("
+ " select"
+ " select"
@@ -550,6 +623,11 @@ open class DashboardService(
+ " when coalesce(round(sum(i.issueAmount) / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) < 1 then 'Negative'"
+ " when coalesce(round(sum(i.issueAmount) / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) < 1 then 'Negative'"
+ " end as cashFlowStatus,"
+ " end as cashFlowStatus,"
+ " coalesce(round(sum(i.issueAmount) / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) as cpi,"
+ " coalesce(round(sum(i.issueAmount) / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) as cpi,"
+ " coalesce(round(p.totalFee / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) as projectedCpi,"
+ " case"
+ " when coalesce(round(p.totalFee / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) >= 1 then 'Positive'"
+ " when coalesce(round(p.totalFee / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) < 1 then 'Negative'"
+ " end as projectedCashFlowStatus,"
+ " case"
+ " case"
+ " when p.totalFee - sum(i.issueAmount) >= 0 then coalesce(round(p.totalFee - sum(i.issueAmount),2),0)"
+ " when p.totalFee - sum(i.issueAmount) >= 0 then coalesce(round(p.totalFee - sum(i.issueAmount),2),0)"
+ " when p.totalFee - sum(i.issueAmount) < 0 then 0"
+ " when p.totalFee - sum(i.issueAmount) < 0 then 0"
@@ -653,6 +731,11 @@ open class DashboardService(
+ " when coalesce(round(sum(i.issueAmount) / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) < 1 then 'Negative'"
+ " when coalesce(round(sum(i.issueAmount) / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) < 1 then 'Negative'"
+ " end as cashFlowStatus,"
+ " end as cashFlowStatus,"
+ " coalesce(round(sum(i.issueAmount) / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) as cpi,"
+ " coalesce(round(sum(i.issueAmount) / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) as cpi,"
+ " coalesce(round(p.expectedTotalFee / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) as projectedCpi,"
+ " case"
+ " when coalesce(round(p.expectedTotalFee / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) >= 1 then 'Positive'"
+ " when coalesce(round(p.expectedTotalFee / (COALESCE(expenditure.cumulativeExpenditure,0)),2),0) < 1 then 'Negative'"
+ " end as projectedCashFlowStatus,"
// + " case"
// + " case"
// + " when coalesce(round(sum(p.expectedTotalFee) * 0.8,2),0) <= COALESCE(expenditure.cumulativeExpenditure,0) then coalesce(round(sum(p.expectedTotalFee) * 0.8,2),0) - coalesce(sum(i.issueAmount),0)"
// + " when coalesce(round(sum(p.expectedTotalFee) * 0.8,2),0) <= COALESCE(expenditure.cumulativeExpenditure,0) then coalesce(round(sum(p.expectedTotalFee) * 0.8,2),0) - coalesce(sum(i.issueAmount),0)"
// + " when coalesce(round(sum(p.expectedTotalFee) * 0.8,2),0) > COALESCE(expenditure.cumulativeExpenditure,0) and COALESCE(expenditure.cumulativeExpenditure,0) < coalesce(sum(i.issueAmount),0) then 0"
// + " when coalesce(round(sum(p.expectedTotalFee) * 0.8,2),0) > COALESCE(expenditure.cumulativeExpenditure,0) and COALESCE(expenditure.cumulativeExpenditure,0) < coalesce(sum(i.issueAmount),0) then 0"
@@ -850,7 +933,9 @@ open class DashboardService(
+ " coalesce (sum(i.issueAmount) - sum(i.paidAmount),0) as receivable,"
+ " coalesce (sum(i.issueAmount) - sum(i.paidAmount),0) as receivable,"
+ " coalesce (round(sum(p.expectedTotalFee)*0.8,2),0) as totalBudget,"
+ " coalesce (round(sum(p.expectedTotalFee)*0.8,2),0) as totalBudget,"
+ " coalesce (expenditure.expenditure,0) as totalExpenditure,"
+ " coalesce (expenditure.expenditure,0) as totalExpenditure,"
+ " coalesce (sum(p.expectedTotalFee)*0.8 - expenditure.expenditure,0) as expenditureReceivable"
+ " coalesce (sum(p.expectedTotalFee)*0.8 - expenditure.expenditure,0) as expenditureReceivable,"
+ " sum(p.expectedTotalFee) as totalProjectFee,"
+ " coalesce (round(sum(i.issueAmount)/sum(p.expectedTotalFee)*100,0),0) as invoicedPercentage"
+ " from project p"
+ " from project p"
+ " left join ("
+ " left join ("
+ " select"
+ " select"
@@ -1194,7 +1279,9 @@ open class DashboardService(
"select"
"select"
+ " concat(p.code,'-',p.name) as projectCodeAndName,"
+ " concat(p.code,'-',p.name) as projectCodeAndName,"
+ " p.expectedTotalFee as totalFee,"
+ " p.expectedTotalFee as totalFee,"
+ " expenditure.expenditure as expenditure,"
+ " p.expectedTotalFee * 0.8 as totalBudget,"
+ " coalesce (expenditure.expenditure,0) as expenditure,"
+ " (p.expectedTotalFee * 0.8) - coalesce (expenditure.expenditure,0) as remainingBudget,"
+ " case"
+ " case"
+ " when p.expectedTotalFee - expenditure.expenditure >= 0 then 'Within Budget'"
+ " when p.expectedTotalFee - expenditure.expenditure >= 0 then 'Within Budget'"
+ " when p.expectedTotalFee - expenditure.expenditure < 0 then 'Overconsumption'"
+ " when p.expectedTotalFee - expenditure.expenditure < 0 then 'Overconsumption'"