Browse Source

Add client type to project

tags/Baseline_30082024_BACKEND_UAT
Wayne 1 year ago
parent
commit
ff402849c1
6 changed files with 21 additions and 0 deletions
  1. +5
    -0
      src/main/java/com/ffii/tsms/modules/data/service/CustomerService.kt
  2. +4
    -0
      src/main/java/com/ffii/tsms/modules/project/entity/Project.kt
  3. +4
    -0
      src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt
  4. +1
    -0
      src/main/java/com/ffii/tsms/modules/project/web/models/EditProjectDetails.kt
  5. +1
    -0
      src/main/java/com/ffii/tsms/modules/project/web/models/NewProjectRequest.kt
  6. +6
    -0
      src/main/resources/db/changelog/changes/20240812_01_wayne/01_project_add_customer_type.sql

+ 5
- 0
src/main/java/com/ffii/tsms/modules/data/service/CustomerService.kt View File

@@ -11,6 +11,7 @@ import com.ffii.tsms.modules.project.web.models.SaveCustomerRequest
import org.springframework.beans.BeanUtils import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import java.util.Optional import java.util.Optional
import kotlin.jvm.optionals.getOrNull


@Service @Service
open class CustomerService( open class CustomerService(
@@ -37,6 +38,10 @@ open class CustomerService(
return customerRepository.findByCode(code); return customerRepository.findByCode(code);
} }


open fun findCustomerType(id: Long): CustomerType? {
return customerTypeRepository.findById(id).getOrNull()
}

open fun createClientCode(): String { open fun createClientCode(): String {
val prefix = "CT" val prefix = "CT"




+ 4
- 0
src/main/java/com/ffii/tsms/modules/project/entity/Project.kt View File

@@ -135,4 +135,8 @@ open class Project : BaseEntity<Long>() {
@ManyToOne @ManyToOne
@JoinColumn(name = "subsidiaryContactId") @JoinColumn(name = "subsidiaryContactId")
open var subsidiaryContact: SubsidiaryContact? = null open var subsidiaryContact: SubsidiaryContact? = null

@ManyToOne
@JoinColumn(name = "customerTypeId")
open var customerType: CustomerType? = null
} }

+ 4
- 0
src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt View File

@@ -181,6 +181,7 @@ open class ProjectsService(
.orElseThrow() else null .orElseThrow() else null
val teamLead = staffRepository.findById(request.projectLeadId).orElseThrow() val teamLead = staffRepository.findById(request.projectLeadId).orElseThrow()
val customer = customerService.findCustomer(request.clientId) val customer = customerService.findCustomer(request.clientId)
val customerType = request.clientTypeId?.let { customerService.findCustomerType(it) } ?: customer.customerType
val subsidiaryContact = val subsidiaryContact =
if (request.clientContactId != null) subsidiaryContactRepository.findById(request.clientContactId) if (request.clientContactId != null) subsidiaryContactRepository.findById(request.clientContactId)
.orElse(null) else null .orElse(null) else null
@@ -255,6 +256,7 @@ open class ProjectsService(
this.customerSubsidiary = customerSubsidiary this.customerSubsidiary = customerSubsidiary
this.customerContact = if (customerSubsidiary == null) clientContact else null this.customerContact = if (customerSubsidiary == null) clientContact else null
this.subsidiaryContact = if (customerSubsidiary != null) subsidiaryContact 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 }, 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,
clientTypeId = it.customerType?.id ?: it.customer?.customerType?.id,
clientContactId = it.subsidiaryContact?.id ?: it.customerContact?.id, clientContactId = it.subsidiaryContact?.id ?: it.customerContact?.id,
// subsidiaryContact.find { contact -> contact.name == it.custLeadName }?.id ?: customerContact.find { contact -> contact.name == it.custLeadName }?.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,
@@ -745,6 +748,7 @@ open class ProjectsService(
valueTransform = { it.percentage!! } valueTransform = { it.percentage!! }
), ),
projectActualEnd = null, projectActualEnd = null,
clientTypeId = null,
taskTemplateId = taskTemplate.id, taskTemplateId = taskTemplate.id,
taskGroups = taskGroups, taskGroups = taskGroups,
milestones = mapOf( milestones = mapOf(


+ 1
- 0
src/main/java/com/ffii/tsms/modules/project/web/models/EditProjectDetails.kt View File

@@ -29,6 +29,7 @@ data class EditProjectDetails(
val clientId: Long?, val clientId: Long?,
val clientContactId: Long?, val clientContactId: Long?,
val clientSubsidiaryId: Long?, val clientSubsidiaryId: Long?,
val clientTypeId: Long?,


// Allocation // Allocation
val totalManhour: Double?, val totalManhour: Double?,


+ 1
- 0
src/main/java/com/ffii/tsms/modules/project/web/models/NewProjectRequest.kt View File

@@ -34,6 +34,7 @@ data class NewProjectRequest(
val clientId: Long, val clientId: Long,
val clientContactId: Long?, val clientContactId: Long?,
val clientSubsidiaryId: Long?, val clientSubsidiaryId: Long?,
val clientTypeId: Long?,


// Allocation // Allocation
val totalManhour: Double, val totalManhour: Double,


+ 6
- 0
src/main/resources/db/changelog/changes/20240812_01_wayne/01_project_add_customer_type.sql View File

@@ -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);

Loading…
Cancel
Save