Переглянути джерело

Update report

tags/Baseline_30082024_BACKEND_UAT
MSI\2Fi 1 рік тому
джерело
коміт
b82d6d557c
1 змінених файлів з 67 додано та 4 видалено
  1. +67
    -4
      src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt

+ 67
- 4
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<Map<String, Any>>()
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<FinancialYear> {
val financialYearDates = mutableListOf<FinancialYear>()

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<Map<String, Any>>,
@@ -2293,6 +2351,7 @@ open class ReportService(
val convertEndMonth = YearMonth.of(endDate.year, endDate.month)

val monthRange: MutableList<Map<String, Any>> = ArrayList()

var currentDate = startDate
if (currentDate == endDate){
monthRange.add(
@@ -2312,6 +2371,7 @@ open class ReportService(
currentDate = currentDate.plusMonths(1)
}


val info: Map<String, Any> = manhoursSpent.first() { it.containsKey("info") }["info"] as Map<String, Any>
val staffInfoList: List<Map<String, Any>> =
manhoursSpent.first() { it.containsKey("staffInfoList") }["staffInfoList"] as List<Map<String, Any>>
@@ -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))


Завантаження…
Відмінити
Зберегти