Bladeren bron

Stock TRF v2

master
kelvin.yau 18 uur geleden
bovenliggende
commit
66d6acb4b5
2 gewijzigde bestanden met toevoegingen van 46 en 11 verwijderingen
  1. +16
    -4
      src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt
  2. +30
    -7
      src/main/java/com/ffii/fpsms/modules/stock/service/StockTransferRecordService.kt

+ 16
- 4
src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt Bestand weergeven

@@ -1454,7 +1454,19 @@ open class StockInLineService(
} }
val savedStockIn = stockInRepository.save(stockIn) val savedStockIn = stockInRepository.save(stockIn)


// Step 2: Create StockInLine and link to existing InventoryLotLine
// Step 2: Increase qty on the matched target lot line instead of creating a new lot line
val updatedInventoryLotLine = existingInventoryLotLine.apply {
this.inQty = (this.inQty ?: BigDecimal.ZERO).add(request.acceptedQty)
this.status = inventoryLotLineService.deriveInventoryLotLineStatus(
this.status,
this.inQty,
this.outQty,
this.holdQty
)
}
val savedInventoryLotLine = inventoryLotLineRepository.saveAndFlush(updatedInventoryLotLine)

// Step 3: Create StockInLine and link to existing InventoryLotLine
val item = itemRepository.findById(request.itemId).orElseThrow() val item = itemRepository.findById(request.itemId).orElseThrow()


val stockInLine = StockInLine().apply { val stockInLine = StockInLine().apply {
@@ -1472,12 +1484,12 @@ open class StockInLineService(
this.dnNo = request.dnNo this.dnNo = request.dnNo
this.type = request.type this.type = request.type
// Link to existing InventoryLot and InventoryLotLine // Link to existing InventoryLot and InventoryLotLine
this.inventoryLot = existingInventoryLotLine.inventoryLot
this.inventoryLotLine = existingInventoryLotLine
this.inventoryLot = savedInventoryLotLine.inventoryLot
this.inventoryLotLine = savedInventoryLotLine
} }
val savedStockInLine = saveAndFlush(stockInLine) val savedStockInLine = saveAndFlush(stockInLine)


// Step 3: Create Stock Ledger entry
// Step 4: Create Stock Ledger entry
createStockLedgerForStockIn(savedStockInLine, request.acceptedQty.toDouble()) createStockLedgerForStockIn(savedStockInLine, request.acceptedQty.toDouble())


return savedStockInLine return savedStockInLine


+ 30
- 7
src/main/java/com/ffii/fpsms/modules/stock/service/StockTransferRecordService.kt Bestand weergeven

@@ -12,8 +12,6 @@ import com.ffii.fpsms.modules.stock.web.model.StockInRequest
import com.ffii.fpsms.modules.stock.web.model.StockOutRequest import com.ffii.fpsms.modules.stock.web.model.StockOutRequest
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional import org.springframework.transaction.annotation.Transactional
import java.math.BigDecimal
import java.time.LocalDate
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


@@ -29,6 +27,10 @@ open class StockTransferRecordService(
jdbcDao, jdbcDao,
stockTransferRecordRepository stockTransferRecordRepository
) { ) {
private enum class TransferStockInMode {
MERGED_EXISTING_LOT,
CREATED_NEW_LOT
}


@Transactional @Transactional
open fun createStockTransfer(request: CreateStockTransferRequest): MessageResponse { open fun createStockTransfer(request: CreateStockTransferRequest): MessageResponse {
@@ -36,7 +38,7 @@ open class StockTransferRecordService(
val stockOutLine = createStockOut(request) val stockOutLine = createStockOut(request)


// Step 2: Stock In - using generic function // Step 2: Stock In - using generic function
val stockInLine = createStockIn(request)
val (stockInLine, stockInMode) = createStockIn(request)


// Step 3: Create Stock Transfer Record // Step 3: Create Stock Transfer Record
val stockTransferRecord = createStockTransferRecord(request, stockOutLine, stockInLine) val stockTransferRecord = createStockTransferRecord(request, stockOutLine, stockInLine)
@@ -44,9 +46,15 @@ open class StockTransferRecordService(
return MessageResponse( return MessageResponse(
id = stockTransferRecord.id, id = stockTransferRecord.id,
name = "Stock Transfer Record", name = "Stock Transfer Record",
code = "STOCK_TRANSFER_CREATED",
code = when (stockInMode) {
TransferStockInMode.MERGED_EXISTING_LOT -> "MERGED_EXISTING_LOT"
TransferStockInMode.CREATED_NEW_LOT -> "CREATED_NEW_LOT"
},
type = "success", type = "success",
message = "Stock transfer completed successfully",
message = when (stockInMode) {
TransferStockInMode.MERGED_EXISTING_LOT -> "Stock transfer completed successfully (merged into existing target lot)"
TransferStockInMode.CREATED_NEW_LOT -> "Stock transfer completed successfully (created new target lot)"
},
errorPosition = null errorPosition = null
) )
} }
@@ -62,7 +70,7 @@ open class StockTransferRecordService(
return stockOutLineService.createStockOut(stockOutRequest) return stockOutLineService.createStockOut(stockOutRequest)
} }


private fun createStockIn(request: CreateStockTransferRequest): StockInLine {
private fun createStockIn(request: CreateStockTransferRequest): Pair<StockInLine, TransferStockInMode> {
// Step 1: Get inventoryLotLine to extract item information // Step 1: Get inventoryLotLine to extract item information
val inventoryLotLine = inventoryLotLineRepository.findById(request.inventoryLotLineId) val inventoryLotLine = inventoryLotLineRepository.findById(request.inventoryLotLineId)
.orElseThrow { IllegalArgumentException("InventoryLotLine not found with id: ${request.inventoryLotLineId}") } .orElseThrow { IllegalArgumentException("InventoryLotLine not found with id: ${request.inventoryLotLineId}") }
@@ -107,7 +115,22 @@ open class StockTransferRecordService(
warehouseId = request.warehouseId warehouseId = request.warehouseId
) )


return stockInLineService.createStockIn(stockInRequest)
val existingTargetLotLine = inventoryLotLineRepository.findByLotNoAndItemIdAndWarehouseId(
lotNo = lotNo,
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
}
} }


private fun createStockTransferRecord( private fun createStockTransferRecord(


Laden…
Annuleren
Opslaan