|
@@ -25,6 +25,7 @@ import java.math.BigDecimal |
|
|
import java.time.LocalDate |
|
|
import java.time.LocalDate |
|
|
import java.time.LocalDateTime |
|
|
import java.time.LocalDateTime |
|
|
import com.ffii.core.utils.PdfUtils; |
|
|
import com.ffii.core.utils.PdfUtils; |
|
|
|
|
|
import com.ffii.fpsms.modules.master.entity.WarehouseRepository |
|
|
import java.io.FileNotFoundException |
|
|
import java.io.FileNotFoundException |
|
|
import java.time.format.DateTimeFormatter |
|
|
import java.time.format.DateTimeFormatter |
|
|
|
|
|
|
|
@@ -39,8 +40,9 @@ open class StockInLineService( |
|
|
private val stockInRepository: StockInRepository, |
|
|
private val stockInRepository: StockInRepository, |
|
|
private val stockInLineRepository: StockInLineRepository, |
|
|
private val stockInLineRepository: StockInLineRepository, |
|
|
private val inventoryLotRepository: InventoryLotRepository, |
|
|
private val inventoryLotRepository: InventoryLotRepository, |
|
|
|
|
|
private val inventoryLotLineRepository: InventoryLotLineRepository, |
|
|
private val itemRepository: ItemsRepository, |
|
|
private val itemRepository: ItemsRepository, |
|
|
private val inventoryLotService: InventoryLotService, |
|
|
|
|
|
|
|
|
private val warehouseRepository: WarehouseRepository, |
|
|
): AbstractBaseEntityService<StockInLine, Long, StockInLineRepository>(jdbcDao, stockInLineRepository) { |
|
|
): AbstractBaseEntityService<StockInLine, Long, StockInLineRepository>(jdbcDao, stockInLineRepository) { |
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
@Throws(IOException::class) |
|
@@ -93,6 +95,20 @@ open class StockInLineService( |
|
|
val savedInventoryLot = inventoryLotRepository.saveAndFlush(inventoryLot) |
|
|
val savedInventoryLot = inventoryLotRepository.saveAndFlush(inventoryLot) |
|
|
return savedInventoryLot |
|
|
return savedInventoryLot |
|
|
} |
|
|
} |
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
|
|
@Transactional |
|
|
|
|
|
fun saveInventoryLotLineWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): InventoryLotLine { |
|
|
|
|
|
val inventoryLotLine = InventoryLotLine() |
|
|
|
|
|
val warehouse = warehouseRepository.findById(request.warehouseId!!).orElseThrow() |
|
|
|
|
|
inventoryLotLine.apply { |
|
|
|
|
|
this.inventoryLot = stockInLine.inventoryLot |
|
|
|
|
|
this.warehouse = warehouse |
|
|
|
|
|
this.inQty = request.acceptedQty |
|
|
|
|
|
this.status = "available" |
|
|
|
|
|
} |
|
|
|
|
|
val savedInventoryLotLine = inventoryLotLineRepository.saveAndFlush(inventoryLotLine) |
|
|
|
|
|
return savedInventoryLotLine |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
@Throws(IOException::class) |
|
|
@Transactional |
|
|
@Transactional |
|
@@ -134,29 +150,24 @@ open class StockInLineService( |
|
|
// return list of stock in line, update data grid with the list |
|
|
// return list of stock in line, update data grid with the list |
|
|
if (request.acceptedQty.compareTo(stockInLine.acceptedQty) == 0) { |
|
|
if (request.acceptedQty.compareTo(stockInLine.acceptedQty) == 0) { |
|
|
var savedInventoryLot: InventoryLot? = null |
|
|
var savedInventoryLot: InventoryLot? = null |
|
|
|
|
|
var savedInventoryLotLine: InventoryLotLine? = null // maybe remove this later |
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|
if (request.status == StockInLineStatus.COMPLETE.status) { |
|
|
|
|
|
// if (request.expiryDate == null) { |
|
|
|
|
|
// return MessageResponse( |
|
|
|
|
|
// id = null, |
|
|
|
|
|
// code = null, |
|
|
|
|
|
// name = null, |
|
|
|
|
|
// type = "Found Null", |
|
|
|
|
|
// message = "missing expiry", |
|
|
|
|
|
// errorPosition = "expiryDate", |
|
|
|
|
|
// ) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
println(savedInventoryLot) |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
if (request.status == StockInLineStatus.COMPLETE.status) { |
|
|
|
|
|
savedInventoryLotLine = saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
} |
|
|
} |
|
|
stockInLine.apply { |
|
|
stockInLine.apply { |
|
|
// user = null |
|
|
// user = null |
|
|
productionDate = request.productionDate?.atStartOfDay() // maybe need to change the request to LocalDateTime |
|
|
|
|
|
productLotNo = request.productLotNo |
|
|
|
|
|
receiptDate = request.receiptDate?.atStartOfDay() |
|
|
|
|
|
status = request.status |
|
|
|
|
|
expiryDate = stockInLine.expiryDate ?: request.expiryDate |
|
|
|
|
|
lotNo = savedInventoryLot?.lotNo |
|
|
|
|
|
|
|
|
this.productionDate = request.productionDate?.atStartOfDay() // maybe need to change the request to LocalDateTime |
|
|
|
|
|
this.productLotNo = request.productLotNo |
|
|
|
|
|
this.receiptDate = request.receiptDate?.atStartOfDay() |
|
|
|
|
|
this.status = request.status |
|
|
|
|
|
this.expiryDate = stockInLine.expiryDate ?: request.expiryDate |
|
|
|
|
|
this.inventoryLot = stockInLine.inventoryLot ?: savedInventoryLot |
|
|
|
|
|
this.lotNo = stockInLine.lotNo ?: savedInventoryLot?.lotNo |
|
|
|
|
|
this.lotNo = savedInventoryLot?.lotNo |
|
|
} |
|
|
} |
|
|
val savedStockInLine = saveAndFlush(stockInLine) |
|
|
val savedStockInLine = saveAndFlush(stockInLine) |
|
|
val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) |
|
|
val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) |
|
@@ -183,42 +194,38 @@ open class StockInLineService( |
|
|
val newStockInLine = StockInLine() |
|
|
val newStockInLine = StockInLine() |
|
|
newStockInLine.apply { |
|
|
newStockInLine.apply { |
|
|
this.item = stockInLine.item |
|
|
this.item = stockInLine.item |
|
|
itemNo = stockInLine.itemNo |
|
|
|
|
|
|
|
|
this.itemNo = stockInLine.itemNo |
|
|
this.purchaseOrderLine = stockInLine.purchaseOrderLine |
|
|
this.purchaseOrderLine = stockInLine.purchaseOrderLine |
|
|
this.stockIn = stockInLine.stockIn |
|
|
this.stockIn = stockInLine.stockIn |
|
|
demandQty = stockInLine.demandQty |
|
|
|
|
|
acceptedQty = stockInLine.acceptedQty!!.minus(request.acceptedQty) |
|
|
|
|
|
price = stockInLine.price |
|
|
|
|
|
priceUnit = stockInLine.priceUnit |
|
|
|
|
|
productionDate = stockInLine.productionDate |
|
|
|
|
|
expiryDate = stockInLine.expiryDate |
|
|
|
|
|
status = stockInLine.status // this does update status |
|
|
|
|
|
user = stockInLine.user |
|
|
|
|
|
|
|
|
this.demandQty = stockInLine.demandQty |
|
|
|
|
|
this.acceptedQty = stockInLine.acceptedQty!!.minus(request.acceptedQty) |
|
|
|
|
|
this.price = stockInLine.price |
|
|
|
|
|
this.priceUnit = stockInLine.priceUnit |
|
|
|
|
|
this.inventoryLot = stockInLine.inventoryLot |
|
|
|
|
|
this.lotNo = stockInLine.lotNo |
|
|
|
|
|
this.productionDate = stockInLine.productionDate |
|
|
|
|
|
this.expiryDate = stockInLine.expiryDate |
|
|
|
|
|
this.status = stockInLine.status // this does update status |
|
|
|
|
|
this.user = stockInLine.user |
|
|
} |
|
|
} |
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|
var savedInventoryLot: InventoryLot? = null |
|
|
var savedInventoryLot: InventoryLot? = null |
|
|
if (request.status == StockInLineStatus.COMPLETE.status) { |
|
|
|
|
|
// if (request.expiryDate == null) { |
|
|
|
|
|
// return MessageResponse( |
|
|
|
|
|
// id = null, |
|
|
|
|
|
// code = null, |
|
|
|
|
|
// name = null, |
|
|
|
|
|
// type = "Found Null", |
|
|
|
|
|
// message = "missing expiry", |
|
|
|
|
|
// errorPosition = "expiryDate", |
|
|
|
|
|
// ) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
var savedInventoryLotLine: InventoryLotLine? = null // maybe remove this later |
|
|
|
|
|
if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
println(savedInventoryLot) |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
if (request.status == StockInLineStatus.COMPLETE.status) { |
|
|
|
|
|
savedInventoryLotLine = saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
} |
|
|
} |
|
|
stockInLine.apply { |
|
|
stockInLine.apply { |
|
|
receiptDate = request.receiptDate?.atStartOfDay() |
|
|
|
|
|
productionDate = request.productionDate?.atStartOfDay() |
|
|
|
|
|
acceptedQty = request.acceptedQty |
|
|
|
|
|
status = request.status |
|
|
|
|
|
lotNo = savedInventoryLot?.lotNo |
|
|
|
|
|
expiryDate = stockInLine.expiryDate ?: request.expiryDate |
|
|
|
|
|
productLotNo = request.productLotNo |
|
|
|
|
|
|
|
|
this.receiptDate = request.receiptDate?.atStartOfDay() |
|
|
|
|
|
this.productionDate = request.productionDate?.atStartOfDay() |
|
|
|
|
|
this.acceptedQty = request.acceptedQty |
|
|
|
|
|
this.status = request.status |
|
|
|
|
|
this.inventoryLot = savedInventoryLot ?: stockInLine.inventoryLot |
|
|
|
|
|
this.lotNo = savedInventoryLot?.lotNo ?: stockInLine.lotNo |
|
|
|
|
|
this.expiryDate = stockInLine.expiryDate ?: request.expiryDate |
|
|
|
|
|
this.productLotNo = request.productLotNo |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
val stockInLineEntries = listOf(stockInLine, newStockInLine) |
|
|
val stockInLineEntries = listOf(stockInLine, newStockInLine) |
|
@@ -249,8 +256,7 @@ open class StockInLineService( |
|
|
} |
|
|
} |
|
|
val inputStream = resource.inputStream |
|
|
val inputStream = resource.inputStream |
|
|
val poLabel = JasperCompileManager.compileReport(inputStream) |
|
|
val poLabel = JasperCompileManager.compileReport(inputStream) |
|
|
val qrCodeInfo = stockInLineRepository.findQrCodeInfoByIdInAndDeletedFalse(request.stockInLineIds).toMutableList() |
|
|
|
|
|
println(qrCodeInfo) |
|
|
|
|
|
|
|
|
val qrCodeInfo = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(request.stockInLineIds).toMutableList() |
|
|
val fields = mutableListOf<MutableMap<String ,Any>>() |
|
|
val fields = mutableListOf<MutableMap<String ,Any>>() |
|
|
for (info in qrCodeInfo) { |
|
|
for (info in qrCodeInfo) { |
|
|
val field = mutableMapOf<String, Any>() |
|
|
val field = mutableMapOf<String, Any>() |
|
@@ -259,7 +265,7 @@ open class StockInLineService( |
|
|
",stockInLineId:${info.id}" |
|
|
",stockInLineId:${info.id}" |
|
|
) |
|
|
) |
|
|
// field["itemId"] = info.itemId |
|
|
// field["itemId"] = info.itemId |
|
|
field["itemName"] = info.itemName |
|
|
|
|
|
|
|
|
field["itemName"] = info.itemName!! |
|
|
field["itemNo"] = info.itemNo |
|
|
field["itemNo"] = info.itemNo |
|
|
field["poCode"] = info.poCode |
|
|
field["poCode"] = info.poCode |
|
|
field["itemType"] = info.itemType |
|
|
field["itemType"] = info.itemType |
|
|