|
@@ -1983,6 +1983,78 @@ open class DashboardService( |
|
|
|
|
|
|
|
|
return jdbcDao.queryForList(sql.toString(), args) |
|
|
return jdbcDao.queryForList(sql.toString(), args) |
|
|
} |
|
|
} |
|
|
|
|
|
fun CompanyTeamCashFlowSQL(args: Map<String, Any>): List<Map<String, Any>> { |
|
|
|
|
|
val sql = StringBuilder("with projectExpense as (" |
|
|
|
|
|
+ " select " |
|
|
|
|
|
+ " month(pe.issueDate) as month, " |
|
|
|
|
|
+ " sum(pe.amount) as projectExpense " |
|
|
|
|
|
+ " from project_expense pe " |
|
|
|
|
|
+ " left join project p on p.code = pe.projectId " |
|
|
|
|
|
+ " left join staff s on s.id = p.teamLead " |
|
|
|
|
|
+ " where pe.deleted = false " |
|
|
|
|
|
+ " and year(pe.issueDate) = :year " |
|
|
|
|
|
+ (if (args["teamId"] != null) " and s.teamId = :teamId " else "") |
|
|
|
|
|
+ " group by month " |
|
|
|
|
|
+ " ) " |
|
|
|
|
|
+ " , invoice as ( " |
|
|
|
|
|
+ " select " |
|
|
|
|
|
+ " month(receiptDate) as month, " |
|
|
|
|
|
+ " sum(issueAmount) as income " |
|
|
|
|
|
+ " from invoice i " |
|
|
|
|
|
+ " left join project p on p.code = i.projectCode " |
|
|
|
|
|
+ " left join staff s on s.id = p.teamLead " |
|
|
|
|
|
+ " where i.deleted = false " |
|
|
|
|
|
+ " and year(i.receiptDate) = :year " |
|
|
|
|
|
+ (if (args["teamId"] != null) " and s.teamId = :teamId " else "") |
|
|
|
|
|
+ " group by month " |
|
|
|
|
|
+ " ) " |
|
|
|
|
|
+ " , manpowerExpense as ( " |
|
|
|
|
|
+ " with p_cte as ( " |
|
|
|
|
|
+ " select " |
|
|
|
|
|
+ " p.*, " |
|
|
|
|
|
+ " s.teamId " |
|
|
|
|
|
+ " from project p " |
|
|
|
|
|
+ " left join staff s on s.id = p.teamLead " |
|
|
|
|
|
+ " where p.deleted = false " |
|
|
|
|
|
+ (if (args["teamId"] != null) " and s.teamId = :teamId " else "") |
|
|
|
|
|
+ " ) " |
|
|
|
|
|
+ " select " |
|
|
|
|
|
+ " month(t.recordDate) as month, " |
|
|
|
|
|
+ " SUM( " |
|
|
|
|
|
+ " (COALESCE(t.normalConsumed, 0) + COALESCE(t.otConsumed, 0)) * " |
|
|
|
|
|
+ " COALESCE(sal.hourlyRate, sal2.hourlyRate) * " |
|
|
|
|
|
+ " CASE " |
|
|
|
|
|
+ " WHEN tl.teamId != p.teamId THEN 1.15 " |
|
|
|
|
|
+ " ELSE 1 " |
|
|
|
|
|
+ " END " |
|
|
|
|
|
+ " ) AS manpowerExpense " |
|
|
|
|
|
+ " from ( " |
|
|
|
|
|
+ " SELECT * " |
|
|
|
|
|
+ " FROM timesheet t " |
|
|
|
|
|
+ " where t.deleted = false " |
|
|
|
|
|
+ " and t.projectId is not null " |
|
|
|
|
|
+ " and year(t.recordDate) = :year " |
|
|
|
|
|
+ " ) t " |
|
|
|
|
|
+ " inner join p_cte p on p.id = t.projectId " |
|
|
|
|
|
+ " left join team_log tl on tl.staffId = t.staffId and t.recordDate >= tl.`from` AND (t.recordDate <= tl.`to` or tl.`to` is null) " |
|
|
|
|
|
+ " left JOIN salary_effective se ON se.staffId = t.staffId and t.recordDate between se.startDate AND se.endDate " |
|
|
|
|
|
+ " left join salary sal on sal.salaryPoint = se.salaryId " |
|
|
|
|
|
+ " left join staff s on s.id = t.staffId and se.id is null " |
|
|
|
|
|
+ " left join salary sal2 on sal2.salaryPoint = s.salaryId " |
|
|
|
|
|
+ " group by month " |
|
|
|
|
|
+ " ) " |
|
|
|
|
|
+ " select " |
|
|
|
|
|
+ " me.month, " |
|
|
|
|
|
+ " coalesce(me.manpowerExpense, 0) + coalesce(pe.projectExpense, 0) as expenditure, " |
|
|
|
|
|
+ " coalesce(i.income,0) as income, " |
|
|
|
|
|
+ " SUM(COALESCE(me.manpowerExpense, 0)) OVER (ORDER BY me.month) AS cumulativeExpenditure, " |
|
|
|
|
|
+ " SUM(COALESCE(i.income, 0)) OVER (ORDER BY me.month) AS cumulativeIncome " |
|
|
|
|
|
+ " from manpowerExpense me " |
|
|
|
|
|
+ " left join projectExpense pe on pe.month = me.month " |
|
|
|
|
|
+ " left join invoice i on i.month = me.month; " |
|
|
|
|
|
) |
|
|
|
|
|
return jdbcDao.queryForList(sql.toString(), args) |
|
|
|
|
|
} |
|
|
fun TeamCashFlowIncome(args: Map<String, Any>): List<Map<String, Any>> { |
|
|
fun TeamCashFlowIncome(args: Map<String, Any>): List<Map<String, Any>> { |
|
|
val sql = StringBuilder("select" |
|
|
val sql = StringBuilder("select" |
|
|
+ " months.month as monthInvoice," |
|
|
+ " months.month as monthInvoice," |
|
@@ -2844,7 +2916,7 @@ open class DashboardService( |
|
|
+ " from staff s" |
|
|
+ " from staff s" |
|
|
+ " left join staff_allocation sa on sa.staff_id = s.id" |
|
|
+ " left join staff_allocation sa on sa.staff_id = s.id" |
|
|
+ " left join project p on sa.project_id = p.id" |
|
|
+ " left join project p on sa.project_id = p.id" |
|
|
+ " left join timesheet t on p.id = t.projectId and s.id = t.staffId" |
|
|
|
|
|
|
|
|
+ " left join timesheet t on s.id = t.staffId" |
|
|
+ " where s.id = :staffId" |
|
|
+ " where s.id = :staffId" |
|
|
+ " and t.recordDate >= :startdate" |
|
|
+ " and t.recordDate >= :startdate" |
|
|
+ " and t.recordDate <= last_day(:startdate)" |
|
|
+ " and t.recordDate <= last_day(:startdate)" |
|
@@ -3444,13 +3516,18 @@ open class DashboardService( |
|
|
+ " from project p " |
|
|
+ " from project p " |
|
|
+ " left join staff s on s.id = p.teamLead " |
|
|
+ " left join staff s on s.id = p.teamLead " |
|
|
+ " where p.deleted = false " |
|
|
+ " where p.deleted = false " |
|
|
|
|
|
+ " and p.status = 'On-going' " |
|
|
+ " ) " |
|
|
+ " ) " |
|
|
+ " select " |
|
|
+ " select " |
|
|
+ " projectId, " |
|
|
+ " projectId, " |
|
|
+ " CASE WHEN tl.teamId = p.teamId " |
|
|
|
|
|
+ " then sum((coalesce(t.normalConsumed, 0) + coalesce(t.otConsumed, 0)) * coalesce(sal.hourlyRate, sal2.hourlyRate)) " |
|
|
|
|
|
+ " else sum((coalesce(t.normalConsumed, 0) + coalesce(t.otConsumed, 0)) * coalesce(sal.hourlyRate, sal2.hourlyRate)) " |
|
|
|
|
|
+ " end as manhourExpense " |
|
|
|
|
|
|
|
|
+ " SUM( " |
|
|
|
|
|
+ " (COALESCE(t.normalConsumed, 0) + COALESCE(t.otConsumed, 0)) * " |
|
|
|
|
|
+ " COALESCE(sal.hourlyRate, sal2.hourlyRate) * " |
|
|
|
|
|
+ " CASE " |
|
|
|
|
|
+ " WHEN tl.teamId != p.teamId THEN 1 " |
|
|
|
|
|
+ " ELSE 1 " |
|
|
|
|
|
+ " END " |
|
|
|
|
|
+ " ) AS manhourExpense " |
|
|
+ " from ( " |
|
|
+ " from ( " |
|
|
+ " SELECT * " |
|
|
+ " SELECT * " |
|
|
+ " FROM timesheet t " |
|
|
+ " FROM timesheet t " |
|
@@ -3461,12 +3538,12 @@ open class DashboardService( |
|
|
+ " and t.projectId is not null " |
|
|
+ " and t.projectId is not null " |
|
|
+ " ) t " |
|
|
+ " ) t " |
|
|
+ " left join p_cte p on p.id = t.projectId " |
|
|
+ " left join p_cte p on p.id = t.projectId " |
|
|
+ " left join team_log tl on tl.staffId = t.staffId and t.recordDate between tl.`from` AND tl.`to` " |
|
|
|
|
|
|
|
|
+ " left join team_log tl on tl.staffId = t.staffId and t.recordDate >= tl.`from` AND (t.recordDate <= tl.`to` or tl.`to` is null) " |
|
|
+ " left JOIN salary_effective se ON se.staffId = t.staffId and t.recordDate between se.startDate AND se.endDate " |
|
|
+ " left JOIN salary_effective se ON se.staffId = t.staffId and t.recordDate between se.startDate AND se.endDate " |
|
|
+ " left join salary sal on sal.salaryPoint = se.salaryId " |
|
|
+ " left join salary sal on sal.salaryPoint = se.salaryId " |
|
|
+ " left join staff s on s.id = t.staffId and se.id is null " |
|
|
+ " left join staff s on s.id = t.staffId and se.id is null " |
|
|
+ " left join salary sal2 on sal2.salaryPoint = s.salaryId " |
|
|
+ " left join salary sal2 on sal2.salaryPoint = s.salaryId " |
|
|
+ " GROUP BY t.projectId, tl.teamId, p.teamId " |
|
|
|
|
|
|
|
|
+ " GROUP BY t.projectId " |
|
|
+ " ) " |
|
|
+ " ) " |
|
|
// invoice data |
|
|
// invoice data |
|
|
+ " , invoice_data as ( " |
|
|
+ " , invoice_data as ( " |
|
@@ -3475,7 +3552,7 @@ open class DashboardService( |
|
|
+ " sum(coalesce(i.issueAmount, 0)) as invoicedAmount, " |
|
|
+ " sum(coalesce(i.issueAmount, 0)) as invoicedAmount, " |
|
|
+ " sum(coalesce(i.paidAmount, 0)) as paidAmount " |
|
|
+ " sum(coalesce(i.paidAmount, 0)) as paidAmount " |
|
|
+ " from invoice i " |
|
|
+ " from invoice i " |
|
|
+ " left join project p on p.code = i.projectCode " |
|
|
|
|
|
|
|
|
+ " inner join project p on p.code = i.projectCode and p.status = 'On-going' " |
|
|
+ " left join staff s on s.id = p.teamlead " |
|
|
+ " left join staff s on s.id = p.teamlead " |
|
|
+ " where i.deleted = false " |
|
|
+ " where i.deleted = false " |
|
|
+ (if (args.containsKey("startDate") && args.containsKey("endDate")) " and i.invoiceDate between :startDate AND :endDate " |
|
|
+ (if (args.containsKey("startDate") && args.containsKey("endDate")) " and i.invoiceDate between :startDate AND :endDate " |
|
@@ -3489,7 +3566,7 @@ open class DashboardService( |
|
|
+ " pe.projectId, " |
|
|
+ " pe.projectId, " |
|
|
+ " sum(amount) as projectExpense " |
|
|
+ " sum(amount) as projectExpense " |
|
|
+ " from project_expense pe " |
|
|
+ " from project_expense pe " |
|
|
+ " left join project p on p.id = pe.projectId " |
|
|
|
|
|
|
|
|
+ " left join project p on p.id = pe.projectId and p.status = 'On-going' " |
|
|
+ " left join staff s on s.id = p.teamlead " |
|
|
+ " left join staff s on s.id = p.teamlead " |
|
|
+ " where pe.deleted = false " |
|
|
+ " where pe.deleted = false " |
|
|
+ (if (args.containsKey("startDate") && args.containsKey("endDate")) " and pe.issueDate between :startDate AND :endDate " |
|
|
+ (if (args.containsKey("startDate") && args.containsKey("endDate")) " and pe.issueDate between :startDate AND :endDate " |
|
@@ -3525,7 +3602,7 @@ open class DashboardService( |
|
|
+ " left join invoice_data id on id.projectId = p.id " |
|
|
+ " left join invoice_data id on id.projectId = p.id " |
|
|
+ " left join project_expense pe on pe.projectId = p.id " |
|
|
+ " left join project_expense pe on pe.projectId = p.id " |
|
|
+ " where p.status = 'On-going' " |
|
|
+ " where p.status = 'On-going' " |
|
|
+ (if (args.containsKey("teamId")) "where s.teamId = :teamId" else "") |
|
|
|
|
|
|
|
|
+ (if (args.containsKey("teamId")) "and s.teamId = :teamId" else "") |
|
|
+ " order by p.id " |
|
|
+ " order by p.id " |
|
|
+ " ) result ") |
|
|
+ " ) result ") |
|
|
return jdbcDao.queryForList(sql.toString(), args) |
|
|
return jdbcDao.queryForList(sql.toString(), args) |
|
|