|
|
@@ -1801,4 +1801,73 @@ open class ReportService( |
|
|
|
return workbook |
|
|
|
} |
|
|
|
|
|
|
|
fun getCostAndExpense(status: String): List<Map<String,Any?>>{ |
|
|
|
val sql = StringBuilder( |
|
|
|
" with cte_timesheet as ( " |
|
|
|
+ " Select p.code, s.name as staff, IFNULL(t.normalConsumed, 0) as normalConsumed, IFNULL(t.otConsumed , 0) as otConsumed, s2.salaryPoint, s2.hourlyRate, t.staffId," |
|
|
|
+ " t.recordDate" |
|
|
|
+ " from timesheet t" |
|
|
|
+ " left join project_task pt on pt.id = t.projectTaskId" |
|
|
|
+ " left join project p ON p.id = pt.project_id" |
|
|
|
+ " left join staff s on s.id = t.staffId" |
|
|
|
+ " left join salary s2 on s.salaryId = s2.salaryPoint" |
|
|
|
+ " left join team t2 on t2.id = s.teamId" |
|
|
|
+ " )" |
|
|
|
+ " select p.code, p.description, c.name as client, concat(t.code, \' - \', t.name) as teamLead, p.expectedTotalFee," |
|
|
|
+ " SUM(IFNULL(cte_ts.normalConsumed, 0)) as normalConsumed," |
|
|
|
+ " SUM(IFNULL(cte_ts.otConsumed, 0)) as otConsumed," |
|
|
|
+ " IFNULL(cte_ts.hourlyRate, 0) as hourlyRate" |
|
|
|
+ " from project p" |
|
|
|
+ " left join cte_timesheet cte_ts on p.code = cte_ts.code" |
|
|
|
+ " left join customer c on c.id = p.customerId" |
|
|
|
+ " left join tsmsdb.team t on t.teamLead = p.teamLead" |
|
|
|
+ " left join staff s on s.id = cte_ts.staffId" |
|
|
|
+ " left join grade g on g.id = s.gradeId" |
|
|
|
+ " left join team t2 on t2.id = s.teamId" |
|
|
|
+ " where ISNULL(p.code) = False" |
|
|
|
) |
|
|
|
if(status != "All"){ |
|
|
|
sql.append( |
|
|
|
" and p.status = :status" |
|
|
|
) |
|
|
|
} |
|
|
|
sql.append( |
|
|
|
" group by p.code, p.description , c.name, teamLead, p.expectedTotalFee , hourlyRate" + " order by p.code" |
|
|
|
) |
|
|
|
|
|
|
|
val args = mapOf( |
|
|
|
"status" to status |
|
|
|
) |
|
|
|
|
|
|
|
val otFactor = BigDecimal(1).toDouble() |
|
|
|
val queryList = jdbcDao.queryForList(sql.toString(), args) |
|
|
|
val costAndExpenseList = mutableListOf<Map<String, Any?>>() |
|
|
|
|
|
|
|
for(item in queryList){ |
|
|
|
val hourlyRate = (item.getValue("hourlyRate") as BigDecimal).toDouble() |
|
|
|
if(item["code"] !in costAndExpenseList){ |
|
|
|
costAndExpenseList.add( |
|
|
|
mapOf( |
|
|
|
"code" to item["code"], |
|
|
|
"description" to item["description"], |
|
|
|
"client" to item["client"], |
|
|
|
"teamLead" to item["teamLead"], |
|
|
|
"budget" to item["expectedTotalFee"], |
|
|
|
"totalManhours" to item["normalConsumed"] as Double + item["otConsumed"] as Double, |
|
|
|
"manhourExpenditure" to (hourlyRate * item["normalConsumed"] as Double ) |
|
|
|
+ (hourlyRate * item["otConsumed"]as Double * otFactor) |
|
|
|
) |
|
|
|
) |
|
|
|
}else{ |
|
|
|
val existingMap = costAndExpenseList.find { it.containsValue(item["code"]) }!! |
|
|
|
costAndExpenseList[costAndExpenseList.indexOf(existingMap)] = existingMap.toMutableMap().apply { |
|
|
|
put("totalManhours", get("manhours") as Double + (item["normalConsumed"] as Double + item["otConsumed"] as Double)) |
|
|
|
put("manhourExpenditure", get("manhourExpenditure") as Double + ((hourlyRate * item["normalConsumed"] as Double ) |
|
|
|
+ (hourlyRate * item["otConsumed"]as Double * otFactor))) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return costAndExpenseList |
|
|
|
} |
|
|
|
} |