| @@ -0,0 +1,38 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.entity | |||||
| import com.ffii.core.entity.BaseEntity | |||||
| import com.ffii.fpsms.modules.master.entity.Shop | |||||
| import jakarta.persistence.* | |||||
| import jakarta.validation.constraints.NotNull | |||||
| import jakarta.validation.constraints.Size | |||||
| import java.time.Instant | |||||
| import java.time.LocalDateTime | |||||
| @Entity | |||||
| @Table(name = "purchase_quotation") | |||||
| open class PurchaseQuotation : BaseEntity<Long>(){ | |||||
| @Size(max = 30) | |||||
| @NotNull | |||||
| @Column(name = "code", nullable = false, length = 30) | |||||
| open var code: String? = null | |||||
| @Column(name = "expiryDate") | |||||
| open var expiryDate: LocalDateTime? = null | |||||
| @Column(name = "effectiveDate") | |||||
| open var effectiveDate: LocalDateTime? = null | |||||
| @ManyToOne | |||||
| @JoinColumn(name = "shopId") | |||||
| open var shop: Shop? = null | |||||
| @Size(max = 500) | |||||
| @Column(name = "remarks", length = 500) | |||||
| open var remarks: String? = null | |||||
| @Column(name = "m18Id") | |||||
| open var m18Id: Long? = null | |||||
| @Column(name = "m18LastModifyDate") | |||||
| open var m18LastModifyDate: LocalDateTime? = null | |||||
| } | |||||
| @@ -0,0 +1,39 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.entity | |||||
| import com.ffii.core.entity.BaseEntity | |||||
| import com.ffii.fpsms.modules.master.entity.Items | |||||
| import com.ffii.fpsms.modules.master.entity.UomConversion | |||||
| import jakarta.persistence.* | |||||
| import jakarta.validation.constraints.Size | |||||
| import java.time.Instant | |||||
| import java.time.LocalDateTime | |||||
| @Entity | |||||
| @Table(name = "purchase_quotation_line") | |||||
| open class PurchaseQuotationLine : BaseEntity<Long>() { | |||||
| @ManyToOne | |||||
| @JoinColumn(name = "purchaseQuotationId") | |||||
| open var purchaseQuotation: PurchaseQuotation? = null | |||||
| @ManyToOne | |||||
| @JoinColumn(name = "itemId") | |||||
| open var item: Items? = null | |||||
| @Size(max = 30) | |||||
| @Column(name = "code", length = 30) | |||||
| open var code: String? = null | |||||
| @Size(max = 30) | |||||
| @Column(name = "description", length = 30) | |||||
| open var description: String? = null | |||||
| @ManyToOne | |||||
| @JoinColumn(name = "uomId") | |||||
| open var uom: UomConversion? = null | |||||
| @Column(name = "m18Id") | |||||
| open var m18Id: Long? = null | |||||
| @Column(name = "m18LastModifyDate") | |||||
| open var m18LastModifyDate: LocalDateTime? = null | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.entity | |||||
| import com.ffii.core.support.AbstractRepository | |||||
| import org.springframework.stereotype.Repository | |||||
| import java.io.Serializable | |||||
| @Repository | |||||
| interface PurchaseQuotationLineRepository : AbstractRepository<PurchaseQuotationLine, Long>{ | |||||
| fun findByM18IdAndDeletedIsFalse(m18Id: Long): PurchaseQuotationLine? | |||||
| fun findByIdAndDeletedIsFalse(id: Serializable): PurchaseQuotationLine? | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.entity | |||||
| import com.ffii.core.support.AbstractRepository | |||||
| import org.springframework.stereotype.Repository | |||||
| import java.io.Serializable | |||||
| @Repository | |||||
| interface PurchaseQuotationRepository : AbstractRepository<PurchaseQuotation, Long> { | |||||
| fun findByIdAndDeletedIsFalse(id: Serializable): PurchaseQuotation? | |||||
| fun findByM18IdAndDeletedIsFalse(m18Id: Long): PurchaseQuotation? | |||||
| } | |||||
| @@ -0,0 +1,56 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.service | |||||
| import com.ffii.fpsms.modules.master.service.ItemUomService | |||||
| import com.ffii.fpsms.modules.master.service.ItemsService | |||||
| import com.ffii.fpsms.modules.master.service.UomConversionService | |||||
| import com.ffii.fpsms.modules.purchaseQuotation.entity.PurchaseQuotationLine | |||||
| import com.ffii.fpsms.modules.purchaseQuotation.entity.PurchaseQuotationLineRepository | |||||
| import com.ffii.fpsms.modules.purchaseQuotation.web.model.SavePurchaseQuotationLineRequest | |||||
| import com.ffii.fpsms.modules.purchaseQuotation.web.model.SavePurchaseQuotationLineResponse | |||||
| import org.springframework.stereotype.Service | |||||
| @Service | |||||
| open class PurchaseQuotationLineService ( | |||||
| private val purchaseQuotationLineRepository: PurchaseQuotationLineRepository, | |||||
| private val purchaseQuotationService: PurchaseQuotationService, | |||||
| private val itemsService: ItemsService, | |||||
| private val uomConversionService: UomConversionService, | |||||
| private val itemUomService: ItemUomService, | |||||
| ) { | |||||
| open fun findById(id: Long): PurchaseQuotationLine? { | |||||
| return purchaseQuotationLineRepository.findByIdAndDeletedIsFalse(id); | |||||
| } | |||||
| open fun findByM18Id(m18Id: Long): PurchaseQuotationLine? { | |||||
| return purchaseQuotationLineRepository.findByM18IdAndDeletedIsFalse(m18Id); | |||||
| } | |||||
| open fun savePurchaseQuotationLine(request: SavePurchaseQuotationLineRequest): SavePurchaseQuotationLineResponse { | |||||
| val purchaseQuotationLine = request.m18Id?.let { findByM18Id(it) } ?: request.id?.let { findById(it) } ?: PurchaseQuotationLine() | |||||
| val purchaseQuotation = request.purchaseQuotationId?.let { purchaseQuotationService.findById(it) } | |||||
| val item = request.m18ItemId?.let { itemsService.findByM18Id(it) } ?: request.itemId?.let { itemsService.findById(it) } | |||||
| val uom = request.uomId?.let { uomConversionService.findById(it) } ?: item?.id?.let { itemUomService.findPurchaseUnitByM18ItemId(it)?.uom } | |||||
| purchaseQuotationLine.apply { | |||||
| this.purchaseQuotation = purchaseQuotation | |||||
| this.item = item | |||||
| code = request.code | |||||
| description = request.description | |||||
| this.uom = uom | |||||
| m18Id = request.m18Id ?: this.m18Id | |||||
| m18LastModifyDate = request.m18LastModifyDate ?: this.m18LastModifyDate | |||||
| } | |||||
| val response = purchaseQuotationLineRepository.saveAndFlush(purchaseQuotationLine).let { | |||||
| SavePurchaseQuotationLineResponse( | |||||
| id = it.id, | |||||
| itemCode = it.item?.code, | |||||
| code = it.code, | |||||
| description = it.description, | |||||
| uomCode = it.uom?.code | |||||
| ) | |||||
| } | |||||
| return response | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,50 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.service | |||||
| import com.ffii.fpsms.modules.master.service.ShopService | |||||
| import com.ffii.fpsms.modules.purchaseQuotation.entity.PurchaseQuotation | |||||
| import com.ffii.fpsms.modules.purchaseQuotation.entity.PurchaseQuotationRepository | |||||
| import com.ffii.fpsms.modules.purchaseQuotation.web.model.SavePurchaseQuotationRequest | |||||
| import com.ffii.fpsms.modules.purchaseQuotation.web.model.SavePurchaseQuotationResponse | |||||
| import org.springframework.stereotype.Service | |||||
| @Service | |||||
| open class PurchaseQuotationService( | |||||
| private val purchaseQuotationRepository: PurchaseQuotationRepository, | |||||
| private val shopService: ShopService, | |||||
| ) { | |||||
| open fun findById(id: Long): PurchaseQuotation? { | |||||
| return purchaseQuotationRepository.findByIdAndDeletedIsFalse(id); | |||||
| } | |||||
| open fun findByM18Id(m18Id: Long): PurchaseQuotation? { | |||||
| return purchaseQuotationRepository.findByM18IdAndDeletedIsFalse(m18Id); | |||||
| } | |||||
| open fun savePurchaseQuotation(request: SavePurchaseQuotationRequest): SavePurchaseQuotationResponse { | |||||
| val purchaseQuotation = request.m18Id?.let { findByM18Id(it) } ?: request.id?.let { findById(it) } ?: PurchaseQuotation() | |||||
| val shop = request.m18ShopId?.let { shopService.findVendorByM18Id(it) } ?: request.shopId?.let { shopService.findById(it) } | |||||
| purchaseQuotation.apply { | |||||
| code = request.code | |||||
| expiryDate = request.expiryDate | |||||
| effectiveDate = request.effectiveDate | |||||
| this.shop = shop | |||||
| remarks = request.remarks | |||||
| m18Id = request.m18Id | |||||
| m18LastModifyDate = request.m18LastModifyDate | |||||
| } | |||||
| val response = purchaseQuotationRepository.saveAndFlush(purchaseQuotation).let { | |||||
| SavePurchaseQuotationResponse( | |||||
| id = it.id, | |||||
| code = it.code, | |||||
| expiryDate = it.expiryDate, | |||||
| effectiveDate = it.effectiveDate, | |||||
| shopCode = it.shop?.code, | |||||
| remarks = it.remarks | |||||
| ) | |||||
| } | |||||
| return response | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,16 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.web.model | |||||
| import java.time.LocalDateTime | |||||
| data class SavePurchaseQuotationLineRequest( | |||||
| val id: Long? = null, | |||||
| val purchaseQuotationId: Long? = null, | |||||
| val itemId: Long? = null, | |||||
| val m18ItemId: Long? = null, | |||||
| val code: String? = null, | |||||
| val description: String? = null, | |||||
| val uomId: Long? = null, | |||||
| val m18UomId: Long? = null, | |||||
| val m18Id: Long? = null, | |||||
| val m18LastModifyDate: LocalDateTime? = null | |||||
| ) | |||||
| @@ -0,0 +1,11 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.web.model | |||||
| import java.time.LocalDateTime | |||||
| data class SavePurchaseQuotationLineResponse ( | |||||
| val id: Long? = null, | |||||
| val itemCode: String? = null, | |||||
| val code: String? = null, | |||||
| val description: String? = null, | |||||
| val uomCode: String? = null, | |||||
| ) | |||||
| @@ -0,0 +1,15 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.web.model | |||||
| import java.time.LocalDateTime | |||||
| data class SavePurchaseQuotationRequest( | |||||
| val id: Long? = null, | |||||
| val code: String? = null, | |||||
| val expiryDate: LocalDateTime? = null, | |||||
| val effectiveDate: LocalDateTime? = null, | |||||
| val shopId: Long? = null, | |||||
| val m18ShopId: Long? = null, | |||||
| val remarks: String? = null, | |||||
| val m18Id: Long? = null, | |||||
| val m18LastModifyDate: LocalDateTime? = null, | |||||
| ) | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.ffii.fpsms.modules.purchaseQuotation.web.model | |||||
| import java.time.LocalDateTime | |||||
| data class SavePurchaseQuotationResponse( | |||||
| val id: Long? = null, | |||||
| val code: String? = null, | |||||
| val expiryDate: LocalDateTime? = null, | |||||
| val effectiveDate: LocalDateTime? = null, | |||||
| val shopCode: String? = null, | |||||
| val remarks: String? = null, | |||||
| ) | |||||