package com.ffii.fpsms.modules.deliveryOrder.entity

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.stereotype.Repository

@Repository
interface DeliveryOrderPickOrderRepository : JpaRepository<DeliveryOrderPickOrder, Long> {
    @Query(
        value = """
            SELECT dop.deliveryNoteCode
            FROM delivery_order_pick_order dop
            WHERE dop.deleted = 0
              AND dop.deliveryNoteCode LIKE CONCAT(:prefix, '%')
            ORDER BY dop.deliveryNoteCode DESC
            LIMIT 1
        """,
        nativeQuery = true,
    )
    fun findLatestDeliveryNoteCodeByPrefix(@Param("prefix") prefix: String): String?


}