@@ -2,7 +2,7 @@ package com.ffii.fpsms.modules.purchaseOrder.enums | |||||
enum class PurchaseOrderLineStatus(val value: String) { | enum class PurchaseOrderLineStatus(val value: String) { | ||||
PENDING("pending"), | PENDING("pending"), | ||||
PICKING("picking"), | |||||
RECEIVING("receiving"), | |||||
COMPLETED("completed"); | COMPLETED("completed"); | ||||
} | } | ||||
@@ -22,6 +22,8 @@ import com.ffii.fpsms.modules.stock.entity.StockInLineRepository | |||||
import com.ffii.fpsms.modules.stock.entity.StockInRepository | import com.ffii.fpsms.modules.stock.entity.StockInRepository | ||||
import com.ffii.fpsms.modules.stock.web.model.StockInLineStatus | import com.ffii.fpsms.modules.stock.web.model.StockInLineStatus | ||||
import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
import org.springframework.transaction.annotation.Transactional | |||||
import java.io.IOException | |||||
import java.util.HashMap | import java.util.HashMap | ||||
import java.util.Objects | import java.util.Objects | ||||
import kotlin.jvm.optionals.getOrDefault | import kotlin.jvm.optionals.getOrDefault | ||||
@@ -31,7 +33,6 @@ import kotlin.jvm.optionals.getOrNull | |||||
open class PurchaseOrderService( | open class PurchaseOrderService( | ||||
private val jdbcDao: JdbcDao, | private val jdbcDao: JdbcDao, | ||||
private val purchaseOrderRepository: PurchaseOrderRepository, | private val purchaseOrderRepository: PurchaseOrderRepository, | ||||
private val purchaseOrderLineRepository: PurchaseOrderLineRepository, | |||||
private val polRepository: PurchaseOrderLineRepository, | private val polRepository: PurchaseOrderLineRepository, | ||||
private val shopRepository: ShopRepository, | private val shopRepository: ShopRepository, | ||||
private val m18DataLogRepository: M18DataLogRepository, | private val m18DataLogRepository: M18DataLogRepository, | ||||
@@ -89,6 +90,8 @@ open class PurchaseOrderService( | |||||
return purchaseOrderRepository.findTopByM18DataLogIdAndDeletedIsFalseOrderByModifiedDesc(m18DataLogId) | return purchaseOrderRepository.findTopByM18DataLogIdAndDeletedIsFalseOrderByModifiedDesc(m18DataLogId) | ||||
} | } | ||||
@Throws(IOException::class) | |||||
@Transactional | |||||
open fun savePurchaseOrder(request: SavePurchaseOrderRequest): SavePurchaseOrderResponse { | open fun savePurchaseOrder(request: SavePurchaseOrderRequest): SavePurchaseOrderResponse { | ||||
val purchaseOrder = | val purchaseOrder = | ||||
request.id?.let { purchaseOrderRepository.findById(it).getOrDefault(PurchaseOrder()) } ?: PurchaseOrder() | request.id?.let { purchaseOrderRepository.findById(it).getOrDefault(PurchaseOrder()) } ?: PurchaseOrder() | ||||
@@ -132,13 +135,28 @@ open class PurchaseOrderService( | |||||
return savedPurchaseOrder | return savedPurchaseOrder | ||||
} | } | ||||
fun checkPolAndCompletePo(id: Long): MessageResponse { | |||||
val unfinishedLines = purchaseOrderLineRepository | |||||
.findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse( | |||||
purchaseOrderId = id, | |||||
status = PurchaseOrderLineStatus.COMPLETED | |||||
) | |||||
@Throws(IOException::class) | |||||
@Transactional | |||||
open fun startPo(id: Long): MessageResponse { | |||||
val po = purchaseOrderRepository.findById(id).orElseThrow() | |||||
po.apply { | |||||
status = PurchaseOrderStatus.RECEIVING | |||||
} | |||||
val savedPo = purchaseOrderRepository.saveAndFlush(po) | |||||
return MessageResponse( | |||||
id = savedPo.id, | |||||
name = savedPo.code, | |||||
code = savedPo.code, | |||||
type = PurchaseOrderStatus.RECEIVING.value, | |||||
message = "Update Success", | |||||
errorPosition = null, | |||||
entity = savedPo, | |||||
) | |||||
} | |||||
@Throws(IOException::class) | |||||
@Transactional | |||||
open fun checkPolAndCompletePo(id: Long): MessageResponse { | |||||
val unfinishedLines = polRepository.findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse(purchaseOrderId = id, status = PurchaseOrderLineStatus.COMPLETED) | |||||
val po = purchaseOrderRepository.findById(id).orElseThrow() | val po = purchaseOrderRepository.findById(id).orElseThrow() | ||||
if (unfinishedLines.isEmpty()) { | if (unfinishedLines.isEmpty()) { | ||||
po.apply { | po.apply { | ||||
@@ -23,6 +23,10 @@ class PurchaseOrderController( | |||||
return purchaseOrderService.getDetailedPo(id) | return purchaseOrderService.getDetailedPo(id) | ||||
} | } | ||||
@PostMapping("/start/{id}") // purchaseOrderId | |||||
fun startPo(@PathVariable id: Long): MessageResponse { | |||||
return purchaseOrderService.startPo(id) | |||||
} | |||||
@PostMapping("/check/{id}") // purchaseOrderId | @PostMapping("/check/{id}") // purchaseOrderId | ||||
fun checkPolAndCompletePo(@PathVariable id: Long): MessageResponse { | fun checkPolAndCompletePo(@PathVariable id: Long): MessageResponse { | ||||
return purchaseOrderService.checkPolAndCompletePo(id) | return purchaseOrderService.checkPolAndCompletePo(id) | ||||
@@ -23,6 +23,8 @@ interface StockInLineInfo { | |||||
val acceptedQty: BigDecimal | val acceptedQty: BigDecimal | ||||
val price: BigDecimal? | val price: BigDecimal? | ||||
val priceUnit: BigDecimal? | val priceUnit: BigDecimal? | ||||
@get:Value("#{target.item?.shelfLife}") | |||||
val shelfLife: Double? | |||||
val receiptDate: LocalDateTime? | val receiptDate: LocalDateTime? | ||||
val productionDate: LocalDateTime? | val productionDate: LocalDateTime? | ||||
val expiryDate: LocalDate? | val expiryDate: LocalDate? | ||||
@@ -64,8 +64,20 @@ open class StockInLineService( | |||||
val stockInLine = StockInLine() | val stockInLine = StockInLine() | ||||
val item = itemRepository.findById(request.itemId).orElseThrow() | val item = itemRepository.findById(request.itemId).orElseThrow() | ||||
val purchaseOrderLine = polRepository.findById(request.purchaseOrderLineId).orElseThrow() | val purchaseOrderLine = polRepository.findById(request.purchaseOrderLineId).orElseThrow() | ||||
val stockIn = stockInRepository.findByPurchaseOrderIdAndDeletedFalse(request.purchaseOrderId) | |||||
?: stockInService.create(SaveStockInRequest(purchaseOrderId = request.purchaseOrderId)).entity as StockIn | |||||
var stockIn = stockInRepository.findByPurchaseOrderIdAndDeletedFalse(request.purchaseOrderId) | |||||
purchaseOrderLine.apply { | |||||
status = PurchaseOrderLineStatus.RECEIVING | |||||
} | |||||
polRepository.saveAndFlush(purchaseOrderLine) | |||||
if (stockIn == null) { | |||||
stockIn = stockInService.create(SaveStockInRequest(purchaseOrderId = request.purchaseOrderId)).entity as StockIn | |||||
// update po status to receiving | |||||
val po = purchaseOrderRepository.findById(request.purchaseOrderId).orElseThrow() | |||||
po.apply { | |||||
status = PurchaseOrderStatus.RECEIVING | |||||
} | |||||
purchaseOrderRepository.save(po) | |||||
} | |||||
stockInLine.apply { | stockInLine.apply { | ||||
this.item = item | this.item = item | ||||
itemNo = item.code | itemNo = item.code | ||||
@@ -112,6 +124,7 @@ open class StockInLineService( | |||||
@Transactional | @Transactional | ||||
fun saveInventoryLotLineWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): InventoryLotLine { | fun saveInventoryLotLineWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): InventoryLotLine { | ||||
val inventoryLotLine = InventoryLotLine() | val inventoryLotLine = InventoryLotLine() | ||||
println(request.warehouseId!!) | |||||
val warehouse = warehouseRepository.findById(request.warehouseId!!).orElseThrow() | val warehouse = warehouseRepository.findById(request.warehouseId!!).orElseThrow() | ||||
inventoryLotLine.apply { | inventoryLotLine.apply { | ||||
this.inventoryLot = stockInLine.inventoryLot | this.inventoryLot = stockInLine.inventoryLot | ||||
@@ -148,10 +161,8 @@ open class StockInLineService( | |||||
@Transactional | @Transactional | ||||
fun updatePurchaseOrderStatus(request: SaveStockInLineRequest) { | fun updatePurchaseOrderStatus(request: SaveStockInLineRequest) { | ||||
if (request.status == StockInLineStatus.COMPLETE.status) { | if (request.status == StockInLineStatus.COMPLETE.status) { | ||||
val unfinishedLines = polRepository.findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse( | |||||
purchaseOrderId = request.purchaseOrderId, | |||||
status = PurchaseOrderLineStatus.COMPLETED | |||||
) | |||||
val unfinishedLines = polRepository | |||||
.findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse(purchaseOrderId = request.purchaseOrderId, status = PurchaseOrderLineStatus.COMPLETED) | |||||
if (unfinishedLines.isEmpty()) { | if (unfinishedLines.isEmpty()) { | ||||
val po = purchaseOrderRepository.findById(request.purchaseOrderId).orElseThrow() | val po = purchaseOrderRepository.findById(request.purchaseOrderId).orElseThrow() | ||||
po.apply { | po.apply { | ||||
@@ -223,7 +234,7 @@ open class StockInLineService( | |||||
val savedStockInLine = saveAndFlush(stockInLine) | val savedStockInLine = saveAndFlush(stockInLine) | ||||
// check if all line completed | // check if all line completed | ||||
updatePurchaseOrderLineStatus(request) | updatePurchaseOrderLineStatus(request) | ||||
updatePurchaseOrderStatus(request) | |||||
// updatePurchaseOrderStatus(request) | |||||
// val allLineByStockInId = find | // val allLineByStockInId = find | ||||
val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) | val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) | ||||
// println("checkpoint2") | // println("checkpoint2") | ||||
@@ -297,7 +308,7 @@ open class StockInLineService( | |||||
val lineInfoList = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(ids) | val lineInfoList = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(ids) | ||||
// check if all line completed | // check if all line completed | ||||
updatePurchaseOrderLineStatus(request) | updatePurchaseOrderLineStatus(request) | ||||
updatePurchaseOrderStatus(request) | |||||
// updatePurchaseOrderStatus(request) | |||||
return MessageResponse( | return MessageResponse( | ||||
id = stockInLine.id, | id = stockInLine.id, | ||||
@@ -29,7 +29,7 @@ data class SaveStockInRequest( | |||||
val orderDate: Long? = null, | val orderDate: Long? = null, | ||||
val estimatedCompleteDate: LocalDateTime? = null, | val estimatedCompleteDate: LocalDateTime? = null, | ||||
val completeDate: LocalDateTime? = null, | val completeDate: LocalDateTime? = null, | ||||
val status: LocalDateTime? = null, | |||||
val status: String? = null, | |||||
val stockOutId: Long? = null, | val stockOutId: Long? = null, | ||||
// val m18 | // val m18 | ||||
) | ) | ||||