|
|
@@ -57,12 +57,12 @@ open class StockInLineService( |
|
|
|
private val itemRepository: ItemsRepository, |
|
|
|
private val warehouseRepository: WarehouseRepository, |
|
|
|
private val itemUomRespository: ItemUomRespository, |
|
|
|
): AbstractBaseEntityService<StockInLine, Long, StockInLineRepository>(jdbcDao, stockInLineRepository) { |
|
|
|
): AbstractBaseEntityService<StockInLine, Long, StockInLineRepository>(jdbcDao, stockInLineRepository) { |
|
|
|
|
|
|
|
open fun getStockInLineInfo(stockInLineId: Long): StockInLineInfo { |
|
|
|
return stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(stockInLineId) |
|
|
|
} |
|
|
|
open fun getReceiveedStockInLineInfo(stockInLineId: Long): StockInLineInfo { |
|
|
|
open fun getReceivedStockInLineInfo(stockInLineId: Long): StockInLineInfo { |
|
|
|
return stockInLineRepository.findStockInLineInfoByIdAndStatusAndDeletedFalse(id = stockInLineId, status = StockInLineStatus.RECEIVED.status).orElseThrow() |
|
|
|
} |
|
|
|
@Throws(IOException::class) |
|
|
@@ -144,9 +144,9 @@ open class StockInLineService( |
|
|
|
itemId = request.itemId |
|
|
|
) |
|
|
|
val convertedBaseQty = if (stockItemUom != null) { |
|
|
|
request.acceptedQty * stockItemUom.ratioN!! / stockItemUom.ratioD!! |
|
|
|
(request.acceptQty?:request.acceptedQty) * stockItemUom.ratioN!! / stockItemUom.ratioD!! |
|
|
|
} else { |
|
|
|
request.acceptedQty |
|
|
|
(request.acceptQty?:request.acceptedQty) |
|
|
|
} |
|
|
|
inventoryLotLine.apply { |
|
|
|
this.inventoryLot = stockInLine.inventoryLot |
|
|
@@ -203,12 +203,12 @@ open class StockInLineService( |
|
|
|
println(request.status) |
|
|
|
if (request.status == StockInLineStatus.RECEIVING.status) { |
|
|
|
val unQcedLines = stockInLineRepository.findStockInLineInfoByPurchaseOrderLineIdAndDeletedFalse(purchaseOrderLineId = request.purchaseOrderLineId) |
|
|
|
.filter { |
|
|
|
it.status != StockInLineStatus.RECEIVING.status |
|
|
|
&& it.status != StockInLineStatus.RECEIVED.status |
|
|
|
&& it.status != StockInLineStatus.COMPLETE.status |
|
|
|
&& it.status != StockInLineStatus.REJECT.status |
|
|
|
} |
|
|
|
.filter { |
|
|
|
it.status != StockInLineStatus.RECEIVING.status |
|
|
|
&& it.status != StockInLineStatus.RECEIVED.status |
|
|
|
&& it.status != StockInLineStatus.COMPLETE.status |
|
|
|
&& it.status != StockInLineStatus.REJECT.status |
|
|
|
} |
|
|
|
if (unQcedLines.isEmpty()) { |
|
|
|
// all stock in lines finished |
|
|
|
// change status of purchase order line |
|
|
@@ -226,7 +226,7 @@ open class StockInLineService( |
|
|
|
val unfinishedLines = stockInLineRepository.findStockInLineInfoByPurchaseOrderLineIdAndDeletedFalse(purchaseOrderLineId = request.purchaseOrderLineId) |
|
|
|
.filter { |
|
|
|
it.status != StockInLineStatus.COMPLETE.status |
|
|
|
&& it.status != StockInLineStatus.REJECT.status |
|
|
|
&& it.status != StockInLineStatus.REJECT.status |
|
|
|
} |
|
|
|
println("unfinishedLines") |
|
|
|
println(unfinishedLines) |
|
|
@@ -247,14 +247,14 @@ open class StockInLineService( |
|
|
|
@Transactional |
|
|
|
open fun update(request: SaveStockInLineRequest): MessageResponse { |
|
|
|
val stockInLine = if (request.id != null) stockInLineRepository.findById(request.id!!).orElseThrow() |
|
|
|
else return MessageResponse( |
|
|
|
id = null, |
|
|
|
code = null, |
|
|
|
name = null, |
|
|
|
type = "Found Null", |
|
|
|
message = "stock in line id is null", |
|
|
|
errorPosition = null, |
|
|
|
) |
|
|
|
else return MessageResponse( |
|
|
|
id = null, |
|
|
|
code = null, |
|
|
|
name = null, |
|
|
|
type = "Found Null", |
|
|
|
message = "stock in line id is null", |
|
|
|
errorPosition = null, |
|
|
|
) |
|
|
|
// val allStockInLine = stockInLineRepository.findAllStockInLineInfoByStockInIdAndDeletedFalse(stockInLine!!.stockIn!!.id!!) |
|
|
|
|
|
|
|
if (stockInLine.expiryDate != null && request.expiryDate == null) { |
|
|
@@ -263,133 +263,148 @@ open class StockInLineService( |
|
|
|
} |
|
|
|
} |
|
|
|
// TODO: check all status to prevent reverting progress due to multiple users access to the same po? |
|
|
|
|
|
|
|
// return list of stock in line, update data grid with the list |
|
|
|
if (request.acceptedQty.compareTo(stockInLine.acceptedQty) == 0) { |
|
|
|
var savedInventoryLot: InventoryLot? = null |
|
|
|
var savedInventoryLotLine: InventoryLotLine? = null // maybe remove this later |
|
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|
|
if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
|
savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
|
} |
|
|
|
if (request.status == StockInLineStatus.COMPLETE.status) { |
|
|
|
savedInventoryLotLine = saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
|
} |
|
|
|
// println("checkpoint1") |
|
|
|
stockInLine.apply { |
|
|
|
this.productionDate = request.productionDate?.atStartOfDay() // maybe need to change the request to LocalDateTime |
|
|
|
this.productLotNo = request.productLotNo |
|
|
|
this.dnNo = request.dnNo |
|
|
|
this.dnDate = request.dnDate?.atStartOfDay() |
|
|
|
this.acceptedQty = request.acceptedQty |
|
|
|
this.demandQty = request.acceptQty |
|
|
|
this.invoiceNo = request.invoiceNo |
|
|
|
this.receiptDate = request.receiptDate?.atStartOfDay() |
|
|
|
// this.status = request.status |
|
|
|
this.expiryDate = stockInLine.expiryDate ?: request.expiryDate |
|
|
|
this.remarks = stockInLine.remarks ?: request.remarks |
|
|
|
} |
|
|
|
if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
|
// Putaway |
|
|
|
var savedInventoryLotLine: InventoryLotLine? = null |
|
|
|
|
|
|
|
savedInventoryLotLine = saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
|
stockInLine.apply { |
|
|
|
// user = null |
|
|
|
this.productionDate = request.productionDate?.atStartOfDay() // maybe need to change the request to LocalDateTime |
|
|
|
this.productLotNo = request.productLotNo |
|
|
|
this.dnNo = request.dnNo |
|
|
|
this.dnDate = request.dnDate?.atStartOfDay() |
|
|
|
this.invoiceNo = request.invoiceNo |
|
|
|
this.receiptDate = request.receiptDate?.atStartOfDay() |
|
|
|
this.status = request.status |
|
|
|
this.expiryDate = stockInLine.expiryDate ?: request.expiryDate |
|
|
|
this.inventoryLot = stockInLine.inventoryLot ?: savedInventoryLot |
|
|
|
this.status = StockInLineStatus.COMPLETE.status |
|
|
|
this.inventoryLotLine = savedInventoryLotLine |
|
|
|
this.lotNo = stockInLine.lotNo ?: savedInventoryLot?.lotNo |
|
|
|
this.remarks = stockInLine.remarks ?: request.remarks |
|
|
|
} |
|
|
|
val savedStockInLine = saveAndFlush(stockInLine) |
|
|
|
// check if all line completed |
|
|
|
updatePurchaseOrderLineStatus(request) |
|
|
|
// updatePurchaseOrderStatus(request) |
|
|
|
// val allLineByStockInId = find |
|
|
|
val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) |
|
|
|
// println("checkpoint2") |
|
|
|
return MessageResponse( |
|
|
|
id = savedStockInLine.id, |
|
|
|
code = null, |
|
|
|
name = null, |
|
|
|
type = "update Success", |
|
|
|
message = "stock in line update status success", |
|
|
|
errorPosition = null, |
|
|
|
entity = listOf(lineInfo) |
|
|
|
) |
|
|
|
} else { |
|
|
|
if (request.acceptedQty <= BigDecimal(0) ) { |
|
|
|
return MessageResponse( |
|
|
|
id = null, |
|
|
|
code = null, |
|
|
|
name = null, |
|
|
|
type = "acceptedQty == 0", |
|
|
|
message = "acceptedQty cannot be 0", |
|
|
|
errorPosition = "request.acceptedQty", |
|
|
|
) |
|
|
|
} |
|
|
|
} else if (request.status == StockInLineStatus.PENDING.status) { |
|
|
|
// QC |
|
|
|
if (request.qcAccept == true) { |
|
|
|
// Accepted |
|
|
|
if (request.acceptedQty > BigDecimal(0)) { |
|
|
|
var savedInventoryLot: InventoryLot? = null |
|
|
|
|
|
|
|
// var newLineAcceptedQty = 0.0 |
|
|
|
// if (request.rejectQty != null && request.rejectQty!! > BigDecimal.ZERO) { |
|
|
|
// |
|
|
|
// } |
|
|
|
val newStockInLine = StockInLine() |
|
|
|
newStockInLine.apply { |
|
|
|
this.item = stockInLine.item |
|
|
|
this.itemNo = stockInLine.itemNo |
|
|
|
this.purchaseOrder = stockInLine.purchaseOrderLine?.purchaseOrder |
|
|
|
this.purchaseOrderLine = stockInLine.purchaseOrderLine |
|
|
|
this.productLotNo = stockInLine.productLotNo |
|
|
|
this.dnNo = stockInLine.dnNo |
|
|
|
this.dnDate = stockInLine.dnDate |
|
|
|
this.invoiceNo = stockInLine.invoiceNo |
|
|
|
this.remarks = stockInLine.remarks ?: request.remarks |
|
|
|
this.receiptDate = stockInLine.receiptDate |
|
|
|
this.stockIn = stockInLine.stockIn |
|
|
|
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 |
|
|
|
// if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
|
savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
|
// } |
|
|
|
// println("checkpoint1") |
|
|
|
stockInLine.apply { |
|
|
|
this.status = StockInLineStatus.RECEIVED.status; |
|
|
|
this.inventoryLot = stockInLine.inventoryLot ?: savedInventoryLot |
|
|
|
this.lotNo = stockInLine.lotNo ?: savedInventoryLot?.lotNo |
|
|
|
} |
|
|
|
} else { |
|
|
|
return MessageResponse( |
|
|
|
id = null, |
|
|
|
code = null, |
|
|
|
name = null, |
|
|
|
type = "acceptedQty == 0", |
|
|
|
message = "acceptedQty cannot be 0", |
|
|
|
errorPosition = "request.acceptedQty", |
|
|
|
) |
|
|
|
} |
|
|
|
// if (request.acceptedQty.compareTo(stockInLine.acceptedQty) != 0) { |
|
|
|
// // Partial Accept |
|
|
|
// if (request.acceptedQty <= BigDecimal(0)) { |
|
|
|
// return MessageResponse( |
|
|
|
// id = null, |
|
|
|
// code = null, |
|
|
|
// name = null, |
|
|
|
// type = "acceptedQty == 0", |
|
|
|
// message = "acceptedQty cannot be 0", |
|
|
|
// errorPosition = "request.acceptedQty", |
|
|
|
// ) |
|
|
|
// } |
|
|
|
// val newStockInLine = StockInLine() |
|
|
|
// newStockInLine.apply { |
|
|
|
// this.item = stockInLine.item |
|
|
|
// this.itemNo = stockInLine.itemNo |
|
|
|
// this.purchaseOrder = stockInLine.purchaseOrderLine?.purchaseOrder |
|
|
|
// this.purchaseOrderLine = stockInLine.purchaseOrderLine |
|
|
|
// this.productLotNo = stockInLine.productLotNo |
|
|
|
// this.dnNo = stockInLine.dnNo |
|
|
|
// this.invoiceNo = stockInLine.invoiceNo |
|
|
|
// this.remarks = stockInLine.remarks ?: request.remarks |
|
|
|
// this.receiptDate = stockInLine.receiptDate |
|
|
|
// this.stockIn = stockInLine.stockIn |
|
|
|
// 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 = StockInLineStatus.RECEIVING.status// stockInLine.status // this does update status |
|
|
|
// this.user = stockInLine.user |
|
|
|
// } |
|
|
|
// saveQcResultWhenStockIn(request, stockInLine) |
|
|
|
// var savedInventoryLot: InventoryLot? = null |
|
|
|
// var savedInventoryLotLine: InventoryLotLine? = null // maybe remove this later |
|
|
|
// if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
|
// savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
|
// } |
|
|
|
// if (request.status == StockInLineStatus.COMPLETE.status) { |
|
|
|
// savedInventoryLotLine = |
|
|
|
// saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
|
// } |
|
|
|
// stockInLine.apply { |
|
|
|
// this.acceptedQty = request.acceptedQty |
|
|
|
// this.status = StockInLineStatus.RECEIVED.status//request.status |
|
|
|
// this.inventoryLot = savedInventoryLot ?: stockInLine.inventoryLot |
|
|
|
// this.inventoryLotLine = savedInventoryLotLine |
|
|
|
// this.lotNo = savedInventoryLot?.lotNo ?: stockInLine.lotNo |
|
|
|
// } |
|
|
|
// |
|
|
|
// val stockInLineEntries = listOf(stockInLine, newStockInLine) |
|
|
|
// val savedEntries = stockInLineRepository.saveAllAndFlush(stockInLineEntries) |
|
|
|
// val ids = savedEntries.map { it.id!! } |
|
|
|
// val lineInfoList = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(ids) |
|
|
|
// // check if all line completed |
|
|
|
// updatePurchaseOrderLineStatus(request) |
|
|
|
// |
|
|
|
// return MessageResponse( |
|
|
|
// id = stockInLine.id, |
|
|
|
// code = null, |
|
|
|
// name = null, |
|
|
|
// type = "Save success", |
|
|
|
// message = "created 2 stock in line", |
|
|
|
// errorPosition = null, |
|
|
|
// entity = lineInfoList |
|
|
|
// ) |
|
|
|
// } |
|
|
|
} else if (request.qcAccept == false) { |
|
|
|
// Rejected |
|
|
|
stockInLine.apply { |
|
|
|
this.status = StockInLineStatus.REJECT.status |
|
|
|
} |
|
|
|
} |
|
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|
|
var savedInventoryLot: InventoryLot? = null |
|
|
|
var savedInventoryLotLine: InventoryLotLine? = null // maybe remove this later |
|
|
|
if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
|
savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
|
} |
|
|
|
if (request.status == StockInLineStatus.COMPLETE.status) { |
|
|
|
savedInventoryLotLine = saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
|
} |
|
|
|
stockInLine.apply { |
|
|
|
this.receiptDate = request.receiptDate?.atStartOfDay() |
|
|
|
this.productionDate = request.productionDate?.atStartOfDay() |
|
|
|
this.acceptedQty = request.acceptedQty |
|
|
|
this.status = request.status |
|
|
|
this.inventoryLot = savedInventoryLot ?: stockInLine.inventoryLot |
|
|
|
this.inventoryLotLine = savedInventoryLotLine |
|
|
|
this.lotNo = savedInventoryLot?.lotNo ?: stockInLine.lotNo |
|
|
|
this.expiryDate = stockInLine.expiryDate ?: request.expiryDate |
|
|
|
this.productLotNo = stockInLine.productLotNo ?: request.productLotNo |
|
|
|
this.dnNo = stockInLine.dnNo ?: request.dnNo |
|
|
|
this.dnDate = stockInLine.dnDate ?: request.dnDate?.atStartOfDay() |
|
|
|
this.invoiceNo = stockInLine.invoiceNo ?: request.invoiceNo |
|
|
|
this.remarks = stockInLine.remarks ?: request.remarks |
|
|
|
} |
|
|
|
} |
|
|
|
val savedStockInLine = saveAndFlush(stockInLine) |
|
|
|
// check if all line completed |
|
|
|
updatePurchaseOrderLineStatus(request) |
|
|
|
val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) |
|
|
|
|
|
|
|
val stockInLineEntries = listOf(stockInLine, newStockInLine) |
|
|
|
val savedEntries = stockInLineRepository.saveAllAndFlush(stockInLineEntries) |
|
|
|
val ids = savedEntries.map { it.id!! } |
|
|
|
val lineInfoList = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(ids) |
|
|
|
// check if all line completed |
|
|
|
updatePurchaseOrderLineStatus(request) |
|
|
|
// updatePurchaseOrderStatus(request) |
|
|
|
return MessageResponse( |
|
|
|
id = savedStockInLine.id, |
|
|
|
code = null, |
|
|
|
name = null, |
|
|
|
type = "update Success", |
|
|
|
message = "stock in line update status success", |
|
|
|
errorPosition = null, |
|
|
|
entity = listOf(lineInfo) |
|
|
|
) |
|
|
|
|
|
|
|
return MessageResponse( |
|
|
|
id = stockInLine.id, |
|
|
|
code = null, |
|
|
|
name = null, |
|
|
|
type = "Save success", |
|
|
|
message = "created 2 stock in line", |
|
|
|
errorPosition = null, |
|
|
|
entity = lineInfoList |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|