|
|
@@ -13,6 +13,8 @@ import org.springframework.stereotype.Service |
|
|
import org.springframework.transaction.annotation.Transactional |
|
|
import org.springframework.transaction.annotation.Transactional |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLineRepository |
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLineRepository |
|
|
import com.ffii.fpsms.modules.stock.entity.enum.InventoryLotLineStatus |
|
|
import com.ffii.fpsms.modules.stock.entity.enum.InventoryLotLineStatus |
|
|
|
|
|
import org.springframework.http.HttpStatus |
|
|
|
|
|
import org.springframework.web.server.ResponseStatusException |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
@@ -110,21 +112,28 @@ open class StockTransferRecordService( |
|
|
warehouseId = request.warehouseId |
|
|
warehouseId = request.warehouseId |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
val existingTargetLotLine = inventoryLotLineRepository.findByLotNoAndItemIdAndWarehouseId( |
|
|
|
|
|
|
|
|
val warehouseId = request.warehouseId |
|
|
|
|
|
val mergeCandidates = inventoryLotLineRepository.findAllByLotNoAndItemIdAndWarehouseIdAndStatus( |
|
|
lotNo = lotNo, |
|
|
lotNo = lotNo, |
|
|
itemId = itemId, |
|
|
itemId = itemId, |
|
|
warehouseId = request.warehouseId |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return if ( |
|
|
|
|
|
existingTargetLotLine != null && |
|
|
|
|
|
existingTargetLotLine.status == InventoryLotLineStatus.AVAILABLE && |
|
|
|
|
|
existingTargetLotLine.id != inventoryLotLine.id |
|
|
|
|
|
) { |
|
|
|
|
|
stockInLineService.createStockInForExistingInventoryLotLine(stockInRequest, existingTargetLotLine) to |
|
|
|
|
|
TransferStockInMode.MERGED_EXISTING_LOT |
|
|
|
|
|
} else { |
|
|
|
|
|
stockInLineService.createStockIn(stockInRequest) to TransferStockInMode.CREATED_NEW_LOT |
|
|
|
|
|
|
|
|
warehouseId = warehouseId, |
|
|
|
|
|
status = InventoryLotLineStatus.AVAILABLE, |
|
|
|
|
|
).filter { it.id != inventoryLotLine.id } |
|
|
|
|
|
|
|
|
|
|
|
return when { |
|
|
|
|
|
mergeCandidates.isEmpty() -> |
|
|
|
|
|
stockInLineService.createStockIn(stockInRequest) to TransferStockInMode.CREATED_NEW_LOT |
|
|
|
|
|
mergeCandidates.size == 1 -> |
|
|
|
|
|
stockInLineService.createStockInForExistingInventoryLotLine( |
|
|
|
|
|
stockInRequest, |
|
|
|
|
|
mergeCandidates.single(), |
|
|
|
|
|
) to TransferStockInMode.MERGED_EXISTING_LOT |
|
|
|
|
|
else -> |
|
|
|
|
|
throw ResponseStatusException( |
|
|
|
|
|
HttpStatus.BAD_REQUEST, |
|
|
|
|
|
"目標倉在同一品項與批號下有多筆可用的庫存批號行,無法自動併批;請檢查資料。" + |
|
|
|
|
|
" (Multiple AVAILABLE inventory lot lines for same warehouse, item, lotNo.)", |
|
|
|
|
|
) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|