|
@@ -3924,13 +3924,25 @@ open class DashboardService( |
|
|
+ " ) " |
|
|
+ " ) " |
|
|
// invoice data |
|
|
// invoice data |
|
|
+ " , invoice_data as ( " |
|
|
+ " , invoice_data as ( " |
|
|
|
|
|
+ " with uninvoiced as ( " |
|
|
|
|
|
+ " select " |
|
|
|
|
|
+ " p.id as projectId, " |
|
|
|
|
|
+ " p.expectedTotalFee - sum(coalesce(i.issueAmount, 0)) as uninvoicedAmount " |
|
|
|
|
|
+ " from invoice i " |
|
|
|
|
|
+ " inner join project p on p.code = i.projectCode and p.status = 'On-going' " |
|
|
|
|
|
+ " where i.deleted = false " |
|
|
|
|
|
+ (if (args.containsKey("endDate")) " and i.invoiceDate <= :endDate " else "") |
|
|
|
|
|
+ " group by p.id, p.expectedTotalFee " |
|
|
|
|
|
+ " ) " |
|
|
+ " select " |
|
|
+ " select " |
|
|
+ " p.id as projectId, " |
|
|
+ " p.id as projectId, " |
|
|
+ " 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 " |
|
|
|
|
|
+ " ,u.uninvoicedAmount " |
|
|
+ " from invoice i " |
|
|
+ " from invoice i " |
|
|
+ " inner join project p on p.code = i.projectCode and p.status = 'On-going' " |
|
|
+ " 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 " |
|
|
|
|
|
+ " left join uninvoiced u on u.projectId = p.id " |
|
|
+ " 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 " |
|
|
else if (args.containsKey("endDate")) " and i.invoiceDate <= :endDate " |
|
|
else if (args.containsKey("endDate")) " and i.invoiceDate <= :endDate " |
|
@@ -3951,6 +3963,17 @@ open class DashboardService( |
|
|
else "") |
|
|
else "") |
|
|
+ " group by pe.projectId " |
|
|
+ " group by pe.projectId " |
|
|
+ " ) " |
|
|
+ " ) " |
|
|
|
|
|
+ " , projectFee as ( " |
|
|
|
|
|
+ " select " |
|
|
|
|
|
+ " m.projectId, " |
|
|
|
|
|
+ " sum(mp.amount) as projectFee " |
|
|
|
|
|
+ " from milestone_payment mp " |
|
|
|
|
|
+ " left join milestone m on m.id = mp.milestoneId " |
|
|
|
|
|
+ (if (args.containsKey("startDate") && args.containsKey("endDate")) " where mp.`date` >= :startDate and mp.`date` <= :endDate " |
|
|
|
|
|
else if (args.containsKey("endDate")) " where mp.`date` <= :endDate " |
|
|
|
|
|
else "") |
|
|
|
|
|
+ " group by m.projectId " |
|
|
|
|
|
+ " ) " |
|
|
+ " select " |
|
|
+ " select " |
|
|
+ " * " |
|
|
+ " * " |
|
|
+ " from ( " |
|
|
+ " from ( " |
|
@@ -3964,10 +3987,11 @@ open class DashboardService( |
|
|
+ " c.name as customerName, " |
|
|
+ " c.name as customerName, " |
|
|
+ " c.code as customerCode, " |
|
|
+ " c.code as customerCode, " |
|
|
+ " su.name as subsidiary, " |
|
|
+ " su.name as subsidiary, " |
|
|
+ " p.expectedTotalFee as totalFee, " |
|
|
|
|
|
+ " (p.expectedTotalFee - ifnull(p.subContractFee, 0)) * 0.8 as totalBudget, " |
|
|
|
|
|
|
|
|
+ " coalesce(pf.projectFee, 0) as totalFee, " |
|
|
|
|
|
+ " (coalesce(pf.projectFee, 0) - ifnull(p.subContractFee, 0)) * 0.8 as totalBudget, " |
|
|
+ " coalesce(me.manhourExpense, 0) as manhourExpense, " |
|
|
+ " coalesce(me.manhourExpense, 0) as manhourExpense, " |
|
|
+ " coalesce(id.invoicedAmount, 0) as invoicedAmount, " |
|
|
+ " coalesce(id.invoicedAmount, 0) as invoicedAmount, " |
|
|
|
|
|
+ " coalesce(id.uninvoicedAmount, 0) as uninvoicedAmount, " |
|
|
+ " coalesce(id.paidAmount, 0) as paidAmount, " |
|
|
+ " coalesce(id.paidAmount, 0) as paidAmount, " |
|
|
+ " coalesce(pe.projectExpense, 0) as projectExpense " |
|
|
+ " coalesce(pe.projectExpense, 0) as projectExpense " |
|
|
+ " from project p " |
|
|
+ " from project p " |
|
@@ -3978,7 +4002,9 @@ open class DashboardService( |
|
|
+ " left join manhourExpense me on me.projectId = p.id " |
|
|
+ " left join manhourExpense me on me.projectId = p.id " |
|
|
+ " 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 " |
|
|
|
|
|
+ " left join projectFee pf on pf.projectId = p.id " |
|
|
+ " where p.status = 'On-going' " |
|
|
+ " where p.status = 'On-going' " |
|
|
|
|
|
+ " and p.deleted = false " |
|
|
+ (if (args.containsKey("teamId")) "and s.teamId = :teamId" else "") |
|
|
+ (if (args.containsKey("teamId")) "and s.teamId = :teamId" else "") |
|
|
+ " order by p.code " |
|
|
+ " order by p.code " |
|
|
+ " ) result ") |
|
|
+ " ) result ") |
|
|