|
@@ -42,9 +42,9 @@ open class ReportService( |
|
|
|
|
|
|
|
|
// ==============================|| GENERATE REPORT ||============================== // |
|
|
// ==============================|| GENERATE REPORT ||============================== // |
|
|
|
|
|
|
|
|
fun genFinancialStatusReport(projectId: Long): ByteArray { |
|
|
|
|
|
|
|
|
fun genFinancialStatusReport(teamLeadId: Long): ByteArray { |
|
|
|
|
|
|
|
|
val financialStatus: List<Map<String, Any>> = getFinancialStatus(projectId) |
|
|
|
|
|
|
|
|
val financialStatus: List<Map<String, Any>> = getFinancialStatus(teamLeadId) |
|
|
|
|
|
|
|
|
val otFactor = BigDecimal(1) |
|
|
val otFactor = BigDecimal(1) |
|
|
|
|
|
|
|
@@ -53,10 +53,10 @@ open class ReportService( |
|
|
for (item in financialStatus){ |
|
|
for (item in financialStatus){ |
|
|
val normalConsumed = item.getValue("normalConsumed") as Double |
|
|
val normalConsumed = item.getValue("normalConsumed") as Double |
|
|
val hourlyRate = item.getValue("hourlyRate") as BigDecimal |
|
|
val hourlyRate = item.getValue("hourlyRate") as BigDecimal |
|
|
println("normalConsumed------------- $normalConsumed") |
|
|
|
|
|
println("hourlyRate------------- $hourlyRate") |
|
|
|
|
|
|
|
|
// println("normalConsumed------------- $normalConsumed") |
|
|
|
|
|
// println("hourlyRate------------- $hourlyRate") |
|
|
val manHourRate = normalConsumed.toBigDecimal().multiply(hourlyRate) |
|
|
val manHourRate = normalConsumed.toBigDecimal().multiply(hourlyRate) |
|
|
println("manHourRate------------ $manHourRate") |
|
|
|
|
|
|
|
|
// println("manHourRate------------ $manHourRate") |
|
|
|
|
|
|
|
|
val otConsumed = item.getValue("otConsumed") as Double |
|
|
val otConsumed = item.getValue("otConsumed") as Double |
|
|
val manOtHourRate = otConsumed.toBigDecimal().multiply(hourlyRate).multiply(otFactor) |
|
|
val manOtHourRate = otConsumed.toBigDecimal().multiply(hourlyRate).multiply(otFactor) |
|
@@ -88,9 +88,9 @@ open class ReportService( |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
println("tempList---------------------- $tempList") |
|
|
|
|
|
|
|
|
// println("tempList---------------------- $tempList") |
|
|
|
|
|
|
|
|
val workbook: Workbook = createFinancialStatusReport(FINANCIAL_STATUS_REPORT, tempList) |
|
|
|
|
|
|
|
|
val workbook: Workbook = createFinancialStatusReport(FINANCIAL_STATUS_REPORT, tempList, teamLeadId) |
|
|
|
|
|
|
|
|
val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() |
|
|
val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() |
|
|
workbook.write(outputStream) |
|
|
workbook.write(outputStream) |
|
@@ -170,6 +170,7 @@ open class ReportService( |
|
|
private fun createFinancialStatusReport( |
|
|
private fun createFinancialStatusReport( |
|
|
templatePath: String, |
|
|
templatePath: String, |
|
|
projects: List<Map<String, Any>>, |
|
|
projects: List<Map<String, Any>>, |
|
|
|
|
|
teamLeadId: Long |
|
|
) : Workbook { |
|
|
) : Workbook { |
|
|
|
|
|
|
|
|
val resource = ClassPathResource(templatePath) |
|
|
val resource = ClassPathResource(templatePath) |
|
@@ -369,8 +370,20 @@ open class ReportService( |
|
|
genDateCell.setCellValue(LocalDate.now().toString()) |
|
|
genDateCell.setCellValue(LocalDate.now().toString()) |
|
|
|
|
|
|
|
|
rowNum = 2 |
|
|
rowNum = 2 |
|
|
|
|
|
val row2: Row = sheet.getRow(rowNum) |
|
|
|
|
|
val row2Cell = row2.createCell(2) |
|
|
|
|
|
if (teamLeadId < 0) { |
|
|
|
|
|
row2Cell.setCellValue("All") |
|
|
|
|
|
}else{ |
|
|
|
|
|
row2Cell.apply { |
|
|
|
|
|
cellFormula = "D15" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
rowNum = 4 |
|
|
rowNum = 4 |
|
|
|
|
|
val row4: Row = sheet.getRow(rowNum) |
|
|
|
|
|
val row4Cell = row4.createCell(2) |
|
|
|
|
|
row4Cell.setCellValue(projects.size.toString()) |
|
|
|
|
|
|
|
|
rowNum = 5 |
|
|
rowNum = 5 |
|
|
val row5: Row = sheet.getRow(rowNum) |
|
|
val row5: Row = sheet.getRow(rowNum) |
|
@@ -1037,16 +1050,21 @@ open class ReportService( |
|
|
return workbook |
|
|
return workbook |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
open fun getFinancialStatus(projectId: Long?): List<Map<String, Any>> { |
|
|
|
|
|
|
|
|
open fun getFinancialStatus(teamLeadId: Long?): List<Map<String, Any>> { |
|
|
val sql = StringBuilder( |
|
|
val sql = StringBuilder( |
|
|
" with cte_invoice as (select p.code, sum(i.issueAmount) as sumIssuedAmount , sum(i.paidAmount) as sumPaidAmount" |
|
|
" with cte_invoice as (select p.code, sum(i.issueAmount) as sumIssuedAmount , sum(i.paidAmount) as sumPaidAmount" |
|
|
+ " from invoice i" |
|
|
+ " from invoice i" |
|
|
+ " left join project p on p.code = i.projectCode" |
|
|
+ " left join project p on p.code = i.projectCode" |
|
|
+ " group by p.code" |
|
|
+ " group by p.code" |
|
|
+ ")" |
|
|
|
|
|
+ " Select p.code, p.description, c.name, t2.name, p.planStart , p.planEnd , p.expectedTotalFee ," |
|
|
|
|
|
+ " s.name , IFNULL(t.normalConsumed, 0) as normalConsumed, IFNULL(t.otConsumed , 0) as otConsumed, s2.hourlyRate," |
|
|
|
|
|
+ " cte_i.sumIssuedAmount, cte_i.sumPaidAmount" |
|
|
|
|
|
|
|
|
+ " )," |
|
|
|
|
|
+ " cte_teamLead as (" |
|
|
|
|
|
+ " select p.teamLead, p.code, t.name as teamName , t.code as teamCode" |
|
|
|
|
|
+ " from project p" |
|
|
|
|
|
+ " left join team t on t.id = p.teamLead" |
|
|
|
|
|
+ " )" |
|
|
|
|
|
+ " Select p.code, p.description, c.name as client, concat(cte_t.teamCode, \' - \', cte_t.teamName) as teamLead, p.planStart , p.planEnd , p.expectedTotalFee ," |
|
|
|
|
|
+ " s.name as staff , IFNULL(t.normalConsumed, 0) as normalConsumed, IFNULL(t.otConsumed , 0) as otConsumed, s2.hourlyRate," |
|
|
|
|
|
+ " IFNULL(cte_i.sumIssuedAmount, 0) as sumIssuedAmount , IFNULL(cte_i.sumPaidAmount, 0) as sumPaidAmount " |
|
|
+ " from timesheet t" |
|
|
+ " from timesheet t" |
|
|
+ " left join project_task pt on pt.id = t.projectTaskId" |
|
|
+ " left join project_task pt on pt.id = t.projectTaskId" |
|
|
+ " left join project p ON p.id = pt.project_id" |
|
|
+ " left join project p ON p.id = pt.project_id" |
|
@@ -1055,13 +1073,15 @@ open class ReportService( |
|
|
+ " left join customer c on c.id = p.customerId" |
|
|
+ " left join customer c on c.id = p.customerId" |
|
|
+ " left join team t2 on t2.id = s.teamId" |
|
|
+ " left join team t2 on t2.id = s.teamId" |
|
|
+ " left join cte_invoice cte_i on cte_i.code = p.code" |
|
|
+ " left join cte_invoice cte_i on cte_i.code = p.code" |
|
|
|
|
|
+ " left join cte_teamLead cte_t on cte_t.code = p.code" |
|
|
|
|
|
+ " where p.status = \'On-going\' " |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
if (projectId!! > 0) { |
|
|
|
|
|
sql.append(" where p.id = :projectId ") |
|
|
|
|
|
|
|
|
if (teamLeadId!! > 0) { |
|
|
|
|
|
sql.append(" and p.teamLead = :teamLeadId ") |
|
|
} |
|
|
} |
|
|
sql.append(" order by p.code") |
|
|
sql.append(" order by p.code") |
|
|
val args = mapOf("projectId" to projectId) |
|
|
|
|
|
|
|
|
val args = mapOf("teamLeadId" to teamLeadId) |
|
|
|
|
|
|
|
|
return jdbcDao.queryForList(sql.toString(), args) |
|
|
return jdbcDao.queryForList(sql.toString(), args) |
|
|
} |
|
|
} |
|
|