<?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.base.gsp.dao.DxiGspQualityReviewDMapper">

	<resultMap id="map" type="com.prolog.cs.base.gsp.vo.GspQualityCheckMoveItemVo">
		<result column="lineid" property="lineId"/>
		<result column="billid" property="billId"/>
		<result column="billno" property="billNo"/>
		<result column="branchid" property="warehouseId"/>
		<result column="branchcode" property="warehouseCode"/>
		<result column="branchname" property="warehouseName"/>
		<result column="consignorid" property="cargoOwnerId"/>
		<result column="consignorcode" property="cargoOwnerCode"/>
		<result column="consignorname" property="cargoOwnerName"/>

		<result column="itemid" property="itemId"/>
		<result column="itemcode" property="itemCode"/>
		<result column="itemname" property="itemName"/>
		<result column="item_specs" property="itemSpecs"/>
		<result column="manufacturer" property="manufacturerName"/>
		<result column="pack_size" property="packSize"/>
		<result column="pack_units" property="packUnits"/>
		<result column="approval_number" property="approvalNumber"/>
		<result column="paper_no" property="paperNo"/>

		<result column="lot_no" property="lotNum"/>
		<result column="batch_no" property="batchNum"/>
		<result column="pdate_from" property="productionDate"/>
		<result column="valid_until" property="expiredDate"/>

		<result column="qty" property="qty"/>
		<result column="review_qty" property="reviewQty"/>

		<result column="ref_billtype" property="refBilltype"/>

	</resultMap>

	<select id="findQualityReview4MovePick" resultType="com.prolog.cs.base.gsp.vo.GspQualityCheckMoveVo">
		SELECT
			h.BRANCHID as warehouseId,
			h.BRANCHNAME as warehouseName,
			h. CONSIGNORID as cargoOwnerId,
			h.CONSIGNORNAME as cargoOwnerName,
			h.BILLID as billId,
			h.CREATEBY as creatorName,
			h.CREATEDATE as gmtCreate,
			h.LASTMODIFYBY as modifierName,
			h.LASTMODIFYDATE as gmtModified
		FROM DXI_GSP_QUALITY_REVIEW_D d
		LEFT JOIN DXI_GSP_QUALITY_REVIEW_H h
		ON d.BILLID = h.BILLID
		WHERE d.END_STATUS=30 and d.inf_status = 'N'
		<if test="warehouseId != null  and warehouseId !=''">
			and h.warehouse_id = #{warehouseId}
		</if>
		<if test="cargoOwnerId != null  and cargoOwnerId !=''">
			and h.consignorid = #{cargoOwnerId}
		</if>
		<if test="requestBilltype != null  and requestBilltype !=''">
			and h.request_billtype = #{requestBilltype}
		</if>
		<if test="billno != null  and billno !=''">
			and h.billno = #{billno}
		</if>
		order by h.CREATEDATE desc
	</select>


	<select id="findQualityReview4MoveItemPick" resultMap="map">
		SELECT
			h.*,
			d.*
		FROM DXI_GSP_QUALITY_REVIEW_D d
		LEFT JOIN DXI_GSP_QUALITY_REVIEW_H h
		ON d.BILLID = h.BILLID
		where d.BILLID = #{billId} and d.END_STATUS=30
		order by d.SEQNO asc
	</select>

</mapper>
