|
|
@@ -1564,6 +1564,7 @@ open class DashboardService( |
|
|
|
return jdbcDao.queryForList(sql.toString(), args) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun CashFlowReceivableAndExpenditure(args: Map<String, Any>): List<Map<String, Any>> { |
|
|
|
val sql = StringBuilder( |
|
|
|
// "select" |
|
|
@@ -1607,64 +1608,74 @@ open class DashboardService( |
|
|
|
// + " ) as expenditure on 1=1" |
|
|
|
// + " where p.id in (:projectIds)" |
|
|
|
// + " group by expenditure.expenditure" |
|
|
|
" select" |
|
|
|
+ " coalesce (round(sum(i.paidAmount)/sum(i.issueAmount)*100,0),0) as receivedPercentage," |
|
|
|
+ " coalesce (round(expenditure.expenditure/((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*0.8)*100,0),0) as expenditurePercentage," |
|
|
|
+ " coalesce (sum(i.issueAmount),0) as totalInvoiced," |
|
|
|
+ " coalesce (sum(i.paidAmount),0) as totalReceived," |
|
|
|
+ " coalesce (sum(i.issueAmount) - sum(i.paidAmount),0) as receivable," |
|
|
|
+ " coalesce (round((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*0.8,2),0) as totalBudget," |
|
|
|
+ " coalesce (expenditure.expenditure,0) as totalExpenditure," |
|
|
|
+ " coalesce ((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*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" |
|
|
|
+ " left join (" |
|
|
|
+ " select" |
|
|
|
+ " p3.id as pid," |
|
|
|
+ " sum(i3.issueAmount) as issueAmount," |
|
|
|
+ " sum(i3.paidAmount) as paidAmount" |
|
|
|
+ " from project p3" |
|
|
|
+ " left join invoice i3 on p3.code = i3.projectCode" |
|
|
|
+ " where p3.deleted = 0" |
|
|
|
+ " and p3.status = 'On-going'" |
|
|
|
+ " and i3.deleted = 0" //update invoice deletable |
|
|
|
+ " group by p3.id" |
|
|
|
+ " ) as i on i.pid = p.id" |
|
|
|
+ " left join(" |
|
|
|
+ " select" |
|
|
|
+ " sum(r.expenditure) as expenditure" |
|
|
|
+ " from(" |
|
|
|
+ " select" |
|
|
|
+ " t3.id," |
|
|
|
+ " (coalesce(sum(t3.normalConsumed),0) * se.hourlyRate) + (coalesce(sum(t3.otConsumed),0) * se.hourlyRate * 1.0) as expenditure" |
|
|
|
+ " from (" |
|
|
|
+ " select" |
|
|
|
+ " t2.id as tid," |
|
|
|
+ " t2.recordDate as timesheet_record_date," |
|
|
|
+ " s.id as staff_id," |
|
|
|
+ " se.id as salary_effective_id," |
|
|
|
+ " se.salaryId," |
|
|
|
+ " se.startdate as salary_effective_start_date," |
|
|
|
+ " coalesce(se.enddate,now()) as salary_effective_end_date," |
|
|
|
+ " s2.hourlyRate as hourlyRate" |
|
|
|
+ " from project p" |
|
|
|
+ " left join project_task pt on p.id = pt.project_id" |
|
|
|
+ " left join timesheet t2 on pt.id = t2.projectTaskId" |
|
|
|
+ " left join staff s on t2.staffId = s.id" |
|
|
|
+ " left join salary_effective se on t2.recordDate >= se.`date` and s.id = se.staffId" |
|
|
|
+ " left join salary s2 on se.salaryId = s2.salaryPoint" |
|
|
|
+ " where t2.id is not null" |
|
|
|
+ " and p.id in (:projectIds)" |
|
|
|
+ " group by t2.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate" |
|
|
|
+ " ) as se" |
|
|
|
+ " left join timesheet t3 on se.tid = t3.id" |
|
|
|
+ " where t3.recordDate >= se.salary_effective_start_date and t3.recordDate <= se.salary_effective_end_date" |
|
|
|
+ " group by t3.id, se.hourlyRate" |
|
|
|
+ " ) as r" |
|
|
|
+ " ) as expenditure on 1=1" |
|
|
|
+ " where p.id in (:projectIds)" |
|
|
|
+ " group by expenditure.expenditure" |
|
|
|
"with pe_cte as (" |
|
|
|
+ " select" |
|
|
|
+ " pe.projectId," |
|
|
|
+ " sum(coalesce(amount)) as expense" |
|
|
|
+ " from project_expense pe" |
|
|
|
+ " where deleted = false" |
|
|
|
+ " group by pe.projectId" |
|
|
|
+ " )" |
|
|
|
+ " select" |
|
|
|
+ " group_concat(p.id) as ids," |
|
|
|
+ " sum(pc.expense) as expense," |
|
|
|
+ " coalesce (round(sum(i.paidAmount)/sum(i.issueAmount)*100,0),0) as receivedPercentage," |
|
|
|
+ " coalesce (round(expenditure.expenditure/((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*0.8)*100,0),0) as expenditurePercentage," |
|
|
|
+ " coalesce (sum(i.issueAmount),0) as totalInvoiced," |
|
|
|
+ " coalesce (sum(i.paidAmount),0) as totalReceived," |
|
|
|
+ " coalesce (sum(i.issueAmount) - sum(i.paidAmount),0) as receivable," |
|
|
|
+ " coalesce (round((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*0.8,2),0) as totalBudget," |
|
|
|
+ " coalesce (expenditure.expenditure + sum(pc.expense), 0) as totalExpenditure," |
|
|
|
+ " coalesce ((sum(p.expectedTotalFee) - sum(ifnull(p.subContractFee, 0)))*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" |
|
|
|
+ " left join pe_cte pc on pc.projectId = p.id" |
|
|
|
+ " left join (" |
|
|
|
+ " select" |
|
|
|
+ " p3.id as pid," |
|
|
|
+ " sum(i3.issueAmount) as issueAmount," |
|
|
|
+ " sum(i3.paidAmount) as paidAmount" |
|
|
|
+ " from project p3" |
|
|
|
+ " left join invoice i3 on p3.code = i3.projectCode" |
|
|
|
+ " where p3.deleted = 0" |
|
|
|
+ " and p3.status = 'On-going'" |
|
|
|
+ " and i3.deleted = 0 group by p3.id" |
|
|
|
+ " ) as i on i.pid = p.id" |
|
|
|
+ " left join(" |
|
|
|
+ " select" |
|
|
|
+ " sum(r.expenditure) as expenditure" |
|
|
|
+ " from(" |
|
|
|
+ " select" |
|
|
|
+ " t3.id," |
|
|
|
+ " (coalesce(sum(t3.normalConsumed),0) * se.hourlyRate) + (coalesce(sum(t3.otConsumed),0) * se.hourlyRate * 1.0) as expenditure" |
|
|
|
+ " from (" |
|
|
|
+ " select" |
|
|
|
+ " t2.id as tid," |
|
|
|
+ " t2.recordDate as timesheet_record_date," |
|
|
|
+ " s.id as staff_id," |
|
|
|
+ " se.id as salary_effective_id," |
|
|
|
+ " se.salaryId," |
|
|
|
+ " se.startdate as salary_effective_start_date," |
|
|
|
+ " coalesce(se.enddate,now()) as salary_effective_end_date," |
|
|
|
+ " s2.hourlyRate as hourlyRate" |
|
|
|
+ " from project p" |
|
|
|
+ " left join project_task pt on p.id = pt.project_id" |
|
|
|
+ " left join timesheet t2 on pt.id = t2.projectTaskId" |
|
|
|
+ " left join staff s on t2.staffId = s.id" |
|
|
|
+ " left join salary_effective se on t2.recordDate >= se.`date` and s.id = se.staffId" |
|
|
|
+ " left join salary s2 on se.salaryId = s2.salaryPoint" |
|
|
|
+ " where t2.id is not null" |
|
|
|
+ " and p.id in (:projectIds)" |
|
|
|
+ " group by t2.id, s.id, se.id, se.salaryId,se.date, s2.hourlyRate" |
|
|
|
+ " ) as se" |
|
|
|
+ " left join timesheet t3 on se.tid = t3.id" |
|
|
|
+ " where t3.recordDate >= se.salary_effective_start_date and t3.recordDate <= se.salary_effective_end_date" |
|
|
|
+ " group by t3.id, se.hourlyRate" |
|
|
|
+ " ) as r" |
|
|
|
+ " ) as expenditure on 1=1" |
|
|
|
+ " where p.id in (:projectIds)" |
|
|
|
+ " group by expenditure.expenditure" |
|
|
|
) |
|
|
|
|
|
|
|
return jdbcDao.queryForList(sql.toString(), args) |
|
|
|