<?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.ReceivingRecordBackDMapper">
	<resultMap id="map" type="com.prolog.cs.biz.inbound.model.ReceivingRecordBackD">
		<result column="line_id" property="lineId"/>
		<result column="billid" property="billid"/>
		<result column="billno" property="billno"/>
		<result column="seqno" property="seqno"/>
		<result column="ref_billtype" property="refBilltype"/>
		<result column="ref_billid" property="refBillid"/>
		<result column="ref_billno" property="refBillno"/>
		<result column="ref_seqno" property="refSeqno"/>
		<result column="consignorid" property="consignorid"/>
		<result column="consignorcode" property="consignorcode"/>
		<result column="consignorname" property="consignorname"/>
		<result column="itemid" property="itemid"/>
		<result column="itemcode" property="itemcode"/>
		<result column="itemname" property="itemname"/>
		<result column="parernt_itemid" property="parerntItemid"/>
		<result column="category_id" property="categoryId"/>
		<result column="pack_size" property="packSize"/>
		<result column="pack_units" property="packUnits"/>
		<result column="lot_no" property="lotNo"/>
		<result column="batch_no" property="batchNo"/>
		<result column="pdate_from" property="pdateFrom"/>
		<result column="valid_until" property="validUntil"/>
		<result column="manufacturer" property="manufacturer"/>
		<result column="affirmed_pcs" property="affirmedPcs"/>
		<result column="affirmed_odd" property="affirmedOdd"/>
		<result column="affirmed_freeqty" property="affirmedFreeqty"/>
		<result column="affirmed_qty" property="affirmedQty"/>
		<result column="affirmed_weight" property="affirmedWeight"/>
		<result column="affirmed_volume" property="affirmedVolume"/>
		<result column="shipment_place" property="shipmentPlace"/>
		<result column="attr_str1" property="attrStr1"/>
		<result column="attr_str2" property="attrStr2"/>
		<result column="attr_str3" property="attrStr3"/>
		<result column="attr_str4" property="attrStr4"/>
		<result column="attr_str5" property="attrStr5"/>
		<result column="createby" property="createby"/>
		<result column="createdate" property="createdate"/>
		<result column="lastmodifyby" property="lastmodifyby"/>
		<result column="lastmodifydate" property="lastmodifydate"/>
		<result column="p_enterpriseid" property="pEnterpriseid"/>
		<result column="p_enterprisename" property="pEnterprisename"/>
		<result column="stockstatus" property="stockstatus"/>
		<result column="shipment_date" property="shipmentDate"/>
		<result column="temperaturec_type" property="temperaturecType"/>
		<result column="ship_arrive_time" property="shipArriveTime"/>
		<result column="ship_arrive_tem_perature" property="shipArriveTemPerature"/>
		<result column="tempcinfo" property="tempcinfo"/>
		<result column="carriername" property="carriername"/>
		<result column="item_health_register_nbr" property="itemHealthRegisterNbr"/>
		<result column="item_health_register_nbr_en" property="itemHealthRegisterNbrEn"/>
		<result column="item_health_approval_nbr" property="itemHealthApprovalNbr"/>
		<result column="country_origin_id" property="countryOriginId"/>
		<result column="sterilizeexpdate" property="sterilizeexpdate"/>
		<result column="STERILIZELOTNO" property="sterilizesno"/>
		<result column="carrierUnit" property="carrierUnit"/>
		<result column="shipping_type" property="shippingType"/>
	</resultMap>

	<select id="getRcvInsertData" resultMap="map">
		SELECT
		t1.RCV_LINE_ID AS LINE_ID,
		t1.RCV_HEADER_ID AS BILLID,
		t5.AUTO_BILL_NUM AS BILLNO,
		coalesce(T3.REF_BILLTYPE,'-') AS REF_BILLTYPE,
		t3.BILLID AS REF_BILLID,
		t3.BILLNO AS REF_BILLNO,
		t2.LINEID AS REF_SEQNO,
		t2.SEQNO,
		t2.CONSIGNORID,
		coalesce(t2.CONSIGNORCODE,t2.CONSIGNORID) as CONSIGNORCODE,
		t2.CONSIGNORNAME,
		t2.ITEMID,
		t2.ITEMCODE,
		t2.ITEMNAME,
		t2.PARERNT_ITEMID,
		t4.SPECIFICATION AS CATEGORY_ID,
		t2.PACK_SIZE,
		t2.PACK_UNITS,
		t1.MANUFACTURER_LOT_NUM AS LOT_NO,
		t1.BATCH_NUM AS BATCH_NO,
		t1.BATCH_PRODUCTION_DATE AS PDATE_FROM,
		t1.BATCH_EXPIRED_DATE as VALID_UNTIL,
		t2.MANUFACTURER,
		t1.ODD_CASE_QTY AS AFFIRMED_PCS,
		t1.ODD_PIECE_QTY AS AFFIRMED_ODD,
		t2.FREE_QTY AS AFFIRMED_FREEQTY,
		t1.PIECE_QTY AS AFFIRMED_QTY,
		( t1.PIECE_QTY * COALESCE( t1.ITEM_WEIGHT, 0 ) ) AS AFFIRMED_WEIGHT,
		( t1.PIECE_QTY * COALESCE( t1.ITEM_VOLUME, 0 ) ) AS AFFIRMED_VOLUME,
		t3.shipment_place,
		t2.ATTR_STR1,
		t2.ATTR_STR2,
		t2.ATTR_STR3,
		t2.ATTR_STR4,
		t2.ATTR_STR5,
		t2.CREATEBY,
		t2.CREATEDATE,
		t2.LASTMODIFYBY,
		t2.LASTMODIFYDATE,
		t2.P_ENTERPRISEID,
		t2.P_ENTERPRISENAME,
		case when  t1.STOCK_STATUS = '0' then '1'
		when  t1.STOCK_STATUS = '1' then '4'
		when  t1.STOCK_STATUS = '2' then '3'
		when  t1.STOCK_STATUS = '3' then '2'
		end  STOCKSTATUS,
		t3.shipment_date,
		t6.TEMPERATUREC_TYPE,
		t6.SHIP_ARRIVE_TIME,
		t6.ship_arrive_tem_perature,
		t6.tempcinfo,
		t6.CARRIERNAME,
		t4.item_health_register_nbr,
		t4.item_health_register_nbr_en,
		t1.approval_number as item_health_approval_nbr,
		t1.production_place as country_origin_id,
		t4.sterilizeexpdate,
		t4.STERILIZELOTNO,
		t3.CARRIER_UNIT,
		t3.SHIPPING_TYPE
		FROM WMS_IN_RCV_LINES t1
		LEFT JOIN OMS_ASN_BILL_D t2 ON t1.ASN_LINE_ID = t2.LINEID
		LEFT JOIN OMS_ASN_BILL_H t3 ON t1.ASN_HEADER_ID = t3.BILLID
		LEFT JOIN WMS_IN_RCV_LINES_PROFILES t4 ON t1.RCV_LINE_ID = t4.RCV_LINE_ID
		LEFT JOIN WMS_IN_RCV_HEADERS t5 ON t1.RCV_HEADER_ID = t5.RCV_HEADER_ID
		LEFT JOIN WMS_IN_RCV_HEADERS_PROFILES T6 ON T1.RCV_HEADER_ID = T6.RCV_HEADER_ID
		WHERE 1=1
		AND t1.PIECE_QTY &gt; 0
			<if test="rcvHeaderId != null  and rcvHeaderId !=''">
				and T1.RCV_HEADER_ID = #{rcvHeaderId}
			</if>
	</select>

	<select id="getRqcInsertData" resultMap="map">
		SELECT
			t1.RQC_LINE_ID AS LINE_ID,
			t1.RQC_HEADER_ID AS BILLID,
			t5.AUTO_BILL_NUM AS BILLNO,
			coalesce(T3.REF_BILLTYPE,'-') AS REF_BILLTYPE,
			t3.BILLID AS REF_BILLID,
			t3.BILLNO AS REF_BILLNO,
			t2.LINEID AS REF_SEQNO,
			t2.SEQNO,
			t2.CONSIGNORID,
			coalesce(t2.CONSIGNORCODE,t2.CONSIGNORID) as CONSIGNORCODE,
			t2.CONSIGNORNAME,
			t2.ITEMID,
			t2.ITEMCODE,
			t2.ITEMNAME,
			t2.PARERNT_ITEMID,
			t4.SPECIFICATION AS CATEGORY_ID,
			t2.PACK_SIZE,
			t2.PACK_UNITS,
			t7.MANUFACTURER_LOT_NUM AS LOT_NO,
			t7.BATCH_NUM AS BATCH_NO,
			t7.BATCH_PRODUCTION_DATE AS PDATE_FROM,
			t7.BATCH_EXPIRED_DATE as VALID_UNTIL,
			t2.MANUFACTURER,
			t1.ODD_CASE_QTY AS AFFIRMED_PCS,
			t1.ODD_PIECE_QTY AS AFFIRMED_ODD,
			t2.FREE_QTY AS AFFIRMED_FREEQTY,
			t1.PIECE_QTY AS AFFIRMED_QTY,
			( t1.PIECE_QTY * COALESCE( t7.ITEM_WEIGHT, 0 ) ) AS AFFIRMED_WEIGHT,
			( t1.PIECE_QTY * COALESCE( t7.ITEM_VOLUME, 0 ) ) AS AFFIRMED_VOLUME,
			t3.shipment_place,
			t2.ATTR_STR1,
			t2.ATTR_STR2,
			t2.ATTR_STR3,
			t2.ATTR_STR4,
			t2.ATTR_STR5,
			t2.CREATEBY,
			t2.CREATEDATE,
			t2.LASTMODIFYBY,
			t2.LASTMODIFYDATE,
			t2.P_ENTERPRISEID,
			t2.P_ENTERPRISENAME,
			case when  t1.STOCK_STATUS = '0' then '1'
			when  t1.STOCK_STATUS = '1' then '2'
			when  t1.STOCK_STATUS = '2' then '3'
			when  t1.STOCK_STATUS = '3' then '4'
			end  STOCKSTATUS,
			t3.shipment_date,
			t6.TEMPERATUREC_TYPE,
			t6.SHIP_ARRIVE_TIME,
			t6.ship_arrive_tem_perature,
			t6.tempcinfo,
			t6.CARRIERNAME,
			t4.item_health_register_nbr,
			t4.item_health_register_nbr_en,
			t7.approval_number as item_health_approval_nbr,
			t7.production_place as country_origin_id,
			t4.sterilizeexpdate,
			t4.STERILIZELOTNO,
			t3.CARRIER_UNIT,
			t3.SHIPPING_TYPE
		FROM WMS_IN_RQC_LINES t1
			LEFT JOIN OMS_ASN_BILL_D t2 ON t1.ASN_LINE_ID = t2.LINEID
			LEFT JOIN OMS_ASN_BILL_H t3 ON t1.ASN_HEADER_ID = t3.BILLID
			LEFT JOIN WMS_IN_RCV_LINES_PROFILES t4 ON t1.RCV_LINE_ID = t4.RCV_LINE_ID
			LEFT JOIN WMS_IN_RQC_HEADERS t5 ON t1.RQC_HEADER_ID = t5.RQC_HEADER_ID
			LEFT JOIN WMS_IN_RCV_HEADERS_PROFILES T6 ON T1.RCV_HEADER_ID = T6.RCV_HEADER_ID
			LEFT JOIN WMS_IN_RCV_LINES t7 ON t1.RCV_LINE_ID = t7.RCV_LINE_ID
		WHERE 1=1
		AND t1.PIECE_QTY &gt; 0
		<if test="rqcHeaderId != null  and rqcHeaderId !=''">
			and T1.RQC_HEADER_ID = #{rqcHeaderId}
		</if>
	</select>
</mapper>
