| @@ -856,7 +856,7 @@ open class ReportService( | |||
| val dateFormatter = | |||
| if (dateType == "Date") DateTimeFormatter.ofPattern("yyyy/MM/dd") else DateTimeFormatter.ofPattern("MMM YYYY") | |||
| val combinedResults = | |||
| (invoices.map { it.receiptDate } + timesheets.map { it.recordDate }).filterNotNull().sortedBy { it } | |||
| (invoices.map { it.receiptDate } + timesheets.map { it.recordDate } + projectExpenses.map{ it.issueDate }).filterNotNull().sortedBy { it } | |||
| .map { it.format(dateFormatter) }.distinct() | |||
| val groupedTimesheets = timesheets.sortedBy { it.recordDate } | |||
| .groupBy { timesheetEntry -> timesheetEntry.recordDate?.format(dateFormatter).toString() } | |||
| @@ -902,8 +902,8 @@ open class ReportService( | |||
| ) | |||
| } | |||
| } | |||
| // println("grouped Project Expense") | |||
| // println(groupedProjectExpense) | |||
| println("grouped Project Expense") | |||
| println(groupedProjectExpense) | |||
| // groupedTimesheets.entries.forEach { (key, value) -> | |||
| // logger.info("key: $key") | |||
| // logger.info("value: " + value.sumOf { it }) | |||
| @@ -1060,6 +1060,102 @@ open class ReportService( | |||
| } | |||
| } | |||
| if (groupedProjectExpense.containsKey(result)) { | |||
| if (dateType == "Date") { | |||
| groupedProjectExpense[result]!!.forEachIndexed { _, expense -> | |||
| sheet.createRow(rowIndex++).apply { | |||
| createCell(0).apply { | |||
| setCellValue(result) | |||
| } | |||
| createCell(1).apply { | |||
| setCellValue(0.0) | |||
| cellStyle.dataFormat = accountingStyle | |||
| } | |||
| createCell(2).apply { | |||
| setCellValue(expense["projectExpense"] as Double? ?: 0.0) | |||
| cellStyle.dataFormat = accountingStyle | |||
| } | |||
| createCell(3).apply { | |||
| setCellValue(0.0) | |||
| cellStyle.dataFormat = accountingStyle | |||
| } | |||
| createCell(4).apply { | |||
| val lastRow = rowIndex - 1 | |||
| if (lastRow == 16) { | |||
| cellFormula = | |||
| "C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString()) | |||
| } else { | |||
| cellFormula = | |||
| "IF(B{currentRow}>0,E{lastRow}-B{currentRow}-C{currentRow},E{lastRow}+D{currentRow}-C{currentRow})".replace( | |||
| "{currentRow}", | |||
| rowIndex.toString() | |||
| ).replace("{lastRow}", lastRow.toString()) | |||
| } | |||
| cellStyle.dataFormat = accountingStyle | |||
| } | |||
| createCell(5)?.apply { | |||
| setCellValue( | |||
| "Expense No.: " + (expense["expenseNo"] as String? ?: "N/A").toString() | |||
| ) | |||
| } | |||
| } | |||
| } | |||
| } else { | |||
| // groupedInvoices[result]!!.forEachIndexed { _, invoice -> | |||
| sheet.createRow(rowIndex++).apply { | |||
| createCell(0).apply { | |||
| setCellValue(result) | |||
| } | |||
| createCell(1).apply { | |||
| setCellValue(0.0) | |||
| cellStyle.dataFormat = accountingStyle | |||
| } | |||
| createCell(2).apply { | |||
| setCellValue(groupedProjectExpense[result]?.sumOf { it["projectExpense"] as Double } ?: 0.0) | |||
| cellStyle.dataFormat = accountingStyle | |||
| } | |||
| createCell(3).apply { | |||
| setCellValue(0.0) | |||
| cellStyle.dataFormat = accountingStyle | |||
| } | |||
| createCell(4).apply { | |||
| val lastRow = rowIndex - 1 | |||
| if (lastRow == 16) { | |||
| cellFormula = | |||
| "C{currentRow}-B{currentRow}".replace("{currentRow}", rowIndex.toString()) | |||
| } else { | |||
| cellFormula = | |||
| "IF(B{currentRow}>0,E{lastRow}-B{currentRow}-C{currentRow},E{lastRow}+D{currentRow}-C{currentRow})".replace( | |||
| "{currentRow}", | |||
| rowIndex.toString() | |||
| ).replace("{lastRow}", lastRow.toString()) | |||
| } | |||
| cellStyle.dataFormat = accountingStyle | |||
| } | |||
| createCell(5)?.apply { | |||
| // setCellValue(invoice["description"].toString()) | |||
| val expenseNos = groupedProjectExpense[result]?.map { it["expenseNo"] } | |||
| if (expenseNos?.size != null && expenseNos.size > 1) { | |||
| // setCellValue("Invoice Receipt: " + (groupedInvoices[result]?.map { it["invoiceNo"] }?.joinToString() ?: "N/A").toString()) | |||
| setCellValue("Multiple Expenses") | |||
| } else { | |||
| setCellValue("Expense No.: " + (expenseNos?.joinToString() ?: "N/A").toString()) | |||
| } | |||
| } | |||
| // } | |||
| } | |||
| } | |||
| } | |||
| } | |||