diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/QrCodeInfo.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/QrCodeInfo.kt index 9efb7ad..2614893 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/QrCodeInfo.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/QrCodeInfo.kt @@ -29,5 +29,6 @@ interface QrCodeInfo { // stockInLine } data class LotLineToQrcode ( - val inventoryLotLineId: Long + val inventoryLotLineId: Long, + val isTransfer: String? = null ) 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 0413eea..818d051 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 @@ -14,7 +14,7 @@ import com.ffii.fpsms.modules.stock.entity.projection.InventoryLotLineInfo import com.ffii.fpsms.modules.stock.entity.projection.LotLineToQrcode import com.ffii.fpsms.modules.stock.web.InventoryLotLineController import com.ffii.fpsms.modules.stock.web.model.UpdateInventoryLotLineStatusRequest - +import org.springframework.context.annotation.Lazy import com.ffii.fpsms.modules.stock.web.model.ExportQrCodeRequest import com.ffii.fpsms.modules.stock.web.model.SaveInventoryLotLineRequest import com.ffii.fpsms.modules.stock.web.model.SearchInventoryLotLineInfoRequest @@ -38,6 +38,8 @@ import com.ffii.fpsms.modules.stock.web.model.QrCodeAnalysisRequest import com.ffii.fpsms.modules.stock.web.model.QrCodeAnalysisResponse import com.ffii.fpsms.modules.stock.web.model.ScannedLotInfo import com.ffii.fpsms.modules.stock.web.model.SameItemLotInfo +import com.ffii.fpsms.modules.jobOrder.service.JobOrderService +import com.ffii.fpsms.modules.jobOrder.web.model.ExportFGStockInLabelRequest @Service open class InventoryLotLineService( @@ -46,7 +48,9 @@ open class InventoryLotLineService( private val warehouseRepository: WarehouseRepository, private val itemUomRespository: ItemUomRespository, private val stockInLineRepository: StockInLineRepository, - private val inventoryRepository: InventoryRepository + private val inventoryRepository: InventoryRepository, + @Lazy + private val jobOrderService: JobOrderService ) { open fun findById(id: Long): Optional { return inventoryLotLineRepository.findById(id) @@ -184,32 +188,41 @@ open class InventoryLotLineService( } val inputStream = resource.inputStream val poLabel = JasperCompileManager.compileReport(inputStream) -// val stockInLineInfo = stockInLineRepository.findStockInLineInfoByInventoryLotLineId(request.inventoryLotLineId).orElseThrow() + + // 1. 从 inventoryLotLineId 获取 inventory_lot_line val inventoryLotLine = inventoryLotLineRepository.findById(request.inventoryLotLineId).orElseThrow() - val stockInLineInfo = inventoryLotLine.inventoryLot?.stockInLine?.id?.let { stockInLineRepository.findStockInLineInfoById(it).orElseThrow() } ?: throw NoSuchElementException() + + // 2. 通过 inventory_lot_line.inventoryLot.stockInLine 获取 stock_in_line 信息(用于其他字段) + val stockInLineInfo = inventoryLotLine.inventoryLot?.stockInLine?.id?.let { + stockInLineRepository.findStockInLineInfoById(it).orElseThrow() + } ?: throw NoSuchElementException("StockInLine not found for inventoryLotLineId=${request.inventoryLotLineId}") val qrCodeInfo = listOf(stockInLineInfo) -// val qrCodeInfo = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(request.stockInLineIds).toMutableList() val fields = mutableListOf>() for (info in qrCodeInfo) { val field = mutableMapOf() val qrContent = QrContent(itemId = info.itemId, stockInLineId = info.id) val qrCodeContent = (Json.encodeToString(qrContent)) -// field["itemId"] = info.itemId + + // 使用 stockInLineInfo 的其他字段 field["itemName"] = info.itemName ?: "N/A" field["itemNo"] = info.itemNo field["poCode"] = info.poCode ?: "N/A" field["itemType"] = info.itemType ?: "N/A" - val stockItemUom = itemUomRespository.findBaseUnitByItemIdAndStockUnitIsTrueAndDeletedIsFalse(info.itemId) - val purchaseItemUom = itemUomRespository.findByItemIdAndPurchaseUnitIsTrueAndDeletedIsFalse(info.itemId) - val stockQty = if (stockItemUom != null && purchaseItemUom != null) { - (info.acceptedQty) * (purchaseItemUom.ratioN!! / purchaseItemUom.ratioD!!) / (stockItemUom.ratioN!! / stockItemUom.ratioD!!) - } else { - info.acceptedQty - } - field["acceptedQty"] = "%.2f".format(stockQty) - field["uom"] = inventoryLotLine.stockUom?.uom?.udfudesc ?: stockItemUom?.uom?.udfudesc ?: info.uom?.udfudesc?.toString() ?: "N/A" + + // 3. 计算 inventory_lot_line 的剩余数量(onHandQty) + val zero = BigDecimal.ZERO + val onHandQty = (inventoryLotLine.inQty ?: zero) + // .minus(inventoryLotLine.outQty ?: zero) + // .minus(inventoryLotLine.holdQty ?: zero) + + // 4. 使用 inventory_lot_line 的剩余数量(已经是库存单位,无需转换) + field["acceptedQty"] = "%.2f".format(onHandQty) + + // 5. 使用 inventory_lot_line.stockUom 获取 UOM(通过 stockItemUomId) + field["uom"] = inventoryLotLine.stockUom?.uom?.udfudesc ?: "N/A" + field["productionDate"] = info.productionDate?.format(DateTimeFormatter.ISO_LOCAL_DATE) ?: "" field["expiryDate"] = info.expiryDate?.format(DateTimeFormatter.ISO_LOCAL_DATE) ?: "" field["lotNo"] = info.lotNo!! @@ -219,7 +232,8 @@ open class InventoryLotLineService( fields.add(field) } val params: MutableMap = mutableMapOf( - "poCode" to (qrCodeInfo[0].poCode ?: "N/A") + "poCode" to (qrCodeInfo[0].poCode ?: "N/A"), + "isTransfer" to (request.isTransfer ?: "") ) return mapOf( "report" to PdfUtils.fillReport(poLabel,fields, params), @@ -227,6 +241,32 @@ open class InventoryLotLineService( ); } + @Throws(IOException::class) + @Transactional + open fun exportLabelForInventoryLotLine(inventoryLotLineId: Long): Map { + val inventoryLotLine = inventoryLotLineRepository.findById(inventoryLotLineId).orElseThrow() + val stockInLine = inventoryLotLine.inventoryLot?.stockInLine + + return when { + stockInLine?.jobOrder != null -> { + val result = jobOrderService.exportFGStockInLabel( + ExportFGStockInLabelRequest(stockInLineId = stockInLine.id!!) + ) + mapOf( + "report" to (result["report"]!!), + "fileName" to (result["filename"] ?: "label") + ) + } + stockInLine?.stockTransferRecord != null -> { + val targetLocation = stockInLine.stockTransferRecord?.targetLocation ?: "" + exportStockInLineQrcode( + LotLineToQrcode(inventoryLotLineId = inventoryLotLineId, isTransfer = "轉倉至 $targetLocation") + ) + } + else -> exportStockInLineQrcode(LotLineToQrcode(inventoryLotLineId = inventoryLotLineId)) + } + } + @Transactional open fun updateInventoryLotLineQuantities(request: UpdateInventoryLotLineQuantitiesRequest): MessageResponse { try { diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt index 0a67655..74dbc93 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt @@ -618,7 +618,8 @@ open class StockInLineService( fields.add(field) } val params: MutableMap = mutableMapOf( - "poCode" to (qrCodeInfo[0].poCode ?: "N/A") //TODO change to JO code for JO + "poCode" to (qrCodeInfo[0].poCode ?: "N/A"), //TODO change to JO code for JO + "isTransfer" to "" ) return mapOf( "report" to PdfUtils.fillReport(poLabel,fields, params), 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 d7580a1..c86d521 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 @@ -79,7 +79,7 @@ class InventoryLotLineController ( response.characterEncoding = "utf-8"; response.contentType = "application/pdf"; val out: OutputStream = response.outputStream - val pdf = inventoryLotLineService.exportStockInLineQrcode(request) + val pdf = inventoryLotLineService.exportLabelForInventoryLotLine(request.inventoryLotLineId) val jasperPrint = pdf["report"] as JasperPrint response.addHeader("filename", "${pdf["fileName"]}.pdf") out.write(JasperExportManager.exportReportToPdf(jasperPrint)); diff --git a/src/main/resources/qrCodeLabel/poItemPDF.jrxml b/src/main/resources/qrCodeLabel/poItemPDF.jrxml index 3a99743..44606a4 100644 --- a/src/main/resources/qrCodeLabel/poItemPDF.jrxml +++ b/src/main/resources/qrCodeLabel/poItemPDF.jrxml @@ -9,6 +9,7 @@ + @@ -172,6 +173,20 @@ + + + + + + + + + + + + + +