<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.oqpo.api.mapper.inoutmng.ShmtOdrMapper">

    <select id="selectShmtTargetOdrGridList" resultType="com.oqpo.api.entity.pomng.PchOdrBaseInfoEntity">
        select base.brand_id, fn_brand_nm(base.brand_id) as brand_nm, base.pch_podr_unq_no
               , ptcl.pch_podr_dtl_no as 'pchOdrDtlInfo.pch_podr_dtl_no'
                ,ptcl.item_id as 'pchOdrDtlInfo.item_id' , ptcl.item_nm as 'pchOdrDtlInfo.item_nm', base.whs_id, fn_whs_nm(base.brand_id, base.whs_id) as whs_nm
                ,base.location, fn_whs_location_nm(base.brand_id, base.whs_id, base.location) as location_nm
                ,ptcl.unit_amt as 'pchOdrDtlInfo.unit_amt', ptcl.podr_qty as 'pchOdrDtlInfo.podr_qty'
                , ptcl.podr_qty as 'pchOdrDtlInfo.shmt_qty', nvl(stck.stck_qty,0) as 'pchOdrDtlInfo.stck_qty'
                ,itm.expry_yn as 'pchOdrDtlInfo.expry_yn', itm.expry_period as 'pchOdrDtlInfo.expry_period'
                , date_format(adddate(now(), interval itm.expry_period day),'%Y.%m.%d') as 'pchOdrDtlInfo.expry_date'
                ,ptcl.podr_amt as 'pchOdrDtlInfo.podr_amt', date_format(base.dlv_req_dt,'%Y.%m.%d') as dlv_req_dt, base.shmt_whs_id, base.shmt_location
                ,fn_whs_nm(base.brand_id, base.shmt_whs_id) as shmt_whs_nm
                ,fn_whs_location_nm(base.brand_id, base.shmt_whs_id, base.shmt_location) as shmt_location_nm
        from   pch_odr_base_info base
        join pch_odr_dtl_ptcl ptcl on base.pch_podr_unq_no = ptcl.pch_podr_unq_no and ptcl.podr_dtl_st_cd = 'POD0'
        <if test="sItemNm != null and sItemNm != ''">
                and (ptcl.item_id like concat('%',#{sItemNm},'%') or ptcl.item_nm like concat('%',#{sItemNm},'%'))
        </if>
        join item_base_info itm on ptcl.item_id = itm.item_id
        left outer join stck_mgnt_base_info stck on base.brand_id = stck.brand_id and base.shmt_whs_id = stck.whs_id and base.shmt_location = stck.location
        and ptcl.item_id = stck.item_id
        where  1=1
        and    base.brand_id = #{sBrandId}
        and    base.dlv_req_dt between #{fromDt} and #{toDt}
        and    base.dlv_dvsn = 'DL01'  -- 본사배송구분
        and    base.whs_dvsn = 'W02'  -- 납품매장창고구분
        <if test="sShmtWhsId != null and sShmtWhsId != ''">
        and    base.shmt_whs_id = #{sShmtWhsId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
        and    base.whs_id = #{sWhsId}
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by pch_req_unq_no asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by pch_req_unq_no desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by pch_req_unq_no desc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectShmtTargetOdrGridCnt" resultType="int">
        select count(*) as cnt
        from   pch_odr_base_info base
        join pch_odr_dtl_ptcl ptcl on base.pch_podr_unq_no = ptcl.pch_podr_unq_no and ptcl.podr_dtl_st_cd = 'POD0'
        <if test="sItemNm != null and sItemNm != ''">
            and (ptcl.item_id like concat('%',#{sItemNm},'%') or ptcl.item_nm like concat('%',#{sItemNm},'%'))
        </if>
        join item_base_info itm on ptcl.item_id = itm.item_id
        left outer join stck_mgnt_base_info stck on base.brand_id = stck.brand_id and base.shmt_whs_id = stck.whs_id and base.shmt_location = stck.location
        and ptcl.item_id = stck.item_id
        where  1=1
        and    base.brand_id = #{sBrandId}
        and    base.dlv_req_dt between #{fromDt} and #{toDt}
        and    base.dlv_dvsn = 'DL01'  -- 본사배송구분
        and    base.whs_dvsn = 'W02'  -- 납품매장창고구분
        <if test="sShmtWhsId != null and sShmtWhsId != ''">
            and    base.shmt_whs_id = #{sShmtWhsId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
            and    base.whs_id = #{sWhsId}
        </if>

    </select>

    <insert id="insertShmtOdrBase">
        insert into shmt_odr_base_info
            (shmt_req_unq_no, shmt_req_st_cd, shmt_reg_dt, shmt_whs_id, shmt_location
            , whs_dvsn, brand_id, store_id, podr_dvsn, item_qty
            , shmt_total_amt,  podr_mgr_nm, dlv_req_dt, whs_id, location
            , sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        values
            (#{entity.shmtReqUnqNo}, #{entity.shmtReqStCd}, date_format(now(),'%Y%m%d'), #{entity.shmtWhsId}, #{entity.shmtLocation}
            , #{entity.whsDvsn}, #{entity.brandId}, #{entity.storeId}, #{entity.podrDvsn}, #{entity.itemQty}
            , #{entity.shmtTotalAmt}, #{entity.podrMgrNm}, #{entity.dlvReqDt}, #{entity.whsId}
            , #{entity.location}, NOW(), #{userId}, NOW(), #{userId})
    </insert>

    <insert id="insertShmtOdrDtl">
        insert into shmt_odr_dtl_ptcl
            (shmt_req_unq_no, shmt_req_dtl_no, item_id, item_nm, unit_amt
            , unit, podr_qty, podr_amt, shmt_qty, shmt_amt, expry_date
            , pch_podr_unq_no, pch_podr_dtl_no, pch_req_unq_no, pch_req_dtl_no, shmt_dtl_st_cd
            , sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        values
        <foreach collection="gridInsertData" item="item" separator=",">
            (#{item.shmtReqUnqNo}, #{item.shmtReqDtlNo}, #{item.itemId}, #{item.itemNm}, #{item.unitAmt}
            , #{item.unit}, #{item.podrQty}, #{item.podrAmt}, #{item.shmtQty}, #{item.shmtAmt}, #{item.expryDate}
            , #{item.pchPodrUnqNo}, #{item.pchPodrDtlNo}, #{item.pchReqUnqNo}, #{item.pchReqDtlNo}, 'SHMD1'
            , NOW(), #{userId}, NOW(), #{userId})
        </foreach>
    </insert>

    <select id="selectShmtJobDataList" resultType="com.oqpo.api.entity.pomng.PchOdrBaseInfoEntity">
        select base.brand_id,base.pch_podr_unq_no, ptcl.pch_podr_dtl_no as 'pchOdrDtlInfo.pch_podr_dtl_no'
                ,ptcl.item_id as 'pchOdrDtlInfo.item_id' , ptcl.item_nm as 'pchOdrDtlInfo.item_nm', base.whs_id
                ,base.location, ptcl.unit_amt as 'pchOdrDtlInfo.unit_amt', ptcl.podr_qty as 'pchOdrDtlInfo.podr_qty'
                ,nvl(stck.stck_qty,0) as 'pchOdrDtlInfo.stck_qty'
                ,itm.expry_yn as 'pchOdrDtlInfo.expry_yn', nvl(itm.expry_period,0) as 'pchOdrDtlInfo.expry_period'
                ,ptcl.podr_amt as 'pchOdrDtlInfo.podr_amt', date_format(base.dlv_req_dt,'%Y.%m.%d') as dlv_req_dt
                , base.shmt_whs_id, base.shmt_location, ptcl.pch_req_unq_no as 'pchOdrDtlInfo.pch_req_unq_no' , ptcl.pch_req_dtl_no as 'pchOdrDtlInfo.pch_req_dtl_no'
                , base.store_id , base.podr_mgr_nm , base.podr_mgr_tel_no
                , fn_get_telno((select tel_no from store_base_info where store_id = base.store_id )) as deli_tel_no
                , date_format(base.podr_dt,'%Y%m%d') as podr_dt
                , base.spply_id, fn_spply_nm(base.spply_id) as spply_nm, , base.store_id
        from   pch_odr_base_info base
        join pch_odr_dtl_ptcl ptcl on base.pch_podr_unq_no = ptcl.pch_podr_unq_no and ptcl.podr_dtl_st_cd = 'POD0'
        join item_base_info itm on ptcl.item_id = itm.item_id
        left outer join stck_mgnt_base_info stck on base.brand_id = stck.brand_id and base.shmt_whs_id = stck.whs_id and base.shmt_location = stck.location
        and ptcl.item_id = stck.item_id
        where  1=1
        and    base.brand_id = #{brandId}
        and    concat(base.pch_podr_unq_no,ptcl.pch_podr_dtl_no) in
        <foreach collection="gridInsertData" item="item" separator="," open="(" close=")">
            concat(#{item.pchPodrUnqNo},#{item.pchPodrDtlNo})
        </foreach>
        order by  base.brand_id, base.shmt_whs_id, base.shmt_location, base.whs_id,base.location
    </select>

    <insert id="insertDeliInfoMngt">
        INSERT INTO deli_info_mgnt
        (dlv_sttmt_unq_no, spply_id, spply_nm, dlv_reg_dt, dlv_amt
        , dlv_mgr_nm, dlv_mgr_tel_no, dlv_mgr_emal, dlv_mgr_mbl_no, vndr_tel_no
        , dlv_st_cd, podr_reg_dt, dlv_req_dt, dlv_sch_dt, dlv_cmplt_dt
        , whs_id, location, whs_dvsn, brand_id,store_id
        , sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        VALUES
        (#{entity.dlvSttmtUnqNo}, #{entity.spplyId}, #{entity.spplyNm}, date_format(now(),'%Y%m%d'), #{entity.dlvAmt}
        , #{entity.dlvMgrNm}, #{entity.dlvMgrTelNo}, #{entity.dlvMgrEmal}, #{entity.dlvMgrMblNo}, #{entity.vndrTelNo}
        , #{entity.dlvStCd}, #{entity.podrRegDt}, #{entity.dlvReqDt}, #{entity.dlvSchDt}, #{entity.dlvCmpltDt}
        , #{entity.whsId}, #{entity.location}, #{entity.whsDvsn}, #{entity.brandId}, #{entity.storeId}
        , NOW(), #{userId}, NOW(), #{userId})
    </insert>

    <insert id="insertDeliDtlPtcl" >
        INSERT INTO deli_dtl_ptcl
        (dlv_sttmt_unq_no, dlv_sttmt_dtl_no, pch_podr_unq_no, pch_podr_dtl_no, pch_req_unq_no
        , pch_req_dtl_no, item_id, item_nm, unit, unit_amt
        , price_unit, podr_qty, dlv_qty, podr_amt, dlv_amt
        , expry_date, delay_yn, delay_rsn,dlv_dtl_st_cd
        , shmt_req_unq_no, shmt_req_dtl_no
        , sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        VALUES
        <foreach collection="gridInsertData" item="item" separator=",">
        (#{item.dlvSttmtUnqNo}, #{item.dlvSttmtDtlNo}, #{item.pchPodrUnqNo}, #{item.pchPodrDtlNo}, #{item.pchReqUnqNo}
        , #{item.pchReqDtlNo}, #{item.itemId}, #{item.itemNm}, #{item.unit}, #{item.unitAmt}
        , #{item.priceUnit}, #{item.podrQty}, #{item.dlvQty}, #{item.podrAmt}, #{item.dlvAmt}
        , #{item.expryDate}, #{item.delayYn}, #{item.delayRsn}, 'DLD0'
        , #{item.shmtReqUnqNo}, #{item.shmtReqDtlNo}
        , NOW(), #{userId}, NOW(), #{userId})
        </foreach>
    </insert>

    <select id="selectShmtSearchGridList" resultType="com.oqpo.api.entity.inoutmng.ShmtOdrBaseEntity">
        /*  shmtOdr.selectShmtSearchGridList */
        select base.shmt_req_unq_no , ptcl.shmt_req_dtl_no as 'shmtOdrDtlInfo.shmt_req_dtl_no' ,  base.brand_id, fn_brand_nm(base.brand_id) as brand_nm
               ,ptcl.pch_podr_unq_no as 'shmtOdrDtlInfo.pch_podr_unq_no' , ptcl.pch_podr_dtl_no as 'shmtOdrDtlInfo.pch_podr_dtl_no'
               ,base.shmt_req_st_cd, fn_code_nm('SHMT_REQ_ST_CD',base.shmt_req_st_cd) as shmt_req_st_nm  , ptcl.item_id as 'shmtOdrDtlInfo.item_id'
               ,ptcl.item_nm as 'shmtOdrDtlInfo.item_nm'  , base.whs_id, fn_whs_nm(base.brand_id, base.whs_id) as whs_nm
               ,base.location, fn_whs_location_nm(base.brand_id, base.whs_id, base.location) as location_nm  , ptcl.shmt_qty as 'shmtOdrDtlInfo.shmt_qty'
               ,ptcl.shmt_amt as 'shmtOdrDtlInfo.shmt_amt' , nvl(proc.whs_qty,0) as 'whsProcInfo.whs_qty' , nvl(proc.whs_amt,0) as 'whsProcInfo.whs_amt'
               ,date_format(proc.whs_dt,'%Y.%m.%d') as 'whsProcInfo.whs_dt', proc.whs_cnfm_nm as 'whsProcInfo.whs_cnfm_nm'
               ,deli.dlv_sttmt_unq_no
        from  shmt_odr_base_info base
         join shmt_odr_dtl_ptcl ptcl on base.shmt_req_unq_no = ptcl.shmt_req_unq_no
         join deli_dtl_ptcl deli on deli.pch_podr_unq_no = ptcl.pch_podr_unq_no and deli.pch_podr_dtl_no = ptcl.pch_podr_dtl_no
         left outer join whs_proc_info_ptcl proc on proc.dlv_sttmt_unq_no = deli.dlv_sttmt_unq_no and proc.dlv_sttmt_dtl_no = deli.dlv_sttmt_dtl_no
        where 1=1
        and   base.brand_id = #{sBrandId}
        <if test="fromDt != null and fromDt != '' and toDt != null and toDt != ''">
        and   base.shmt_reg_dt between #{fromDt} and #{toDt}
        </if>
        <if test="sShmtWhsId != null and sShmtWhsId != ''">
        and   base.shmt_whs_id = #{sShmtWhsId}
        </if>
        <if test="sShmtReqStCd != null and sShmtReqStCd != ''">
        and   base.shmt_req_st_cd = #{sShmtReqStCd}
        </if>
        <if test="swhsId != null and swhsId != ''">
        and   base.whs_id = #{swhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
        and   (ptcl.item_id like concat('%', #{sItemNm},'%') or ptcl.item_nm like concat('%',#{sItemNm},'%'))
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by pch_req_unq_no asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by pch_req_unq_no desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by pch_req_unq_no desc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectShmtSearchGridCnt" resultType="int">
        /*  shmtOdr.selectShmtSearchGridCnt */
        select count(*)
        from  shmt_odr_base_info base
        join shmt_odr_dtl_ptcl ptcl on base.shmt_req_unq_no = ptcl.shmt_req_unq_no
        join deli_dtl_ptcl deli on deli.pch_podr_unq_no = ptcl.pch_podr_unq_no and deli.pch_podr_dtl_no = ptcl.pch_podr_dtl_no
        left outer join whs_proc_info_ptcl proc on proc.dlv_sttmt_unq_no = deli.dlv_sttmt_unq_no and proc.dlv_sttmt_dtl_no = deli.dlv_sttmt_dtl_no
        where 1=1
        and   base.brand_id = #{sBrandId}
        <if test="fromDt != null and fromDt != '' and toDt != null and toDt != ''">
            and   base.shmt_reg_dt between #{fromDt} and #{toDt}
        </if>
        <if test="sShmtWhsId != null and sShmtWhsId != ''">
            and   base.shmt_whs_id = #{sShmtWhsId}
        </if>
        <if test="sShmtReqStCd != null and sShmtReqStCd != ''">
            and   base.shmt_req_st_cd = #{sShmtReqStCd}
        </if>
        <if test="swhsId != null and swhsId != ''">
            and   base.whs_id = #{swhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and   (ptcl.item_id like concat('%', #{sItemNm},'%') or ptcl.item_nm like concat('%',#{sItemNm},'%'))
        </if>
    </select>

    <select id="selectInvInfo" resultType="com.oqpo.api.entity.inoutmng.DeliInfoMgntEntity">
        select  date_format(deli.dlv_reg_dt,'%Y.%m.%d') as dlv_reg_dt, deli.dlv_sttmt_unq_no, date_format(deli.dlv_sch_dt,'%Y.%m.%d') as dvl_sch_dt
            , deli.dlv_mgr_nm,  fn_get_telno( deli.dlv_mgr_tel_no) as dlv_mgr_tel_no
            , fn_whs_nm(deli.brand_id, deli.whs_id) as whs_nm,  fn_whs_location_nm(deli.brand_id, deli.whs_id, deli.location) as location_nm
            , whs.mgr_tel_no, deli.spply_id
            , case when  deli.spply_id is null or deli.spply_id = ''  then 'DL01' else 'DL02'  end as deli_dvsn  -- 배송주체
            , deli.whs_dvsn -- 납품정보
            , concat(whs.addr1 ,' ',whs.addr2) as whs_addr
            , fn_get_telno(whs.mgr_tel_no) as whs_mgr_tel_no
        from   deli_info_mgnt deli
        join   whs_mgnt_base_info whs on whs.brand_id = deli.brand_id and whs.whs_id = deli.whs_id
        where  deli.brand_id = #{brandId}
        and    deli.dlv_sttmt_unq_no = #{dlvSttmtUnqNo}
    </select>

    <select id="selectInvDtlList" resultType="com.oqpo.api.entity.inoutmng.DeliDtlMgntEntity">
        select ptcl.pch_podr_unq_no, ptcl.item_id, ptcl.item_nm, ptcl.podr_qty, ptcl.dlv_qty, date_format(ptcl.expry_date,'%Y.%m.%d') as expry_date
        from deli_info_mgnt info
            , deli_dtl_ptcl ptcl
        where 1 = 1
        and info.dlv_sttmt_unq_no = ptcl.dlv_sttmt_unq_no
        and info.brand_id = #{brandId}
        and info.dlv_sttmt_unq_no = #{dlvSttmtUnqNo}
    </select>

    <select id="selectSpplyTargetOdrGridList" resultType="com.oqpo.api.entity.pomng.PchOdrBaseInfoEntity">
        select base.brand_id, fn_brand_nm(base.brand_id) as brand_nm, base.pch_podr_unq_no
            , ptcl.pch_podr_dtl_no as 'pchOdrDtlInfo.pch_podr_dtl_no'
            ,ptcl.item_id as 'pchOdrDtlInfo.item_id' , ptcl.item_nm as 'pchOdrDtlInfo.item_nm', base.whs_id, fn_whs_nm(base.brand_id, base.whs_id) as whs_nm
            ,base.location, fn_whs_location_nm(base.brand_id, base.whs_id, base.location) as location_nm
            ,ptcl.unit_amt as 'pchOdrDtlInfo.unit_amt', ptcl.podr_qty as 'pchOdrDtlInfo.podr_qty'
            , ptcl.podr_qty as 'pchOdrDtlInfo.shmt_qty'
            ,ptcl.podr_amt as 'pchOdrDtlInfo.podr_amt', date_format(base.dlv_req_dt,'%Y.%m.%d') as dlv_req_dt, base.shmt_whs_id, base.shmt_location
        from   pch_odr_base_info base
        join pch_odr_dtl_ptcl ptcl on base.pch_podr_unq_no = ptcl.pch_podr_unq_no and ptcl.podr_dtl_st_cd = 'POD0'
        <if test="sItemNm != null and sItemNm != ''">
        and (ptcl.item_id like concat('%',#{sItemNm},'%') or ptcl.item_nm like concat('%',#{sItemNm},'%') or ptcl.pch_podr_unq_no like concat('%',#{sItemNm},'%'))
        </if>
        join item_base_info itm on ptcl.item_id = itm.item_id
        left outer join stck_mgnt_base_info stck on base.brand_id = stck.brand_id and base.shmt_whs_id = stck.whs_id and base.shmt_location = stck.location
        and ptcl.item_id = stck.item_id
        where  1=1
        and    base.brand_id = #{sBrandId}
        and    base.dlv_req_dt between #{fromDt} and #{toDt}
        and    base.dlv_dvsn = 'DL02'  -- 본사배송구분
        and    base.spply_id = #{sSpplyId}
        <if test="sWhsId != null and sWhsId != ''">
        and   base.whs_id =  #{sWhsId}
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by base.pch_podr_unq_no asc, ptcl.pch_podr_dtl_no asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by base.pch_podr_unq_no desc, ptcl.pch_podr_dtl_no desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by base.pch_podr_unq_no asc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectSpplyTargetOdrGridCnt" resultType="int">
        select count(*)
        from   pch_odr_base_info base
        join pch_odr_dtl_ptcl ptcl on base.pch_podr_unq_no = ptcl.pch_podr_unq_no and ptcl.podr_dtl_st_cd = 'POD0'
        <if test="sItemNm != null and sItemNm != ''">
            and (ptcl.item_id like concat('%',#{sItemNm},'%') or ptcl.item_nm like concat('%',#{sItemNm},'%') or ptcl.pch_podr_unq_no like concat('%',#{sItemNm},'%'))
        </if>
        join item_base_info itm on ptcl.item_id = itm.item_id
        left outer join stck_mgnt_base_info stck on base.brand_id = stck.brand_id and base.shmt_whs_id = stck.whs_id and base.shmt_location = stck.location
        and ptcl.item_id = stck.item_id
        where  1=1
        and    base.brand_id = #{sBrandId}
        and    base.dlv_req_dt between #{fromDt} and #{toDt}
        and    base.dlv_dvsn = 'DL02'  -- 본사배송구분
        and    base.spply_id = #{sSpplyId}
        <if test="sWhsId != null and sWhsId != ''">
            and   base.whs_id =  #{sWhsId}
        </if>

    </select>

    <select id="selectSpplyShmtOdrInfo" resultType="com.oqpo.api.entity.pomng.PchOdrBaseInfoEntity">
    select  base.brand_id, fn_brand_nm(base.brand_id) as brand_nm, base.pch_podr_unq_no, date_format(now(), '%Y.%m.%d') as dlv_req_dt
        , (select sum(podr_amt) from  pch_odr_dtl_ptcl where pch_podr_unq_no = '22102500006015' and podr_dtl_st_cd = 'POD0' ) as podr_total_amt
        , base.whs_id, fn_whs_nm(base.brand_id, base.whs_id) as whs_nm
        , base.location, fn_whs_location_nm(brand_id, base.whs_id, base.location) as location_nm
        , fn_get_telno((select tel_no from store_base_info where store_id = base.store_id )) as deli_tel_no
    from    pch_odr_base_info base
    where  1=1
    and    base.brand_id = #{brandId}
    and    base.spply_id = #{spplyId}
    and    base.dlv_dvsn = 'DL02'
    and    base.pch_podr_unq_no = #{pchPodrUnqNo}
    </select>

    <select id="selectSpplyShmtOdrList" resultType="com.oqpo.api.entity.pomng.PchOdrDtlPtclEntity">
    select ptcl.pch_podr_unq_no, ptcl.pch_podr_dtl_no, ptcl.item_id, ptcl.item_nm, ptcl.unit, ptcl.podr_qty, ptcl.podr_qty as shmt_qty
            ,itm.expry_yn as expry_yn, itm.expry_period as expry_period
            , date_format(adddate(now(), interval itm.expry_period day),'%Y.%m.%d') as expry_date
    from   pch_odr_dtl_ptcl ptcl
    join   item_base_info itm on ptcl.item_id = itm.item_id
    where  ptcl.pch_podr_unq_no = #{pchPodrUnqNo}
    and    ptcl.podr_dtl_st_cd = 'POD0'
    </select>

    <select id="selectDeliGridList" resultType="com.oqpo.api.entity.inoutmng.DeliInfoMgntEntity">
        select info.brand_id, fn_brand_nm(info.brand_id) as brand_nm, info.dlv_sttmt_unq_no
            , info.spply_id, info.spply_nm, info.dlv_st_cd, fn_code_nm(upper('dlv_st_cd'), info.dlv_st_cd) as dlv_st_nm
            , info.whs_id, info.location, fn_whs_nm(info.brand_id, info.whs_id) as whs_nm
            , fn_whs_location_nm(info.brand_id, info.whs_id, info.location) as location_nm
            , date_format(info.podr_reg_dt, '%Y.%m.%d') as podr_reg_dt, date_format(info.dlv_req_dt, '%y.%m.%d') as dlv_req_dt
            , date_format(info.dlv_reg_dt, '%Y.%m.%d') as dlv_req_dt, date_format(info.dlv_sch_dt, '%y.%m.%d') as dlv_sch_dt
            , date_format(info.dlv_cmplt_dt, '%y.%m.%d') as dlv_cmplt_dt
            , ptcl.item_id as 'deliDtlMgntInfo.item_id', ptcl.item_nm as 'deliDtlMgntInfo.item_nm'
            , ptcl.podr_qty as 'deliDtlMgntInfo.podr_qty', ptcl.dlv_qty as 'deliDtlMgntInfo.dlv_qty'
            , ptcl.unit as 'deliDtlMgntInfo.unit', ptcl.unit_amt as 'deliDtlMgntInfo.unit_amt'
            , info.dlv_mgr_nm , info.dlv_mgr_mbl_no
        from deli_info_mgnt info
             , deli_dtl_ptcl ptcl
        where 1 = 1
        and info.dlv_sttmt_unq_no = ptcl.dlv_sttmt_unq_no
        and info.brand_id = #{sBrandId}
        <if test="dtGubun eq '1'.toString()">
            and info.podr_reg_dt between #{fromDt} and #{toDt}  -- 1인경우 발주생성일로 조회
        </if>
        <if test="dtGubun eq '2'.toString()">
            and info.dlv_req_dt between #{fromDt} and #{toDt}   -- 2인경우 납품요청일로 조회
        </if>
        <if test="dtGubun eq '3'.toString()">
            and info.dlv_sch_dt between #{fromDt} and #{toDt}    -- 3인경우 납품예정일로 조회
        </if>
        <if test="dtGubun eq '4'.toString()">
            and info.dlv_cmplt_dt between #{fromDt} and #{toDt}    -- 3인경우 납품완료일 조회
        </if>
        <if test="sDlvStCd != null and sDlvStCd != ''">
            and info.dlv_st_cd = #{sDlvStCd}  -- 납품상태
        </if>
        <if test="sSpplyId != null and sSpplyId != ''">
            and info.spply_id = #{sSpplyId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
            and info.whs_id = #{sWhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.item_nm like concat('%', #{sItemNm}, '%'))
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by pch_req_unq_no asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by pch_req_unq_no desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by pch_req_unq_no desc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectDeliGridCnt" resultType="int">
        select count(*)
        from deli_info_mgnt info
        , deli_dtl_ptcl ptcl
        where 1 = 1
        and info.dlv_sttmt_unq_no = ptcl.dlv_sttmt_unq_no
        and info.brand_id = #{sBrandId}
        <if test="dtGubun eq '1'.toString()">
            and info.podr_reg_dt between #{fromDt} and #{toDt}  -- 1인경우 발주생성일로 조회
        </if>
        <if test="dtGubun eq '2'.toString()">
            and info.dlv_req_dt between #{fromDt} and #{toDt}   -- 2인경우 납품요청일로 조회
        </if>
        <if test="dtGubun eq '3'.toString()">
            and info.dlv_sch_dt between #{fromDt} and #{toDt}    -- 3인경우 납품예정일로 조회
        </if>
        <if test="dtGubun eq '4'.toString()">
            and info.dlv_cmplt_dt between #{fromDt} and #{toDt}    -- 3인경우 납품완료일 조회
        </if>
        <if test="sDlvStCd != null and sDlvStCd != ''">
            and info.dlv_st_cd = #{sDlvStCd}  -- 납품상태
        </if>
        <if test="sSpplyId != null and sSpplyId != ''">
            and info.spply_id = #{sSpplyId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
            and info.whs_id = #{sWhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.item_nm like concat('%', #{sItemNm}, '%'))
        </if>
    </select>

    <select id="selectSpplyDeliGridList" resultType="com.oqpo.api.entity.inoutmng.DeliInfoMgntEntity">
        select info.brand_id, fn_brand_nm(info.brand_id) as brand_nm, info.dlv_sttmt_unq_no
        , info.spply_id, info.spply_nm, info.dlv_st_cd, fn_code_nm(upper('dlv_st_cd'), info.dlv_st_cd) as dlv_st_nm
        , info.whs_id, info.location, fn_whs_nm(info.brand_id, info.whs_id) as whs_nm
        , fn_whs_location_nm(info.brand_id, info.whs_id, info.location) as location_nm
        , date_format(info.podr_reg_dt, '%Y.%m.%d') as podr_reg_dt, date_format(info.dlv_req_dt, '%y.%m.%d') as dlv_req_dt
        , date_format(info.dlv_reg_dt, '%Y.%m.%d') as dlv_req_dt, date_format(info.dlv_sch_dt, '%y.%m.%d') as dlv_sch_dt
        , date_format(info.dlv_cmplt_dt, '%y.%m.%d') as dlv_cmplt_dt
        , ptcl.item_id as 'deliDtlMgntInfo.item_id', ptcl.item_nm as 'deliDtlMgntInfo.item_nm'
        , ptcl.podr_qty as 'deliDtlMgntInfo.podr_qty', ptcl.dlv_qty as 'deliDtlMgntInfo.dlv_qty'
        , ptcl.unit as 'deliDtlMgntInfo.unit', ptcl.unit_amt as 'deliDtlMgntInfo.unit_amt'
        , info.dlv_mgr_nm , info.dlv_mgr_mbl_no
        from deli_info_mgnt info
        , deli_dtl_ptcl ptcl
        where 1 = 1
        and info.dlv_sttmt_unq_no = ptcl.dlv_sttmt_unq_no
        and info.brand_id = #{sBrandId}
        and info.spply_id = #{sSpplyId}
        and info.dlv_sch_dt between #{fromDt} and #{toDt}  -- 납품 예정일
        <if test="sWhsId != null and sWhsId != ''">
            and info.whs_id = #{sWhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.item_nm like concat('%', #{sItemNm}, '%'))
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by pch_req_unq_no asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by pch_req_unq_no desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by pch_req_unq_no desc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectSpplyDeliGridCnt" resultType="int">
        select count(*)
        from deli_info_mgnt info
        , deli_dtl_ptcl ptcl
        where 1 = 1
        and info.dlv_sttmt_unq_no = ptcl.dlv_sttmt_unq_no
        and info.brand_id = #{sBrandId}
        and info.spply_id = #{sSpplyId}
        and info.dlv_sch_dt between #{fromDt} and #{toDt}  -- 납품 예정일
        <if test="sWhsId != null and sWhsId != ''">
            and info.whs_id = #{sWhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.item_nm like concat('%', #{sItemNm}, '%'))
        </if>
    </select>

    <select id="selectWarehouseTargetGridList" resultType="com.oqpo.api.entity.inoutmng.DeliInfoMgntEntity">
        select info.brand_id, fn_brand_nm(info.brand_id) as brand_nm
                , info.dlv_sttmt_unq_no, ptcl.dlv_sttmt_dtl_no as 'deliDtlMgntInfo.dlv_sttmt_dtl_no'
                , ptcl.item_id as 'deliDtlMgntInfo.item_id' , ptcl.item_nm as 'deliDtlMgntInfo.item_nm'
                , ptcl.podr_qty as 'deliDtlMgntInfo.podr_qty', ptcl.dlv_qty as 'deliDtlMgntInfo.dlv_qty'
                , ptcl.dlv_qty as 'deliDtlMgntInfo.whs_qty' , ptcl.dlv_qty * ptcl.unit_amt as 'deliDtlMgntInfo.whs_amt'
                , ptcl.unit_amt as 'deliDtlMgntInfo.unit_amt'
                , info.whs_id, info.location, fn_whs_nm(info.brand_id, info.whs_id) as whs_nm
                , fn_whs_location_nm(info.brand_id, info.whs_id, info.location) as location_nm
                , date_format(info.dlv_sch_dt, '%Y.%m.%d %H:%i:%s') as dlv_sch_dt
                , date_format(info.dlv_req_dt, '%Y.%m.%d %H:%i:%s') as dlv_req_dt
                , info.dlv_mgr_nm, info.dlv_mgr_mbl_no, fn_get_telno(info.dlv_mgr_tel_no) AS dlv_mgr_tel_no
                , ptcl.pch_podr_unq_no as 'deliDtlMgntInfo.pch_podr_unq_no', ptcl.pch_podr_dtl_no as 'deliDtlMgntInfo.pch_podr_dtl_no'
                , ptcl.pch_req_unq_no as 'deliDtlMgntInfo.pch_req_unq_no', ptcl.pch_req_dtl_no as 'deliDtlMgntInfo.pch_req_dlt_no'
                , ptcl.unit as 'deliDtlMgntInfo.unit', info.dlv_cmplt_dt as 'deliDtlMgntInfo.dlv_cmplt_dt'
                , info.spply_id as 'deliDtlMgntInfo.spply_id', info.spply_nm as 'deliDtlMgntInfo.spply_nm'
        from deli_info_mgnt info
        , deli_dtl_ptcl ptcl
        where 1 = 1
        and info.dlv_sttmt_unq_no = ptcl.dlv_sttmt_unq_no
        and info.brand_id = #{sBrandId}
        and info.dlv_sch_dt between #{fromDt} and #{toDt}
        and info.dlv_st_cd = 'DLV0'
        and ptcl.dlv_dtl_st_cd = 'DLD0'
        and info.whs_id = #{sWhsId}
        <if test="sSpplyId != null and sSpplyId != ''">
        and info.spply_id = #{sSpplyId}
        </if>
        <if test="sDlvSttmtUnqNo != null and sDlvSttmtUnqNo != ''">
        and info.dlv_sttmt_unq_no like concat('%',#{sDlvSttmtUnqNo},'%')
        </if>
        <if test="sItemNm != null and sItemNm != ''">
        and (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.item_nm like concat('%', #{sItemNm}, '%'))
        </if>
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by pch_req_unq_no asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by pch_req_unq_no desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by pch_req_unq_no desc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectWarehouseTargetGridCnt" resultType="int">
        select count(*)
        from deli_info_mgnt info
            , deli_dtl_ptcl ptcl
        where 1 = 1
        and info.dlv_sttmt_unq_no = ptcl.dlv_sttmt_unq_no
        and info.brand_id = #{sBrandId}
        and info.dlv_sch_dt between #{fromDt} and #{toDt}
        and info.dlv_st_cd = 'DLV0'
        and ptcl.dlv_dtl_st_cd = 'DLD0'
        and info.whs_id = #{sWhsId}
        <if test="sSpplyId != null and sSpplyId != ''">
            and info.spply_id = #{sSpplyId}
        </if>
        <if test="sDlvSttmtUnqNo != null and sDlvSttmtUnqNo != ''">
            and info.dlv_sttmt_unq_no like concat('%',#{sDlvSttmtUnqNo},'%')
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and (ptcl.item_id like concat('%', #{sItemNm}, '%') or ptcl.item_nm like concat('%', #{sItemNm}, '%'))
        </if>
    </select>

    <insert id="insertWhsProcInfoPtcl">
        insert into whs_proc_info_ptcl   /* insertWhsProcInfoPtcl */
        (whs_mgnt_unq_no, dlv_sttmt_dtl_no, dlv_sttmt_unq_no, brand_id, store_id
        , whs_dt,  whs_id, location, whs_dvsn, podr_qty, dlv_qty
        , whs_qty, unit, dlv_req_dt, dlv_sch_dt, dlv_cmplt_dt
        , whs_cnfm_nm, dlv_mgr_nm, dlv_mgr_tel_no, dlv_mgr_emal, dlv_mgr_mbl_no
        , item_id, item_nm, whs_amt, whs_dlv_chrg, dlv_mgr_id
        , dlv_cnfm_doc_file_no, sttl_yn, pch_podr_unq_no, pch_podr_dtl_no, pch_req_unq_no
        , pch_req_dtl_no, shmt_req_unq_no, shmt_req_dtl_no,  sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id
        , spply_id, spply_nm , unit_amt)
        values
        <foreach collection="gridUpdateData" item="item" separator=",">
        (#{item.whsMgntUnqNo}, #{item.dlvSttmtDtlNo}, #{item.dlvSttmtUnqNo}, #{item.brandId}, #{item.storeId}
        , date_format(now(),'%Y%m%d'),#{item.whsId}, #{item.location}, #{item.whsDvsn}, #{item.podrQty}, #{item.dlvQty}
        , #{item.whsQty}, #{item.unit}, #{item.dlvReqDt}, #{item.dlvSchDt}, date_format(now(),'%Y%m%d')
        , #{item.whsCnfmNm}, #{item.dlvMgrNm}, #{item.dlvMgrTelNo}, #{item.dlvMgrEmal}, #{item.dlvMgrMblNo}
        , #{item.itemId}, #{item.itemNm}, #{item.whsAmt}, #{item.whsDlvChrg}, #{item.dlvMgrId}
        , #{item.dlvCnfmDocFileNo}, #{item.sttlYn}, #{item.pchPodrUnqNo}, #{item.pchPodrDtlNo}, #{item.pchReqUnqNo}
        , #{item.pchReqDtlNo}, #{item.shmtReqUnqNo}, #{item.shmtReqDtlNo}, NOW(), #{userId}, NOW(), #{userId}
        , #{item.spplyId} , #{item.spplyNm}, #{item.unitAmt})
        </foreach>
    </insert>

    <select id="selectWarehouseProcList" resultType="com.oqpo.api.entity.inoutmng.DeliInfoMgntEntity">
        select	/* shmtOdr.selectWarehouseProcList  */info.brand_id, info.store_id
                , info.dlv_sttmt_unq_no, ptcl.dlv_sttmt_dtl_no as 'deliDtlMgntInfo.dlv_sttmt_dtl_no'
                , info.whs_id, info.location, info.spply_id, info.spply_nm
                , info.whs_dvsn, ptcl.podr_qty as 'deliDtlMgntInfo.podr_qty'
                , ptcl.dlv_qty as 'deliDtlMgntInfo.dlv_qty', ptcl.unit as 'deliDtlMgntInfo.unit'
                , ptcl.unit_amt as 'deliDtlMgntInfo.unit_amt', info.dlv_req_dt, info.dlv_sch_dt
                , info.dlv_mgr_nm, info.dlv_mgr_mbl_no, info.dlv_mgr_tel_no
                , ptcl.item_id as 'deliDtlMgntInfo.item_id' , ptcl.item_nm as 'deliDtlMgntInfo.item_nm'
                , ptcl.pch_podr_unq_no as 'deliDtlMgntInfo.pch_podr_unq_no', ptcl.pch_podr_dtl_no as 'deliDtlMgntInfo.pch_podr_dtl_no'
                , ptcl.pch_req_unq_no as 'deliDtlMgntInfo.pch_req_unq_no', ptcl.pch_req_dtl_no as 'deliDtlMgntInfo.pch_req_dlt_no'
                , ptcl.shmt_req_unq_no as 'deliDtlMgntInfo.shmt_req_unq_no' , ptcl.shmt_req_dtl_no as 'deliDtlMgntInfo.shmt_req_dtl_no'
                , ptcl.podr_amt as 'deliDtlMgntInfo.podr_amt'
        from deli_info_mgnt info
        join deli_dtl_ptcl ptcl on info.dlv_sttmt_unq_no = ptcl.dlv_sttmt_unq_no
               and concat(ptcl.dlv_sttmt_unq_no, ptcl.dlv_sttmt_dtl_no) in
                <foreach collection="gridUpdateData" item="item" separator="," open="(" close=")">
                #{item.dlvSttmtDtlNo}
                </foreach>
                and ptcl.dlv_dtl_st_cd = 'DLD0'
        where 1=1
        and info.brand_id = #{brandId}
        and info.dlv_st_cd = 'DLV0'
        and info.whs_id = #{whsId}
    </select>


    <update id="updateDeliDtlStCd" >
        /* updateDeliDtlStCd */
        <foreach collection="gridUpdateData" item="item" separator=";">
            UPDATE deli_dtl_ptcl SET
            dlv_dtl_st_cd = #{item.dlvDtlStCd},       /* 상태처리 */
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
            WHERE dlv_sttmt_unq_no =  #{item.dlvSttmtUnqNo}
            AND dlv_sttmt_dtl_no = #{item.dlvSttmtDtlNo}
        </foreach>
    </update>


    <select id="selectDeliInfoStList" resultType="com.oqpo.api.entity.inoutmng.DeliInfoMgntEntity">
        select gdlv.dlv_sttmt_unq_no
                , case when gdlv.dlv0 > 0 then 'DLV0'
                when gdlv.dlv0 = 0 and gdlv.dlv1 > 0 then  'DLV1'
                when gdlv.dlv0 = 0 and gdlv.dlv1 = 0 then  'DLV2'
                else '' end as  dlv_st_cd
        from  (
                select  dlv_sttmt_unq_no
                    , sum(case when dlv_dtl_st_cd = 'DLD0' then 1 else 0 end) as dlv0
                    , sum(case when dlv_dtl_st_cd = 'DLD1' then 1 else 0 end) as dlv1
                    , sum(case when dlv_dtl_st_cd = 'DLD2' then 1 else 0 end) as dlv2
                from deli_dtl_ptcl
                where dlv_sttmt_unq_no in
                    <foreach collection="gridUpdateData" item="item" separator="," open="(" close=")">
                     #{item.dlvSttmtUnqNo}
                    </foreach>
                group by dlv_sttmt_unq_no
        ) gdlv
    </select>

    <update id="updateDeliInfoStCd" >
        /* updateDeliInfoStCd */
        <foreach collection="gridUpdateData" item="item" separator=";">
            UPDATE deli_info_mgnt SET
                    dlv_st_cd = #{item.dlvStCd},       /* 상태처리 */
                    sys_chg_dttm = NOW(),
                    sys_chg_id = #{userId}
            WHERE dlv_sttmt_unq_no =  #{item.dlvSttmtUnqNo}
        </foreach>
    </update>


    <update id="updateShmtDtlStCd" >
        /* updateShmtDtlStCd */
        <foreach collection="gridUpdateData" item="item" separator=";">
            UPDATE shmt_odr_dtl_ptcl SET
            shmt_dtl_st_cd = #{item.shmtDtlStCd},       /* 상태처리 */
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
            WHERE shmt_req_unq_no =  #{item.shmtReqUnqNo}
            AND shmt_req_dtl_no = #{item.shmtReqDtlNo}
        </foreach>
    </update>

    <select id="selectShmtInfoStList" resultType="com.oqpo.api.entity.inoutmng.ShmtOdrDtlEntity">
        select gdlv.shmt_req_unq_no
        , case when gdlv.shmd1 > 0 then 'SHM1'
        when gdlv.shmd1 = 0 and gdlv.shmd2 > 0 then  'SHM2'
        when gdlv.shmd1 = 0 and gdlv.shmd2 = 0 then  'SHM3'
        else '' end as  shmt_req_st_cd
        from  (
        select  shmt_req_unq_no
        , sum(case when shmt_dtl_st_cd = 'SHMD1' then 1 else 0 end) as shmd1
        , sum(case when shmt_dtl_st_cd = 'SHMD2' then 1 else 0 end) as shmd2
        , sum(case when shmt_dtl_st_cd = 'SHMD3' then 1 else 0 end) as shmd3
        from shmt_odr_dtl_ptcl
        where shmt_req_unq_no in
        <foreach collection="gridUpdateData" item="item" separator="," open="(" close=")">
            #{item.shmtReqUnqNo}
        </foreach>
        group by shmt_req_unq_no
        ) gdlv

    </select>

    <update id="updateShmtInfoStCd" >
        /* updateShmtInfoStCd */
        <foreach collection="gridUpdateData" item="item" separator=";">
            UPDATE shmt_odr_base_info SET
            shmt_req_st_cd = #{item.shmtReqStCd},       /* 상태처리 */
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
            WHERE shmt_odr_unq_no =  #{item.shmtReqUnqNo}
        </foreach>
    </update>


    <update id="updatePchPodrDtlStCd" >
        /* updatePchPodrDtlStCd */
        <foreach collection="gridUpdateData" item="item" separator=";">
            UPDATE pch_odr_dtl_ptcl SET
            podr_dtl_st_cd = #{item.podrDtlStCd},       /* 상태처리 */
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
            WHERE pch_podr_unq_no =  #{item.pchPodrUnqNo}
            AND pch_podr_dtl_no = #{item.pchPodrDtlNo}
        </foreach>
    </update>

    <select id="selectWarehouseList" resultType="com.oqpo.api.entity.stockmng.WhsProcInfoPtclEntity">
       select whs.pch_podr_unq_no, whs.pch_podr_dtl_no, whs.dlv_sttmt_unq_no, whs.dlv_sttmt_dtl_no
             , whs.podr_qty, whs.dlv_qty, whs.whs_qty
             , date_format(whs.dlv_req_dt, '%Y.%m.%d') as dlv_req_dt
             , date_format(whs.dlv_sch_dt, '%Y.%m.%d') as dlv_sch_dt
             , date_format(whs.dlv_cmplt_dt, '%Y.%m.%d') as dlv_cmplt_dt
             , whs.whs_cnfm_nm, whs.dlv_mgr_nm, whs.dlv_mgr_tel_no
             , whs.item_id, whs.item_nm, whs.unit, whs.whs_amt, whs.dlv_cnfm_doc_file_no
          from whs_proc_info_ptcl whs
         where 1 = 1
         and whs.whs_dt between #{fromDt} and #{toDt}
         and   whs.brand_id = #{sBrandId}
        <if test="sStoreId != null and sStoreId != ''">
         and   whs.store_id = #{sStoreId}
        </if>
        <if test="sPchPodrUnqNo != null and sPchPodrUnqNo != ''">
           and whs.pch_podr_unq_no like concat('%', #{sPchPodrUnqNo}, '%')
        </if>
        <if test="sSpplyId != null and sSpplyId != ''">
           and whs.spply_id =  #{sSpplyId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
           and whs.whs_id = #{sWhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
           and (whs.item_id like concat('%', #{sItemNm}, '%') or whs.item_nm like concat('%', #{sItemNm}, '%'))
        </if>

        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        order by pch_req_unq_no asc
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        order by pch_req_unq_no desc
                    </if>
                </if>
            </when>
            <otherwise>
                order by pch_req_unq_no desc
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectWarehouseCnt" resultType="int">
        select count(*)
        from whs_proc_info_ptcl whs
        where 1 = 1
        and whs.whs_dt between #{fromDt} and #{toDt}
        and   whs.brand_id = #{sBrandId}
        <if test="sStoreId != null and sStoreId != ''">
            and   whs.store_id = #{sStoreId}
        </if>
        <if test="sPchPodrUnqNo != null and sPchPodrUnqNo != ''">
            and whs.pch_podr_unq_no like concat('%', #{sPchPodrUnqNo}, '%')
        </if>
        <if test="sSpplyId != null and sSpplyId != ''">
            and whs.spply_id =  #{sSpplyId}
        </if>
        <if test="sWhsId != null and sWhsId != ''">
            and whs.whs_id = #{sWhsId}
        </if>
        <if test="sItemNm != null and sItemNm != ''">
            and (whs.item_id like concat('%', #{sItemNm}, '%') or whs.item_nm like concat('%', #{sItemNm}, '%'))
        </if>
    </select>
</mapper>
