|
@@ -4,8 +4,11 @@ import com.ffii.core.support.AbstractBaseEntityService |
|
|
import com.ffii.core.support.JdbcDao |
|
|
import com.ffii.core.support.JdbcDao |
|
|
import com.ffii.fpsms.modules.common.CodeGenerator |
|
|
import com.ffii.fpsms.modules.common.CodeGenerator |
|
|
import com.ffii.fpsms.modules.master.entity.ItemsRepository |
|
|
import com.ffii.fpsms.modules.master.entity.ItemsRepository |
|
|
|
|
|
import com.ffii.fpsms.modules.master.entity.QcItemRepository |
|
|
import com.ffii.fpsms.modules.master.web.models.MessageResponse |
|
|
import com.ffii.fpsms.modules.master.web.models.MessageResponse |
|
|
import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderLineRepository |
|
|
import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderLineRepository |
|
|
|
|
|
import com.ffii.fpsms.modules.qc.entity.QcResult |
|
|
|
|
|
import com.ffii.fpsms.modules.qc.entity.QcResultRepository |
|
|
import com.ffii.fpsms.modules.stock.entity.* |
|
|
import com.ffii.fpsms.modules.stock.entity.* |
|
|
import com.ffii.fpsms.modules.stock.web.model.SaveStockInLineRequest |
|
|
import com.ffii.fpsms.modules.stock.web.model.SaveStockInLineRequest |
|
|
import com.ffii.fpsms.modules.stock.web.model.SaveStockInRequest |
|
|
import com.ffii.fpsms.modules.stock.web.model.SaveStockInRequest |
|
@@ -23,6 +26,8 @@ import java.time.LocalDateTime |
|
|
open class StockInLineService( |
|
|
open class StockInLineService( |
|
|
private val jdbcDao: JdbcDao, |
|
|
private val jdbcDao: JdbcDao, |
|
|
private val polRepository: PurchaseOrderLineRepository, |
|
|
private val polRepository: PurchaseOrderLineRepository, |
|
|
|
|
|
private val qcItemsRepository: QcItemRepository, |
|
|
|
|
|
private val qcResultRepository: QcResultRepository, |
|
|
private val stockInService: StockInService, |
|
|
private val stockInService: StockInService, |
|
|
private val stockInRepository: StockInRepository, |
|
|
private val stockInRepository: StockInRepository, |
|
|
private val stockInLineRepository: StockInLineRepository, |
|
|
private val stockInLineRepository: StockInLineRepository, |
|
@@ -60,6 +65,7 @@ open class StockInLineService( |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
@Transactional |
|
|
@Transactional |
|
|
fun saveInventoryLotWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): InventoryLot { |
|
|
fun saveInventoryLotWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): InventoryLot { |
|
|
val inventoryLot = InventoryLot() |
|
|
val inventoryLot = InventoryLot() |
|
@@ -79,18 +85,39 @@ open class StockInLineService( |
|
|
} |
|
|
} |
|
|
return inventoryLotRepository.saveAndFlush(inventoryLot) |
|
|
return inventoryLotRepository.saveAndFlush(inventoryLot) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
|
|
@Transactional |
|
|
|
|
|
fun saveQcResultWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): List<QcResult>? { |
|
|
|
|
|
if (!request.qcResult.isNullOrEmpty()) { |
|
|
|
|
|
val qcResultEntries = request.qcResult!!.map { |
|
|
|
|
|
val qcItem = qcItemsRepository.findById(it.qcItemId).orElseThrow() |
|
|
|
|
|
val item = itemRepository.findById(stockInLine.item!!.id!!).orElseThrow() |
|
|
|
|
|
QcResult().apply { |
|
|
|
|
|
this.qcItem = qcItem |
|
|
|
|
|
this.item = item |
|
|
|
|
|
this.stockInLine = stockInLine |
|
|
|
|
|
this.failQty = it.failQty |
|
|
|
|
|
this.type = "qc" // default as qc for now |
|
|
|
|
|
this.remarks = it.remarks |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return qcResultRepository.saveAllAndFlush(qcResultEntries) |
|
|
|
|
|
} |
|
|
|
|
|
return null |
|
|
|
|
|
} |
|
|
@Throws(IOException::class) |
|
|
@Throws(IOException::class) |
|
|
@Transactional |
|
|
@Transactional |
|
|
open fun update(request: SaveStockInLineRequest): MessageResponse { |
|
|
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, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
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, |
|
|
|
|
|
) |
|
|
if (stockInLine.expiryDate != null && request.expiryDate == null) { |
|
|
if (stockInLine.expiryDate != null && request.expiryDate == null) { |
|
|
request.apply { |
|
|
request.apply { |
|
|
expiryDate = stockInLine.expiryDate |
|
|
expiryDate = stockInLine.expiryDate |
|
@@ -99,9 +126,9 @@ 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 |
|
|
|
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|
if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
if (request.expiryDate == null) { |
|
|
if (request.expiryDate == null) { |
|
|
println("trigger1?") |
|
|
|
|
|
return MessageResponse( |
|
|
return MessageResponse( |
|
|
id = null, |
|
|
id = null, |
|
|
code = null, |
|
|
code = null, |
|
@@ -113,8 +140,6 @@ open class StockInLineService( |
|
|
} |
|
|
} |
|
|
savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) |
|
|
} |
|
|
} |
|
|
// if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
|
|
|
// } |
|
|
|
|
|
stockInLine.apply { |
|
|
stockInLine.apply { |
|
|
// user = null |
|
|
// user = null |
|
|
productionDate = request.productionDate?.atStartOfDay() // maybe need to change the request to LocalDateTime |
|
|
productionDate = request.productionDate?.atStartOfDay() // maybe need to change the request to LocalDateTime |
|
@@ -161,6 +186,7 @@ open class StockInLineService( |
|
|
status = stockInLine.status // this does update status |
|
|
status = stockInLine.status // this does update status |
|
|
user = stockInLine.user |
|
|
user = stockInLine.user |
|
|
} |
|
|
} |
|
|
|
|
|
saveQcResultWhenStockIn(request, stockInLine) |
|
|
var savedInventoryLot: InventoryLot? = null |
|
|
var savedInventoryLot: InventoryLot? = null |
|
|
if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
if (request.status == StockInLineStatus.RECEIVED.status) { |
|
|
if (request.expiryDate == null) { |
|
|
if (request.expiryDate == null) { |
|
|