diff --git a/src/main/java/com/ffii/tsms/modules/data/service/CustomerService.kt b/src/main/java/com/ffii/tsms/modules/data/service/CustomerService.kt index 9202f2d..e0fee79 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/CustomerService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/CustomerService.kt @@ -11,6 +11,7 @@ import com.ffii.tsms.modules.project.web.models.SaveCustomerRequest import org.springframework.beans.BeanUtils import org.springframework.stereotype.Service import java.util.Optional +import kotlin.jvm.optionals.getOrNull @Service open class CustomerService( @@ -37,6 +38,10 @@ open class CustomerService( return customerRepository.findByCode(code); } + open fun findCustomerType(id: Long): CustomerType? { + return customerTypeRepository.findById(id).getOrNull() + } + open fun createClientCode(): String { val prefix = "CT" diff --git a/src/main/java/com/ffii/tsms/modules/project/entity/Project.kt b/src/main/java/com/ffii/tsms/modules/project/entity/Project.kt index 0793275..77a3e36 100644 --- a/src/main/java/com/ffii/tsms/modules/project/entity/Project.kt +++ b/src/main/java/com/ffii/tsms/modules/project/entity/Project.kt @@ -135,4 +135,8 @@ open class Project : BaseEntity() { @ManyToOne @JoinColumn(name = "subsidiaryContactId") open var subsidiaryContact: SubsidiaryContact? = null + + @ManyToOne + @JoinColumn(name = "customerTypeId") + open var customerType: CustomerType? = null } \ No newline at end of file diff --git a/src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt b/src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt index 90fefea..0892abd 100644 --- a/src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt +++ b/src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt @@ -181,6 +181,7 @@ open class ProjectsService( .orElseThrow() else null val teamLead = staffRepository.findById(request.projectLeadId).orElseThrow() val customer = customerService.findCustomer(request.clientId) + val customerType = request.clientTypeId?.let { customerService.findCustomerType(it) } ?: customer.customerType val subsidiaryContact = if (request.clientContactId != null) subsidiaryContactRepository.findById(request.clientContactId) .orElse(null) else null @@ -255,6 +256,7 @@ open class ProjectsService( this.customerSubsidiary = customerSubsidiary this.customerContact = if (customerSubsidiary == null) clientContact else null this.subsidiaryContact = if (customerSubsidiary != null) subsidiaryContact else null + this.customerType = customerType } @@ -403,6 +405,7 @@ open class ProjectsService( buildingTypeIds = it.buildingTypes.mapNotNull { buildingType -> buildingType.id }, workNatureIds = it.workNatures.mapNotNull { workNature -> workNature.id }, clientId = it.customer?.id, + clientTypeId = it.customerType?.id ?: it.customer?.customerType?.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, @@ -745,6 +748,7 @@ open class ProjectsService( valueTransform = { it.percentage!! } ), projectActualEnd = null, + clientTypeId = null, taskTemplateId = taskTemplate.id, taskGroups = taskGroups, milestones = mapOf( diff --git a/src/main/java/com/ffii/tsms/modules/project/web/models/EditProjectDetails.kt b/src/main/java/com/ffii/tsms/modules/project/web/models/EditProjectDetails.kt index 0cb0f1e..d89d1c9 100644 --- a/src/main/java/com/ffii/tsms/modules/project/web/models/EditProjectDetails.kt +++ b/src/main/java/com/ffii/tsms/modules/project/web/models/EditProjectDetails.kt @@ -29,6 +29,7 @@ data class EditProjectDetails( val clientId: Long?, val clientContactId: Long?, val clientSubsidiaryId: Long?, + val clientTypeId: Long?, // Allocation val totalManhour: Double?, diff --git a/src/main/java/com/ffii/tsms/modules/project/web/models/NewProjectRequest.kt b/src/main/java/com/ffii/tsms/modules/project/web/models/NewProjectRequest.kt index 5fdea98..b3214e6 100644 --- a/src/main/java/com/ffii/tsms/modules/project/web/models/NewProjectRequest.kt +++ b/src/main/java/com/ffii/tsms/modules/project/web/models/NewProjectRequest.kt @@ -34,6 +34,7 @@ data class NewProjectRequest( val clientId: Long, val clientContactId: Long?, val clientSubsidiaryId: Long?, + val clientTypeId: Long?, // Allocation val totalManhour: Double, diff --git a/src/main/resources/db/changelog/changes/20240812_01_wayne/01_project_add_customer_type.sql b/src/main/resources/db/changelog/changes/20240812_01_wayne/01_project_add_customer_type.sql new file mode 100644 index 0000000..9c92237 --- /dev/null +++ b/src/main/resources/db/changelog/changes/20240812_01_wayne/01_project_add_customer_type.sql @@ -0,0 +1,6 @@ +-- liquibase formatted sql +-- changeset wayne:project_add_customer_Type + +ALTER TABLE project ADD customerTypeId INT NULL; + +ALTER TABLE project ADD CONSTRAINT FK_PROJECT_ON_CUSTOMERTYPEID FOREIGN KEY (customerTypeId) REFERENCES customer_type (id);