| @@ -4,6 +4,7 @@ import com.ffii.core.entity.BaseEntity | |||||
| import com.ffii.fpsms.modules.master.web.models.ItemType | import com.ffii.fpsms.modules.master.web.models.ItemType | ||||
| import jakarta.persistence.* | import jakarta.persistence.* | ||||
| import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
| import java.time.LocalDateTime | |||||
| @Entity | @Entity | ||||
| @Table(name = "items") | @Table(name = "items") | ||||
| @@ -37,4 +38,7 @@ open class Items : BaseEntity<Long>() { | |||||
| @Column(name = "m18Id") | @Column(name = "m18Id") | ||||
| open var m18Id: Long? = null | open var m18Id: Long? = null | ||||
| @Column(name = "m18LastModifyDate") | |||||
| open var m18LastModifyDate: LocalDateTime? = null | |||||
| } | } | ||||
| @@ -7,6 +7,10 @@ import org.springframework.stereotype.Repository | |||||
| @Repository | @Repository | ||||
| interface ItemsRepository : AbstractRepository<Items, Long> { | interface ItemsRepository : AbstractRepository<Items, Long> { | ||||
| fun findAllByDeletedFalse(): List<Items>; | fun findAllByDeletedFalse(): List<Items>; | ||||
| fun findByIdAndDeletedFalse(id: Long): Items; | fun findByIdAndDeletedFalse(id: Long): Items; | ||||
| fun findByCodeAndTypeAndDeletedFalse(code: String, type: String): Items?; | fun findByCodeAndTypeAndDeletedFalse(code: String, type: String): Items?; | ||||
| fun findByM18IdAndDeletedIsFalse(m18Id: Long): Items?; | |||||
| } | } | ||||
| @@ -1,63 +1,75 @@ | |||||
| package com.ffii.fpsms.modules.master.entity | package com.ffii.fpsms.modules.master.entity | ||||
| import com.ffii.core.entity.BaseEntity | import com.ffii.core.entity.BaseEntity | ||||
| import com.ffii.fpsms.modules.master.enums.ShopType | |||||
| import com.ffii.fpsms.modules.master.enums.ShopTypeConverter | |||||
| import jakarta.persistence.Column | import jakarta.persistence.Column | ||||
| import jakarta.persistence.Convert | |||||
| import jakarta.persistence.Entity | import jakarta.persistence.Entity | ||||
| import jakarta.persistence.Table | import jakarta.persistence.Table | ||||
| import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
| import jakarta.validation.constraints.Size | import jakarta.validation.constraints.Size | ||||
| import java.time.LocalDateTime | |||||
| @Entity | @Entity | ||||
| @Table(name = "shop") | @Table(name = "shop") | ||||
| open class Shop : BaseEntity<Long>() { | open class Shop : BaseEntity<Long>() { | ||||
| @Size(max = 30) | |||||
| @Size(max = 50) | |||||
| @NotNull | @NotNull | ||||
| @Column(name = "code", nullable = false, length = 30) | |||||
| @Column(name = "code", nullable = false, length = 50) | |||||
| open var code: String? = null | open var code: String? = null | ||||
| @Size(max = 30) | |||||
| @Size(max = 300) | |||||
| @NotNull | @NotNull | ||||
| @Column(name = "name", nullable = false, length = 30) | |||||
| @Column(name = "name", nullable = false, length = 300) | |||||
| open var name: String? = null | open var name: String? = null | ||||
| @Size(max = 30) | |||||
| @Column(name = "brNo", length = 30) | |||||
| @Size(max = 50) | |||||
| @Column(name = "brNo", length = 50) | |||||
| open var brNo: String? = null | open var brNo: String? = null | ||||
| @Size(max = 30) | |||||
| @Column(name = "contactNo", length = 30) | |||||
| @Size(max = 50) | |||||
| @Column(name = "contactNo", length = 50) | |||||
| open var contactNo: String? = null | open var contactNo: String? = null | ||||
| @Size(max = 30) | |||||
| @Column(name = "contactEmail", length = 30) | |||||
| @Size(max = 50) | |||||
| @Column(name = "contactEmail", length = 50) | |||||
| open var contactEmail: String? = null | open var contactEmail: String? = null | ||||
| @Size(max = 30) | |||||
| @Column(name = "contactName", length = 30) | |||||
| @Size(max = 50) | |||||
| @Column(name = "contactName", length = 50) | |||||
| open var contactName: String? = null | open var contactName: String? = null | ||||
| @Size(max = 30) | |||||
| @Column(name = "addr1", length = 30) | |||||
| @Size(max = 300) | |||||
| @Column(name = "addr1", length = 300) | |||||
| open var addr1: String? = null | open var addr1: String? = null | ||||
| @Size(max = 30) | |||||
| @Column(name = "addr2", length = 30) | |||||
| @Size(max = 300) | |||||
| @Column(name = "addr2", length = 300) | |||||
| open var addr2: String? = null | open var addr2: String? = null | ||||
| @Size(max = 30) | |||||
| @Column(name = "addr3", length = 30) | |||||
| @Size(max = 300) | |||||
| @Column(name = "addr3", length = 300) | |||||
| open var addr3: String? = null | open var addr3: String? = null | ||||
| @Size(max = 30) | |||||
| @Column(name = "addr4", length = 30) | |||||
| @Size(max = 300) | |||||
| @Column(name = "addr4", length = 300) | |||||
| open var addr4: String? = null | open var addr4: String? = null | ||||
| @Size(max = 30) | |||||
| @Column(name = "district", length = 30) | |||||
| @Size(max = 300) | |||||
| @Column(name = "district", length = 300) | |||||
| open var district: String? = null | open var district: String? = null | ||||
| @Size(max = 10) | |||||
| @Convert(converter = ShopTypeConverter::class) | |||||
| @Column(name = "type", length = 10) | @Column(name = "type", length = 10) | ||||
| open var type: String? = null | |||||
| open var type: ShopType? = null | |||||
| @NotNull | |||||
| @Column(name = "m18Id", nullable = false) | |||||
| open var m18Id: Long? = null | |||||
| @NotNull | |||||
| @Column(name = "m18LastModifyDate", nullable = false) | |||||
| open var m18LastModifyDate: LocalDateTime? = null | |||||
| } | } | ||||
| @@ -5,4 +5,9 @@ import org.springframework.stereotype.Repository | |||||
| @Repository | @Repository | ||||
| interface ShopRepository : AbstractRepository<Shop, Long> { | interface ShopRepository : AbstractRepository<Shop, Long> { | ||||
| fun findAllByDeletedIsFalse(): List<Shop> | |||||
| fun findByIdAndDeletedIsFalse(id: Long): Shop? | |||||
| fun findByM18IdAndDeletedIsFalse(m18Id: Long): Shop? | |||||
| } | } | ||||
| @@ -0,0 +1,6 @@ | |||||
| package com.ffii.fpsms.modules.master.enums | |||||
| enum class ShopType(val value: String) { | |||||
| SUPPLIER("supplier"), | |||||
| SHOP("shop"); | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| package com.ffii.fpsms.modules.master.enums | |||||
| import jakarta.persistence.AttributeConverter | |||||
| import jakarta.persistence.Converter | |||||
| @Converter(autoApply = true) | |||||
| class ShopTypeConverter : AttributeConverter<ShopType, String> { | |||||
| override fun convertToDatabaseColumn(type: ShopType?): String? { | |||||
| return type?.value | |||||
| } | |||||
| override fun convertToEntityAttribute(value: String?): ShopType? { | |||||
| return value?.let { v -> | |||||
| ShopType.entries.find { it.value == v } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -48,6 +48,11 @@ open class ItemsService( | |||||
| return jdbcDao.queryForList(sql.toString(), args); | return jdbcDao.queryForList(sql.toString(), args); | ||||
| } | } | ||||
| open fun findByM18Id(m18Id: Long): Items? { | |||||
| return itemsRepository.findByM18IdAndDeletedIsFalse(m18Id) | |||||
| } | |||||
| // QcCheck included item | // QcCheck included item | ||||
| open fun getItem(id: Long): ItemWithQcResponse { | open fun getItem(id: Long): ItemWithQcResponse { | ||||
| val list = listOf(1,2) | val list = listOf(1,2) | ||||
| @@ -83,7 +88,7 @@ open class ItemsService( | |||||
| @Throws(IOException::class) | @Throws(IOException::class) | ||||
| @Transactional | @Transactional | ||||
| open fun saveItem(request: NewItemRequest): MessageResponse { | open fun saveItem(request: NewItemRequest): MessageResponse { | ||||
| val duplicatedItem = itemsRepository.findByCodeAndTypeAndDeletedFalse(request.code, request.type.name) | |||||
| val duplicatedItem = itemsRepository.findByCodeAndTypeAndDeletedFalse(request.code, request.type.type) | |||||
| if (duplicatedItem != null && duplicatedItem.id != request.id) { | if (duplicatedItem != null && duplicatedItem.id != request.id) { | ||||
| return MessageResponse( | return MessageResponse( | ||||
| id = request.id, | id = request.id, | ||||
| @@ -94,7 +99,8 @@ open class ItemsService( | |||||
| errorPosition = "code" | errorPosition = "code" | ||||
| ) | ) | ||||
| } | } | ||||
| val item = if (request.id != null && request.id > 0) itemsRepository.findByIdAndDeletedFalse(request.id) | |||||
| val item = if (request.m18Id != null) findByM18Id(request.m18Id) ?: Items() | |||||
| else if (request.id != null && request.id > 0) itemsRepository.findByIdAndDeletedFalse(request.id) | |||||
| else Items() | else Items() | ||||
| item.apply { | item.apply { | ||||
| code = request.code | code = request.code | ||||
| @@ -104,7 +110,9 @@ open class ItemsService( | |||||
| shelfLife = request.shelfLife | shelfLife = request.shelfLife | ||||
| countryOfOrigin = request.countryOfOrigin | countryOfOrigin = request.countryOfOrigin | ||||
| maxQty = request.maxQty | maxQty = request.maxQty | ||||
| this.type = request.type.name | |||||
| this.type = request.type.type | |||||
| m18Id = request.m18Id ?: this.m18Id | |||||
| m18LastModifyDate = request.m18LastModifyDate ?: this.m18LastModifyDate | |||||
| } | } | ||||
| val savedItem = itemsRepository.saveAndFlush(item) | val savedItem = itemsRepository.saveAndFlush(item) | ||||
| return MessageResponse( | return MessageResponse( | ||||
| @@ -4,7 +4,11 @@ import com.ffii.core.support.AbstractBaseEntityService | |||||
| import com.ffii.core.support.JdbcDao | import com.ffii.core.support.JdbcDao | ||||
| import com.ffii.fpsms.modules.master.entity.QcItem | import com.ffii.fpsms.modules.master.entity.QcItem | ||||
| import com.ffii.fpsms.modules.master.entity.QcItemRepository | import com.ffii.fpsms.modules.master.entity.QcItemRepository | ||||
| import com.ffii.fpsms.modules.master.web.models.SaveQcItemRequest | |||||
| import com.ffii.fpsms.modules.master.web.models.SaveQcItemResponse | |||||
| import jakarta.validation.Valid | |||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
| import org.springframework.web.bind.annotation.RequestBody | |||||
| @Service | @Service | ||||
| open class QcItemService( | open class QcItemService( | ||||
| @@ -31,4 +35,49 @@ open class QcItemService( | |||||
| return allQcItems() | return allQcItems() | ||||
| } | } | ||||
| open fun saveQcItem(@Valid @RequestBody request: SaveQcItemRequest): SaveQcItemResponse { | |||||
| // val qcItemProperties = QcItem::class.members.filterIsInstance<KProperty<QcItem>>() | |||||
| val errors = mutableMapOf<String, String>() | |||||
| val id = request.id | |||||
| val qcItem = if (id != null) qcItemRepository.findById(id).orElseThrow() else QcItem() | |||||
| // check duplicated code | |||||
| val duplicateQcItem = findQcItemByCode(request.code) | |||||
| if (duplicateQcItem != null && duplicateQcItem.id != qcItem.id) { | |||||
| errors["code"] = "Code is duplicated" | |||||
| } | |||||
| if (errors.isNotEmpty()) { | |||||
| request.let { | |||||
| SaveQcItemResponse( | |||||
| id = it.id, | |||||
| code = it.code, | |||||
| name = it.name, | |||||
| description = it.description, | |||||
| errors = errors | |||||
| ) | |||||
| } | |||||
| } | |||||
| // Save Qc Item | |||||
| qcItem.apply { | |||||
| code = request.code | |||||
| name = request.name | |||||
| description = request.description | |||||
| } | |||||
| val savedQcItem = qcItemRepository.save(qcItem) | |||||
| return savedQcItem.let { | |||||
| SaveQcItemResponse( | |||||
| id = it.id, | |||||
| code = it.code, | |||||
| name = it.name, | |||||
| description = it.description, | |||||
| errors = null | |||||
| ) | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,62 @@ | |||||
| package com.ffii.fpsms.modules.master.service | |||||
| import com.ffii.fpsms.modules.master.entity.Shop | |||||
| import com.ffii.fpsms.modules.master.entity.ShopRepository | |||||
| import com.ffii.fpsms.modules.master.enums.ShopType | |||||
| import com.ffii.fpsms.modules.master.web.models.SaveShopRequest | |||||
| import com.ffii.fpsms.modules.master.web.models.SaveShopResponse | |||||
| import org.springframework.stereotype.Service | |||||
| import kotlin.jvm.optionals.getOrDefault | |||||
| @Service | |||||
| open class ShopService( | |||||
| val shopRepository: ShopRepository | |||||
| ) { | |||||
| open fun findAll(): List<Shop> { | |||||
| return shopRepository.findAllByDeletedIsFalse() | |||||
| } | |||||
| open fun findById(id: Long): Shop? { | |||||
| return shopRepository.findByIdAndDeletedIsFalse(id) | |||||
| } | |||||
| open fun findByM18Id(m18Id: Long): Shop? { | |||||
| return shopRepository.findByM18IdAndDeletedIsFalse(m18Id) | |||||
| } | |||||
| open fun saveShop(request: SaveShopRequest): SaveShopResponse { | |||||
| val shop = if (request.m18Id != null) { | |||||
| findByM18Id(request.m18Id) ?: Shop() | |||||
| } else { | |||||
| request.id?.let { shopRepository.findById(it).getOrDefault(Shop()) } ?: Shop() | |||||
| } | |||||
| val type = request.type?.let { type -> ShopType.entries.find { it.value == type } } | |||||
| shop.apply { | |||||
| code = request.code | |||||
| name = request.name | |||||
| brNo = request.brNo | |||||
| contactNo = request.contactNo | |||||
| contactEmail = request.contactEmail | |||||
| contactName = request.contactName | |||||
| addr1 = request.addr1 | |||||
| addr2 = request.addr2 | |||||
| addr3 = request.addr3 | |||||
| addr4 = request.addr4 | |||||
| district = request.district | |||||
| this.type = type | |||||
| m18Id = request.m18Id ?: this.m18Id | |||||
| m18LastModifyDate = request.m18LastModifyDate ?: this.m18LastModifyDate | |||||
| } | |||||
| val response = shopRepository.saveAndFlush(shop).let { | |||||
| SaveShopResponse( | |||||
| id = it.id, | |||||
| code = it.code, | |||||
| name = it.name, | |||||
| ) | |||||
| } | |||||
| return response | |||||
| } | |||||
| } | |||||
| @@ -2,8 +2,9 @@ package com.ffii.fpsms.modules.master.web.models | |||||
| import jakarta.validation.constraints.NotBlank | import jakarta.validation.constraints.NotBlank | ||||
| import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
| import java.time.LocalDateTime | |||||
| enum class ItemType(type: String) { | |||||
| enum class ItemType(val type: String) { | |||||
| MATERIAL("mat"), | MATERIAL("mat"), | ||||
| BY_PRODUCT("byp"), | BY_PRODUCT("byp"), | ||||
| PRODUCT("product"), | PRODUCT("product"), | ||||
| @@ -24,6 +25,7 @@ data class NewItemRequest( | |||||
| val countryOfOrigin: String?, | val countryOfOrigin: String?, | ||||
| val maxQty: Double?, | val maxQty: Double?, | ||||
| val m18Id: Long?, | val m18Id: Long?, | ||||
| val m18LastModifyDate: LocalDateTime?, | |||||
| // val type: List<NewTypeRequest>?, | // val type: List<NewTypeRequest>?, | ||||
| // val uom: List<NewUomRequest>?, | // val uom: List<NewUomRequest>?, | ||||
| // val weightUnit: List<NewWeightUnitRequest>?, | // val weightUnit: List<NewWeightUnitRequest>?, | ||||
| @@ -0,0 +1,21 @@ | |||||
| package com.ffii.fpsms.modules.master.web.models | |||||
| import java.time.LocalDateTime | |||||
| data class SaveShopRequest ( | |||||
| val id: Long?, | |||||
| val code: String?, | |||||
| val name: String?, | |||||
| val brNo: String?, | |||||
| val contactNo: String?, | |||||
| val contactEmail: String?, | |||||
| val contactName: String?, | |||||
| val addr1: String?, | |||||
| val addr2: String?, | |||||
| val addr3: String?, | |||||
| val addr4: String?, | |||||
| val district: String?, | |||||
| val type: String?, | |||||
| val m18Id: Long?, | |||||
| val m18LastModifyDate: LocalDateTime?, | |||||
| ) | |||||
| @@ -0,0 +1,7 @@ | |||||
| package com.ffii.fpsms.modules.master.web.models | |||||
| data class SaveShopResponse ( | |||||
| val id: Long?, | |||||
| val code: String?, | |||||
| val name: String?, | |||||
| ) | |||||
| @@ -2,7 +2,9 @@ package com.ffii.fpsms.modules.purchaseOrder.entity | |||||
| import com.ffii.core.entity.BaseEntity | import com.ffii.core.entity.BaseEntity | ||||
| import com.ffii.fpsms.modules.master.entity.Shop | import com.ffii.fpsms.modules.master.entity.Shop | ||||
| import com.ffii.fpsms.modules.stock.entity.M18DataLog | |||||
| import com.ffii.fpsms.m18.entity.M18DataLog | |||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus | |||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatusConverter | |||||
| import jakarta.persistence.* | import jakarta.persistence.* | ||||
| import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
| import jakarta.validation.constraints.Size | import jakarta.validation.constraints.Size | ||||
| @@ -24,16 +26,16 @@ open class PurchaseOrder : BaseEntity<Long>() { | |||||
| @Column(name = "orderDate") | @Column(name = "orderDate") | ||||
| open var orderDate: LocalDateTime? = null | open var orderDate: LocalDateTime? = null | ||||
| @Column(name = "estimatedCompleteDate") | |||||
| open var estimatedCompleteDate: LocalDate? = null | |||||
| @Column(name = "estimatedArrivalDate") | |||||
| open var estimatedArrivalDate: LocalDateTime? = null | |||||
| @Column(name = "completeDate") | @Column(name = "completeDate") | ||||
| open var completeDate: LocalDateTime? = null | open var completeDate: LocalDateTime? = null | ||||
| @Size(max = 10) | |||||
| @NotNull | @NotNull | ||||
| @Column(name = "status", nullable = false, length = 10) | @Column(name = "status", nullable = false, length = 10) | ||||
| open var status: String? = null | |||||
| @Convert(converter = PurchaseOrderStatusConverter::class) | |||||
| open var status: PurchaseOrderStatus? = null | |||||
| @NotNull | @NotNull | ||||
| @ManyToOne(fetch = FetchType.LAZY, optional = false) | @ManyToOne(fetch = FetchType.LAZY, optional = false) | ||||
| @@ -2,7 +2,10 @@ package com.ffii.fpsms.modules.purchaseOrder.entity | |||||
| import com.ffii.core.entity.BaseEntity | import com.ffii.core.entity.BaseEntity | ||||
| import com.ffii.fpsms.modules.master.entity.Items | import com.ffii.fpsms.modules.master.entity.Items | ||||
| import com.ffii.fpsms.modules.stock.entity.M18DataLog | |||||
| import com.ffii.fpsms.m18.entity.M18DataLog | |||||
| import com.ffii.fpsms.modules.master.enums.ShopTypeConverter | |||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus | |||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatusConverter | |||||
| import jakarta.persistence.* | import jakarta.persistence.* | ||||
| import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
| import jakarta.validation.constraints.Size | import jakarta.validation.constraints.Size | ||||
| @@ -10,7 +13,7 @@ import java.math.BigDecimal | |||||
| @Entity | @Entity | ||||
| @Table(name = "purchase_order_line") | @Table(name = "purchase_order_line") | ||||
| class PurchaseOrderLine : BaseEntity<Long>(){ | |||||
| open class PurchaseOrderLine : BaseEntity<Long>(){ | |||||
| @NotNull | @NotNull | ||||
| @ManyToOne(fetch = FetchType.LAZY, optional = false) | @ManyToOne(fetch = FetchType.LAZY, optional = false) | ||||
| @JoinColumn(name = "itemId", nullable = false) | @JoinColumn(name = "itemId", nullable = false) | ||||
| @@ -21,6 +24,11 @@ class PurchaseOrderLine : BaseEntity<Long>(){ | |||||
| @Column(name = "itemNo", nullable = false, length = 20) | @Column(name = "itemNo", nullable = false, length = 20) | ||||
| open var itemNo: String? = null | open var itemNo: String? = null | ||||
| // @NotNull | |||||
| // @ManyToOne(fetch = FetchType.LAZY, optional = false) | |||||
| // @JoinColumn(name = "uomId", nullable = false) | |||||
| // open var uom: UomConversion? = null | |||||
| @NotNull | @NotNull | ||||
| @ManyToOne(fetch = FetchType.LAZY, optional = false) | @ManyToOne(fetch = FetchType.LAZY, optional = false) | ||||
| @JoinColumn(name = "purchaseOrderId", nullable = false) | @JoinColumn(name = "purchaseOrderId", nullable = false) | ||||
| @@ -36,10 +44,10 @@ class PurchaseOrderLine : BaseEntity<Long>(){ | |||||
| @Column(name = "priceUnit", length = 5) | @Column(name = "priceUnit", length = 5) | ||||
| open var priceUnit: String? = null | open var priceUnit: String? = null | ||||
| @Size(max = 10) | |||||
| @Convert(converter = PurchaseOrderLineStatusConverter::class) | |||||
| @NotNull | @NotNull | ||||
| @Column(name = "status", nullable = false, length = 10) | @Column(name = "status", nullable = false, length = 10) | ||||
| open var status: String? = null | |||||
| open var status: PurchaseOrderLineStatus? = null | |||||
| @NotNull | @NotNull | ||||
| @ManyToOne(fetch = FetchType.LAZY, optional = false) | @ManyToOne(fetch = FetchType.LAZY, optional = false) | ||||
| @@ -2,7 +2,9 @@ package com.ffii.fpsms.modules.purchaseOrder.entity | |||||
| import com.ffii.core.support.AbstractRepository | import com.ffii.core.support.AbstractRepository | ||||
| import org.springframework.stereotype.Repository | import org.springframework.stereotype.Repository | ||||
| import java.io.Serializable | |||||
| @Repository | @Repository | ||||
| interface PurchaseOrderLineRepository : AbstractRepository<PurchaseOrderLine, Long> { | interface PurchaseOrderLineRepository : AbstractRepository<PurchaseOrderLine, Long> { | ||||
| fun findByM18DataLogIdAndDeletedIsFalse(m18datalogId: Serializable): PurchaseOrderLine? | |||||
| } | } | ||||
| @@ -2,7 +2,9 @@ package com.ffii.fpsms.modules.purchaseOrder.entity | |||||
| import com.ffii.core.support.AbstractRepository | import com.ffii.core.support.AbstractRepository | ||||
| import org.springframework.stereotype.Repository | import org.springframework.stereotype.Repository | ||||
| import java.io.Serializable | |||||
| @Repository | @Repository | ||||
| interface PurchaseOrderRepository : AbstractRepository<PurchaseOrder, Long> { | interface PurchaseOrderRepository : AbstractRepository<PurchaseOrder, Long> { | ||||
| fun findByM18DataLogIdAndDeletedIsFalse(m18datalogId: Serializable): PurchaseOrder? | |||||
| } | } | ||||
| @@ -0,0 +1,10 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.enums | |||||
| import com.ffii.fpsms.modules.master.enums.ShopType | |||||
| enum class PurchaseOrderLineStatus(val value: String) { | |||||
| PENDING("pending"), | |||||
| PICKING("picking"), | |||||
| COMPLETED("completed"); | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.enums | |||||
| import jakarta.persistence.AttributeConverter | |||||
| import jakarta.persistence.Converter | |||||
| @Converter(autoApply = true) | |||||
| class PurchaseOrderLineStatusConverter : AttributeConverter<PurchaseOrderLineStatus, String> { | |||||
| override fun convertToDatabaseColumn(status: PurchaseOrderLineStatus?): String? { | |||||
| return status?.value | |||||
| } | |||||
| override fun convertToEntityAttribute(value: String?): PurchaseOrderLineStatus? { | |||||
| return value?.let { v -> | |||||
| PurchaseOrderLineStatus.entries.find { it.value == v } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,16 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.enums | |||||
| import com.ffii.fpsms.modules.master.enums.ShopType | |||||
| enum class PurchaseOrderStatus(val value: String) { | |||||
| PENDING ("pending"), | |||||
| RECEIVING ("receiving"), | |||||
| COMPLETED ("completed"); | |||||
| companion object { | |||||
| fun fromValue(value: String): ShopType { | |||||
| return ShopType.entries.find { it.value == value } | |||||
| ?: throw IllegalArgumentException("No enum constant with value: $value") | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.enums | |||||
| import jakarta.persistence.AttributeConverter | |||||
| import jakarta.persistence.Converter | |||||
| @Converter(autoApply = true) | |||||
| class PurchaseOrderStatusConverter : AttributeConverter<PurchaseOrderStatus, String>{ | |||||
| override fun convertToDatabaseColumn(status: PurchaseOrderStatus?): String? { | |||||
| return status?.value | |||||
| } | |||||
| override fun convertToEntityAttribute(value: String?): PurchaseOrderStatus? { | |||||
| return value?.let { v -> | |||||
| PurchaseOrderStatus.entries.find { it.value == v } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,67 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.service | |||||
| import com.ffii.fpsms.m18.entity.M18DataLogRepository | |||||
| import com.ffii.fpsms.modules.master.entity.ItemsRepository | |||||
| import com.ffii.fpsms.modules.master.service.ItemsService | |||||
| import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrder | |||||
| import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderLine | |||||
| import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderLineRepository | |||||
| import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderRepository | |||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus | |||||
| import com.ffii.fpsms.modules.purchaseOrder.web.model.SavePurchaseOrderLineRequest | |||||
| import com.ffii.fpsms.modules.purchaseOrder.web.model.SavePurchaseOrderLineResponse | |||||
| import org.springframework.stereotype.Service | |||||
| import java.math.BigDecimal | |||||
| import kotlin.jvm.optionals.getOrDefault | |||||
| import kotlin.jvm.optionals.getOrNull | |||||
| @Service | |||||
| open class PurchaseOrderLineService( | |||||
| val purchaseOrderLineRepository: PurchaseOrderLineRepository, | |||||
| val itemsService: ItemsService, | |||||
| val itemsRepository: ItemsRepository, | |||||
| val purchaseOrderRepository: PurchaseOrderRepository, | |||||
| val m18DataLogRepository: M18DataLogRepository | |||||
| ) { | |||||
| open fun allPurchaseOrderLine(): List<PurchaseOrderLine> { | |||||
| return purchaseOrderLineRepository.findAll() | |||||
| } | |||||
| open fun findPurchaseOrderLineByM18Id(m18DataLogId: Long): PurchaseOrderLine? { | |||||
| return purchaseOrderLineRepository.findByM18DataLogIdAndDeletedIsFalse(m18DataLogId) | |||||
| } | |||||
| open fun savePurchaseOrderLine(request: SavePurchaseOrderLineRequest): SavePurchaseOrderLineResponse { | |||||
| val purchaseOrderLine = | |||||
| request.id?.let { purchaseOrderLineRepository.findById(it).getOrDefault(PurchaseOrderLine()) } | |||||
| ?: PurchaseOrderLine() | |||||
| val item = request.itemId?.let { itemsRepository.findById(it).getOrNull() } | |||||
| val purchaseOrder = request.purchaseOrderId?.let { purchaseOrderRepository.findById(it).getOrNull() } | |||||
| val status = request.status?.let { status -> PurchaseOrderLineStatus.entries.find { it.value == status } } | |||||
| val m18DataLog = request.m18DataLogId?.let { m18DataLogRepository.findById(it).getOrNull() } | |||||
| purchaseOrderLine.apply { | |||||
| this.item = item | |||||
| itemNo = item?.code | |||||
| this.purchaseOrder = purchaseOrder | |||||
| qty = request.qty | |||||
| price = request.price | |||||
| priceUnit = request.priceUnit | |||||
| this.status = status | |||||
| this.m18DataLog = m18DataLog ?: this.m18DataLog | |||||
| } | |||||
| val savedPurchaseOrderLine = purchaseOrderLineRepository.saveAndFlush(purchaseOrderLine).let { | |||||
| SavePurchaseOrderLineResponse( | |||||
| id = it.id, | |||||
| itemNo = it.itemNo, | |||||
| qty = it.qty, | |||||
| price = it.price, | |||||
| priceUnit = it.priceUnit, | |||||
| status = it.status?.value | |||||
| ) | |||||
| } | |||||
| return savedPurchaseOrderLine | |||||
| } | |||||
| } | |||||
| @@ -1,14 +1,60 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.service | package com.ffii.fpsms.modules.purchaseOrder.service | ||||
| import com.ffii.fpsms.m18.entity.M18DataLogRepository | |||||
| import com.ffii.fpsms.modules.master.entity.ShopRepository | |||||
| import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrder | import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrder | ||||
| import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderRepository | import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderRepository | ||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus | |||||
| import com.ffii.fpsms.modules.purchaseOrder.web.model.SavePurchaseOrderRequest | |||||
| import com.ffii.fpsms.modules.purchaseOrder.web.model.SavePurchaseOrderResponse | |||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
| import kotlin.jvm.optionals.getOrDefault | |||||
| import kotlin.jvm.optionals.getOrNull | |||||
| @Service | @Service | ||||
| open class PurchaseOrderService( | open class PurchaseOrderService( | ||||
| val purchaseOrderRepository: PurchaseOrderRepository | |||||
| val purchaseOrderRepository: PurchaseOrderRepository, | |||||
| val shopRepository: ShopRepository, | |||||
| val m18DataLogRepository: M18DataLogRepository, | |||||
| ) { | ) { | ||||
| open fun allPurchaseOrder(): List<PurchaseOrder> { | open fun allPurchaseOrder(): List<PurchaseOrder> { | ||||
| return purchaseOrderRepository.findAll() | return purchaseOrderRepository.findAll() | ||||
| } | } | ||||
| open fun findPurchaseOrderByM18Id(m18DataLogId: Long): PurchaseOrder? { | |||||
| return purchaseOrderRepository.findByM18DataLogIdAndDeletedIsFalse(m18DataLogId) | |||||
| } | |||||
| open fun savePurchaseOrder(request: SavePurchaseOrderRequest): SavePurchaseOrderResponse { | |||||
| val purchaseOrder = | |||||
| request.id?.let { purchaseOrderRepository.findById(it).getOrDefault(PurchaseOrder()) } ?: PurchaseOrder() | |||||
| val supplier = request.supplierId?.let { shopRepository.findById(it).getOrNull() } | |||||
| val status = request.status?.let { status -> PurchaseOrderStatus.entries.find { it.value == status } } | |||||
| val m18DataLog = request.m18DataLogId?.let { m18DataLogRepository.findById(it).getOrNull() } | |||||
| //Need check duplicate? | |||||
| purchaseOrder.apply { | |||||
| code = request.code | |||||
| this.supplier = supplier | |||||
| orderDate = request.orderDate | |||||
| estimatedArrivalDate = request.estimatedArrivalDate | |||||
| completeDate = request.completeDate | |||||
| this.status = status | |||||
| this.m18DataLog = m18DataLog | |||||
| } | |||||
| val savedPurchaseOrder = purchaseOrderRepository.saveAndFlush(purchaseOrder).let { | |||||
| SavePurchaseOrderResponse( | |||||
| id = it.id, | |||||
| code = it.code, | |||||
| supplierCode = it.supplier?.code, | |||||
| orderDate = it.orderDate, | |||||
| estimatedArrivalDate = it.estimatedArrivalDate, | |||||
| completeDate = it.completeDate, | |||||
| status = it.status?.value | |||||
| ) | |||||
| } | |||||
| return savedPurchaseOrder | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,16 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.web.model | |||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus | |||||
| import java.math.BigDecimal | |||||
| data class SavePurchaseOrderLineRequest( | |||||
| val id: Long?, | |||||
| val itemId: Long?, | |||||
| val uomId: Long?, | |||||
| val purchaseOrderId: Long?, | |||||
| val qty: BigDecimal?, | |||||
| val price: BigDecimal?, | |||||
| val priceUnit: String?, | |||||
| val status: String?, | |||||
| val m18DataLogId: Long?, | |||||
| ) | |||||
| @@ -0,0 +1,13 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.web.model | |||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus | |||||
| import java.math.BigDecimal | |||||
| data class SavePurchaseOrderLineResponse ( | |||||
| val id: Long?, | |||||
| val itemNo: String?, | |||||
| val qty: BigDecimal?, | |||||
| val price: BigDecimal?, | |||||
| val priceUnit: String?, | |||||
| val status: String?, | |||||
| ) | |||||
| @@ -0,0 +1,16 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.web.model | |||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus | |||||
| import java.time.LocalDate | |||||
| import java.time.LocalDateTime | |||||
| data class SavePurchaseOrderRequest ( | |||||
| val id: Long?, | |||||
| val code: String?, | |||||
| val supplierId: Long?, | |||||
| val orderDate: LocalDateTime?, | |||||
| val estimatedArrivalDate: LocalDateTime?, | |||||
| val completeDate: LocalDateTime?, | |||||
| val status: String?, | |||||
| val m18DataLogId: Long? | |||||
| ) | |||||
| @@ -0,0 +1,15 @@ | |||||
| package com.ffii.fpsms.modules.purchaseOrder.web.model | |||||
| import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus | |||||
| import java.time.LocalDate | |||||
| import java.time.LocalDateTime | |||||
| data class SavePurchaseOrderResponse ( | |||||
| val id: Long?, | |||||
| val code: String?, | |||||
| val supplierCode: String?, | |||||
| val orderDate: LocalDateTime?, | |||||
| val estimatedArrivalDate: LocalDateTime?, | |||||
| val completeDate: LocalDateTime?, | |||||
| val status: String?, | |||||
| ) | |||||
| @@ -1,6 +1,7 @@ | |||||
| package com.ffii.fpsms.modules.stock.entity | package com.ffii.fpsms.modules.stock.entity | ||||
| import com.ffii.core.entity.BaseEntity | import com.ffii.core.entity.BaseEntity | ||||
| import com.ffii.fpsms.m18.entity.M18DataLog | |||||
| import com.ffii.fpsms.modules.master.entity.Items | import com.ffii.fpsms.modules.master.entity.Items | ||||
| import com.ffii.fpsms.modules.stock.entity.enum.StockInLineStatus | import com.ffii.fpsms.modules.stock.entity.enum.StockInLineStatus | ||||
| import com.ffii.fpsms.modules.user.entity.User | import com.ffii.fpsms.modules.user.entity.User | ||||