|
|
@@ -10,11 +10,14 @@ import com.ffii.tsms.modules.project.entity.projections.InvoiceSearchInfo |
|
|
|
import com.ffii.tsms.modules.project.web.models.NewProjectRequest |
|
|
|
import org.springframework.stereotype.Service |
|
|
|
import org.springframework.transaction.annotation.Transactional |
|
|
|
import java.time.LocalDate |
|
|
|
import java.time.format.DateTimeFormatter |
|
|
|
|
|
|
|
@Service |
|
|
|
open class ProjectsService( |
|
|
|
private val projectRepository: ProjectRepository, |
|
|
|
private val customerService: CustomerService, |
|
|
|
private val tasksService: TasksService, |
|
|
|
private val customerContactService: CustomerContactService, |
|
|
|
private val projectCategoryRepository: ProjectCategoryRepository, |
|
|
|
private val staffRepository: StaffRepository, |
|
|
@@ -24,7 +27,10 @@ open class ProjectsService( |
|
|
|
private val contractTypeRepository: ContractTypeRepository, |
|
|
|
private val locationRepository: LocationRepository, |
|
|
|
private val buildingTypeRepository: BuildingTypeRepository, |
|
|
|
private val workNatureRepository: WorkNatureRepository |
|
|
|
private val workNatureRepository: WorkNatureRepository, |
|
|
|
private val milestoneRepository: MilestoneRepository, |
|
|
|
private val gradeAllocationRepository: GradeAllocationRepository, |
|
|
|
private val projectTaskRepository: ProjectTaskRepository |
|
|
|
) { |
|
|
|
open fun allProjects(): List<ProjectSearchInfo> { |
|
|
|
return projectRepository.findProjectSearchInfoBy() |
|
|
@@ -61,15 +67,16 @@ open class ProjectsService( |
|
|
|
val customer = customerService.findCustomer(request.clientId) |
|
|
|
val clientContact = customerContactService.findByContactId(request.clientContactId) |
|
|
|
|
|
|
|
val allTasksMap = tasksService.allTasks().associateBy { it.id } |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Add tasks, milestones |
|
|
|
val project = |
|
|
|
Project().apply { |
|
|
|
name = request.projectName |
|
|
|
description = request.projectDescription |
|
|
|
code = request.projectCode |
|
|
|
expectedTotalFee = request.expectedProjectFee |
|
|
|
totalManhour = request.totalManhour |
|
|
|
|
|
|
|
this.projectCategory = projectCategory |
|
|
|
this.fundingType = fundingType |
|
|
|
this.serviceType = serviceType |
|
|
@@ -85,8 +92,51 @@ open class ProjectsService( |
|
|
|
custLeadPhone = clientContact.phone |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Milestones and tasks |
|
|
|
val tasksToSave = mutableListOf<ProjectTask>() |
|
|
|
val milestones = request.milestones.entries.map { (taskStageId, requestMilestone) -> |
|
|
|
Milestone().apply { |
|
|
|
val newMilestone = this |
|
|
|
this.project = project |
|
|
|
this.startDate = LocalDate.parse(requestMilestone.startDate) |
|
|
|
this.endDate = LocalDate.parse(requestMilestone.endDate) |
|
|
|
this.milestonePayments = requestMilestone.payments.map { |
|
|
|
MilestonePayment().apply { |
|
|
|
this.description = it.description |
|
|
|
this.amount = it.amount |
|
|
|
this.date = LocalDate.parse(it.date) |
|
|
|
this.milestone = newMilestone |
|
|
|
} |
|
|
|
}.toMutableList() |
|
|
|
|
|
|
|
// Tasks |
|
|
|
val taskGroupAllocation = request.taskGroups[taskStageId] |
|
|
|
this.stagePercentAllocation = taskGroupAllocation?.percentAllocation |
|
|
|
|
|
|
|
taskGroupAllocation?.taskIds?.map { taskId -> ProjectTask().apply { |
|
|
|
this.project = project |
|
|
|
this.milestone = newMilestone |
|
|
|
this.task = allTasksMap[taskId] |
|
|
|
} }?.let { tasksToSave.addAll(it) } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: Get Grades from db |
|
|
|
// Grade allocation (from manhourPercentageByGrade) |
|
|
|
// request.manhourPercentageByGrade.entries.map { |
|
|
|
// GradeAllocation().apply { |
|
|
|
// this.project = project |
|
|
|
// this.manhour = it.value |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
val savedProject = projectRepository.save(project) |
|
|
|
milestoneRepository.saveAll(milestones) |
|
|
|
projectTaskRepository.saveAll(tasksToSave) |
|
|
|
|
|
|
|
// Staff allocation |
|
|
|
val allocatedStaff = staffRepository.findAllById(request.allocatedStaffIds) |
|
|
|
val staffAllocations = allocatedStaff.map { staff -> StaffAllocation().apply { |
|
|
|
this.project = savedProject |
|
|
|