|
|
@@ -3903,6 +3903,7 @@ open class ReportService( |
|
|
|
return workbook |
|
|
|
} |
|
|
|
// Use to Calculate cummunlative expenditure |
|
|
|
// TO DO: Add isCrossTeam |
|
|
|
data class TimesheetData( |
|
|
|
val normalConsumed: Double, |
|
|
|
val otConsumed: Double, |
|
|
@@ -3913,6 +3914,7 @@ open class ReportService( |
|
|
|
val projectCode: String, |
|
|
|
val planStart: LocalDate, |
|
|
|
val planEnd: LocalDate |
|
|
|
// val isCrossTeam: Boolean |
|
|
|
) |
|
|
|
|
|
|
|
data class SalaryEffectiveInfo( |
|
|
@@ -3947,6 +3949,12 @@ open class ReportService( |
|
|
|
fun getManHoursSpentByTeam(teamLeadId: Long?): List<TimesheetData>{ |
|
|
|
val sql = StringBuilder( |
|
|
|
"select coalesce(t.normalConsumed, 0) as normalConsumed, coalesce(t.otConsumed, 0) as otConsumed, t.recordDate, t.staffId, s2.hourlyRate, s2.salaryPoint, p.code, p.planStart, p.planEnd" |
|
|
|
// For later calculating cross team charge |
|
|
|
// + ",CASE" |
|
|
|
// + " when s.teamId is NUll then null" |
|
|
|
// + " when s.teamId = p.teamLead then 1" |
|
|
|
// + " else 0" |
|
|
|
// + " END as IsCrossTeam" |
|
|
|
+ " from timesheet t" |
|
|
|
+ " left join project p on t.projectId = p.id" |
|
|
|
+ " left join staff s on t.staffId = s.id" |
|
|
@@ -4070,6 +4078,9 @@ open class ReportService( |
|
|
|
// } |
|
|
|
fun calculateProjectExpenditures(timesheetDataList: List<TimesheetData>): Map<String, BigDecimal> { |
|
|
|
val otFactor = BigDecimal(1.0) |
|
|
|
// For cross Team Calculation |
|
|
|
// val crossTeamCharge = BigDecimal(1.15) |
|
|
|
// If isCrossTeam is true, normal an ot expenditure will times the cross team charge |
|
|
|
return timesheetDataList |
|
|
|
.groupBy { it.projectCode } |
|
|
|
.mapValues { (_, projectTimesheets) -> |
|
|
@@ -4084,6 +4095,7 @@ open class ReportService( |
|
|
|
|
|
|
|
|
|
|
|
// Update timesheet data with salary effective data, then group by project code, group by staff Id and group by Year Month |
|
|
|
// Used for checking data |
|
|
|
// Data foramt: |
|
|
|
// "M-0976": { |
|
|
|
// "184": { |
|
|
@@ -4108,13 +4120,16 @@ open class ReportService( |
|
|
|
fun sumTimesheetDataByMonth(timesheetDataList: List<TimesheetData>): Map<String, ProjectSummary> { |
|
|
|
|
|
|
|
return timesheetDataList |
|
|
|
.groupBy { it.projectCode } |
|
|
|
.groupBy { it.projectCode } // Group timesheet data by project code |
|
|
|
.mapValues { (_, projectTimesheets) -> |
|
|
|
val staffData = projectTimesheets.groupBy { it.staffId } |
|
|
|
// Process each project's timesheet data |
|
|
|
val staffData = projectTimesheets.groupBy { it.staffId } // Group by staff ID |
|
|
|
.mapValues { (_, staffTimesheets) -> |
|
|
|
// Process each staff member's timesheet data |
|
|
|
val monthlyData = staffTimesheets.groupBy { timesheet -> |
|
|
|
YearMonth.from(timesheet.recordDate) |
|
|
|
YearMonth.from(timesheet.recordDate) // Group by month |
|
|
|
}.mapValues { (_, monthTimesheets) -> |
|
|
|
// Calculate monthly summary for each staff member |
|
|
|
MonthSummary( |
|
|
|
hourlyRate = monthTimesheets.maxByOrNull { it.recordDate }?.hourlyRate ?: BigDecimal.ZERO, |
|
|
|
salaryPoint = monthTimesheets.maxByOrNull { it.recordDate }?.salaryPoint ?: 0, |
|
|
|