Просмотр исходного кода

stock transfer update, with qr code adoption

master
kelvin.yau 6 часов назад
Родитель
Сommit
7c6eefd155
5 измененных файлов: 76 добавлений и 19 удалений
  1. +2
    -1
      src/main/java/com/ffii/fpsms/modules/stock/entity/projection/QrCodeInfo.kt
  2. +56
    -16
      src/main/java/com/ffii/fpsms/modules/stock/service/InventoryLotLineService.kt
  3. +2
    -1
      src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt
  4. +1
    -1
      src/main/java/com/ffii/fpsms/modules/stock/web/InventoryLotLineController.kt
  5. +15
    -0
      src/main/resources/qrCodeLabel/poItemPDF.jrxml

+ 2
- 1
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
)

+ 56
- 16
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<InventoryLotLine> {
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<MutableMap<String ,Any>>()

for (info in qrCodeInfo) {
val field = mutableMapOf<String, Any>()
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<String, Any> = 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<String, Any> {
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 {


+ 2
- 1
src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt Просмотреть файл

@@ -618,7 +618,8 @@ open class StockInLineService(
fields.add(field)
}
val params: MutableMap<String, Any> = 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),


+ 1
- 1
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));


+ 15
- 0
src/main/resources/qrCodeLabel/poItemPDF.jrxml Просмотреть файл

@@ -9,6 +9,7 @@
<parameter name="qrCode" class="java.awt.Image"/>
<parameter name="acceptedQty" class="java.math.BigDecimal"/>
<parameter name="uom" class="java.lang.String"/>
<parameter name="isTransfer" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
@@ -172,6 +173,20 @@
</textElement>
<textFieldExpression><![CDATA[$F{expiryDate}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="250" y="216" width="150" height="44" uuid="d66a64b0-3335-4846-bcb0-a67594520055">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<printWhenExpression><![CDATA[$P{isTransfer} != null && !$P{isTransfer}.toString().trim().isEmpty()]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="2.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="微軟正黑體" size="12" isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{isTransfer}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

Загрузка…
Отмена
Сохранить