From cb7848cbb4c3e4944b4660d00d9bf020f3044787 Mon Sep 17 00:00:00 2001 From: "DESKTOP\\derek" Date: Tue, 17 Sep 2024 12:30:00 +0800 Subject: [PATCH 1/2] update --- .../java/com/ffii/tsms/modules/report/service/ReportService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt index 528ddb8..387f165 100644 --- a/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt +++ b/src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt @@ -2038,7 +2038,7 @@ open class ReportService( val sql = StringBuilder( "SELECT" + " CAST(DATE_FORMAT(t.recordDate, '%d') AS SIGNED) AS recordDate, " - + " sum(t.normalConsumed) + sum(t.otConsumed) as totalConsumed " + + " coalesce(sum(t.normalConsumed), 0) + coalesce(sum(t.otConsumed), 0) " + " from timesheet t " + " left join project p on p.id = t.projectId " + " where t.staffId = :staffId " From 98d9689b3bd9d6c227bb00c10b240767e13202c6 Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Tue, 17 Sep 2024 12:39:46 +0800 Subject: [PATCH 2/2] update --- .../modules/data/service/DashboardService.kt | 127 ++++++++++-------- 1 file changed, 69 insertions(+), 58 deletions(-) diff --git a/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt b/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt index db036c0..91af2fa 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/DashboardService.kt @@ -1564,6 +1564,7 @@ open class DashboardService( return jdbcDao.queryForList(sql.toString(), args) } + fun CashFlowReceivableAndExpenditure(args: Map): List> { 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)