From 6d0beb5ebef0ef08d2a07d53454edd8ced1ad092 Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Fri, 25 Jul 2025 18:23:51 +0800 Subject: [PATCH] [Inventory] Update Inventory --- .../entity/InventoryLotLineRepository.kt | 5 ++++ .../stock/entity/InventoryRepository.kt | 4 +++ .../stock/entity/projection/InventoryInfo.kt | 6 ++++- .../entity/projection/InventoryLotLineInfo.kt | 13 ++++++++- .../stock/service/InventoryLotLineService.kt | 15 +++++++++-- .../modules/stock/service/InventoryService.kt | 27 +++++++++++++------ .../modules/stock/web/InventoryController.kt | 8 ++++++ .../stock/web/InventoryLotLineController.kt | 19 ++++++++----- .../SearchInventoryLotLineInfoRequest.kt | 7 +++++ .../stock/web/model/SearchInventoryRequest.kt | 9 +++++++ 10 files changed, 94 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryLotLineInfoRequest.kt create mode 100644 src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryRequest.kt diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt index 06aa883..c49f4cc 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt @@ -3,6 +3,8 @@ package com.ffii.fpsms.modules.stock.entity import com.ffii.core.support.AbstractRepository import com.ffii.fpsms.modules.stock.entity.projection.CurrentInventoryItemInfo import com.ffii.fpsms.modules.stock.entity.projection.InventoryLotLineInfo +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable import org.springframework.data.jpa.repository.Query import org.springframework.stereotype.Repository import java.io.Serializable @@ -11,6 +13,9 @@ import java.io.Serializable interface InventoryLotLineRepository : AbstractRepository { fun findInventoryLotLineInfoByInventoryLotItemIdIn(ids: List): List + @Query("select ill from InventoryLotLine ill where :id is null or ill.inventoryLot.item.id = :id") + fun findInventoryLotLineInfoByItemId(id: Long?, pageable: Pageable): Page + @Query(""" select i.id as id, diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt index c913694..4d5ae3e 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt @@ -3,6 +3,8 @@ package com.ffii.fpsms.modules.stock.entity import com.ffii.core.support.AbstractRepository import com.ffii.fpsms.modules.master.entity.Items import com.ffii.fpsms.modules.stock.entity.projection.InventoryInfo +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable import org.springframework.stereotype.Repository import java.io.Serializable import java.util.Optional @@ -11,6 +13,8 @@ import java.util.Optional interface InventoryRepository: AbstractRepository { fun findInventoryInfoByDeletedIsFalse(): List + fun findInventoryInfoByItemCodeContainsAndItemNameContainsAndItemTypeContainsAndDeletedIsFalse(code: String, name: String, type: String, pageable: Pageable): Page + fun findInventoryInfoByItemIdInAndDeletedIsFalse(itemIds: List): List fun findInventoryInfoByItemInAndDeletedIsFalse(items: List): List diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/InventoryInfo.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/InventoryInfo.kt index 69fefbf..f7bd2d9 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/InventoryInfo.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/InventoryInfo.kt @@ -26,8 +26,12 @@ interface InventoryInfo{ val uomCode: String? @get:Value("#{target.item.itemUoms.^[purchaseUnit == true && deleted == false]?.uom.udfudesc}") val uomUdfudesc: String? -// @get:Value("#{target.qty * target.uom.gramPerSmallestUnit}") + // @get:Value("#{target.qty * target.uom.gramPerSmallestUnit}") // val germPerSmallestUnit: BigDecimal? + @get:Value("#{(target.onHandQty - target.onHoldQty - target.unavailableQty)}") + val qtyPerSmallestUnit: BigDecimal? + @get:Value("#{target.item.itemUoms.^[baseUnit == true && deleted == false]?.uom.udfudesc}") + val baseUom: String? // @get:Value("#{target.qty * (target.uom.unit4 != '' ? target.uom.unit4Qty " + // ": target.uom.unit3 != '' ? target.uom.unit3Qty " + // ": target.uom.unit2 != '' ? target.uom.unit2Qty " + diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/InventoryLotLineInfo.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/InventoryLotLineInfo.kt index c1314a6..38d159e 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/InventoryLotLineInfo.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/InventoryLotLineInfo.kt @@ -8,6 +8,7 @@ interface InventoryLotLineItemInfo { val id: Long val code: String val name: String + val type: String } interface InventoryLotLineWarehouseInfo { @@ -20,13 +21,23 @@ interface InventoryLotLineWarehouseInfo { interface InventoryLotLineInfo { val id: Long? - + @get:Value("#{target.inventoryLot.lotNo}") + val lotNo: String? @get:Value("#{target.inventoryLot.item}") val item: InventoryLotLineItemInfo? val warehouse: InventoryLotLineWarehouseInfo? + @get:Value("#{((target.inQty ?: 0) - (target.outQty ?: 0) - (target.holdQty ?: 0)) / (target.inventoryLot.item.itemUoms.^[salesUnit == true && deleted == false]?.ratioN / target.inventoryLot.item.itemUoms.^[salesUnit == true && deleted == false]?.ratioD)}") + var availableQty: BigDecimal? + @get:Value("#{(target.inQty ?: 0)/ (target.inventoryLot.item.itemUoms.^[salesUnit == true && deleted == false]?.ratioN / target.inventoryLot.item.itemUoms.^[salesUnit == true && deleted == false]?.ratioD)}") var inQty: BigDecimal? + @get:Value("#{(target.outQty ?: 0)/ (target.inventoryLot.item.itemUoms.^[salesUnit == true && deleted == false]?.ratioN / target.inventoryLot.item.itemUoms.^[salesUnit == true && deleted == false]?.ratioD)}") var outQty: BigDecimal? + @get:Value("#{(target.holdQty ?: 0)/ (target.inventoryLot.item.itemUoms.^[salesUnit == true && deleted == false]?.ratioN / target.inventoryLot.item.itemUoms.^[salesUnit == true && deleted == false]?.ratioD)}") var holdQty: BigDecimal? + @get:Value("#{(target.inQty ?: 0) - (target.outQty ?: 0) - (target.holdQty ?: 0)}") + val qtyPerSmallestUnit: BigDecimal? + @get:Value("#{target.inventoryLot.item.itemUoms.^[baseUnit == true && deleted == false]?.uom.udfudesc}") + val baseUom: String? @get:Value("#{target.status.value}") val status: String? diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryLotLineService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryLotLineService.kt index b469a6b..d5b5899 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryLotLineService.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryLotLineService.kt @@ -1,5 +1,6 @@ package com.ffii.fpsms.modules.stock.service +import com.ffii.core.response.RecordsRes import com.ffii.fpsms.modules.master.entity.ItemUomRespository import com.ffii.fpsms.modules.master.entity.WarehouseRepository import com.ffii.fpsms.modules.stock.entity.InventoryLotLine @@ -8,9 +9,9 @@ import com.ffii.fpsms.modules.stock.entity.InventoryLotRepository import com.ffii.fpsms.modules.stock.entity.enum.InventoryLotLineStatus import com.ffii.fpsms.modules.stock.entity.projection.InventoryLotLineInfo import com.ffii.fpsms.modules.stock.web.model.SaveInventoryLotLineRequest +import com.ffii.fpsms.modules.stock.web.model.SearchInventoryLotLineInfoRequest +import org.springframework.data.domain.PageRequest import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Propagation -import org.springframework.transaction.annotation.Transactional import java.math.BigDecimal import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -30,6 +31,16 @@ open class InventoryLotLineService( return inventoryLotLineRepository.findInventoryLotLineInfoByInventoryLotItemIdIn(itemIds) } + open fun allInventoryLotLinesByPage(request: SearchInventoryLotLineInfoRequest): RecordsRes { + val pageable = PageRequest.of(request.pageNum ?: 0, request.pageSize ?: 10); + + val response = inventoryLotLineRepository.findInventoryLotLineInfoByItemId(request.itemId, pageable) + + val records = response.content + val total = response.totalElements + return RecordsRes(records, total.toInt()); + } + open fun saveInventoryLotLine(request: SaveInventoryLotLineRequest): InventoryLotLine { val inventoryLotLine = request.id?.let { inventoryLotLineRepository.findById(it).getOrNull() } ?: InventoryLotLine() diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryService.kt index 46640a2..161deff 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryService.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/InventoryService.kt @@ -1,24 +1,19 @@ package com.ffii.fpsms.modules.stock.service +import com.ffii.core.response.RecordsRes import com.ffii.core.support.AbstractBaseEntityService import com.ffii.core.support.JdbcDao -import com.ffii.fpsms.modules.common.CodeGenerator import com.ffii.fpsms.modules.master.entity.Items import com.ffii.fpsms.modules.master.entity.ItemsRepository import com.ffii.fpsms.modules.master.entity.UomConversionRepository import com.ffii.fpsms.modules.master.service.ItemUomService import com.ffii.fpsms.modules.master.service.UomConversionService -import com.ffii.fpsms.modules.master.web.models.MessageResponse import com.ffii.fpsms.modules.stock.entity.Inventory import com.ffii.fpsms.modules.stock.entity.InventoryRepository import com.ffii.fpsms.modules.stock.entity.projection.InventoryInfo -import com.ffii.fpsms.modules.stock.web.model.SaveInventoryRequest +import com.ffii.fpsms.modules.stock.web.model.SearchInventoryRequest +import org.springframework.data.domain.PageRequest import org.springframework.stereotype.Service -import java.io.IOException -import java.math.BigDecimal -import java.time.LocalDate -import java.time.format.DateTimeFormatter -import kotlin.jvm.optionals.getOrNull @Service open class InventoryService( @@ -39,6 +34,22 @@ open class InventoryService( return inventoryRepository.findInventoryInfoByDeletedIsFalse(); } + open fun allInventoriesByPage(request: SearchInventoryRequest): RecordsRes{ + val pageable = PageRequest.of(request.pageNum ?: 0, request.pageSize ?: 10) + + val response = inventoryRepository.findInventoryInfoByItemCodeContainsAndItemNameContainsAndItemTypeContainsAndDeletedIsFalse( + code = request.code, + name = request.name, + type = request.type, + pageable = pageable + ) + + val records = response.content + val total = response.totalElements + + return RecordsRes(records, total.toInt()); + } + open fun allInventoriesByItems(items: List): List{ return inventoryRepository.findInventoryInfoByItemInAndDeletedIsFalse(items); } diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/InventoryController.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/InventoryController.kt index f2aa678..55e8c04 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/web/InventoryController.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/InventoryController.kt @@ -1,8 +1,11 @@ package com.ffii.fpsms.modules.stock.web +import com.ffii.core.response.RecordsRes import com.ffii.fpsms.modules.stock.entity.projection.InventoryInfo import com.ffii.fpsms.modules.stock.service.InventoryService +import com.ffii.fpsms.modules.stock.web.model.SearchInventoryRequest import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.ModelAttribute import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @@ -15,4 +18,9 @@ class InventoryController( fun allInventories(): List { return inventoryService.allInventories() } + + @GetMapping("/getRecordByPage") + fun allInventoriesByPage(@ModelAttribute request: SearchInventoryRequest): RecordsRes { + return inventoryService.allInventoriesByPage(request); + } } \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/InventoryLotLineController.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/InventoryLotLineController.kt index 4b57907..54701e4 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/web/InventoryLotLineController.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/InventoryLotLineController.kt @@ -1,23 +1,22 @@ package com.ffii.fpsms.modules.stock.web +import com.ffii.core.response.RecordsRes import com.ffii.fpsms.modules.pickOrder.web.models.ConsoPickOrderRequest import com.ffii.fpsms.modules.stock.entity.InventoryLotLineRepository import com.ffii.fpsms.modules.stock.entity.StockInLineRepository +import com.ffii.fpsms.modules.stock.entity.projection.InventoryLotLineInfo +import com.ffii.fpsms.modules.stock.service.InventoryLotLineService import com.ffii.fpsms.modules.stock.web.model.LotLineInfo +import com.ffii.fpsms.modules.stock.web.model.SearchInventoryLotLineInfoRequest import jakarta.validation.Valid -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestParam -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* import java.math.BigDecimal @RequestMapping("/inventoryLotLine") @RestController class InventoryLotLineController ( private val inventoryLotLineRepository: InventoryLotLineRepository, + private val inventoryLotLineService: InventoryLotLineService, private val stockInLineRepository: StockInLineRepository, ){ @@ -30,6 +29,12 @@ class InventoryLotLineController ( return inventoryLotLineRepository.findCurrentInventoryByItems(request.ids) } + @GetMapping("/getRecordByPage") + fun allInventoryLotLinesByPage(@ModelAttribute request: SearchInventoryLotLineInfoRequest): RecordsRes { + println(request.itemId) + return inventoryLotLineService.allInventoryLotLinesByPage(request); + } + @GetMapping("/lot-detail/{stockInLineId}") fun getLotDetail(@Valid @PathVariable stockInLineId: Long): LotLineInfo { val stockInLine = stockInLineRepository.findById(stockInLineId).orElseThrow() diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryLotLineInfoRequest.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryLotLineInfoRequest.kt new file mode 100644 index 0000000..7c7206e --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryLotLineInfoRequest.kt @@ -0,0 +1,7 @@ +package com.ffii.fpsms.modules.stock.web.model + +data class SearchInventoryLotLineInfoRequest( + val itemId: Long? = null, + val pageSize: Int?, + val pageNum: Int? +) diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryRequest.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryRequest.kt new file mode 100644 index 0000000..4f473a6 --- /dev/null +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SearchInventoryRequest.kt @@ -0,0 +1,9 @@ +package com.ffii.fpsms.modules.stock.web.model + +data class SearchInventoryRequest( + val code: String, + val name: String, + val type: String, + val pageNum: Int?, + val pageSize: Int? +)