|
|
|
@@ -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 { |
|
|
|
|