|
@@ -4,6 +4,7 @@ import com.ffii.tsms.modules.data.entity.* |
|
|
import com.ffii.tsms.modules.data.service.CustomerContactService |
|
|
import com.ffii.tsms.modules.data.service.CustomerContactService |
|
|
import com.ffii.tsms.modules.project.entity.projections.ProjectSearchInfo |
|
|
import com.ffii.tsms.modules.project.entity.projections.ProjectSearchInfo |
|
|
import com.ffii.tsms.modules.data.service.CustomerService |
|
|
import com.ffii.tsms.modules.data.service.CustomerService |
|
|
|
|
|
import com.ffii.tsms.modules.data.service.GradeService |
|
|
import com.ffii.tsms.modules.project.entity.* |
|
|
import com.ffii.tsms.modules.project.entity.* |
|
|
import com.ffii.tsms.modules.project.entity.projections.InvoiceInfoSearchInfo |
|
|
import com.ffii.tsms.modules.project.entity.projections.InvoiceInfoSearchInfo |
|
|
import com.ffii.tsms.modules.project.entity.projections.InvoiceSearchInfo |
|
|
import com.ffii.tsms.modules.project.entity.projections.InvoiceSearchInfo |
|
@@ -20,6 +21,7 @@ open class ProjectsService( |
|
|
private val tasksService: TasksService, |
|
|
private val tasksService: TasksService, |
|
|
private val customerContactService: CustomerContactService, |
|
|
private val customerContactService: CustomerContactService, |
|
|
private val subsidiaryService: SubsidiaryService, |
|
|
private val subsidiaryService: SubsidiaryService, |
|
|
|
|
|
private val gradeService: GradeService, |
|
|
private val projectCategoryRepository: ProjectCategoryRepository, |
|
|
private val projectCategoryRepository: ProjectCategoryRepository, |
|
|
private val staffRepository: StaffRepository, |
|
|
private val staffRepository: StaffRepository, |
|
|
private val staffAllocationRepository: StaffAllocationRepository, |
|
|
private val staffAllocationRepository: StaffAllocationRepository, |
|
@@ -71,6 +73,7 @@ open class ProjectsService( |
|
|
|
|
|
|
|
|
val allTasksMap = tasksService.allTasks().associateBy { it.id } |
|
|
val allTasksMap = tasksService.allTasks().associateBy { it.id } |
|
|
val taskGroupMap = tasksService.allTaskGroups().associateBy { it.id } |
|
|
val taskGroupMap = tasksService.allTaskGroups().associateBy { it.id } |
|
|
|
|
|
val gradeMap = gradeService.allGrades().associateBy { it.id } |
|
|
|
|
|
|
|
|
val project = |
|
|
val project = |
|
|
Project().apply { |
|
|
Project().apply { |
|
@@ -100,46 +103,47 @@ open class ProjectsService( |
|
|
|
|
|
|
|
|
// Milestones and tasks |
|
|
// Milestones and tasks |
|
|
val tasksToSave = mutableListOf<ProjectTask>() |
|
|
val tasksToSave = mutableListOf<ProjectTask>() |
|
|
val milestones = request.milestones.entries.map { (taskStageId, requestMilestone) -> |
|
|
|
|
|
|
|
|
val milestones = request.taskGroups.entries.map { (taskStageId, taskGroupAllocation) -> |
|
|
Milestone().apply { |
|
|
Milestone().apply { |
|
|
val newMilestone = this |
|
|
val newMilestone = this |
|
|
|
|
|
val requestMilestone = request.milestones[taskStageId] |
|
|
this.project = project |
|
|
this.project = project |
|
|
this.taskGroup = taskGroupMap[taskStageId] |
|
|
this.taskGroup = taskGroupMap[taskStageId] |
|
|
this.startDate = requestMilestone.startDate?.let { LocalDate.parse(it) } |
|
|
|
|
|
this.endDate = requestMilestone.endDate?.let { LocalDate.parse(it) } |
|
|
|
|
|
this.milestonePayments = requestMilestone.payments.map { |
|
|
|
|
|
|
|
|
this.startDate = requestMilestone?.startDate?.let { LocalDate.parse(it) } |
|
|
|
|
|
this.endDate = requestMilestone?.endDate?.let { LocalDate.parse(it) } |
|
|
|
|
|
this.milestonePayments = requestMilestone?.payments?.map { |
|
|
MilestonePayment().apply { |
|
|
MilestonePayment().apply { |
|
|
this.description = it.description |
|
|
this.description = it.description |
|
|
this.amount = it.amount |
|
|
this.amount = it.amount |
|
|
this.date = LocalDate.parse(it.date) |
|
|
this.date = LocalDate.parse(it.date) |
|
|
this.milestone = newMilestone |
|
|
this.milestone = newMilestone |
|
|
} |
|
|
} |
|
|
}.toMutableList() |
|
|
|
|
|
|
|
|
}?.toMutableList() ?: mutableListOf() |
|
|
|
|
|
|
|
|
// Tasks |
|
|
// Tasks |
|
|
val taskGroupAllocation = request.taskGroups[taskStageId] |
|
|
|
|
|
this.stagePercentAllocation = taskGroupAllocation?.percentAllocation |
|
|
|
|
|
|
|
|
this.stagePercentAllocation = taskGroupAllocation.percentAllocation |
|
|
|
|
|
|
|
|
taskGroupAllocation?.taskIds?.map { taskId -> ProjectTask().apply { |
|
|
|
|
|
|
|
|
taskGroupAllocation.taskIds.map { taskId -> ProjectTask().apply { |
|
|
this.project = project |
|
|
this.project = project |
|
|
this.milestone = newMilestone |
|
|
this.milestone = newMilestone |
|
|
this.task = allTasksMap[taskId] |
|
|
this.task = allTasksMap[taskId] |
|
|
} }?.let { tasksToSave.addAll(it) } |
|
|
|
|
|
|
|
|
} }.let { tasksToSave.addAll(it) } |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: Get Grades from db |
|
|
|
|
|
// Grade allocation (from manhourPercentageByGrade) |
|
|
// Grade allocation (from manhourPercentageByGrade) |
|
|
// request.manhourPercentageByGrade.entries.map { |
|
|
|
|
|
// GradeAllocation().apply { |
|
|
|
|
|
// this.project = project |
|
|
|
|
|
// this.manhour = it.value |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
val gradeAllocations = request.manhourPercentageByGrade.entries.map { |
|
|
|
|
|
GradeAllocation().apply { |
|
|
|
|
|
this.project = project |
|
|
|
|
|
this.manhour = it.value |
|
|
|
|
|
this.grade = gradeMap[it.key] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
val savedProject = projectRepository.save(project) |
|
|
val savedProject = projectRepository.save(project) |
|
|
milestoneRepository.saveAll(milestones) |
|
|
milestoneRepository.saveAll(milestones) |
|
|
projectTaskRepository.saveAll(tasksToSave) |
|
|
projectTaskRepository.saveAll(tasksToSave) |
|
|
|
|
|
gradeAllocationRepository.saveAll(gradeAllocations) |
|
|
|
|
|
|
|
|
// Staff allocation |
|
|
// Staff allocation |
|
|
val allocatedStaff = staffRepository.findAllById(request.allocatedStaffIds) |
|
|
val allocatedStaff = staffRepository.findAllById(request.allocatedStaffIds) |
|
|