<?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.prolog.cs.biz.inbound.dao.IncomingRecordBackHMapper">

	<select id="getInsertData" resultType="com.prolog.cs.biz.inbound.vo.IncomingRecordBackHVO">
		SELECT DISTINCT
		T4.RCV_HEADER_ID AS BILLID,
		T4.AUTO_BILL_NUM AS BILLNO,
		T2.bill_date billdate,
		CASE
		WHEN T4.RCV_TYPE = '2' THEN '2'
		ELSE '1'
		END as billtype,
		coalesce(T2.CONSIGNORCODE ,t3.mtl_owner_num ,T2.CONSIGNORID) consignorcode,
		coalesce(t2.BUYER_ID, 'N/A') AS buyerId,
		coalesce(t2.BUYER_NAME, 'N/A') AS buyerName,
		T2.SHIPPERCODE companyCode,
		T2.BRANCHCODE,
		T2.billno AS refBillno,
		T4.MODIFIER_NAME saleBy,
		T4.RCV_DATE receiptDate,
		T4.AUTO_BILL_NUM AS receiptNo
		FROM
		wms_in_rcv_instock_lines T1
		LEFT JOIN WMS_IN_RCV_HEADERS T4 ON T1.RCV_HEADER_ID = T4.RCV_HEADER_ID
		LEFT JOIN WMS_IN_RCV_HEADERS_PROFILES T3 ON T1.RCV_HEADER_ID = T3.RCV_HEADER_ID
		LEFT JOIN OMS_ASN_BILL_H T2 ON T4.ASN_HEADER_ID = T2.BILLID
		WHERE 1=1
		<if test="rcvHeaderId != null  and rcvHeaderId !=''">
			and T1.RCV_HEADER_ID = #{rcvHeaderId}
		</if>
	</select>

	<select id="getInsertDataReject" resultType="com.prolog.cs.biz.inbound.vo.IncomingRecordBackHVO">
		SELECT DISTINCT
		T4.RCV_HEADER_ID AS BILLID,
		T4.AUTO_BILL_NUM AS BILLNO,
		T2.bill_date billdate,
		CASE
		WHEN T4.RCV_TYPE = '2' THEN '2'
		ELSE '1'
		END as billtype,
		coalesce(T2.CONSIGNORCODE ,t3.mtl_owner_num ,T2.CONSIGNORID) consignorcode,
		coalesce(t2.BUYER_ID, 'N/A') AS buyerId,
		coalesce(t2.BUYER_NAME, 'N/A') AS buyerName,
		T2.SHIPPERCODE companyCode,
		T2.BRANCHCODE,
		T2.billno AS refBillno,
		T4.MODIFIER_NAME saleBy,
		T4.RCV_DATE receiptDate,
		T4.AUTO_BILL_NUM AS receiptNo
		FROM
		WMS_IN_RCV_HEADERS T4
		LEFT JOIN WMS_IN_RCV_HEADERS_PROFILES T3 ON T4.RCV_HEADER_ID = T3.RCV_HEADER_ID
		LEFT JOIN OMS_ASN_BILL_H T2 ON T4.ASN_HEADER_ID = T2.BILLID
		WHERE 1=1
		<if test="rcvHeaderId != null  and rcvHeaderId !=''">
			and T4.RCV_HEADER_ID = #{rcvHeaderId}
		</if>
	</select>
</mapper>
