Просмотр исходного кода

update project cash report & cross team report (salary effective)

add_swagger
cyril.tsui 9 месяцев назад
Родитель
Сommit
d666f70541
2 измененных файлов: 49 добавлений и 80 удалений
  1. +16
    -11
      src/main/java/com/ffii/tsms/modules/data/service/SalaryEffectiveService.kt
  2. +33
    -69
      src/main/java/com/ffii/tsms/modules/report/service/ReportService.kt

+ 16
- 11
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<MonthlyStaffSalaryData> {
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
)
}
}



+ 33
- 69
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<String, Double>().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<String, Double>().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<String, Double>().apply {
this["manHour"] = 0.0
this["salary"] = 0.0
}
// TODO: salary effective
mutableMapOf<String, Double>().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<String, Double>().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<String, Double>().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<String, Double>().apply {
this["manHour"] = 0.0
this["salary"] = 0.0
}
mutableMapOf<String, Double>().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 {


Загрузка…
Отмена
Сохранить