|
|
@@ -44,6 +44,7 @@ open class ReportService( |
|
|
|
private val DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd") |
|
|
|
private val FORMATTED_TODAY = LocalDate.now().format(DATE_FORMATTER) |
|
|
|
|
|
|
|
private val COSTANDEXPENSE_REPORT = "templates/report/AR04_Cost and Expense Report v02.xlsx" |
|
|
|
private val PandL_REPORT = "templates/report/AR07_Project P&L Report v02.xlsx" |
|
|
|
private val FINANCIAL_STATUS_REPORT = "templates/report/EX01_Financial Status Report.xlsx" |
|
|
|
private val PROJECT_CASH_FLOW_REPORT = "templates/report/EX02_Project Cash Flow Report.xlsx" |
|
|
@@ -1986,4 +1987,87 @@ open class ReportService( |
|
|
|
|
|
|
|
return costAndExpenseList |
|
|
|
} |
|
|
|
|
|
|
|
fun createCostAndExpenseWorkbook( |
|
|
|
templatePath: String, |
|
|
|
costAndExpenseList: List<Map<String, Any?>>, |
|
|
|
): Workbook{ |
|
|
|
val resource = ClassPathResource(templatePath) |
|
|
|
val templateInputStream = resource.inputStream |
|
|
|
val workbook: Workbook = XSSFWorkbook(templateInputStream) |
|
|
|
|
|
|
|
val sheet = workbook.getSheetAt(0) |
|
|
|
var rowNum = 0 |
|
|
|
rowNum = 1 |
|
|
|
val row1: Row = sheet.getRow(rowNum) |
|
|
|
val row1Cell = row1.getCell(1) |
|
|
|
row1Cell.setCellValue(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd")).toString()) |
|
|
|
|
|
|
|
rowNum = 6 |
|
|
|
for(item in costAndExpenseList){ |
|
|
|
val index = costAndExpenseList.indexOf(item) |
|
|
|
val row: Row = sheet.getRow(rowNum) ?: sheet.createRow(rowNum) |
|
|
|
val cell = row.getCell(0) ?: row.createCell(0) |
|
|
|
cell.apply { |
|
|
|
setCellValue(index.toDouble()) |
|
|
|
} |
|
|
|
|
|
|
|
val cell1 = row.getCell(1) ?: row.createCell(1) |
|
|
|
cell1.apply { |
|
|
|
setCellValue(item["code"].toString()) |
|
|
|
} |
|
|
|
|
|
|
|
val cell2 = row.getCell(2) ?: row.createCell(2) |
|
|
|
cell2.apply { |
|
|
|
setCellValue(item["description"].toString()) |
|
|
|
} |
|
|
|
|
|
|
|
val cell3 = row.getCell(3) ?: row.createCell(3) |
|
|
|
cell3.apply { |
|
|
|
setCellValue(item["teamLead"].toString()) |
|
|
|
} |
|
|
|
|
|
|
|
val cell4 = row.getCell(4) ?: row.createCell(4) |
|
|
|
cell4.apply { |
|
|
|
setCellValue(item["client"].toString()) |
|
|
|
} |
|
|
|
|
|
|
|
val cell5 = row.getCell(5) ?: row.createCell(5) |
|
|
|
val budget = item["budget"] as Double * 0.8 |
|
|
|
cell5.apply { |
|
|
|
setCellValue(budget) |
|
|
|
} |
|
|
|
|
|
|
|
val cell6 = row.getCell(6) ?: row.createCell(6) |
|
|
|
val manHoutsSpentCost = item["manhourExpenditure"] as Double |
|
|
|
cell6.apply { |
|
|
|
setCellValue(manHoutsSpentCost) |
|
|
|
} |
|
|
|
|
|
|
|
val cell7 = row.getCell(7) ?: row.createCell(7) |
|
|
|
cell7.apply { |
|
|
|
cellFormula = "F${rowNum+1}-G${rowNum+1}" |
|
|
|
} |
|
|
|
|
|
|
|
val cell8 = row.getCell(8) ?: row.createCell(8) |
|
|
|
cell8.apply { |
|
|
|
cellFormula = "H${rowNum+1}/G${rowNum+1}" |
|
|
|
} |
|
|
|
sheet.setRowBreak(rowNum++); |
|
|
|
} |
|
|
|
|
|
|
|
return workbook |
|
|
|
} |
|
|
|
|
|
|
|
fun genCostAndExpenseReport(): ByteArray{ |
|
|
|
val costAndExpenseList = getCostAndExpense("All") |
|
|
|
|
|
|
|
val workbook: Workbook = createCostAndExpenseWorkbook(COSTANDEXPENSE_REPORT, costAndExpenseList) |
|
|
|
|
|
|
|
val outputStream: ByteArrayOutputStream = ByteArrayOutputStream() |
|
|
|
workbook.write(outputStream) |
|
|
|
workbook.close() |
|
|
|
|
|
|
|
return outputStream.toByteArray() |
|
|
|
} |
|
|
|
} |