| @@ -4,6 +4,7 @@ import com.ffii.core.entity.BaseEntity | |||
| import com.ffii.fpsms.modules.master.web.models.ItemType | |||
| import jakarta.persistence.* | |||
| import jakarta.validation.constraints.NotNull | |||
| import java.time.LocalDateTime | |||
| @Entity | |||
| @Table(name = "items") | |||
| @@ -37,4 +38,7 @@ open class Items : BaseEntity<Long>() { | |||
| @Column(name = "m18Id") | |||
| open var m18Id: Long? = null | |||
| @Column(name = "m18LastModifyDate") | |||
| open var m18LastModifyDate: LocalDateTime? = null | |||
| } | |||
| @@ -7,6 +7,10 @@ import org.springframework.stereotype.Repository | |||
| @Repository | |||
| interface ItemsRepository : AbstractRepository<Items, Long> { | |||
| fun findAllByDeletedFalse(): List<Items>; | |||
| fun findByIdAndDeletedFalse(id: Long): Items; | |||
| fun findByCodeAndTypeAndDeletedFalse(code: String, type: String): Items?; | |||
| fun findByM18IdAndDeletedIsFalse(m18Id: Long): Items?; | |||
| } | |||
| @@ -1,63 +1,75 @@ | |||
| package com.ffii.fpsms.modules.master.entity | |||
| 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.Convert | |||
| import jakarta.persistence.Entity | |||
| import jakarta.persistence.Table | |||
| import jakarta.validation.constraints.NotNull | |||
| import jakarta.validation.constraints.Size | |||
| import java.time.LocalDateTime | |||
| @Entity | |||
| @Table(name = "shop") | |||
| open class Shop : BaseEntity<Long>() { | |||
| @Size(max = 30) | |||
| @Size(max = 50) | |||
| @NotNull | |||
| @Column(name = "code", nullable = false, length = 30) | |||
| @Column(name = "code", nullable = false, length = 50) | |||
| open var code: String? = null | |||
| @Size(max = 30) | |||
| @Size(max = 300) | |||
| @NotNull | |||
| @Column(name = "name", nullable = false, length = 30) | |||
| @Column(name = "name", nullable = false, length = 300) | |||
| 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 | |||
| @Size(max = 30) | |||
| @Column(name = "contactNo", length = 30) | |||
| @Size(max = 50) | |||
| @Column(name = "contactNo", length = 50) | |||
| 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 | |||
| @Size(max = 30) | |||
| @Column(name = "contactName", length = 30) | |||
| @Size(max = 50) | |||
| @Column(name = "contactName", length = 50) | |||
| 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 | |||
| @Size(max = 30) | |||
| @Column(name = "addr2", length = 30) | |||
| @Size(max = 300) | |||
| @Column(name = "addr2", length = 300) | |||
| 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 | |||
| @Size(max = 30) | |||
| @Column(name = "addr4", length = 30) | |||
| @Size(max = 300) | |||
| @Column(name = "addr4", length = 300) | |||
| 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 | |||
| @Size(max = 10) | |||
| @Convert(converter = ShopTypeConverter::class) | |||
| @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 | |||
| 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); | |||
| } | |||
| open fun findByM18Id(m18Id: Long): Items? { | |||
| return itemsRepository.findByM18IdAndDeletedIsFalse(m18Id) | |||
| } | |||
| // QcCheck included item | |||
| open fun getItem(id: Long): ItemWithQcResponse { | |||
| val list = listOf(1,2) | |||
| @@ -83,7 +88,7 @@ open class ItemsService( | |||
| @Throws(IOException::class) | |||
| @Transactional | |||
| 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) { | |||
| return MessageResponse( | |||
| id = request.id, | |||
| @@ -94,7 +99,8 @@ open class ItemsService( | |||
| 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() | |||
| item.apply { | |||
| code = request.code | |||
| @@ -104,7 +110,9 @@ open class ItemsService( | |||
| shelfLife = request.shelfLife | |||
| countryOfOrigin = request.countryOfOrigin | |||
| 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) | |||
| return MessageResponse( | |||
| @@ -4,7 +4,11 @@ import com.ffii.core.support.AbstractBaseEntityService | |||
| import com.ffii.core.support.JdbcDao | |||
| import com.ffii.fpsms.modules.master.entity.QcItem | |||
| 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.web.bind.annotation.RequestBody | |||
| @Service | |||
| open class QcItemService( | |||
| @@ -31,4 +35,49 @@ open class QcItemService( | |||
| 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.NotNull | |||
| import java.time.LocalDateTime | |||
| enum class ItemType(type: String) { | |||
| enum class ItemType(val type: String) { | |||
| MATERIAL("mat"), | |||
| BY_PRODUCT("byp"), | |||
| PRODUCT("product"), | |||
| @@ -24,6 +25,7 @@ data class NewItemRequest( | |||
| val countryOfOrigin: String?, | |||
| val maxQty: Double?, | |||
| val m18Id: Long?, | |||
| val m18LastModifyDate: LocalDateTime?, | |||
| // val type: List<NewTypeRequest>?, | |||
| // val uom: List<NewUomRequest>?, | |||
| // 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.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.validation.constraints.NotNull | |||
| import jakarta.validation.constraints.Size | |||
| @@ -24,16 +26,16 @@ open class PurchaseOrder : BaseEntity<Long>() { | |||
| @Column(name = "orderDate") | |||
| open var orderDate: LocalDateTime? = null | |||
| @Column(name = "estimatedCompleteDate") | |||
| open var estimatedCompleteDate: LocalDate? = null | |||
| @Column(name = "estimatedArrivalDate") | |||
| open var estimatedArrivalDate: LocalDateTime? = null | |||
| @Column(name = "completeDate") | |||
| open var completeDate: LocalDateTime? = null | |||
| @Size(max = 10) | |||
| @NotNull | |||
| @Column(name = "status", nullable = false, length = 10) | |||
| open var status: String? = null | |||
| @Convert(converter = PurchaseOrderStatusConverter::class) | |||
| open var status: PurchaseOrderStatus? = null | |||
| @NotNull | |||
| @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.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.validation.constraints.NotNull | |||
| import jakarta.validation.constraints.Size | |||
| @@ -10,7 +13,7 @@ import java.math.BigDecimal | |||
| @Entity | |||
| @Table(name = "purchase_order_line") | |||
| class PurchaseOrderLine : BaseEntity<Long>(){ | |||
| open class PurchaseOrderLine : BaseEntity<Long>(){ | |||
| @NotNull | |||
| @ManyToOne(fetch = FetchType.LAZY, optional = false) | |||
| @JoinColumn(name = "itemId", nullable = false) | |||
| @@ -21,6 +24,11 @@ class PurchaseOrderLine : BaseEntity<Long>(){ | |||
| @Column(name = "itemNo", nullable = false, length = 20) | |||
| open var itemNo: String? = null | |||
| // @NotNull | |||
| // @ManyToOne(fetch = FetchType.LAZY, optional = false) | |||
| // @JoinColumn(name = "uomId", nullable = false) | |||
| // open var uom: UomConversion? = null | |||
| @NotNull | |||
| @ManyToOne(fetch = FetchType.LAZY, optional = false) | |||
| @JoinColumn(name = "purchaseOrderId", nullable = false) | |||
| @@ -36,10 +44,10 @@ class PurchaseOrderLine : BaseEntity<Long>(){ | |||
| @Column(name = "priceUnit", length = 5) | |||
| open var priceUnit: String? = null | |||
| @Size(max = 10) | |||
| @Convert(converter = PurchaseOrderLineStatusConverter::class) | |||
| @NotNull | |||
| @Column(name = "status", nullable = false, length = 10) | |||
| open var status: String? = null | |||
| open var status: PurchaseOrderLineStatus? = null | |||
| @NotNull | |||
| @ManyToOne(fetch = FetchType.LAZY, optional = false) | |||
| @@ -2,7 +2,9 @@ package com.ffii.fpsms.modules.purchaseOrder.entity | |||
| import com.ffii.core.support.AbstractRepository | |||
| import org.springframework.stereotype.Repository | |||
| import java.io.Serializable | |||
| @Repository | |||
| 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 org.springframework.stereotype.Repository | |||
| import java.io.Serializable | |||
| @Repository | |||
| 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 | |||
| 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.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 kotlin.jvm.optionals.getOrDefault | |||
| import kotlin.jvm.optionals.getOrNull | |||
| @Service | |||
| open class PurchaseOrderService( | |||
| val purchaseOrderRepository: PurchaseOrderRepository | |||
| val purchaseOrderRepository: PurchaseOrderRepository, | |||
| val shopRepository: ShopRepository, | |||
| val m18DataLogRepository: M18DataLogRepository, | |||
| ) { | |||
| open fun allPurchaseOrder(): List<PurchaseOrder> { | |||
| 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 | |||
| 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.stock.entity.enum.StockInLineStatus | |||
| import com.ffii.fpsms.modules.user.entity.User | |||