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 3f1d849..95432ae 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 @@ -2555,11 +2555,20 @@ open class ReportService( + " left join salary s2 on s.salaryId = s2.salaryPoint" + " group by p.code" + " )," - + " cte_invoice as (" - + " select p.code, sum(i.issueAmount) as sumIssuedAmount , sum(i.paidAmount) as sumPaidAmount" + + " cte_Iinvoice as (" + + " select p.code, sum(i.issueAmount) as sumIssuedAmount" + " from invoice i" + " left join project p on p.code = i.projectCode" + " where i.deleted = false " + + " and (DATE_FORMAT(i.invoiceDate, '%Y-%m') >= :startMonth and DATE_FORMAT(i.invoiceDate, '%Y-%m') <= :endMonth) " + + " group by p.code" + + " )," + + " cte_Rinvoice as (" + + " select p.code, sum(i.paidAmount) as sumPaidAmount" + + " from invoice i" + + " left join project p on p.code = i.projectCode" + + " where i.deleted = false " + + " and (DATE_FORMAT(i.receiptDate, '%Y-%m') >= :startMonth and DATE_FORMAT(i.receiptDate, '%Y-%m') <= :endMonth) " + " group by p.code" + " )," + " cte_expense as ( " @@ -2571,15 +2580,16 @@ open class ReportService( + " select p.code, p.description, c.name as client, IFNULL(s2.name, \"N/A\") as subsidiary, concat(t.code, \" - \", t.name) as teamLead," + " IFNULL(cte_ts.normalConsumed, 0) as normalConsumed, IFNULL(cte_ts.otConsumed, 0) as otConsumed, DATE_FORMAT(cte_ts.recordDate, '%Y-%m') as recordDate, " + " IFNULL(cte_ts.salaryPoint, 0) as salaryPoint, " - + " (p.expectedTotalFee - IFNULL(cte_i.sumIssuedAmount, 0)) as expectedTotalFee, " - + " IFNULL(cte_ts.hourlyRate, 0) as hourlyRate, IFNULL(cte_i.sumIssuedAmount, 0) as sumIssuedAmount, IFNULL(cte_i.sumPaidAmount, 0) as sumPaidAmount, IFNULL(cte_tss.sumManhourExpenditure, 0) as sumManhourExpenditure," + + " (p.expectedTotalFee - IFNULL(cte_Ii.sumIssuedAmount, 0)) as expectedTotalFee, " + + " IFNULL(cte_ts.hourlyRate, 0) as hourlyRate, IFNULL(cte_Ii.sumIssuedAmount, 0) as sumIssuedAmount, IFNULL(cte_Ri.sumPaidAmount, 0) as sumPaidAmount, IFNULL(cte_tss.sumManhourExpenditure, 0) as sumManhourExpenditure," + " s.name, s.staffId, g.code as gradeCode, g.name as gradeName, t2.code as teamCode, t2.name as teamName, cte_e.amount " + " from project p" + " left join cte_timesheet cte_ts on p.code = cte_ts.code" + " left join cte_timesheet_sum cte_tss on p.code = cte_tss.code" + " left join customer c on c.id = p.customerId" + " left join tsmsdb.team t on t.teamLead = p.teamLead" - + " left join cte_invoice cte_i on cte_i.code = p.code" + + " left join cte_Iinvoice cte_Ii on cte_Ii.code = p.code" + + " left join cte_Rinvoice cte_Ri on cte_Ri.code = p.code" + " 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"