<?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.sunxung.factoring.mapper.invoicemanage.InvoiceGoodsInfoMapper">

	<select id="findListGoods" resultType="com.sunxung.factoring.entity.invoicemanage.InvoiceGoodsInfo">
		select t1.*,IFNULL(t2.usedNum,0) usedNum
		from invoice_goods_info t1
			LEFT JOIN (
			SELECT
				IFNULL( sum( c.open_quantity ), 0 ) usedNum,
				c.settlement_goods_info_id
			FROM
				invoice_goods_info c
				left join invoice_basic_info d on c.invoice_basic_info_id = d.id
			WHERE
				d.invoice_status in (select id from t_dictionary where code in ('invoice_create','invoice_pass'))
			GROUP BY
				c.settlement_goods_info_id
		) t2 on  t1.settlement_goods_info_id = t2.settlement_goods_info_id
		where t1.invoice_basic_info_id = #{invoiceBasicInfoId}
	</select>
</mapper>
