Browse Source

update stock in

master
kelvinsuen 2 months ago
parent
commit
8ea940cb12
8 changed files with 135 additions and 192 deletions
  1. +4
    -4
      src/main/java/com/ffii/fpsms/modules/common/mail/service/MailTemplateService.kt
  2. +1
    -1
      src/main/java/com/ffii/fpsms/modules/purchaseOrder/service/PurchaseOrderService.kt
  3. +2
    -2
      src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogInfo.kt
  4. +1
    -0
      src/main/java/com/ffii/fpsms/modules/stock/entity/StockInRepository.kt
  5. +1
    -1
      src/main/java/com/ffii/fpsms/modules/stock/entity/projection/StockInLineInfo.kt
  6. +93
    -156
      src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt
  7. +26
    -21
      src/main/java/com/ffii/fpsms/modules/stock/service/StockInService.kt
  8. +7
    -7
      src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt

+ 4
- 4
src/main/java/com/ffii/fpsms/modules/common/mail/service/MailTemplateService.kt View File

@@ -93,7 +93,7 @@ open class MailTemplateService(
val supplierEmail: String = "", val supplierEmail: String = "",
val supplierName: String = "", val supplierName: String = "",
val dnNo: String = "", val dnNo: String = "",
val dnDate: String = "",
val receiptDate: String = "",
val poNo: String = "", val poNo: String = "",
val supplierId: String = "", val supplierId: String = "",
val itemNo: String = "", val itemNo: String = "",
@@ -115,7 +115,7 @@ open class MailTemplateService(
val args = mapOf( val args = mapOf(
"\${supplierName}" to supplierName, "\${supplierName}" to supplierName,
"\${dnNo}" to dnNo, "\${dnNo}" to dnNo,
"\${dnDate}" to dnDate,
"\${receiptDate}" to receiptDate,
"\${poNo}" to poNo, "\${poNo}" to poNo,
"\${supplierId}" to supplierId, "\${supplierId}" to supplierId,
"\${itemNo}" to itemNo, "\${itemNo}" to itemNo,
@@ -149,7 +149,7 @@ open class MailTemplateService(
val supplierName = po?.supplier?.name ?: "N/A" val supplierName = po?.supplier?.name ?: "N/A"
val supplierEmail = (if((po?.supplier?.contactEmail).isNullOrEmpty()) "N/A" else po?.supplier?.contactEmail) ?: "N/A" val supplierEmail = (if((po?.supplier?.contactEmail).isNullOrEmpty()) "N/A" else po?.supplier?.contactEmail) ?: "N/A"
val dnNo = stockInLine.dnNo ?: "N/A" val dnNo = stockInLine.dnNo ?: "N/A"
val dnDate = formatter.format(stockInLine.dnDate) ?: "N/A"
val receiptDate = formatter.format(stockInLine.receiptDate) ?: "N/A"
val poNo = po?.code ?: "N/A" val poNo = po?.code ?: "N/A"
val supplierId = po?.supplier?.code ?: "N/A" // Id? val supplierId = po?.supplier?.code ?: "N/A" // Id?
val itemNo = item?.code ?: "N/A" val itemNo = item?.code ?: "N/A"
@@ -193,7 +193,7 @@ open class MailTemplateService(
supplierEmail = supplierEmail, supplierEmail = supplierEmail,
supplierName = supplierName, supplierName = supplierName,
dnNo = dnNo, dnNo = dnNo,
dnDate = dnDate,
receiptDate = receiptDate,
poNo = poNo, poNo = poNo,
supplierId = supplierId, supplierId = supplierId,
itemNo = itemNo, itemNo = itemNo,


+ 1
- 1
src/main/java/com/ffii/fpsms/modules/purchaseOrder/service/PurchaseOrderService.kt View File

@@ -209,7 +209,7 @@ open class PurchaseOrderService(
} }
val mappedPoLine = pol.map { thisPol -> val mappedPoLine = pol.map { thisPol ->
val inLine = stockInLine.filter { it.purchaseOrderLineId == thisPol.id } val inLine = stockInLine.filter { it.purchaseOrderLineId == thisPol.id }
.filter { it.dnDate != null }
.filter { it.receiptDate != null }
val categoryCode = thisPol.item?.qcCategory?.code val categoryCode = thisPol.item?.qcCategory?.code
val qcItems = thisPol.item?.qcCategory?.qcItemCategory?.map { val qcItems = thisPol.item?.qcCategory?.qcItemCategory?.map {
QcForPoLine( QcForPoLine(


+ 2
- 2
src/main/java/com/ffii/fpsms/modules/stock/entity/EscalationLogInfo.kt View File

@@ -25,8 +25,8 @@ interface EscalationLogInfo {
@get:Value("#{target.stockInLine?.dnNo}") @get:Value("#{target.stockInLine?.dnNo}")
val dnNo: String? val dnNo: String?


@get:Value("#{target.stockInLine?.dnDate}")
val dnDate: LocalDateTime?
// @get:Value("#{target.stockInLine?.dnDate}")
// val dnDate: LocalDateTime?


@get:Value("#{target.stockInLine?.item?.code} - #{target.stockInLine?.item?.name}") @get:Value("#{target.stockInLine?.item?.code} - #{target.stockInLine?.item?.name}")
val item: String? val item: String?


+ 1
- 0
src/main/java/com/ffii/fpsms/modules/stock/entity/StockInRepository.kt View File

@@ -7,6 +7,7 @@ import java.io.Serializable


@Repository @Repository
interface StockInRepository : AbstractRepository<StockIn, Long> { interface StockInRepository : AbstractRepository<StockIn, Long> {
fun findByIdAndDeletedFalse(id: Long): StockIn?
fun findByPurchaseOrderIdAndDeletedFalse(purchaseOrderId: Long): StockIn? fun findByPurchaseOrderIdAndDeletedFalse(purchaseOrderId: Long): StockIn?


// @Query(""" // @Query("""


+ 1
- 1
src/main/java/com/ffii/fpsms/modules/stock/entity/projection/StockInLineInfo.kt View File

@@ -43,7 +43,7 @@ interface StockInLineInfo {
@get:Value("#{target.item?.type}") @get:Value("#{target.item?.type}")
val itemType: String val itemType: String
val dnNo: String val dnNo: String
val dnDate: LocalDateTime?
// val dnDate: LocalDateTime?
// val qcDecision: LocalDateTime? // val qcDecision: LocalDateTime?
@get:Value("#{target.escalationLog.^[status.value == 'pending']?.handler?.id}") @get:Value("#{target.escalationLog.^[status.value == 'pending']?.handler?.id}")
val handlerId: Long? val handlerId: Long?


+ 93
- 156
src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt View File

@@ -26,6 +26,8 @@ import com.ffii.core.utils.ZebraPrinterUtil
import com.ffii.fpsms.modules.master.entity.ItemUomRespository import com.ffii.fpsms.modules.master.entity.ItemUomRespository
import com.ffii.fpsms.modules.master.entity.WarehouseRepository import com.ffii.fpsms.modules.master.entity.WarehouseRepository
import com.ffii.fpsms.modules.master.service.PrinterService import com.ffii.fpsms.modules.master.service.PrinterService
import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrder
import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderLine
import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderRepository import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderRepository
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderLineStatus
import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus import com.ffii.fpsms.modules.purchaseOrder.enums.PurchaseOrderStatus
@@ -50,7 +52,7 @@ data class QrContent(val itemId: Long, val stockInLineId: Long)
@Service @Service
open class StockInLineService( open class StockInLineService(
private val jdbcDao: JdbcDao, private val jdbcDao: JdbcDao,
private val purchaseOrderRepository: PurchaseOrderRepository,
private val poRepository: PurchaseOrderRepository,
private val polRepository: PurchaseOrderLineRepository, private val polRepository: PurchaseOrderLineRepository,
private val qcItemsRepository: QcItemRepository, private val qcItemsRepository: QcItemRepository,
private val qcResultRepository: QcResultRepository, private val qcResultRepository: QcResultRepository,
@@ -78,50 +80,74 @@ open class StockInLineService(
@Transactional @Transactional
open fun create(request: SaveStockInLineRequest): MessageResponse { open fun create(request: SaveStockInLineRequest): MessageResponse {
val stockInLine = StockInLine() val stockInLine = StockInLine()
val item = itemRepository.findById(request.itemId).orElseThrow()
val purchaseOrderLine = request.purchaseOrderLineId?.let { polRepository.findById(it).getOrNull() }
val stockTakeLine = request.stockTakeLineId?.let { stockTakeLineRepository.findById(it).getOrNull() }
var stockIn = request.stockInId?.let { stockInRepository.findByIdAndDeletedIsFalse(it) }
?: request.purchaseOrderId?.let { stockInRepository.findByPurchaseOrderIdAndDeletedFalse(it) }
?: request.stockTakeId?.let { stockInRepository.findByStockTakeIdAndDeletedFalse(it) }
purchaseOrderLine?.apply {
status = PurchaseOrderLineStatus.RECEIVING
}
val pol = purchaseOrderLine?.let { polRepository.saveAndFlush(it) }
val pol = if (request.purchaseOrderLineId != null)
request.purchaseOrderLineId?.let { polRepository.findById(it).orElseThrow() }
else null
val stl = if (request.stockTakeId != null)
request.stockTakeId?.let { stockTakeLineRepository.findById(it).getOrNull() }
else null

var stockIn = if (request.stockInId != null) request.stockInId?.let { stockInRepository.findByIdAndDeletedFalse(it) }
else if (pol != null) pol.purchaseOrder?.id?.let { stockInRepository.findByPurchaseOrderIdAndDeletedFalse(it) }
else if (request.stockTakeId != null) request.stockTakeId?.let { stockInRepository.findByStockTakeIdAndDeletedFalse(it) }
else null

if (stockIn == null) { if (stockIn == null) {
stockIn = stockInService.create(SaveStockInRequest(purchaseOrderId = request.purchaseOrderId)).entity as StockIn
stockIn = stockInService.create(SaveStockInRequest(purchaseOrderId = pol?.purchaseOrder?.id)).entity as StockIn
// stockIn = stockInService.create(SaveStockInRequest(purchaseOrderId = request.purchaseOrderId)).entity as StockIn
// var stockIn = stockInRepository.findByPurchaseOrderIdAndDeletedFalse(request.purchaseOrderId)
}
val item = itemRepository.findById(request.itemId).orElseThrow()
// If request contains valid POL
if (pol != null) {
val po = pol.purchaseOrder;
pol.apply {
status = PurchaseOrderLineStatus.RECEIVING
}
val savedPol = polRepository.saveAndFlush(pol)
stockInLine.apply {
this.purchaseOrderLine = savedPol
}

// update po status to receiving // update po status to receiving
val po = request.purchaseOrderId?.let { purchaseOrderRepository.findById(it).getOrNull() }
if (po != null) { if (po != null) {
po.apply { po.apply {
status = PurchaseOrderStatus.RECEIVING status = PurchaseOrderStatus.RECEIVING
} }
purchaseOrderRepository.save(po)
val savedPo = poRepository.save(po)
stockInLine.apply {
this.purchaseOrder = savedPo
}
} }
} }
val allStockInLine = stockInLineRepository.findAllStockInLineInfoByStockInIdAndDeletedFalse(stockIn.id!!)
if (pol != null && pol.qty!! < request.acceptedQty) {
throw BadRequestException()

// If request contains valid stock take id
if (stl != null) {
stockInLine.apply {
this.stockTakeLine = stl
}
} }

// val allStockInLine = stockInLineRepository.findAllStockInLineInfoByStockInIdAndDeletedFalse(stockIn.id!!)
// if (pol.qty!! < request.acceptedQty) {
// throw BadRequestException()
// }
stockInLine.apply { stockInLine.apply {
this.item = item this.item = item
itemNo = item.code itemNo = item.code
this.purchaseOrder = purchaseOrderLine?.purchaseOrder
this.purchaseOrderLine = purchaseOrderLine
this.stockTakeLine = stockTakeLine
this.stockIn = stockIn this.stockIn = stockIn
acceptedQty = request.acceptedQty acceptedQty = request.acceptedQty
dnNo = request.dnNo dnNo = request.dnNo
dnDate = request.dnDate?.atStartOfDay()
receiptDate = request.receiptDate?.atStartOfDay() ?: LocalDateTime.now()
productLotNo = request.productLotNo productLotNo = request.productLotNo
status = StockInLineStatus.PENDING.status status = StockInLineStatus.PENDING.status
} }
val savedInLine = saveAndFlush(stockInLine)
val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedInLine.id!!)
val savedSIL = saveAndFlush(stockInLine)
val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedSIL.id!!)
return MessageResponse( return MessageResponse(
id = savedInLine.id,
code = savedInLine.itemNo,
name = savedInLine.item!!.name,
id = savedSIL.id,
code = savedSIL.itemNo,
name = savedSIL.item!!.name,
type = "stock in line created: status = pending", type = "stock in line created: status = pending",
message = "save success", message = "save success",
errorPosition = null, errorPosition = null,
@@ -274,76 +300,50 @@ open class StockInLineService(


@Throws(IOException::class) @Throws(IOException::class)
@Transactional @Transactional
open fun updatePurchaseOrderStatus(request: SaveStockInLineRequest) {
if (request.status == StockInLineStatus.COMPLETE.status) {
val unfinishedLines = request.purchaseOrderId?.let { polRepository
.findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse(purchaseOrderId = it, status = PurchaseOrderLineStatus.COMPLETED) }
if (unfinishedLines != null && unfinishedLines.isEmpty()) {
val po = purchaseOrderRepository.findById(request.purchaseOrderId).orElseThrow()
po.apply {
status = PurchaseOrderStatus.COMPLETED
}
purchaseOrderRepository.saveAndFlush(po)
} else {

open fun updatePurchaseOrderStatus(po : PurchaseOrder) {
val unfinishedPol = polRepository
.findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse(po.id!!,
PurchaseOrderLineStatus.COMPLETED)
// If all POL is completed
if (unfinishedPol.isEmpty()) {
po.apply {
status = PurchaseOrderStatus.COMPLETED
} }
poRepository.saveAndFlush(po)
} else {

} }
} }
@Throws(IOException::class) @Throws(IOException::class)
@Transactional @Transactional
fun updatePurchaseOrderLineStatus(request: SaveStockInLineRequest) {
println(request.status)
if (request.status == StockInLineStatus.RECEIVING.status) {
val unQcedLines = request.purchaseOrderLineId?.let { stockInLineRepository.findStockInLineInfoByPurchaseOrderLineIdAndDeletedFalse(purchaseOrderLineId = it) }
?.filter {
it.status != StockInLineStatus.RECEIVING.status
&& it.status != StockInLineStatus.RECEIVED.status
&& it.status != StockInLineStatus.COMPLETE.status
&& it.status != StockInLineStatus.REJECT.status
}
if (unQcedLines != null && unQcedLines.isEmpty()) {
// all stock in lines finished
// change status of purchase order line
val purchaseOrderLine = request.purchaseOrderLineId?.let { polRepository.findById(it).orElseThrow() }
if (purchaseOrderLine != null) {
purchaseOrderLine.apply {
fun updatePurchaseOrderLineStatus(pol: PurchaseOrderLine) {
val stockInLines = stockInLineRepository.findStockInLineInfoByPurchaseOrderLineIdAndDeletedFalse(pol.id!!)
val qcLines = stockInLines.filter { it.status == StockInLineStatus.PENDING.status
|| it.status == StockInLineStatus.ESCALATED.status }
val receivingLines = stockInLines.filter { it.status == StockInLineStatus.RECEIVED.status
|| it.status == StockInLineStatus.RECEIVING.status }
// TODO: also check the qty
if (stockInLines.isEmpty()) { // No Stock In Line
pol.apply { status = PurchaseOrderLineStatus.PENDING }
} else {
if (qcLines.isEmpty()) { // No pending QC lines
if (receivingLines.isEmpty()) { // No receiving lines
pol.apply {
status = PurchaseOrderLineStatus.COMPLETED
}
} else { // Only remain receiving lines
pol.apply {
status = PurchaseOrderLineStatus.RECEIVING status = PurchaseOrderLineStatus.RECEIVING
} }
polRepository.saveAndFlush(purchaseOrderLine)
} }
} else { } else {
// still have unQcedLines lines
}
}
if (request.status == StockInLineStatus.COMPLETE.status || request.status == StockInLineStatus.REJECT.status) {
// val unfinishedLines = stockInLineRepository.findStockInLineInfoByPurchaseOrderLineIdAndStatusNotAndDeletedFalse(purchaseOrderLineId = request.purchaseOrderLineId, status = request.status!!)
val unfinishedLines = request.purchaseOrderLineId?.let {
stockInLineRepository.findStockInLineInfoByPurchaseOrderLineIdAndDeletedFalse(
purchaseOrderLineId = it
)
}
?.filter {
it.status != StockInLineStatus.COMPLETE.status
&& it.status != StockInLineStatus.REJECT.status
// still have pending QC lines
pol.apply {
status = PurchaseOrderLineStatus.RECEIVING
} }
println("unfinishedLines")
println(unfinishedLines)
if (unfinishedLines != null && unfinishedLines.isEmpty()) {
// all stock in lines finished
// change status of purchase order line
val purchaseOrderLine = request.purchaseOrderLineId?.let {
polRepository.findById(it).orElseThrow()
}
if (purchaseOrderLine != null) {
purchaseOrderLine.apply {
status = PurchaseOrderLineStatus.COMPLETED
}
polRepository.saveAndFlush(purchaseOrderLine)
}
} else {
// still have unfinished lines
} }
} }
polRepository.saveAndFlush(pol)
} }
@Throws(IOException::class) @Throws(IOException::class)
@Transactional @Transactional
@@ -370,7 +370,7 @@ open class StockInLineService(
this.productionDate = request.productionDate?.atStartOfDay() ?: this.productionDate// maybe need to change the request to LocalDateTime this.productionDate = request.productionDate?.atStartOfDay() ?: this.productionDate// maybe need to change the request to LocalDateTime
this.productLotNo = request.productLotNo ?: this.productLotNo this.productLotNo = request.productLotNo ?: this.productLotNo
this.dnNo = request.dnNo ?: this.dnNo this.dnNo = request.dnNo ?: this.dnNo
this.dnDate = request.dnDate?.atStartOfDay() ?: this.dnDate
// this.dnDate = request.dnDate?.atStartOfDay() ?: this.dnDate
this.acceptedQty = request.acceptedQty this.acceptedQty = request.acceptedQty
this.demandQty = request.acceptQty this.demandQty = request.acceptQty
this.invoiceNo = request.invoiceNo this.invoiceNo = request.invoiceNo
@@ -433,76 +433,6 @@ open class StockInLineService(
errorPosition = "request.acceptedQty", 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) { } else if (request.qcAccept == false) {
if (request.escalationLog != null) { if (request.escalationLog != null) {
// Escalated // Escalated
@@ -522,7 +452,14 @@ open class StockInLineService(
} }
val savedStockInLine = saveAndFlush(stockInLine) val savedStockInLine = saveAndFlush(stockInLine)
// check if all line completed // check if all line completed
updatePurchaseOrderLineStatus(request)
if (savedStockInLine.purchaseOrderLine != null) {
val pol = savedStockInLine.purchaseOrderLine
if (pol != null) {
updatePurchaseOrderLineStatus(pol)
updatePurchaseOrderStatus(pol.purchaseOrder!!)
}
}

val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!)


return MessageResponse( return MessageResponse(


+ 26
- 21
src/main/java/com/ffii/fpsms/modules/stock/service/StockInService.kt View File

@@ -3,6 +3,7 @@ package com.ffii.fpsms.modules.stock.service
import com.ffii.core.support.AbstractBaseEntityService import com.ffii.core.support.AbstractBaseEntityService
import com.ffii.core.support.JdbcDao import com.ffii.core.support.JdbcDao
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.PurchaseOrder
import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderRepository import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderRepository
import com.ffii.fpsms.modules.stock.entity.* import com.ffii.fpsms.modules.stock.entity.*
import com.ffii.fpsms.modules.stock.web.model.SaveStockInRequest import com.ffii.fpsms.modules.stock.web.model.SaveStockInRequest
@@ -11,6 +12,9 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional import org.springframework.transaction.annotation.Transactional
import java.io.IOException import java.io.IOException
import kotlin.jvm.optionals.getOrNull import kotlin.jvm.optionals.getOrNull
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.*


@Service @Service
open class StockInService( open class StockInService(
@@ -18,35 +22,36 @@ open class StockInService(
private val stockInRepository: StockInRepository, private val stockInRepository: StockInRepository,
private val purchaseOrderRepository: PurchaseOrderRepository, private val purchaseOrderRepository: PurchaseOrderRepository,
private val stockTakeRepository: StockTakeRepository, private val stockTakeRepository: StockTakeRepository,
): AbstractBaseEntityService<StockIn, Long, StockInRepository>(jdbcDao, stockInRepository) {
): AbstractBaseEntityService<StockIn, Long, StockInRepository>(jdbcDao, stockInRepository) {


@Throws(IOException::class) @Throws(IOException::class)
@Transactional @Transactional
open fun create(request: SaveStockInRequest): MessageResponse { open fun create(request: SaveStockInRequest): MessageResponse {
val stockIn = StockIn() val stockIn = StockIn()
// val purchaseOrder = if (request.purchaseOrderId != null)
// purchaseOrderRepository.findByIdAndDeletedFalse(request.purchaseOrderId).orElseThrow()
// else return MessageResponse(
// id = null,
// code = null,
// name = null,
// type = "Found Null",
// message = "request.purchaseOrderId is null",
// errorPosition = "Stock In"
// )
val purchaseOrder = request.purchaseOrderId?.let { purchaseOrderRepository.findByIdAndDeletedFalse(request.purchaseOrderId).getOrNull() }
val stockTake = request.stockTakeId?.let { stockTakeRepository.findByIdAndDeletedIsFalse(it) }
stockIn.apply { stockIn.apply {
code = request.code ?: purchaseOrder?.code
supplier = purchaseOrder?.supplier
this.purchaseOrder = purchaseOrder
this.stockTake = stockTake
// shop = purchaseOrder.shop
orderDate = purchaseOrder?.orderDate
estimatedCompleteDate = purchaseOrder?.estimatedArrivalDate?.toLocalDate()
completeDate = purchaseOrder?.completeDate
status = StockInStatus.PENDING.status status = StockInStatus.PENDING.status
orderDate = LocalDateTime.now()
code = LocalDateTime.now().toString().take(19)
} }
if (request.purchaseOrderId != null) {
val purchaseOrder : PurchaseOrder = purchaseOrderRepository.findByIdAndDeletedFalse(request.purchaseOrderId).orElseThrow();
stockIn.apply {
code = purchaseOrder.code
supplier = purchaseOrder.supplier
this.purchaseOrder = purchaseOrder
// shop = purchaseOrder.shop
orderDate = purchaseOrder.orderDate
estimatedCompleteDate = purchaseOrder.estimatedArrivalDate?.toLocalDate()
completeDate = purchaseOrder.completeDate
}
}
if (request.stockTakeId != null) {
val stockTake = request.stockTakeId.let { stockTakeRepository.findByIdAndDeletedIsFalse(it) }
stockIn.apply {
this.stockTake = stockTake
}
}

val savedStockIn = saveAndFlush(stockIn) val savedStockIn = saveAndFlush(stockIn)
return MessageResponse( return MessageResponse(
id = savedStockIn.id, id = savedStockIn.id,


+ 7
- 7
src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt View File

@@ -39,9 +39,12 @@ data class SaveStockInRequest(


data class SaveStockInLineRequest( data class SaveStockInLineRequest(
var id: Long? = null, var id: Long? = null,
var stockInId: Long? = null,
var stockTakeId: Long? = null,
var stockTakeLineId: Long? = null,
var itemId: Long,
var purchaseOrderId: Long? = null, var purchaseOrderId: Long? = null,
var purchaseOrderLineId: Long? = null, var purchaseOrderLineId: Long? = null,
var itemId: Long,
var acceptedQty: BigDecimal, var acceptedQty: BigDecimal,
var acceptQty: BigDecimal?, var acceptQty: BigDecimal?,
var acceptedWeight: BigDecimal? = null, var acceptedWeight: BigDecimal? = null,
@@ -51,18 +54,15 @@ data class SaveStockInLineRequest(
var dnNo: String? = null, var dnNo: String? = null,
var invoiceNo: String? = null, var invoiceNo: String? = null,
var remarks: String? = null, var remarks: String? = null,
var dnDate: LocalDate? = null,
// var dnDate: LocalDate? = null,
var receiptDate: LocalDate? = null, var receiptDate: LocalDate? = null,
var productionDate: LocalDate? = null, var productionDate: LocalDate? = null,
var qcAccept: Boolean? = null, var qcAccept: Boolean? = null,
var qcResult: List<SaveQcResultRequest>? = null, var qcResult: List<SaveQcResultRequest>? = null,
var escalationLog: SaveEscalationLogRequest? = null, var escalationLog: SaveEscalationLogRequest? = null,
var warehouseId: Long?,
var warehouseId: Long? = null,
var rejectQty: BigDecimal? = null, var rejectQty: BigDecimal? = null,
var inventoryLotLines: List<SaveInventoryLotLineForSil>? = null,
var stockTakeLineId: Long? = null,
var stockTakeId: Long? = null,
var stockInId: Long? = null,
var inventoryLotLines: List<SaveInventoryLotLineForSil>? = null
) )


data class SaveInventoryLotLineForSil ( data class SaveInventoryLotLineForSil (


Loading…
Cancel
Save