<?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.cim.idm.dao.PurchaseReturnServiceDao">

    <select id="getPurchaseReturnList" resultType="com.cim.idm.model.PurchaseReturnDto">
        SELECT
            DISTINCT M.RECEIVEREQUESTNAME
        FROM
            MATERIALRECEIVEREQUESTDETAIL M
                LEFT JOIN MATERIALRECEIVEREQUEST R ON
                R.RECEIVEREQUESTNAME = M.RECEIVEREQUESTNAME
        WHERE
            M.SITENAME = #{siteName}
          AND R.RETURNFLAG = 'Y'
          AND R.RECEIVEREQUESTSTATE != 'Completed'
          AND M.ERPFACTORY = #{erpFactory}
          AND M.RECEIVEREQUESTNAME LIKE #{receiverequestname}
    </select>
    <select id="getPurchaseReturnInfo" resultType="com.cim.idm.model.PurchaseReturnDto">
        SELECT
            A.RECEIVEREQUESTNAME,
            A.RECEIVEREQUESTDETAILNAME,
            C.MATERIALSPECNAME,
            A.DESCRIPTION,
            m.FNAME AS MATERIALUNIT,
            A.REQUESTQUANTITY,
            A.CHARGE,
            A.RECEIVEDQUANTITY,
            C.DESC_CN,
            A.ERPLOCATION,
            D.ERPFACTORY,
            D.RETURNFLAG,
            D.SITENAME,
            '0' AS SELECTEDQUANTITY,
            A.SDK_ID,
            A.PHASE
        FROM
            MATERIALRECEIVEREQUESTDETAIL A
                LEFT JOIN MATERIALUNIT m ON
                A.MATERIALUNIT = m.FNUMBER
                LEFT JOIN MATERIALSPEC C ON
                A.MATERIALSPECNAME = C.MATERIALSPECNAME
                LEFT JOIN MATERIALRECEIVEREQUEST D ON
                D.RECEIVEREQUESTNAME = A.RECEIVEREQUESTNAME
        WHERE
            A.SITENAME = #{siteName}
          AND A.RECEIVEREQUESTNAME = #{receiverequestname}
          AND D.RETURNFLAG = 'Y'
        ORDER BY
            A.RECEIVEREQUESTDETAILNAME
    </select>
    <!-- 删除: <select id="getPurPackingInfo" resultType="com.cim.idm.model.PurchaseReturnDto"></select> -->
    <select id="getPurchaseReturnBoxList"
            resultType="com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking">
        SELECT * FROM MATERIALPACKING WHERE 1=1
        AND SHIPREQUESTNAME = #{receiverequestname}
        AND STOCKSTATE = 'Stocked'
    </select>
    <select id="getPurPackingInfo" resultType="com.cim.idm.model.PurchaseReturnDto"></select>
</mapper>

