|
@@ -1,18 +1,32 @@ |
|
|
package com.ffii.fpsms.modules.stock.service |
|
|
package com.ffii.fpsms.modules.stock.service |
|
|
|
|
|
|
|
|
import com.ffii.core.response.RecordsRes |
|
|
import com.ffii.core.response.RecordsRes |
|
|
|
|
|
import com.ffii.core.utils.PdfUtils |
|
|
|
|
|
import com.ffii.core.utils.QrCodeUtil |
|
|
import com.ffii.fpsms.modules.master.entity.ItemUomRespository |
|
|
import com.ffii.fpsms.modules.master.entity.ItemUomRespository |
|
|
import com.ffii.fpsms.modules.master.entity.WarehouseRepository |
|
|
import com.ffii.fpsms.modules.master.entity.WarehouseRepository |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLine |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLine |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLineRepository |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLineRepository |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotRepository |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotRepository |
|
|
|
|
|
import com.ffii.fpsms.modules.stock.entity.StockInLineRepository |
|
|
import com.ffii.fpsms.modules.stock.entity.enum.InventoryLotLineStatus |
|
|
import com.ffii.fpsms.modules.stock.entity.enum.InventoryLotLineStatus |
|
|
import com.ffii.fpsms.modules.stock.entity.projection.InventoryLotLineInfo |
|
|
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.ExportQrCodeRequest |
|
|
import com.ffii.fpsms.modules.stock.web.model.SaveInventoryLotLineRequest |
|
|
import com.ffii.fpsms.modules.stock.web.model.SaveInventoryLotLineRequest |
|
|
import com.ffii.fpsms.modules.stock.web.model.SearchInventoryLotLineInfoRequest |
|
|
import com.ffii.fpsms.modules.stock.web.model.SearchInventoryLotLineInfoRequest |
|
|
|
|
|
import kotlinx.serialization.encodeToString |
|
|
|
|
|
import kotlinx.serialization.json.Json |
|
|
|
|
|
import net.sf.jasperreports.engine.JasperCompileManager |
|
|
|
|
|
import org.springframework.core.io.ClassPathResource |
|
|
import org.springframework.data.domain.PageRequest |
|
|
import org.springframework.data.domain.PageRequest |
|
|
import org.springframework.stereotype.Service |
|
|
import org.springframework.stereotype.Service |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional |
|
|
|
|
|
import java.io.FileNotFoundException |
|
|
|
|
|
import java.io.IOException |
|
|
import java.math.BigDecimal |
|
|
import java.math.BigDecimal |
|
|
|
|
|
import java.time.format.DateTimeFormatter |
|
|
import java.util.Optional |
|
|
import java.util.Optional |
|
|
import kotlin.jvm.optionals.getOrNull |
|
|
import kotlin.jvm.optionals.getOrNull |
|
|
|
|
|
|
|
@@ -21,7 +35,8 @@ open class InventoryLotLineService( |
|
|
private val inventoryLotLineRepository: InventoryLotLineRepository, |
|
|
private val inventoryLotLineRepository: InventoryLotLineRepository, |
|
|
private val inventoryLotRepository: InventoryLotRepository, |
|
|
private val inventoryLotRepository: InventoryLotRepository, |
|
|
private val warehouseRepository: WarehouseRepository, |
|
|
private val warehouseRepository: WarehouseRepository, |
|
|
private val itemUomRespository: ItemUomRespository |
|
|
|
|
|
|
|
|
private val itemUomRespository: ItemUomRespository, |
|
|
|
|
|
private val stockInLineRepository: StockInLineRepository |
|
|
) { |
|
|
) { |
|
|
open fun findById(id: Long): Optional<InventoryLotLine> { |
|
|
open fun findById(id: Long): Optional<InventoryLotLine> { |
|
|
return inventoryLotLineRepository.findById(id) |
|
|
return inventoryLotLineRepository.findById(id) |
|
@@ -72,4 +87,48 @@ open class InventoryLotLineService( |
|
|
|
|
|
|
|
|
return inventoryLotLineRepository.save(inventoryLotLine) |
|
|
return inventoryLotLineRepository.save(inventoryLotLine) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
|
|
@Transactional |
|
|
|
|
|
open fun exportStockInLineQrcode(request: LotLineToQrcode): Map<String, Any> { |
|
|
|
|
|
val QRCODE_PDF = "qrCodeLabel/poItemPDF.jrxml" |
|
|
|
|
|
val resource = ClassPathResource(QRCODE_PDF) |
|
|
|
|
|
if (!resource.exists()) { |
|
|
|
|
|
println("here") |
|
|
|
|
|
throw FileNotFoundException("Report file not found: $QRCODE_PDF") |
|
|
|
|
|
} |
|
|
|
|
|
val inputStream = resource.inputStream |
|
|
|
|
|
val poLabel = JasperCompileManager.compileReport(inputStream) |
|
|
|
|
|
val qrContent = stockInLineRepository.findStockInLineInfoByInventoryLotLineId(request.inventoryLotLineId).orElseThrow() |
|
|
|
|
|
val qrCodeInfo = listOf(qrContent) |
|
|
|
|
|
// 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 |
|
|
|
|
|
field["itemName"] = info.itemName!! |
|
|
|
|
|
field["itemNo"] = info.itemNo |
|
|
|
|
|
field["poCode"] = info.poCode |
|
|
|
|
|
field["itemType"] = info.itemType |
|
|
|
|
|
field["acceptedQty"] = info.acceptedQty.toString() |
|
|
|
|
|
field["uom"] = info.uom.code.toString() |
|
|
|
|
|
field["productionDate"] = info.productionDate?.format(DateTimeFormatter.ISO_LOCAL_DATE) ?: "" |
|
|
|
|
|
field["expiryDate"] = info.expiryDate?.format(DateTimeFormatter.ISO_LOCAL_DATE) ?: "" |
|
|
|
|
|
field["lotNo"] = info.lotNo!! |
|
|
|
|
|
field["supplier"] = info.supplier!! |
|
|
|
|
|
val image = QrCodeUtil.generateQRCodeImage(qrCodeContent) |
|
|
|
|
|
field["qrCode"] = image |
|
|
|
|
|
fields.add(field) |
|
|
|
|
|
} |
|
|
|
|
|
val params: MutableMap<String, Any> = mutableMapOf( |
|
|
|
|
|
"poCode" to qrCodeInfo[0].poCode |
|
|
|
|
|
) |
|
|
|
|
|
return mapOf( |
|
|
|
|
|
"report" to PdfUtils.fillReport(poLabel,fields, params), |
|
|
|
|
|
"fileName" to qrCodeInfo[0].poCode |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |