|
|
@@ -159,12 +159,11 @@ open class ProjectsService( |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Milestones and tasks |
|
|
|
val tasksToSave = mutableListOf<ProjectTask>() |
|
|
|
val milestones = request.taskGroups.entries.map { (taskStageId, taskGroupAllocation) -> |
|
|
|
val taskGroup = taskGroupRepository.findById(taskStageId).orElse(TaskGroup()) |
|
|
|
val milestone = milestoneRepository.findByProjectAndTaskGroup(project, taskGroup) ?: Milestone() |
|
|
|
val taskGroup = taskGroupRepository.findById(taskStageId).orElse(TaskGroup()) ?: TaskGroup() |
|
|
|
val milestone = if (project.id != null && project.id!! > 0L) milestoneRepository.findByProjectAndTaskGroup(project, taskGroup) ?: Milestone() else Milestone() |
|
|
|
milestone.apply { |
|
|
|
val newMilestone = this |
|
|
|
val requestMilestone = request.milestones[taskStageId] |
|
|
@@ -172,9 +171,11 @@ open class ProjectsService( |
|
|
|
this.taskGroup = taskGroupMap[taskStageId] |
|
|
|
this.startDate = requestMilestone?.startDate?.let { LocalDate.parse(it) } |
|
|
|
this.endDate = requestMilestone?.endDate?.let { LocalDate.parse(it) } |
|
|
|
this.milestonePayments.removeAll(this.milestonePayments) |
|
|
|
if (this.milestonePayments.isNotEmpty()) { |
|
|
|
this.milestonePayments.removeAll(this.milestonePayments) |
|
|
|
} |
|
|
|
requestMilestone?.payments?.map { |
|
|
|
val milestonePayment = if (it.id > 0) milestonePaymentRepository.findById(it.id).orElse(MilestonePayment()) else MilestonePayment() |
|
|
|
val milestonePayment = milestonePaymentRepository.findById(it.id).orElse(MilestonePayment()) ?:MilestonePayment() |
|
|
|
this.milestonePayments.add(milestonePayment.apply { |
|
|
|
this.milestone = newMilestone |
|
|
|
this.description = it.description |
|
|
@@ -187,7 +188,8 @@ open class ProjectsService( |
|
|
|
this.stagePercentAllocation = taskGroupAllocation.percentAllocation |
|
|
|
|
|
|
|
taskGroupAllocation.taskIds.map { taskId -> |
|
|
|
val projectTask = projectTaskRepository.findByProjectAndTask(project, allTasksMap[taskId]!!) ?:ProjectTask() |
|
|
|
val projectTask = if (project.id != null && project.id!! > 0L) projectTaskRepository.findByProjectAndTask(project, allTasksMap[taskId]!!) ?:ProjectTask() else ProjectTask() |
|
|
|
|
|
|
|
projectTask.apply { |
|
|
|
this.project = project |
|
|
|
this.milestone = newMilestone |
|
|
@@ -201,7 +203,7 @@ open class ProjectsService( |
|
|
|
|
|
|
|
// Grade allocation (from manhourPercentageByGrade) |
|
|
|
val gradeAllocations = request.manhourPercentageByGrade.entries.map { |
|
|
|
val gradeAllocation = gradeAllocationRepository.findByProjectAndGrade(project, gradeMap[it.key]!!) ?: GradeAllocation() |
|
|
|
val gradeAllocation = if (project.id != null && project.id!! > 0L) gradeAllocationRepository.findByProjectAndGrade(project, gradeMap[it.key]!!) ?: GradeAllocation() else GradeAllocation() |
|
|
|
|
|
|
|
gradeAllocation.apply { |
|
|
|
this.project = project |
|
|
|