|
|
@@ -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 { |
|
|
|