| @@ -17,7 +17,7 @@ class CustomerContactService( | |||||
| } | } | ||||
| fun findByContactId(contactId: Long): CustomerContact { | fun findByContactId(contactId: Long): CustomerContact { | ||||
| return customerContactRepository.findById(contactId).orElseThrow() | |||||
| return customerContactRepository.findById(contactId).orElse(null) | |||||
| } | } | ||||
| fun saveContactsByCustomer(saveCustomerId: Long, saveCustomerContact: List<CustomerContact>) { | fun saveContactsByCustomer(saveCustomerId: Long, saveCustomerContact: List<CustomerContact>) { | ||||
| @@ -123,4 +123,12 @@ open class Project : BaseEntity<Long>() { | |||||
| // @JsonBackReference | // @JsonBackReference | ||||
| @JoinColumn(name = "mainProjectId") | @JoinColumn(name = "mainProjectId") | ||||
| open var mainProject: Project? = null | open var mainProject: Project? = null | ||||
| @ManyToOne | |||||
| @JoinColumn(name = "customerContactId") | |||||
| open var customerContact: CustomerContact? = null | |||||
| @ManyToOne | |||||
| @JoinColumn(name = "subsidiaryContactId") | |||||
| open var subsidiaryContact: SubsidiaryContact? = null | |||||
| } | } | ||||
| @@ -25,7 +25,7 @@ interface ProjectRepository : AbstractRepository<Project, Long> { | |||||
| "") | "") | ||||
| fun getLatestCodeNumberByMainProject(isClpProject: Boolean, id: Serializable?): Long? | fun getLatestCodeNumberByMainProject(isClpProject: Boolean, id: Serializable?): Long? | ||||
| @Query("SELECT max(cast(substring_index(p.code, '-', -1) as long)) FROM Project p WHERE p.code like ?1 and p.id != ?2") | |||||
| @Query("SELECT max(case when length(p.code) - length(replace(p.code, '-', '')) > 1 then cast(substring_index(p.code, '-', -1) as long) end) FROM Project p WHERE p.code like ?1 and p.id != ?2") | |||||
| fun getLatestCodeNumberBySubProject(code: String, id: Serializable?): Long? | fun getLatestCodeNumberBySubProject(code: String, id: Serializable?): Long? | ||||
| fun findAllByStatusIsNotAndMainProjectIsNull(status: String): List<Project> | fun findAllByStatusIsNotAndMainProjectIsNull(status: String): List<Project> | ||||
| @@ -11,6 +11,9 @@ interface ProjectSearchInfo { | |||||
| val code: String? | val code: String? | ||||
| val status: String? | val status: String? | ||||
| @get:Value("#{target.mainProject?.code}") | |||||
| val mainProject: String? | |||||
| @get:Value("#{target.projectCategory.name}") | @get:Value("#{target.projectCategory.name}") | ||||
| val category: String? | val category: String? | ||||
| @@ -210,6 +210,8 @@ open class ProjectsService( | |||||
| custLeadPhone = | custLeadPhone = | ||||
| if (request.isSubsidiaryContact == null || !request.isSubsidiaryContact) clientContact.phone else subsidiaryContact.phone | if (request.isSubsidiaryContact == null || !request.isSubsidiaryContact) clientContact.phone else subsidiaryContact.phone | ||||
| this.customerSubsidiary = customerSubsidiary | this.customerSubsidiary = customerSubsidiary | ||||
| this.customerContact = if (customerSubsidiary == null) clientContact else null | |||||
| this.subsidiaryContact = if (customerSubsidiary != null) subsidiaryContact else null | |||||
| } | } | ||||
| @@ -325,11 +327,11 @@ open class ProjectsService( | |||||
| val project = projectRepository.findById(projectId) | val project = projectRepository.findById(projectId) | ||||
| return project.getOrNull()?.let { | return project.getOrNull()?.let { | ||||
| val subsidiaryContact = it.customerSubsidiary?.id?.let { subsidiaryId -> | |||||
| subsidiaryContactService.findAllBySubsidiaryId(subsidiaryId) | |||||
| } ?: emptyList() | |||||
| val customerContact = it.customer?.id?.let { customerId -> customerContactService.findAllByCustomerId(customerId) } | |||||
| ?: emptyList() | |||||
| // val subsidiaryContact = it.customerSubsidiary?.id?.let { subsidiaryId -> | |||||
| // subsidiaryContactService.findAllBySubsidiaryId(subsidiaryId) | |||||
| // } ?: emptyList() | |||||
| // val customerContact = it.customer?.id?.let { customerId -> customerContactService.findAllByCustomerId(customerId) } | |||||
| // ?: emptyList() | |||||
| val milestoneMap = it.milestones.filter { milestone -> milestone.taskGroup?.id != null } | val milestoneMap = it.milestones.filter { milestone -> milestone.taskGroup?.id != null } | ||||
| .associateBy { milestone -> milestone.taskGroup!!.id!! } | .associateBy { milestone -> milestone.taskGroup!!.id!! } | ||||
| @@ -345,6 +347,7 @@ open class ProjectsService( | |||||
| projectActualEnd = it.actualEnd, | projectActualEnd = it.actualEnd, | ||||
| projectStatus = it.status, | projectStatus = it.status, | ||||
| isClpProject = it.isClpProject, | isClpProject = it.isClpProject, | ||||
| mainProjectId = it.mainProject?.id, | |||||
| serviceTypeId = it.serviceType?.id, | serviceTypeId = it.serviceType?.id, | ||||
| fundingTypeId = it.fundingType?.id, | fundingTypeId = it.fundingType?.id, | ||||
| contractTypeId = it.contractType?.id, | contractTypeId = it.contractType?.id, | ||||
| @@ -353,7 +356,8 @@ open class ProjectsService( | |||||
| buildingTypeIds = it.buildingTypes.mapNotNull { buildingType -> buildingType.id }, | buildingTypeIds = it.buildingTypes.mapNotNull { buildingType -> buildingType.id }, | ||||
| workNatureIds = it.workNatures.mapNotNull { workNature -> workNature.id }, | workNatureIds = it.workNatures.mapNotNull { workNature -> workNature.id }, | ||||
| clientId = it.customer?.id, | clientId = it.customer?.id, | ||||
| clientContactId = subsidiaryContact.find { contact -> contact.name == it.custLeadName }?.id ?: customerContact.find { contact -> contact.name == it.custLeadName }?.id, | |||||
| clientContactId = it.subsidiaryContact?.id ?: it.customerContact?.id, | |||||
| // subsidiaryContact.find { contact -> contact.name == it.custLeadName }?.id ?: customerContact.find { contact -> contact.name == it.custLeadName }?.id, | |||||
| clientSubsidiaryId = it.customerSubsidiary?.id, | clientSubsidiaryId = it.customerSubsidiary?.id, | ||||
| totalManhour = it.totalManhour, | totalManhour = it.totalManhour, | ||||
| manhourPercentageByGrade = gradeAllocationRepository.findByProject(it) | manhourPercentageByGrade = gradeAllocationRepository.findByProject(it) | ||||
| @@ -15,6 +15,7 @@ data class EditProjectDetails( | |||||
| val projectActualEnd: LocalDate?, | val projectActualEnd: LocalDate?, | ||||
| val projectStatus: String?, | val projectStatus: String?, | ||||
| val isClpProject: Boolean?, | val isClpProject: Boolean?, | ||||
| val mainProjectId: Long?, | |||||
| val serviceTypeId: Long?, | val serviceTypeId: Long?, | ||||
| val fundingTypeId: Long?, | val fundingTypeId: Long?, | ||||
| @@ -0,0 +1,20 @@ | |||||
| -- liquibase formatted sql | |||||
| -- changeset cyril:project | |||||
| ALTER TABLE `project` | |||||
| ADD COLUMN `customerContactId` INT NULL DEFAULT NULL AFTER `mainProjectId`, | |||||
| ADD COLUMN `subsidiaryContactId` INT NULL DEFAULT NULL AFTER `customerContactId`, | |||||
| ADD INDEX `FK_PROJECT_ON_CUSTOMERCONTACTID` (`customerContactId` ASC) VISIBLE, | |||||
| ADD INDEX `FK_PROJECT_ON_SUBSIDIARYCONTACTID` (`subsidiaryContactId` ASC) VISIBLE; | |||||
| ; | |||||
| ALTER TABLE `project` | |||||
| ADD CONSTRAINT `FK_PROJECT_ON_CUSTOMERCONTACTID` | |||||
| FOREIGN KEY (`customerContactId`) | |||||
| REFERENCES `customer_contact` (`id`) | |||||
| ON DELETE NO ACTION | |||||
| ON UPDATE NO ACTION, | |||||
| ADD CONSTRAINT `FK_PROJECT_ON_SUBSIDIARYCONTACTID` | |||||
| FOREIGN KEY (`subsidiaryContactId`) | |||||
| REFERENCES `subsidiary_contact` (`id`) | |||||
| ON DELETE NO ACTION | |||||
| ON UPDATE NO ACTION; | |||||