<?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.sttlmng.SttlReqMapper">

    <select id="selectSttlReqGridList" resultType="com.oqpo.api.entity.settmng.StlMgntDtlPtclEntity">
        /* SttlReqMapper.selectSttlReqGridList */
        SELECT stl.brand_id, stl.brand_nm, stl.store_id, stl.store_nm,
            stl.sttl_st_cd, stl.sttl_st_nm,
            stl.item_id, stl.item_nm, stl.unit, stl.unit_amt,
            stl.podr_qty, stl.dlv_qty, stl.whs_col_qty,
            DATE_FORMAT(stl.whs_col_dt, '%Y.%m.%d') AS whs_col_dt,
            stl.whs_col_amt,
            stl.sttl_dvsn, stl.sttl_dvsn_nm,
            stl.podr_unq_no, stl.podr_dtl_no,
            stl.loan_mgnt_unq_no,
            stl.loan_dvsn, stl.loan_dvsn_nm,
            stl.sttl_mgnt_unq_no, stl.sttl_mgnt_dtl_no,
            stl.mgnt_unq_no,            /* 입고관리고유번호/반품관리고유번호 */
            stl.sys_reg_dttm
        FROM (
            SELECT wpip.whs_mgnt_unq_no AS mgnt_unq_no,
            wpip.brand_id, FN_BRAND_NM(wpip.brand_id) AS brand_nm,
            wpip.store_id, FN_STORE_NM(wpip.brand_id, wpip.store_id) AS store_nm,
            smbi.sttl_st_cd, FN_CODE_NM('STTL_ST_CD', smbi.sttl_st_cd) AS sttl_st_nm,           /* 정산상태 */
            wpip.item_id, wpip.item_nm, wpip.unit, wpip.unit_amt,
            wpip.podr_qty, wpip.dlv_qty, wpip.whs_qty AS whs_col_qty, wpip.whs_dt AS whs_col_dt, wpip.whs_amt AS whs_col_amt,
            IFNULL(smdp.sttl_dvsn, 'SW00') AS sttl_dvsn, FN_CODE_NM('STTL_DVSN', IFNULL(smdp.sttl_dvsn, 'SW00')) AS sttl_dvsn_nm, /* 정산구분 */
            wpip.pch_podr_unq_no AS podr_unq_no, wpip.pch_podr_dtl_no AS podr_dtl_no,
            store.loan_mgnt_unq_no,     /* 여신관리고유번호 */
            store.loan_dvsn, FN_CODE_NM('LOAN_DVSN', store.loan_dvsn) AS loan_dvsn_nm,
            smdp.sttl_mgnt_unq_no, smdp.sttl_mgnt_dtl_no,
            wpip.sys_reg_dttm
            FROM whs_proc_info_ptcl wpip                    /* 입고처리정보내역 */
            LEFT OUTER JOIN stl_mgnt_dtl_ptcl smdp          /* 정산관리상세내역 */
            ON wpip.sttl_mgnt_unq_no = smdp.sttl_mgnt_unq_no
            AND wpip.sttl_mgnt_dtl_no = smdp.sttl_mgnt_dtl_no
            LEFT OUTER JOIN stl_mgnt_base_info smbi         /* 정산관리기본정보 */
            ON smdp.sttl_mgnt_unq_no = smbi.sttl_mgnt_unq_no
            INNER JOIN store_base_info store                /* 매장기본정보 */
            ON wpip.brand_id = store.brand_id AND wpip.store_id = store.store_id
            WHERE 1 = 1
            AND wpip.dlv_cmplt_dt BETWEEN #{fromDt} AND #{toDt}
            AND wpip.sttl_yn = 'N'
            AND smbi.sttl_st_cd IN (NULL, 'ST00', 'ST30')   /* 정산요청 이전, 임시저장, 정산반려 */
            AND wpip.brand_id = #{sBrandId}
            AND wpip.store_id = #{sStoreId}
            <if test="sItemNm != null and sItemNm != ''">
            AND wpip.item_nm LIKE CONCAT('%',#{sItemNm},'%')
            </if>
            UNION ALL
            SELECT rpip.rtn_mgnt_unq_no,
            rpip.brand_id, FN_BRAND_NM(rpip.brand_id) AS brand_nm,
            rpip.store_id, FN_STORE_NM(rpip.brand_id, rpip.store_id) AS store_nm,
            smbi.sttl_st_cd, FN_CODE_NM('STTL_ST_CD', smbi.sttl_st_cd) AS sttl_st_nm,           /* 정산상태 */
            rpip.item_id, rpip.item_nm, rpip.unit, rpip.unit_amt,
            rpip.rtn_qty, 0 as dlv_qty, rpip.col_qty, rpip.col_dt, rpip.col_amt,
            IFNULL(smdp.sttl_dvsn, 'SC00') AS sttl_dvsn, FN_CODE_NM('STTL_DVSN', IFNULL(smdp.sttl_dvsn, 'SC00')) AS sttl_dvsn_nm, /* 정산구분 */
            rpip.rtn_podr_unq_no, rpip.rtn_podr_dtl_no,
            store.loan_mgnt_unq_no,     /* 여신관리고유번호 */
            store.loan_dvsn, FN_CODE_NM('LOAN_DVSN', store.loan_dvsn) AS loan_dvsn_nm,
            smdp.sttl_mgnt_unq_no, smdp.sttl_mgnt_dtl_no,
            rpip.sys_reg_dttm
            FROM rtn_proc_info_ptcl rpip                    /* 반품처리정보내역 */
            LEFT OUTER JOIN stl_mgnt_dtl_ptcl smdp          /* 정산관리상세내역 */
            ON rpip.sttl_mgnt_unq_no = smdp.sttl_mgnt_unq_no
            AND rpip.sttl_mgnt_dtl_no = smdp.sttl_mgnt_dtl_no
            LEFT OUTER JOIN stl_mgnt_base_info smbi         /* 정산관리기본정보 */
            ON smdp.sttl_mgnt_unq_no = smbi.sttl_mgnt_unq_no
            INNER JOIN store_base_info store                /* 매장기본정보 */
            ON rpip.brand_id = store.brand_id AND rpip.store_id = store.store_id
            WHERE 1 = 1
            AND rpip.col_dt BETWEEN #{fromDt} AND #{toDt}
            AND rpip.sttl_yn = 'N'
            AND smbi.sttl_st_cd IN (NULL, 'ST00', 'ST30')   /* 정산요청 이전, 임시저장, 정산반려 */
            AND rpip.brand_id = #{sBrandId}
            AND rpip.store_id = #{sStoreId}
            <if test="sItemNm != null and sItemNm != ''">
            AND rpip.item_nm LIKE CONCAT('%',#{sItemNm},'%')
            </if>
        ) stl
        <choose>
            <when test="gridRequest.sidx != null and gridRequest.sidx != ''">
                <if test="gridRequest.sidx == 'VIEW_NUM'.toString()">
                    <if test="gridRequest.sord == 'asc'.toString()">
                        ORDER BY stl.sys_reg_dttm ASC
                    </if>
                    <if test="gridRequest.sord == 'desc'.toString()">
                        ORDER BY stl.sys_reg_dttm DESC
                    </if>
                </if>
            </when>
            <otherwise>
                ORDER BY stl.sys_reg_dttm ASC
            </otherwise>
        </choose>
        <if test="gridRequest.pagingYn == true">
            limit #{gridRequest.gridFirst}, #{gridRequest.gridSize}
        </if>
    </select>

    <select id="selectSttlReqGridCnt" resultType="int">
        /* SttlReqMapper.selectSttlReqGridCnt */
        SELECT SUM(stl.CNT)
        FROM (
            SELECT COUNT(*) AS CNT
            FROM whs_proc_info_ptcl wpip                    /* 입고처리정보내역 */
            LEFT OUTER JOIN stl_mgnt_dtl_ptcl smdp          /* 정산관리상세내역 */
            ON wpip.sttl_mgnt_unq_no = smdp.sttl_mgnt_unq_no
            AND wpip.sttl_mgnt_dtl_no = smdp.sttl_mgnt_dtl_no
            LEFT OUTER JOIN stl_mgnt_base_info smbi         /* 정산관리기본정보 */
            ON smdp.sttl_mgnt_unq_no = smbi.sttl_mgnt_unq_no
            INNER JOIN store_base_info store                /* 매장기본정보 */
            ON wpip.brand_id = store.brand_id AND wpip.store_id = store.store_id
            WHERE 1 = 1
            AND wpip.dlv_cmplt_dt BETWEEN #{fromDt} AND #{toDt}
            AND wpip.sttl_yn = 'N'
            AND smbi.sttl_st_cd IN (NULL, 'ST00', 'ST30')   /* 정산요청 이전, 임시저장, 정산반려 */
            AND wpip.brand_id = #{sBrandId}
            AND wpip.store_id = #{sStoreId}
            <if test="sItemNm != null and sItemNm != ''">
                AND wpip.item_nm LIKE CONCAT('%',#{sItemNm},'%')
            </if>
            UNION ALL
            SELECT COUNT(*) AS CNT
            FROM rtn_proc_info_ptcl rpip                    /* 반품처리정보내역 */
            LEFT OUTER JOIN stl_mgnt_dtl_ptcl smdp          /* 정산관리상세내역 */
            ON rpip.sttl_mgnt_unq_no = smdp.sttl_mgnt_unq_no
            AND rpip.sttl_mgnt_dtl_no = smdp.sttl_mgnt_dtl_no
            LEFT OUTER JOIN stl_mgnt_base_info smbi         /* 정산관리기본정보 */
            ON smdp.sttl_mgnt_unq_no = smbi.sttl_mgnt_unq_no
            INNER JOIN store_base_info store                /* 매장기본정보 */
            ON rpip.brand_id = store.brand_id AND rpip.store_id = store.store_id
            WHERE 1 = 1
            AND rpip.col_dt BETWEEN #{fromDt} AND #{toDt}
            AND rpip.sttl_yn = 'N'
            AND smbi.sttl_st_cd IN (NULL, 'ST00', 'ST30')   /* 정산요청 이전, 임시저장, 정산반려 */
            AND rpip.brand_id = #{sBrandId}
            AND rpip.store_id = #{sStoreId}
            <if test="sItemNm != null and sItemNm != ''">
                AND rpip.item_nm LIKE CONCAT('%',#{sItemNm},'%')
            </if>
        ) stl
    </select>

    <select id="selectStlMgntBaseInfo" resultType="com.oqpo.api.entity.settmng.StlMgntBaseInfoEntity">
        /* SttlReqMapper.selectStlMgntBaseInfo */
        SELECT A.sttl_mgnt_unq_no,
            A.store_id, FN_STORE_NM(A.brand_id, A.store_id) AS store_nm,
            A.spply_id, FN_SPPLY_NM(A.spply_id) AS spply_nm,
            A.brand_id, FN_BRAND_NM(A.brand_id) AS brand_nm,
            A.sttl_st_cd, FN_CODE_NM('STTL_ST_CD', A.sttl_st_cd) AS sttl_st_nm,
            DATE_FORMAT(A.sttl_req_dt, '%Y.%m.%d') AS sttl_req_dt,      /* 정산요청일자 */
            DATE_FORMAT(A.sttl_dt, '%Y.%m.%d') AS sttl_dt,              /* 정산확정일자 */
            A.sttl_req_amt,             /* 정산요청금액 */
            A.sttl_amt,                 /* 정산확정금액 */
            A.rcpt_amt,                 /* 수납금액 */
            (A.sttl_amt - IFNULL(A.rcpt_amt, 0)) AS unpaid_amt,         /* 미납금액 */
            A.sttl_reg_mgr_nm, A.sttl_reg_mgr_id,
            A.sttl_rjct_rsn,
            A.rcpt_yn, DATE_FORMAT(A.rcpt_dt, '%Y.%m.%d') AS rcpt_dt,   /* 수납여부/수납일자 */
            DATE_FORMAT(A.sys_reg_dttm,'%Y.%m.%d %H:%i:%s') AS sys_reg_dttm, A.sys_reg_id, FN_USER_NM(A.sys_reg_id) AS sys_reg_nm,
            DATE_FORMAT(A.sys_chg_dttm,'%Y.%m.%d %H:%i:%s') AS sys_chg_dttm, A.sys_chg_id,
            B.loan_dvsn, FN_CODE_NM('LOAN_DVSN', B.loan_dvsn) AS loan_dvsn_nm,      /* 매장 정상구분 */
            IFNULL(C.acct_bal, 0) AS acct_bal                                       /* 매장 계좌잔액 */
        FROM stl_mgnt_base_info A
        INNER JOIN store_base_info B ON A.brand_id = B.brand_id AND A.store_id = B.store_id
        LEFT JOIN loan_mgnt_base_info C ON B.loan_mgnt_unq_no = C.loan_mgnt_unq_no
        WHERE A.sttl_mgnt_unq_no = #{sttlMgntUnqNo}
    </select>

    <select id="selectStlMgntDtlPtclList" resultType="com.oqpo.api.entity.settmng.StlMgntDtlPtclEntity">
        /* SttlReqMapper.selectStlMgntDtlPtclList */
        SELECT A.sttl_mgnt_unq_no, A.sttl_mgnt_dtl_no,
            A.brand_id, FN_BRAND_NM(A.brand_id) AS brand_nm,
            A.store_id, FN_STORE_NM(A.brand_id, A.store_id) AS store_nm,
            A.item_id, A.item_nm, A.unit, A.unit_amt,
            A.podr_qty, A.dlv_qty,
            A.sttl_dvsn, FN_CODE_NM('STTL_DVSN', A.sttl_dvsn) AS sttl_dvsn_nm,  /* 정산구분 */
            CASE WHEN A.sttl_dvsn = 'SW00' THEN A.whs_qty WHEN A.sttl_dvsn = 'SC00' THEN A.col_qty END AS whs_col_qty,     /* 입고/수거수량 */
            DATE_FORMAT(CASE WHEN A.sttl_dvsn = 'SW00' THEN A.dlv_cmplt_dt WHEN A.sttl_dvsn = 'SC00' THEN A.col_dt END, '%Y.%m.%d') AS whs_col_dt,     /* 입고/수거일자 */
            CASE WHEN A.sttl_dvsn = 'SW00' THEN A.whs_amt WHEN A.sttl_dvsn = 'SC00' THEN A.col_amt END AS whs_col_amt,     /* 입고/수거금액 */
            A.dlv_qty * A.unit_amt AS sttl_req_amt,      /* 정산요청금액 : 납품수량 * 수량 */
            CASE WHEN A.sttl_dvsn = 'SW00' THEN A.pch_podr_unq_no WHEN A.sttl_dvsn = 'SC00' THEN A.rtn_podr_unq_no END AS podr_unq_no,      /* 발주고유번호 */
            CASE WHEN A.sttl_dvsn = 'SW00' THEN A.pch_podr_dtl_no WHEN A.sttl_dvsn = 'SC00' THEN A.rtn_podr_dtl_no END AS podr_dtl_no       /* 발주상세번호 */
        FROM stl_mgnt_dtl_ptcl A
        WHERE A.sttl_mgnt_unq_no = #{sttlMgntUnqNo}
        ORDER BY A.sttl_mgnt_dtl_no ASC
    </select>

    <select id="selectStlMgntDtlPtcl" resultType="com.oqpo.api.entity.settmng.StlMgntDtlPtclEntity">
        /* SttlReqMapper.selectStlMgntDtlPtcl */
        SELECT A.sttl_mgnt_unq_no, A.sttl_mgnt_dtl_no,
            A.brand_id, FN_BRAND_NM(A.brand_id) AS brand_nm,
            A.store_id, FN_STORE_NM(A.brand_id, A.store_id) AS store_nm,
            B.sttl_st_cd, FN_CODE_NM('STTL_ST_CD', B.sttl_st_cd) AS sttl_st_nm,
            A.whs_mgnt_unq_no,          /* 입고관리고유번호 */
            A.rtn_mgnt_unq_no,          /* 반품관리고유번호 */
            A.item_id, A.item_nm, A.unit, A.unit_amt,
            A.podr_qty, A.dlv_qty,
            A.sttl_dvsn, FN_CODE_NM('STTL_DVSN', A.sttl_dvsn) AS sttl_dvsn_nm,  /* 정산구분 */
            CASE WHEN A.sttl_dvsn = 'SW00' THEN A.whs_qty WHEN A.sttl_dvsn = 'SC00' THEN A.col_qty END AS whs_col_qty,     /* 입고/수거수량 */
            DATE_FORMAT(CASE WHEN A.sttl_dvsn = 'SW00' THEN A.dlv_cmplt_dt WHEN A.sttl_dvsn = 'SC00' THEN A.col_dt END, '%Y.%m.%d') AS whs_col_qty,     /* 입고/수거일자 */
            CASE WHEN A.sttl_dvsn = 'SW00' THEN A.whs_amt WHEN A.sttl_dvsn = 'SC00' THEN A.col_amt END AS whs_col_qty,     /* 입고/수거금액 */
            A.dlv_qty * A.unit_amt AS sttl_req_amt,      /* 정산요청금액 : 납품수량 * 수량 */
            CASE WHEN A.sttl_dvsn = 'SW00' THEN A.pch_podr_unq_no WHEN A.sttl_dvsn = 'SC00' THEN A.rtn_podr_unq_no END AS podr_unq_no,      /* 발주고유번호 */
            CASE WHEN A.sttl_dvsn = 'SW00' THEN A.pch_podr_dtl_no WHEN A.sttl_dvsn = 'SC00' THEN A.rtn_podr_dtl_no END AS podr_dtl_no       /* 발주상세번호 */
        FROM stl_mgnt_dtl_ptcl A
        INNER JOIN stl_mgnt_base_info B ON A.sttl_mgnt_unq_no = B.sttl_mgnt_unq_no
        WHERE A.sttl_mgnt_unq_no = #{sttlMgntUnqNo}
          AND A.sttl_mgnt_dtl_no = #{sttlMgntDtlNo}
    </select>

    <insert id="insertStlMgntBaseInfo" >
        /* SttlReqMapper.insertStlMgntBaseInfo */
        INSERT INTO stl_mgnt_base_info
            (sttl_mgnt_unq_no, sttl_req_dt, brand_id, store_id, sttl_st_cd, sttl_req_amt, sttl_dt, sttl_amt, sttl_reg_mgr_nm,
             sttl_reg_mgr_id, sttl_target_cd, sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        VALUES
            (#{entity.sttlMgntUnqNo}, #{entity.sttlReqDt}, #{entity.brandId}, #{entity.storeId}, #{entity.sttlStCd}, #{entity.sttlReqAmt},
             #{entity.sttlDt}, #{entity.sttlAmt}, #{entity.sttlRegMgrNm},
             #{entity.sttlRegMgrId}, #{entity.sttlTargetCd}, NOW(), #{userId}, NOW(), #{userId})
    </insert>

    <update id="updateStlMgntBaseInfo" >
        /* SttlReqMapper.updateStlMgntBaseInfo */
        UPDATE stl_mgnt_base_info SET
            sttl_req_dt = #{entity.sttlReqDt},
            brand_id = #{entity.brandId},
            store_id = #{entity.storeId},
            sttl_st_cd = #{entity.sttlStCd},
            sttl_req_amt = #{entity.sttlReqAmt},
            sttl_dt = #{entity.sttlDt},
            sttl_amt = #{entity.sttlAmt},
            sttl_reg_mgr_nm = #{entity.sttlRegMgrNm},
            sttl_reg_mgr_id = #{entity.sttlRegMgrId},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo}
    </update>

    <delete id="deleteStlMgntBaseInfo" >
        /* SttlReqMapper.deleteStlMgntBaseInfo */
        DELETE FROM stl_mgnt_base_info
         WHERE sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo}
    </delete>

    <insert id="insertStlMgntDtlPtcl" >
        /* SttlReqMapper.insertStlMgntDtlPtcl */
        INSERT INTO stl_mgnt_dtl_ptcl
            (sttl_mgnt_unq_no, sttl_mgnt_dtl_no, brand_id, whs_mgnt_unq_no, rtn_mgnt_unq_no, store_id, item_id, item_nm,
             unit, unit_amt, podr_qty, dlv_qty, whs_qty, col_qty, dlv_cmplt_dt, col_dt, whs_amt, col_amt, sttl_dvsn,
             pch_podr_unq_no, pch_podr_dtl_no, pch_req_unq_no, pch_req_dtl_no, rtn_podr_unq_no, rtn_podr_dtl_no,
             rtn_req_unq_no, rtn_req_dtl_no, sys_reg_dttm, sys_reg_id, sys_chg_dttm, sys_chg_id)
        VALUES
            (#{entity.sttlMgntUnqNo}, #{entity.sttlMgntDtlNo}, #{entity.brandId}, #{entity.whsMgntUnqNo}, #{entity.rtnMgntUnqNo},
             #{entity.storeId}, #{entity.itemId}, #{entity.itemNm}, #{entity.unit}, #{entity.unitAmt}, #{entity.podrQty},
             #{entity.dlvQty}, #{entity.whsQty}, #{entity.colQty}, #{entity.dlvCmpltDt}, #{entity.colDt}, #{entity.whsAmt},
             #{entity.colAmt}, #{entity.sttlDvsn}, #{entity.pchPodrUnqNo}, #{entity.pchPodrDtlNo}, #{entity.pchReqUnqNo},
             #{entity.pchReqDtlNo}, #{entity.rtnPodrUnqNo}, #{entity.rtnPodrDtlNo}, #{entity.rtnReqUnqNo}, #{entity.rtnReqDtlNo},
             NOW(), #{userId}, NOW(), #{userId})
    </insert>

    <update id="updateStlMgntDtlPtcl" >
        /* SttlReqMapper.updateStlMgntDtlPtcl */
        UPDATE stl_mgnt_dtl_ptcl SET
            brand_id = #{entity.brandId},
            whs_mgnt_unq_no = #{entity.whsMgntUnqNo},
            rtn_mgnt_unq_no = #{entity.rtnMgntUnqNo},
            store_id = #{entity.storeId},
            item_id = #{entity.itemId},
            item_nm = #{entity.itemNm},
            unit = #{entity.unit},
            unit_amt = #{entity.unitAmt},
            podr_qty = #{entity.podrQty},
            dlv_qty = #{entity.dlvQty},
            whs_qty = #{entity.whsQty},
            col_qty = #{entity.colQty},
            dlv_cmplt_dt = #{entity.dlvCmpltDt},
            col_dt = #{entity.colDt},
            whs_amt = #{entity.whsAmt},
            col_amt = #{entity.colAmt},
            sttl_dvsn = #{entity.sttlDvsn},
            pch_podr_unq_no = #{entity.pchPodrUnqNo},
            pch_podr_dtl_no = #{entity.pchPodrDtlNo},
            pch_req_unq_no = #{entity.pchReqUnqNo},
            pch_req_dtl_no = #{entity.pchReqDtlNo},
            rtn_podr_unq_no = #{entity.rtnPodrUnqNo},
            rtn_podr_dtl_no = #{entity.rtnPodrDtlNo},
            rtn_req_unq_no = #{entity.rtnReqUnqNo},
            rtn_req_dtl_no = #{entity.rtnReqDtlNo},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo}
          AND sttl_mgnt_dtl_no = #{entity.sttlMgntDtlNo}
    </update>

    <delete id="deleteStlMgntDtlPtcl" >
        /* SttlReqMapper.deleteStlMgntDtlPtcl */
        DELETE FROM stl_mgnt_dtl_ptcl
         WHERE sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo}
           AND sttl_mgnt_dtl_no = #{entity.sttlMgntDtlNo}
    </delete>

    <select id="selectWhsProcInfoPtcl" resultType="com.oqpo.api.entity.stockmng.WhsProcInfoPtclEntity">
        /* SttlReqMapper.selectWhsProcInfoPtcl */
        SELECT A.whs_mgnt_unq_no, A.dlv_sttmt_dtl_no, A.dlv_sttmt_unq_no, A.brand_id, A.store_id,
            A.whs_dt, A.whs_id, A.location, A.spply_id, A.spply_nm, A.whs_dvsn, A.podr_qty, A.dlv_qty, A.whs_qty,
            A.unit, A.unit_amt, A.dlv_req_dt, A.dlv_sch_dt, A.dlv_cmplt_dt, A.whs_cnfm_nm, A.dlv_mgr_nm,
            A.dlv_mgr_tel_no, A.dlv_mgr_emal, A.dlv_mgr_mbl_no, A.item_id, A.item_nm, A.whs_amt, A.whs_dlv_chrg,
            A.dlv_mgr_id, A.dlv_cnfm_doc_file_no, A.sttl_yn, A.pch_podr_unq_no, A.pch_podr_dtl_no, A.pch_req_unq_no,
            A.pch_req_dtl_no, A.shmt_req_unq_no, A.shmt_req_dtl_no, A.sttl_mgnt_unq_no, A.sttl_mgnt_dtl_no,
            DATE_FORMAT(A.sys_reg_dttm,'%Y.%m.%d %H:%i:%s') AS sys_reg_dttm, A.sys_reg_id, DATE_FORMAT(A.sys_chg_dttm,'%Y.%m.%d %H:%i:%s') AS sys_chg_dttm, A.sys_chg_id
        FROM whs_proc_info_ptcl A
        WHERE A.whs_mgnt_unq_no = #{whsMgntUnqNo}
    </select>

    <update id="updateWhsProcInfoPtcl4SttlReq" >
        /* SttlReqMapper.updateWhsProcInfoPtcl4SttlReq */
        UPDATE whs_proc_info_ptcl SET
            sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo},
            sttl_mgnt_dtl_no = #{entity.sttlMgntDtlNo},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE whs_mgnt_unq_no = #{entity.whsMgntUnqNo}
    </update>

    <select id="selectRtnProcInfoPtcl" resultType="com.oqpo.api.entity.rtnmng.RtnProcInfoPtclEntity">
        /* SttlReqMapper.selectRtnProcInfoPtcl */
        SELECT A.rtn_mgnt_unq_no, A.brand_id, A.store_id, A.item_id, A.item_nm, A.whs_id, A.location, A.unit,
            A.unit_amt, A.rtn_qty, A.rtn_odr_qty, A.col_qty, A.col_req_dt, A.col_sch_dt, A.col_dt, A.col_cnfm_nm,
            A.col_mgr_nm, A.col_mgr_tel_no, A.col_mgr_emal, A.col_mgr_mbl_no, A.col_amt, A.col_agr_yn,
            A.col_cnfm_doc_file_no, A.sttl_yn, A.spply_id, A.spply_nm, A.col_cmd_unq_no, A.col_cmd_dtl_no,
            A.rtn_podr_unq_no, A.rtn_podr_dtl_no, A.rtn_req_unq_no, A.rtn_req_dtl_no, A.sttl_mgnt_unq_no,
            A.sttl_mgnt_dtl_no,
            DATE_FORMAT(A.sys_reg_dttm,'%Y.%m.%d %H:%i:%s') AS sys_reg_dttm, A.sys_reg_id, DATE_FORMAT(A.sys_chg_dttm,'%Y.%m.%d %H:%i:%s') AS sys_chg_dttm, A.sys_chg_id
        FROM rtn_proc_info_ptcl A
        WHERE A.rtn_mgnt_unq_no = #{rtnMgntUnqNo}
    </select>

    <update id="updateRtnProcInfoPtcl4SttlReq" >
        /* SttlReqMapper.updateRtnProcInfoPtcl4SttlReq */
        UPDATE rtn_proc_info_ptcl SET
            sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo},
            sttl_mgnt_dtl_no = #{entity.sttlMgntDtlNo},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE rtn_mgnt_unq_no = #{entity.rtnMgntUnqNo}
    </update>

    <update id="updateLoanMgntBaseInfo4SttlReqProc" >
        /* SttlReqMapper.updateLoanMgntBaseInfo4SttlReqProc */
        UPDATE loan_mgnt_base_info SET
            acct_bal = #{entity.acctBal},
            use_amt_total = #{entity.useAmtTotal},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE loan_mgnt_unq_no = #{entity.loanMgntUnqNo}
    </update>

    <update id="updateWhsProcInfoPtcl4SttlReqProc" >
        /* SttlReqMapper.updateWhsProcInfoPtcl4SttlReqProc */
        UPDATE whs_proc_info_ptcl SET
            sttl_yn = 'Y',
            sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo},
            sttl_mgnt_dtl_no = #{entity.sttlMgntDtlNo},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE whs_mgnt_unq_no = #{entity.whsMgntUnqNo}
    </update>

    <update id="updateRtnProcInfoPtcl4SttlReqProc" >
        /* SttlReqMapper.updateRtnProcInfoPtcl4SttlReqProc */
        UPDATE rtn_proc_info_ptcl SET
            sttl_yn = 'Y',
            sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo},
            sttl_mgnt_dtl_no = #{entity.sttlMgntDtlNo},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE rtn_mgnt_unq_no = #{entity.rtnMgntUnqNo}
    </update>

    <update id="updateStlMgntBaseInfo4SttlReqProc" >
        /* SttlReqMapper.updateStlMgntBaseInfo4SttlReqProc */
        UPDATE stl_mgnt_base_info SET
            sttl_req_dt = #{entity.sttlReqDt},
            sttl_st_cd = #{entity.sttlStCd},
            <if test="entity.sttlDt != null and entity.sttlDt != ''">
            sttl_dt = #{entity.sttlDt},
            </if>
            <if test="entity.sttlAmt != null and entity.sttlAmt != ''">
            sttl_amt = #{entity.sttlAmt},
            </if>
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo}
    </update>

    <update id="updateStlMgntBaseInfo4SttlConfirm" >
        /* SttlReqMapper.updateStlMgntBaseInfo4SttlConfirm */
        UPDATE stl_mgnt_base_info SET
            sttl_st_cd = #{entity.sttlStCd},
            sttl_dt = #{entity.sttlDt},
            sttl_amt = #{entity.sttlAmt},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo}
    </update>

    <update id="updateStlMgntBaseInfo4SttlReject" >
        /* SttlReqMapper.updateStlMgntBaseInfo4SttlReject */
        UPDATE stl_mgnt_base_info SET
            sttl_st_cd = #{entity.sttlStCd},
            sttl_rjct_rsn = #{entity.sttlRjctRsn},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo}
    </update>

    <update id="updateStlMgntBaseInfo4Rcpt" >
        /* SttlReqMapper.updateStlMgntBaseInfo4Rcpt */
        UPDATE stl_mgnt_base_info SET
            rcpt_yn = #{entity.rcptYn},
            <if test='"Y".equals(entity.rcptYn)'>
            rcpt_dt = DATE_FORMAT(NOW(),'%Y%m%d'),
            </if>
            rcpt_amt = #{entity.rcptAmt},
            sys_chg_dttm = NOW(),
            sys_chg_id = #{userId}
        WHERE sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo}
    </update>

</mapper>
