package com.ffii.fpsms.modules.stock.entity

import com.ffii.core.support.AbstractRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import java.io.Serializable

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

//    @Query("""
//        select si from StockIn si where si.stockTake.id = :stockTakeId and si.deleted = false
//    """)
    fun findByStockTakeIdAndDeletedFalse(stockTakeId: Long): StockIn?

    fun findByIdAndDeletedIsFalse(id: Serializable): StockIn?

    @Query("""
        select si.code from StockIn si where si.code like :prefix% and si.deleted = false order by si.code desc limit 1
    """)
    fun findLatestCodeByPrefix(prefix: String): String?

}