|
@@ -2117,46 +2117,31 @@ 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( |
|
|
val sql = StringBuilder( |
|
|
"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.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8 as plannedBudget, " |
|
|
|
|
|
+ " sum(t.consumedBudget) as actualConsumedBudget, " |
|
|
|
|
|
+ " 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.normalConsumed + COALESCE(t.otConsumed, 0)) / COALESCE(p.totalManhour, 0) as manhourConsumptionRate, " |
|
|
|
|
|
+ " case " |
|
|
|
|
|
+ " when sum(t.consumedBudget) / ((p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8) >= 1 " |
|
|
|
|
|
+ " or (sum(t.normalConsumed + COALESCE(t.otConsumed, 0)) / COALESCE(p.totalManhour, 0)) >= 1 " |
|
|
|
|
|
+ " then 'Overconsumption' " |
|
|
|
|
|
+ " when sum(t.consumedBudget) / ((p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8) >= :lowerLimit and sum(t.consumedBudget) / ((p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8) <= 1 " |
|
|
|
|
|
+ " or (sum(t.normalConsumed + COALESCE(t.otConsumed, 0)) / COALESCE(p.totalManhour, 0)) >= :lowerLimit and (sum(t.normalConsumed + COALESCE(t.otConsumed, 0)) / COALESCE(p.totalManhour, 0)) <= 1 " |
|
|
|
|
|
+ " then 'Potential Overconsumption' " |
|
|
|
|
|
+ " else 'Within Budget' " |
|
|
|
|
|
+ " END as status " |
|
|
|
|
|
+ " from " |
|
|
|
|
|
+ " (SELECT t.*, (t.normalConsumed + COALESCE(t.otConsumed, 0)) * sal.hourlyRate as consumedBudget " |
|
|
|
|
|
+ " FROM " |
|
|
|
|
|
+ " ( " |
|
|
|
|
|
+ " SELECT t.id AS tid, max(se.date) AS max_date " |
|
|
|
|
|
+ " FROM timesheet t " |
|
|
|
|
|
+ " INNER JOIN salary_effective se ON se.staffId = t.staffId AND se.date <= t.recordDate " |
|
|
|
|
|
+ " GROUP BY t.id " |
|
|
|
|
|
+ " ) max_se " |
|
|
|
|
|
+ " LEFT JOIN timesheet t ON t.id = max_se.tid " |
|
|
|
|
|
+ " LEFT JOIN staff s on s.id = t.staffId " |
|
|
|
|
|
+ " inner join salary_effective se on se.date = max_se.max_date " |
|
|
|
|
|
+ " left join salary sal on se.salaryId = sal.salaryPoint) t " |
|
|
|
|
|
+ " left join project p on p.id = t.projectId " |
|
|
|
|
|
+ " left join team tm on p.teamLead = tm.teamLead " |
|
|
|
|
|
+ " left join customer c on c.id = p.customerId " |
|
|
|
|
|
+ " LEFT JOIN subsidiary ss on p.customerSubsidiaryId = ss.id " |
|
|
|
|
|
+ " WHERE p.deleted = false " |
|
|
|
|
|
+ " and p.status = 'On-going' " |
|
|
|
|
|
|
|
|
" 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.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8 as plannedBudget, sum(t.consumedBudget) as actualConsumedBudget " |
|
|
|
|
|
+ " , 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.normalConsumed + COALESCE(t.otConsumed, 0)) / COALESCE(p.totalManhour, 0) as manhourConsumptionRate " |
|
|
|
|
|
+ " , case when sum(t.consumedBudget) / ((p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8) >= 1 " |
|
|
|
|
|
+ " or (sum(t.normalConsumed + COALESCE(t.otConsumed,0)) / COALESCE(p.totalManhour,0)) >= 1 " |
|
|
|
|
|
+ " then'Overconsumption' when sum(t.consumedBudget)/ ((p.expectedTotalFee - ifnull(p.subContractFee,0)) * 0.8) >= :lowerLimit " |
|
|
|
|
|
+ " and sum(t.consumedBudget)/ ((p.expectedTotalFee - ifnull(p.subContractFee,0)) * 0.8) <= 1 " |
|
|
|
|
|
+ " or(sum(t.normalConsumed+COALESCE(t.otConsumed, 0))/ COALESCE(p.totalManhour, 0)) >= :lowerLimit " |
|
|
|
|
|
+ " and (sum(t.normalConsumed+COALESCE(t.otConsumed, 0))/ COALESCE(p.totalManhour, 0)) <= 1 " |
|
|
|
|
|
+ " then'Potential Overconsumption' else'Within Budget' END as status " |
|
|
|
|
|
+ " from " |
|
|
|
|
|
+ " ( " |
|
|
|
|
|
+ " SELECT t.*, (t.normalConsumed+COALESCE(t.otConsumed, 0)) * sal.hourlyRate as consumedBudget " |
|
|
|
|
|
+ " FROM timesheet t " |
|
|
|
|
|
+ " INNER JOIN salary_effective se ON se.staffId = t.staffId AND t.recordDate BETWEEN se.startDate AND se.endDate " |
|
|
|
|
|
+ " LEFT JOIN salary sal on se.salaryId = sal.salaryPoint " |
|
|
|
|
|
+ " ) t " |
|
|
|
|
|
+ " left join project p on p.id = t.projectId " |
|
|
|
|
|
+ " left join team tm on p.teamLead = tm.teamLead " |
|
|
|
|
|
+ " left join customer c on c.id = p.customerId " |
|
|
|
|
|
+ " left join subsidiary ss on p.customerSubsidiaryId = ss.id " |
|
|
|
|
|
+ " WHERE p.deleted = false and p.status ='On-going' " |
|
|
) |
|
|
) |
|
|
var statusFilter: String = "" |
|
|
var statusFilter: String = "" |
|
|
if (args != null) { |
|
|
if (args != null) { |
|
|