Bläddra i källkod

Add ot hours for timesheet

tags/Baseline_30082024_BACKEND_UAT
Wayne 1 år sedan
förälder
incheckning
1306b7169d
5 ändrade filer med 21 tillägg och 7 borttagningar
  1. +4
    -2
      src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt
  2. +3
    -2
      src/main/java/com/ffii/tsms/modules/timesheet/entity/TimesheetRepository.kt
  3. +6
    -0
      src/main/java/com/ffii/tsms/modules/timesheet/entity/projections/TimesheetHours.kt
  4. +6
    -2
      src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt
  5. +2
    -1
      src/main/java/com/ffii/tsms/modules/timesheet/web/models/TimeEntry.kt

+ 4
- 2
src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt Visa fil

@@ -68,6 +68,8 @@ open class ProjectsService(
staffRepository.findByUserId(user.id).getOrNull()?.let { staff ->
staffAllocationRepository.findAssignedProjectsByStaff(staff)
.mapNotNull { it.project?.let { project ->
val timesheetHours = timesheetRepository.totalHoursConsumedByProject(project)

AssignedProject(
id = project.id!!,
code = project.code!!,
@@ -82,8 +84,8 @@ open class ProjectsService(
) },
hoursAllocated = project.totalManhour ?: 0.0,
hoursAllocatedOther = 0.0,
hoursSpent = timesheetRepository.totalNormalHoursConsumedByProject(project),
hoursSpentOther = 0.0
hoursSpent = timesheetHours.normalConsumed,
hoursSpentOther = timesheetHours.otConsumed
)
} }
}


+ 3
- 2
src/main/java/com/ffii/tsms/modules/timesheet/entity/TimesheetRepository.kt Visa fil

@@ -3,6 +3,7 @@ package com.ffii.tsms.modules.timesheet.entity;
import com.ffii.core.support.AbstractRepository
import com.ffii.tsms.modules.data.entity.Staff
import com.ffii.tsms.modules.project.entity.Project
import com.ffii.tsms.modules.timesheet.entity.projections.TimesheetHours
import org.springframework.data.jpa.repository.Query
import java.time.LocalDate

@@ -12,6 +13,6 @@ interface TimesheetRepository : AbstractRepository<Timesheet, Long> {

fun deleteAllByStaffAndRecordDate(staff: Staff, recordDate: LocalDate)

@Query("SELECT IFNULL(SUM(normalConsumed), 0) FROM Timesheet t JOIN ProjectTask pt on t.projectTask = pt WHERE pt.project = ?1")
fun totalNormalHoursConsumedByProject(project: Project): Double
@Query("SELECT new com.ffii.tsms.modules.timesheet.entity.projections.TimesheetHours(IFNULL(SUM(normalConsumed), 0), IFNULL(SUM(otConsumed), 0)) FROM Timesheet t JOIN ProjectTask pt on t.projectTask = pt WHERE pt.project = ?1")
fun totalHoursConsumedByProject(project: Project): TimesheetHours
}

+ 6
- 0
src/main/java/com/ffii/tsms/modules/timesheet/entity/projections/TimesheetHours.kt Visa fil

@@ -0,0 +1,6 @@
package com.ffii.tsms.modules.timesheet.entity.projections

data class TimesheetHours(
val normalConsumed: Double,
val otConsumed: Double
)

+ 6
- 2
src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt Visa fil

@@ -12,7 +12,6 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import kotlin.jvm.optionals.getOrDefault
import kotlin.jvm.optionals.getOrNull

@Service
@@ -41,6 +40,7 @@ open class TimesheetsService(
this.staff = currentStaff
this.recordDate = entryDate
this.normalConsumed = timeEntry.inputHours
this.otConsumed = timeEntry.otHours
this.projectTask = projectTask
this.remark = timeEntry.remark
}
@@ -68,6 +68,7 @@ open class TimesheetsService(
taskId = timesheet.projectTask?.task?.id,
taskGroupId = timesheet.projectTask?.task?.taskGroup?.id,
inputHours = timesheet.normalConsumed ?: 0.0,
otHours = timesheet.otConsumed ?: 0.0,
remark = timesheet.remark
)
} }
@@ -77,7 +78,10 @@ open class TimesheetsService(
return entries
.groupBy { timeEntry -> Pair(timeEntry.projectId, timeEntry.taskId) }
.values.map { timeEntries ->
timeEntries.reduce { acc, timeEntry -> acc.copy(inputHours = acc.inputHours + timeEntry.inputHours) }
timeEntries.reduce { acc, timeEntry -> acc.copy(
inputHours = (acc.inputHours ?: 0.0) + (timeEntry.inputHours ?: 0.0),
otHours = (acc.otHours ?: 0.0) + (timeEntry.otHours ?: 0.0)
) }
}
}
}

+ 2
- 1
src/main/java/com/ffii/tsms/modules/timesheet/web/models/TimeEntry.kt Visa fil

@@ -6,6 +6,7 @@ data class TimeEntry(
val projectId: Long?,
val taskGroupId: Long?,
val taskId: Long?,
val inputHours: Double,
val inputHours: Double?,
val otHours: Double?,
val remark: String?
)

Laddar…
Avbryt
Spara