From d666f70541fe47fa79a566839e41b3af6cdd52e9 Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Thu, 14 Nov 2024 17:03:09 +0800 Subject: [PATCH] update project cash report & cross team report (salary effective) --- .../data/service/SalaryEffectiveService.kt | 27 +++-- .../modules/report/service/ReportService.kt | 102 ++++++------------ 2 files changed, 49 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/ffii/tsms/modules/data/service/SalaryEffectiveService.kt b/src/main/java/com/ffii/tsms/modules/data/service/SalaryEffectiveService.kt index b24a1fc..455ea4f 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/SalaryEffectiveService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/SalaryEffectiveService.kt @@ -175,7 +175,7 @@ open class SalaryEffectiveService( open fun getMonthlyStaffSalaryData(startDate: LocalDate, endDate: LocalDate): List { val salaryEffective = salaryEffectiveRepository.findAll() - .groupBy { Triple(it.staff.id, it.date.year, it.date.month) } + .groupBy { Triple(it.staff.id, it.date.year, it.date) } .map { (_, se) -> se.maxByOrNull { it.date }!! } @@ -191,23 +191,28 @@ open class SalaryEffectiveService( dateList.forEach{ date -> val staffSalaryEffective = salaryEffective.filter { it.staff.staffId.equals(staff.staffId) } - var currentHourlyRate = staffSalaryEffective.filter { + val currentSalaryEffective = staffSalaryEffective.filter { date.isEqual(it.date.withDayOfMonth(1)) || date.isAfter(it.date.withDayOfMonth(1)) - }.maxByOrNull { it.date } + } - if (currentHourlyRate == null) { - currentHourlyRate = staffSalaryEffective.minByOrNull { it.date } + when (currentSalaryEffective.size) { + 0 -> result += MonthlyStaffSalaryData( + staff = staff, + date = date, + hourlyRate = staffSalaryEffective.minByOrNull { it.date }?.salary?.hourlyRate?.toDouble() ?: staff?.salary?.hourlyRate?.toDouble() ?: 0.0 + ) + else -> currentSalaryEffective.forEach { cse -> + result += MonthlyStaffSalaryData( + staff = staff, + date = cse.date, + hourlyRate = cse.salary?.hourlyRate?.toDouble() ?: staff?.salary?.hourlyRate?.toDouble() ?: 0.0 + ) + } } // if (staff.staffId == "B374") { // logger.info("date:${date} | hourlyRate:${currentHourlyRate?.salary?.hourlyRate}") // } - - result += MonthlyStaffSalaryData( - staff = staff, - date = date, - hourlyRate = currentHourlyRate?.salary?.hourlyRate?.toDouble() ?: staff?.salary?.hourlyRate?.toDouble() ?: 0.0 - ) } } 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 737a5df..7e28ece 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 @@ -885,9 +885,9 @@ open class ReportService( val actualIncome = invoices.sumOf { invoice -> invoice.paidAmount!! } val actualExpenditure = timesheets.sumOf { timesheet -> // timesheet.staff!!.salary.hourlyRate.toDouble() * ((timesheet.normalConsumed ?: 0.0) + (timesheet.otConsumed ?: 0.0)) - (monthlyStaffSalaryEffective.find { - it.staff.staffId == timesheet.staff?.staffId && it.date.year == timesheet.recordDate?.year && it.date.month == timesheet.recordDate?.month - }?.hourlyRate ?: 0.0) * ((timesheet.normalConsumed ?: 0.0) + (timesheet.otConsumed ?: 0.0)) + (monthlyStaffSalaryEffective.filter { + it.staff.id == timesheet.staff?.id && (timesheet.recordDate?.isEqual(it.date) == true || timesheet.recordDate?.isAfter(it.date) == true) + }.maxByOrNull{it.date}?.hourlyRate ?: 0.0) * ((timesheet.normalConsumed ?: 0.0) + (timesheet.otConsumed ?: 0.0)) } val sumProjectExpense = projectExpenses.sumOf { it.amount?: 0.0 } @@ -921,32 +921,27 @@ open class ReportService( rowIndex = 16 val dateFormatter = - if (dateType == "Date") DateTimeFormatter.ofPattern("yyyy/MM/dd") else DateTimeFormatter.ofPattern("MMM YYYY") + if (dateType == "Date") DateTimeFormatter.ofPattern("yyyy/MM/dd") else DateTimeFormatter.ofPattern("MMM yyyy") val combinedResults = (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 } + val groupedTimesheets = timesheets .groupBy { timesheetEntry -> timesheetEntry.recordDate?.format(dateFormatter).toString() } .mapValues { (_, timesheetEntries) -> timesheetEntries.map { timesheet -> - if (timesheet.normalConsumed != null) { - timesheet.normalConsumed!!.plus(timesheet.otConsumed ?: 0.0) -// .times(timesheet.staff!!.salary.hourlyRate.toDouble()) - .times(monthlyStaffSalaryEffective.find { - it.staff.staffId == timesheet.staff?.staffId && it.date.year == timesheet.recordDate?.year && it.date.month == timesheet.recordDate?.month - }?.hourlyRate ?: 0.0) - } else if (timesheet.otConsumed != null) { - timesheet.otConsumed!!.plus(timesheet.normalConsumed ?: 0.0) -// .times(timesheet.staff!!.salary.hourlyRate.toDouble()) - .times(monthlyStaffSalaryEffective.find { - it.staff.staffId == timesheet.staff?.staffId && it.date.year == timesheet.recordDate?.year && it.date.month == timesheet.recordDate?.month - }?.hourlyRate ?: 0.0) - } else { - 0.0 - } + (timesheet.normalConsumed ?: 0.0) + .plus(timesheet.otConsumed ?: 0.0) + .times( + monthlyStaffSalaryEffective.filter { + it.staff.id == timesheet.staff?.id && (timesheet.recordDate?.isEqual(it.date) == true || timesheet.recordDate?.isAfter(it.date) == true) + }.maxByOrNull{it.date}?.hourlyRate ?: 0.0 + ) } - } + }.toSortedMap(compareBy{ if (dateType == "Date") LocalDate.parse(it, dateFormatter) else YearMonth.parse(it, dateFormatter)}) +// groupedTimesheets.forEach { gt -> +// logger.info("GT Key: ${gt.key} | GT Value: ${gt.value}") +// } val groupedInvoices = invoices.sortedBy { it.receiptDate }.filter { it.paidAmount != null } .groupBy { invoiceEntry -> invoiceEntry.receiptDate?.format(dateFormatter).toString() } .mapValues { (_, invoiceEntries) -> @@ -4390,29 +4385,15 @@ open class ReportService( } .mapValues { (_, timesheetEntries) -> timesheetEntries.map { timesheet -> - if (timesheet.normalConsumed != null) { - mutableMapOf().apply { - this["manHour"] = timesheet.normalConsumed!!.plus(timesheet.otConsumed ?: 0.0) - this["salary"] = timesheet.normalConsumed!!.plus(timesheet.otConsumed ?: 0.0) -// .times(timesheet.staff!!.salary.hourlyRate.toDouble()) - .times(monthlyStaffSalaryEffective.find { - it.staff.staffId == timesheet.staff?.staffId && it.date.year == timesheet.recordDate?.year && it.date.month == timesheet.recordDate?.month - }?.hourlyRate ?: 0.0) - } - } else if (timesheet.otConsumed != null) { - mutableMapOf().apply { - this["manHour"] = timesheet.otConsumed!!.plus(timesheet.normalConsumed ?: 0.0) - this["salary"] = timesheet.otConsumed!!.plus(timesheet.normalConsumed ?: 0.0) -// .times(timesheet.staff!!.salary.hourlyRate.toDouble()) - .times(monthlyStaffSalaryEffective.find { - it.staff.staffId == timesheet.staff?.staffId && it.date.year == timesheet.recordDate?.year && it.date.month == timesheet.recordDate?.month - }?.hourlyRate ?: 0.0) - } - } else { - mutableMapOf().apply { - this["manHour"] = 0.0 - this["salary"] = 0.0 - } + // TODO: salary effective + mutableMapOf().apply { + this["manHour"] = (timesheet.normalConsumed ?: 0.0) + .plus(timesheet.otConsumed ?: 0.0) + this["salary"] = (timesheet.normalConsumed ?: 0.0) + .plus(timesheet.otConsumed ?: 0.0) + .times(monthlyStaffSalaryEffective.filter { + it.staff.id == timesheet.staff?.id && (timesheet.recordDate?.isEqual(it.date) == true || timesheet.recordDate?.isAfter(it.date) == true) + }.maxByOrNull{it.date}?.hourlyRate ?: 0.0) } } } @@ -4648,29 +4629,14 @@ open class ReportService( } .mapValues { (_, timesheetEntries) -> timesheetEntries.map { timesheet -> - if (timesheet.normalConsumed != null) { - mutableMapOf().apply { - this["manHour"] = timesheet.normalConsumed!!.plus(timesheet.otConsumed ?: 0.0) - this["salary"] = timesheet.normalConsumed!!.plus(timesheet.otConsumed ?: 0.0) -// .times(timesheet.staff!!.salary.hourlyRate.toDouble()) - .times(monthlyStaffSalaryEffective.find { - it.staff.staffId == timesheet.staff?.staffId && it.date.year == timesheet.recordDate?.year && it.date.month == timesheet.recordDate?.month - }?.hourlyRate ?: 0.0) - } - } else if (timesheet.otConsumed != null) { - mutableMapOf().apply { - this["manHour"] = timesheet.otConsumed!!.plus(timesheet.normalConsumed ?: 0.0) - this["salary"] = timesheet.otConsumed!!.plus(timesheet.normalConsumed ?: 0.0) -// .times(timesheet.staff!!.salary.hourlyRate.toDouble()) - .times(monthlyStaffSalaryEffective.find { - it.staff.staffId == timesheet.staff?.staffId && it.date.year == timesheet.recordDate?.year && it.date.month == timesheet.recordDate?.month - }?.hourlyRate ?: 0.0) - } - } else { - mutableMapOf().apply { - this["manHour"] = 0.0 - this["salary"] = 0.0 - } + mutableMapOf().apply { + this["manHour"] = (timesheet.normalConsumed ?: 0.0) + .plus(timesheet.otConsumed ?: 0.0) + this["salary"] = (timesheet.normalConsumed ?: 0.0) + .plus(timesheet.otConsumed ?: 0.0) + .times(monthlyStaffSalaryEffective.filter { + it.staff.id == timesheet.staff?.id && (timesheet.recordDate?.isEqual(it.date) == true || timesheet.recordDate?.isAfter(it.date) == true) + }.maxByOrNull{ it.date }?.hourlyRate ?: 0.0) } } } @@ -4685,8 +4651,6 @@ open class ReportService( .sortedBy { it.staffId } .distinct() - - // his/her team projects var tempTimesheets = timesheets .filter {