From b82d6d557cca48aa63a22527491a9b32f80c2731 Mon Sep 17 00:00:00 2001 From: "MSI\\2Fi" Date: Tue, 16 Jul 2024 11:58:00 +0800 Subject: [PATCH] Update report --- .../modules/report/service/ReportService.kt | 71 +++++++++++++++++-- 1 file changed, 67 insertions(+), 4 deletions(-) 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 addccc7..0362dac 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 @@ -2147,8 +2147,16 @@ open class ReportService( "description" to projectsCode["description"] ) + val financialYears = getFinancialYearDates(queryStartMonth, queryEndMonth, 10) + val staffInfoList = mutableListOf>() - println("manHoursSpent------- ${manHoursSpent}") +// println("manHoursSpent------- ${manHoursSpent}") + + for (financialYear in financialYears){ +// println("${financialYear.start.year}-${financialYear.start.monthValue} - ${financialYear.end.year}-${financialYear.end.monthValue}") + println("financialYear--------- ${financialYear.start} - ${financialYear.end}") + } + for (item in manHoursSpent) { if (info["teamLead"] != item.getValue("teamLead")) { info["teamLead"] = item.getValue("teamLead") @@ -2175,7 +2183,10 @@ open class ReportService( info["description"] = item.getValue("description") } val hourlyRate = (item.getValue("hourlyRate") as BigDecimal).toDouble() + val recordDate = item.getValue("recordDate") as String + if (!staffInfoList.any { it["staffId"] == item["staffId"] && it["name"] == item["name"] }) { + staffInfoList.add( mapOf( "staffId" to item.getValue("staffId"), @@ -2184,6 +2195,7 @@ open class ReportService( "grade" to item.getValue("gradeCode"), "salaryPoint" to item.getValue("salaryPoint"), "hourlyRate" to hourlyRate, + "financialYears" to financialYears, "hourlySpent" to mutableListOf( mapOf( "recordDate" to item.getValue("recordDate"), @@ -2234,13 +2246,13 @@ open class ReportService( staffInfoList[updatedIndex] = updatedMap } } - println("staffInfoList----------------- $staffInfoList") - println("info----------------- $info") +// println("staffInfoList----------------- $staffInfoList") +// println("info----------------- $info") tempList.add(mapOf("info" to info)) tempList.add(mapOf("staffInfoList" to staffInfoList)) - println("Only Staff Info List --------------------- ${tempList.first() { it.containsKey("staffInfoList") }["staffInfoList"]}") +// println("Only Staff Info List --------------------- ${tempList.first() { it.containsKey("staffInfoList") }["staffInfoList"]}") println("tempList----------------- $tempList") return tempList @@ -2260,6 +2272,52 @@ open class ReportService( return outputStream.toByteArray() } + // For Calculating the Financial Year + data class FinancialYear(val start: YearMonth, val end: YearMonth, val hourlyRate: Double) + + fun getFinancialYearDates(startDate: YearMonth, endDate: YearMonth, financialYearStartMonth: Int): Array { + val financialYearDates = mutableListOf() + + var currentYear = startDate.year + var currentMonth = startDate.monthValue + + // Adjust the current year and month to the previous financial year if the start date is before the financial year start month + if (currentMonth < financialYearStartMonth) { + currentYear-- + currentMonth += 12 + } + + while (currentYear * 100 + currentMonth <= endDate.year * 100 + endDate.monthValue) { + var startMonth = if (financialYearStartMonth == 10) 10 else currentMonth - financialYearStartMonth + 1 + var startYear = currentYear + if (startMonth <= 0) { + startMonth += 12 + startYear -= 1 + } + var endMonth = startMonth + 11 + var endYear = startYear + if (endMonth > 12) { + endMonth -= 12 + endYear += 1 + } + + val financialYear = FinancialYear( + start = YearMonth.of(startYear, startMonth), + end = YearMonth.of(endYear, endMonth), + hourlyRate = 0.0 + ) + financialYearDates.add(financialYear) + + currentMonth += 12 + if (currentMonth > 12) { + currentYear++ + currentMonth -= 12 + } + } + + return financialYearDates.toTypedArray() + } + fun createPandLReportWorkbook( templatePath: String, manhoursSpent: List>, @@ -2293,6 +2351,7 @@ open class ReportService( val convertEndMonth = YearMonth.of(endDate.year, endDate.month) val monthRange: MutableList> = ArrayList() + var currentDate = startDate if (currentDate == endDate){ monthRange.add( @@ -2312,6 +2371,7 @@ open class ReportService( currentDate = currentDate.plusMonths(1) } + val info: Map = manhoursSpent.first() { it.containsKey("info") }["info"] as Map val staffInfoList: List> = manhoursSpent.first() { it.containsKey("staffInfoList") }["staffInfoList"] as List> @@ -2389,6 +2449,8 @@ open class ReportService( } row6Cell.setCellValue(clientSubsidiary) + // Need to be updated to financial year + // Base on the searching criteria rowNum = 9 val row9: Row = sheet.getRow(rowNum) val row9Cell = row9.getCell(3) @@ -2425,6 +2487,7 @@ open class ReportService( sheet.setRowBreak(rowNum++); } + rowNum += 2 val titleRow = sheet.getRow(rowNum) ?: sheet.createRow(rowNum) sheet.addMergedRegion(CellRangeAddress(rowNum, rowNum, 0, monthRange.size + 3))