<?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.dxhy.extend.dao.ExtInvoicePoolDao">
    <sql id="sql_fields_added">
        t.invoice_code invoiceCode,
		t.invoice_no invoiceNo,
		t.invoice_status invoiceStatus,
		t.invoice_type invoiceType,
		DATE_FORMAT(t.invoice_date,'%Y-%m-%d') invoiceDate,
		t.xf_tax_no xfsh,
		t.xf_name xfmc,
		t.total_amount totalAmount,
		t.gf_tax_no gfsh,
		t.gf_name gfmc,
		t.invoice_amount invoiceAmount,
		t.tax_amount taxAmount,
		t.dk_tax_amount yxse,
		t.rzh_yesorno rzzt,
		t.rzlx rzlx,
		DATE_FORMAT(t.rzh_date,'%Y-%m-%d') rzrq,
		t.rzh_type rzfs,
		t.gx_user_name rzr,
		DATE_FORMAT(t.create_date,'%Y-%m-%d') createDate,
		t.collect_status collectStatus,
		t.qs_type qsfs,
		t.qs_status qszt,
		DATE_FORMAT(t.qs_date,'%Y-%m-%d') qsrq,
		t.qs_name qsr,
		DATE_FORMAT(t.payment_date,'%Y-%m') inAccountMonth,
		t.voucher_number voucherNo,
		t.amortize_status amortizeStatus,
		t.amortize_amount amortizeAmount,
		t.remain_amortize_amount remainAmortizeAmount,
		t.amortize_document_number amortizeDocumentNumber,
		t.source_system sourceSystem,
		t.list_status listStatus,
		t.scan_id scanId,
		t.remark,
		t.document_number documentNumber,
		DATE_FORMAT(t.collect_date,'%Y-%m-%d') collectDate,
		t.collect_from collectFrom
    </sql>
    <resultMap id="InvoicePoolHjResultMap"
               type="com.dxhy.extend.entity.ExtAddTaxInvoice">
        <result column="hjsl" property="id"/>
        <result column="hjje" property="invoiceAmount"/>
        <result column="hjse" property="taxAmount"/>
    </resultMap>
    <resultMap id="OtherPoolHjResultMap"
               type="com.dxhy.extend.entity.ExtOtherInvoice">
        <result column="hjsl" property="id"/>
        <result column="hjje" property="invoiceAmount"/>
        <result column="hjse" property="taxAmount"/>
    </resultMap>
    <select id="selectAddTaxHj" parameterType="java.util.Map"
            resultMap="InvoicePoolHjResultMap" databaseId="mysql">
        select count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
        from t_dx_record_invoice t
        where 1=1
        <if test="cjksyf != null and cjksyf!= '' and cjjsyf != null and cjjsyf != ''">
            AND t.create_date BETWEEN #{cjksyf} and #{cjjsyf}
        </if>
        <if test="kpksrq != null and kpksrq!= '' and kpjsrq != null and kpjsrq != ''">
            AND t.invoice_date between #{kpksrq} and #{kpjsrq}
        </if>
        <if test="keyWord != null and keyWord != '' and keyWord != 'null' ">
            and CONCAT(IFNULL(t.invoice_code,''),IFNULL(t.invoice_no,''),IFNULL(t.xf_name,''),IFNULL(t.xf_tax_no,''))
            like
            CONCAT('%',#{keyWord},'%')
        </if>
        <if test="sign != '88'">
            and t.gf_tax_no in
            <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceStatus != null and invoiceStatus != '' and invoiceStatus != 'null' and invoiceStatus != '99'">
            and t.invoice_status = #{invoiceStatus}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' and qszt != '99'">
            and t.qs_status = #{qszt}
        </if>
        <if test="rzzt != null and rzzt != '' and rzzt != 'null' and rzzt != '99' and rzzt != 3">
            and t.rzh_yesorno = #{rzzt}
        </if>
        <if test="rzzt != null and rzzt != '' and rzzt != 'null'  and rzzt == 3">
            and (t.rzh_yesorno = '1' or t.rzh_yesorno = '2')
        </if>
        <if test="rzlx != null and rzlx != '' and rzlx != 'null' and rzlx != '99'">
            and t.rzlx = #{rzlx}
        </if>
        <if test='rzzt == "99"'>
            and t.rzh_yesorno in ('1','2','0')
        </if>
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.rzh_belong_date = #{skssq}
        </if>
        <if test="qsyf != null and qsyf != null and qsyf != '' and qsyf != ''">
            and DATE_FORMAT(t.qs_date,'%Y-%m') = #{qsyf}
        </if>
        <if test="qsr != null and qsr != '' and qsr != 'null' ">
            and t.qs_name like CONCAT(#{qsr},'%')
        </if>
        <if test="rzr != null and rzr != '' and rzr != 'null' ">
            and t.gx_user_name like CONCAT(#{rzr},'%')
        </if>
        <if test="qsfs != null and qsfs != '' and qsfs != 'null' and qsfs != '99'">
            and t.qs_type = #{qsfs}
        </if>
        <if test="postingTimeEnd != null and postingTimeEnd != '' and postingTimeEnd != 'null' and postingTimeEnd != '99' and postingTimeStart != null and postingTimeStart != '' and postingTimeStart != 'null' and postingTimeStart != '99'">
            and t.posting_time between #{postingTimeStart} and #{postingTimeEnd}
        </if>
        <if test="imageNumber != null and imageNumber != '' and imageNumber != 'null' and imageNumber != '99'">
            and t.image_id = #{imageNumber}
        </if>
        <if test="accountPeriod != null and accountPeriod != '' and accountPeriod != 'null' and accountPeriod != '99'">
            and t.account_period = #{accountPeriod}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '1'.toString()">
            and t.inaccount_status = #{inAccountStatus}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '0'.toString()">
            and (t.inaccount_status = '0' or t.inaccount_status = '' or t.inaccount_status is null)
        </if>
        <if test="bzdh != null and bzdh != '' and bzdh != 'null' and badh != '99'">
            and t.bzdh = #{bzdh}
        </if>
        <if test="bzr != null and bzr != '' and bzr != 'null'">
            and t.bzr like concat('%',#{bzr},'%')
        </if>
        <if test="snVoucherNumber != null and snVoucherNumber != '' and snVoucherNumber != 'null' and snVoucherNumber != '99'">
            and t.sn_voucher_number = #{snVoucherNumber}
        </if>
        <if test="inAccountMonth != null and inAccountMonth != null and inAccountMonth != '' and inAccountMonth != ''">
            and DATE_FORMAT(t.payment_date,'%Y-%m') = #{inAccountMonth}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='99'">
            and t.invoice_source = #{invoiceSource}
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode == '99'">
            and (t.comp_code in
            <foreach collection="companyCodes" index="index" item="companyCode" separator="," open="(" close=")">
                #{companyCode}
            </foreach>
            or t.comp_code is null or t.comp_code = ''
            )
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode != '88'">
            and t.comp_code = #{companyCode}
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode == '88'">
            and (t.comp_code = '' or t.comp_code is null)
        </if>
        and t.invoice_type not in ('91','95','97','99','101','00')
    </select>
    <select id="listAddTaxInvoice" parameterType="java.util.Map"
            resultType="com.dxhy.extend.entity.ExtAddTaxInvoice" databaseId="mysql">
        select
        t.invoice_code invoiceCode,
        t.invoice_no invoiceNo,
        t.invoice_status invoiceStatus,
        t.invoice_type invoiceType,
        DATE_FORMAT(t.invoice_date,'%Y-%m-%d') invoiceDate,
        t.xf_tax_no xfsh,
        t.xf_name xfmc,
        t.total_amount totalAmount,
        t.gf_tax_no gfsh,
        t.gf_name gfmc,
        t.invoice_amount invoiceAmount,
        t.tax_amount taxAmount,
        t.dk_tax_amount yxse,
        t.rzh_yesorno rzzt,
        t.rzlx rzlx,
        DATE_FORMAT(t.rzh_date,'%Y-%m-%d') rzrq,
        t.rzh_type rzfs,
        t.gx_user_name rzr,
        DATE_FORMAT(t.create_date,'%Y-%m-%d') createDate,
        t.collect_status collectStatus,
        t.qs_type qsfs,
        t.qs_status qszt,
        DATE_FORMAT(t.qs_date,'%Y-%m-%d') qsrq,
        t.qs_name qsr,
        DATE_FORMAT(t.payment_date,'%Y-%m') inAccountMonth,
        t.payment_status paymentStatus,
        t.voucher_number voucherNo,
        t.sn_voucher_number snVoucherNumber,
        t.posting_time postingTime,
        t.amortize_status amortizeStatus,
        t.amortize_amount amortizeAmount,
        t.remain_amortize_amount remainAmortizeAmount,
        t.amortize_document_number amortizeDocumentNumber,
        t.source_system sourceSystem,
        t.is_sale_list listStatus,
        t.scan_id scanId,
        t.remark,
        t.document_number documentNumber,
        t.image_id imageNumber,
        t.account_period accountPeriod,
        t.inaccount_status inAccountStatus,
        t.bzdh bzdh,
        t.bzr bzr,
        t.posting_time postingTime,
        DATE_FORMAT(t.collect_date,'%Y-%m-%d') collectDate,
        t.collect_from collectFrom,
        t.comp_code compCode
        from t_dx_record_invoice t
        where 1 = 1
        <if test="cjksyf != null and cjksyf!= '' and cjjsyf != null and cjjsyf != ''">
            AND t.create_date BETWEEN #{cjksyf} and #{cjjsyf}
        </if>
        <if test="kpksrq != null and kpksrq!= '' and kpjsrq != null and kpjsrq != ''">
            AND t.invoice_date between #{kpksrq} and #{kpjsrq}
        </if>
        <if test="keyWord != null and keyWord != '' and keyWord != 'null' ">
            and CONCAT(IFNULL(t.invoice_code,''),IFNULL(t.invoice_no,''),IFNULL(t.xf_name,''),IFNULL(t.xf_tax_no,''))
            like
            CONCAT('%',#{keyWord},'%')
        </if>
        <if test="sign != '88'">
            and t.gf_tax_no in
            <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceStatus != null and invoiceStatus != '' and invoiceStatus != 'null' and invoiceStatus != '99'">
            and t.invoice_status = #{invoiceStatus}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' and qszt != '99'">
            and t.qs_status = #{qszt}
        </if>
        <if test="rzzt != null and rzzt != '' and rzzt != 'null' and rzzt != '99' and rzzt != 3">
            and t.rzh_yesorno = #{rzzt}
        </if>
        <if test="rzzt != null and rzzt != '' and rzzt != 'null' and rzzt != '99' and rzzt == 3">
            and (t.rzh_yesorno = '1' or t.rzh_yesorno = '2' )
        </if>
        <if test="rzlx != null and rzlx != '' and rzlx != 'null' and rzlx != '99'">
            and t.rzlx = #{rzlx}
        </if>
        <if test='rzzt == "99"'>
            and t.rzh_yesorno in ('1','2','0')
        </if>
        <if test="skssq != null and skssq != '' and skssq != 'null' ">
            and t.rzh_belong_date = #{skssq}
        </if>
        <if test="qsyf != null and qsyf != null and qsyf != '' and qsyf != ''">
            and DATE_FORMAT(t.qs_date,'%Y-%m') = #{qsyf}
        </if>
        <if test="qsr != null and qsr != '' and qsr != 'null' ">
            and t.qs_name like CONCAT(#{qsr},'%')
        </if>
        <if test="rzr != null and rzr != '' and rzr != 'null' ">
            and t.gx_user_name like CONCAT(#{rzr},'%')
        </if>
        <if test="qsfs != null and qsfs != '' and qsfs != 'null' and qsfs != '99'">
            and t.qs_type = #{qsfs}
        </if>
        <if test="postingTimeEnd != null and postingTimeEnd != '' and postingTimeEnd != 'null' and postingTimeEnd != '99' and postingTimeStart != null and postingTimeStart != '' and postingTimeStart != 'null' and postingTimeStart != '99'">
            and t.posting_time between #{postingTimeStart} and #{postingTimeEnd}
        </if>
        <if test="imageNumber != null and imageNumber != '' and imageNumber != 'null' and imageNumber != '99'">
            and t.image_id = #{imageNumber}
        </if>
        <if test="accountPeriod != null and accountPeriod != '' and accountPeriod != 'null' and accountPeriod != '99'">
            and t.account_period = #{accountPeriod}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '1'.toString()">
            and t.inaccount_status = #{inAccountStatus}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '0'.toString()">
            and (t.inaccount_status = '0' or t.inaccount_status = '' or t.inaccount_status is null)
        </if>
        <if test="bzdh != null and bzdh != '' and bzdh != 'null' and badh != '99'">
            and t.bzdh = #{bzdh}
        </if>
        <if test="bzr != null and bzr != '' and bzr != 'null'">
            and t.bzr like concat('%',#{bzr},'%')
        </if>
        <if test="snVoucherNumber != null and snVoucherNumber != '' and snVoucherNumber != 'null' and snVoucherNumber != '99'">
            and t.sn_voucher_number = #{snVoucherNumber}
        </if>
        <if test="inAccountMonth != null and inAccountMonth != null and inAccountMonth != '' and inAccountMonth != ''">
            and DATE_FORMAT(t.payment_date,'%Y-%m') = #{inAccountMonth}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='99'">
            and t.invoice_source = #{invoiceSource}
        </if>
<!--        <if test="snVoucherNumber !=null and snVoucherNumber !='' and snVoucherNumber !='99'">-->
<!--            and t.sn_voucher_number = #{snVoucherNumber}-->
<!--        </if>-->
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode == '99'">
            and (t.comp_code in
            <foreach collection="companyCodes" index="index" item="companyCode" separator="," open="(" close=")">
                #{companyCode}
            </foreach>
            or t.comp_code is null or t.comp_code = ''
            )
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode != '88'">
            and t.comp_code = #{companyCode}
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode == '88'">
            and (t.comp_code = '' or t.comp_code is null)
        </if>
        and t.invoice_type not in ('91','95','97','99','101','00')
    </select>
    <!--其他发票汇总-->
    <select id="selectOtherHj" parameterType="java.util.Map"
            resultMap="OtherPoolHjResultMap" databaseId="mysql">
        SELECT
        count(1) hjsl,
        sum(t.total_amount) hjje,
        sum(t.tax_amount) hjse
        FROM (select * from
        t_dx_invoice_reimburse
        where invoice_type in
        ('91','94','95','00','97','98','101','102','103','99')
        <if test="cjksyf != null and cjksyf!= '' and cjjsyf != null and cjjsyf != ''">
            AND create_date between #{cjksyf} and #{cjjsyf}
        </if>
        <if test="kpksrq != null and kpksrq!= '' and kpjsrq != null and kpjsrq != ''">
            AND invoice_date between #{kpksrq} and #{kpjsrq}
        </if>
        <if test="keyWord != null and keyWord != '' and keyWord != 'null' ">
            AND CONCAT(IFNULL(invoice_code,''),IFNULL(invoice_no,'')) like CONCAT('%',#{keyWord},'%')
        </if>
<!--        AND gf_tax_no in-->
<!--        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">-->
<!--            #{item}-->
<!--        </foreach>-->
        <if
                test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '999' ">
            AND invoice_type = #{invoiceType}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' and qszt != '99'">
            AND qs_status = #{qszt}
        </if>
        <if test="qsyf != null and qsyf != null and qsyf != '' and qsyf != ''">
            AND DATE_FORMAT(qs_date,'%Y-%m') = #{qsyf}
        </if>
        <if test="qsr != null and qsr != '' and qsr != 'null' ">
            AND qs_name like CONCAT('%',#{qsr},'%')
        </if>
        <if test="qsfs != null and qsfs != '' and qsfs != 'null' and qsfs != '99'">
            AND qs_type = #{qsfs}
        </if>
        <if test="postingTimeEnd != null and postingTimeEnd != '' and postingTimeEnd != 'null' and postingTimeEnd != '99' and postingTimeStart != null and postingTimeStart != '' and postingTimeStart != 'null' and postingTimeStart != '99'">
            and posting_time between #{postingTimeStart} and #{postingTimeEnd}
        </if>
        <if test="imageNumber != null and imageNumber != '' and imageNumber != 'null' and imageNumber != '99'">
            and image_id = #{imageNumber}
        </if>
        <if test="accountPeriod != null and accountPeriod != '' and accountPeriod != 'null' and accountPeriod != '99'">
            and account_period = #{accountPeriod}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '1'.toString()">
            and inaccount_status = #{inAccountStatus}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '0'.toString()">
            and (inaccount_status = '0' or inaccount_status = '' or inaccount_status is null)
        </if>
        <if test="bzdh != null and bzdh != '' and bzdh != 'null' and badh != '99'">
            and bzdh = #{bzdh}
        </if>
        <if test="bzr != null and bzr != '' and bzr != 'null'">
            and bzr like concat('%',#{bzr},'%')
        </if>
        <if test="snVoucherNumber != null and snVoucherNumber != '' and snVoucherNumber != 'null' and snVoucherNumber != '99'">
            and sn_voucher_number = #{snVoucherNumber}
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode == '99'">
            and (comp_code in
            <foreach collection="companyCodes" index="index" item="companyCode" separator="," open="(" close=")">
                #{companyCode}
            </foreach>
            or comp_code is null or comp_code = ''
            )
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode != '88'">
            and comp_code = #{companyCode}
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode == '88'">
            and (comp_code is null or comp_code = '')
        </if>
        GROUP BY uuid having min(create_date) ) t
    </select>
    <select id="listOtherInvoice" parameterType="java.util.Map"
            resultType="com.dxhy.extend.entity.ExtOtherInvoice" databaseId="mysql">
        SELECT
        invoice_type invoiceType,
        invoice_code invoiceCode,
        invoice_no invoiceNo,
        DATE_FORMAT(invoice_date,'%Y-%m-%d') invoiceDate,
        DATE_FORMAT(create_date,'%Y-%m-%d') createDate,
        total_amount invoiceAmount,
        qs_status qszt,
        DATE_FORMAT(qs_date,'%Y-%m-%d') qsrq,
        qs_type qsfs,
        qs_name qsr,
        source_system sourceSystem,
        uuid,
        select_id,
        scan_id scanId,
        account_period accountPeriod,
        image_id imageNumber,
        posting_time postingTime,
        inaccount_status inAccountStatus,
        bzdh bzdh,
        bzr bzr,
        sn_voucher_number snVoucherNumber,
        comp_code compCode
        FROM
        t_dx_invoice_reimburse
        where invoice_type in
        ('91','94','95','00','97','98','101','102','103','99')
        <if test="cjksyf != null and cjksyf!= '' and cjjsyf != null and cjjsyf != ''">
            AND create_date between #{cjksyf} and #{cjjsyf}
        </if>
<!--        AND gf_tax_no in-->
<!--        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">-->
<!--            #{item}-->
<!--        </foreach>-->
        <if test="kpksrq != null and kpksrq!= '' and kpjsrq != null and kpjsrq != ''">
            AND invoice_date between #{kpksrq} and #{kpjsrq}
        </if>
        <if test="keyWord != null and keyWord != '' and keyWord != 'null' ">
            AND CONCAT(IFNULL(invoice_code,''),IFNULL(invoice_no,'')) like CONCAT('%',#{keyWord},'%')
        </if>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '999' ">
            AND invoice_type = #{invoiceType}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' and qszt != '99'">
            AND qs_status = #{qszt}
        </if>
        <if test="qsyf != null and qsyf != null and qsyf != '' and qsyf != ''">
            AND DATE_FORMAT(qs_date,'%Y-%m') = #{qsyf}
        </if>
        <if test="qsr != null and qsr != '' and qsr != 'null' ">
            AND qs_name like CONCAT(#{qsr},'%')
        </if>
        <if test="qsfs != null and qsfs != '' and qsfs != 'null' and qsfs != '99'">
            AND qs_type = #{qsfs}
        </if>

        <if test="snVoucherNumber != null and snVoucherNumber != '' and snVoucherNumber != 'null' and snVoucherNumber != '99'">
            and sn_voucher_number = #{snVoucherNumber}
        </if>

        <if test="postingTimeStart != null and postingTimeStart != '' and postingTimeStart != 'null' and postingTimeStart != '99' and postingTimeEnd != null and postingTimeEnd != '' and postingTimeEnd != 'null' and postingTimeEnd != '99'">
            and posting_time between #{postingTimeStart} and #{postingTimeEnd}
        </if>

        <if test="imageNumber != null and imageNumber != '' and imageNumber != 'null' and imageNumber != '99'">
            and image_id = #{imageNumber}
        </if>

        <if test="accountPeriod != null and accountPeriod != '' and accountPeriod != 'null' and accountPeriod != '99'">
            and account_period = #{accountPeriod}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '1'.toString()">
            and inaccount_status = #{inAccountStatus}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '0'.toString()">
            and (inaccount_status = '0' or inaccount_status = '' or inaccount_status is null)
        </if>
        <if test="bzdh != null and bzdh != '' and bzdh != 'null' and badh != '99'">
            and bzdh = #{bzdh}
        </if>
        <if test="bzr != null and bzr != '' and bzr != 'null'">
            and bzr like concat('%',#{bzr},'%')
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode == '99'">
            and (comp_code in
            <foreach collection="companyCodes" index="index" item="companyCode" separator="," open="(" close=")">
                #{companyCode}
            </foreach>
            or comp_code is null or comp_code = ''
            )
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode != '88'">
            and comp_code = #{companyCode}
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode == '88'">
            and (comp_code is null or comp_code = '')
        </if>
        GROUP BY uuid having min(create_date)
        ORDER BY create_date DESC
    </select>
    <!--销项票池汇总-->
    <select id="selectSaleHj" parameterType="java.util.Map"
            resultMap="InvoicePoolHjResultMap" databaseId="mysql">
        select count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
        from t_dx_sale_record_invoice t
        where 1 = 1
        <if test="cjksyf != null and cjksyf!= '' and cjjsyf != null and cjjsyf != ''">
            AND t.create_date between #{cjksyf} and #{cjjsyf}
        </if>
        <if test="kpksrq != null and kpksrq!= '' and kpjsrq != null and kpjsrq != ''">
            AND t.invoice_date between #{kpksrq} and #{kpjsrq}
        </if>
        <if test="keyWord != null and keyWord != '' and keyWord != 'null' ">
            and CONCAT(IFNULL(t.invoice_code,''),IFNULL(t.invoice_no,''),IFNULL(t.gf_name,''),IFNULL(t.gf_tax_no,''))
            like
            CONCAT('%',#{keyWord},'%')
        </if>
        <if test="sign != '88'">
            and t.xf_tax_no in
            <foreach collection="taxno" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        <if
                test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if
                test="invoiceStatus != null and invoiceStatus != '' and invoiceStatus != 'null' and invoiceStatus != '99'">
            and t.invoice_status = #{invoiceStatus}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' and qszt != '99'">
            and t.qs_status = #{qszt}
        </if>
        <if test="qsyf != null and qsyf != null and qsyf != '' and qsyf != ''">
            and DATE_FORMAT(t.qs_date,'%Y-%m') = #{qsyf}
        </if>
        <if test="qsr != null and qsr != '' and qsr != 'null' ">
            and t.qs_name like CONCAT(#{qsr},'%')
        </if>
        <if test="qsfs != null and qsfs != '' and qsfs != 'null' and qsfs != '99'">
            and t.qs_type = #{qsfs}
        </if>
        <if test="remark != null and remark != '' and remark != 'null' ">
            and t.remark like CONCAT(#{remark},'%')
        </if>
        <if test="listMark != null and listMark != '' and listMark != 'null' and listMark != '99'">
            and t.list_status = #{listMark}
        </if>

        <if
                test="inAccountMonth != null and inAccountMonth != null and inAccountMonth != '' and inAccountMonth != ''">
            and DATE_FORMAT(t.payment_date,'%Y-%m') = #{inAccountMonth}
        </if>
        <if test="incentiveFlag !=null and incentiveFlag !='' and incentiveFlag!= '99'">
            and t.incentive_flag like CONCAT('%',#{incentiveFlag},'%')
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='99'">
            and t.invoice_source = #{invoiceSource}
        </if>
        <if test="snVoucherNumber != null and snVoucherNumber != '' and snVoucherNumber != 'null' and snVoucherNumber != '99'">
            and t.sn_voucher_number = #{snVoucherNumber}
        </if>

        <if test="postingTimeStart != null and postingTimeStart != '' and postingTimeStart != 'null' and postingTimeStart != '99' and postingTimeEnd != null and postingTimeEnd != '' and postingTimeEnd != 'null' and postingTimeEnd != '99'">
            and t.posting_time between #{postingTimeStart} and #{postingTimeEnd}
        </if>

        <if test="imageNumber != null and imageNumber != '' and imageNumber != 'null' and imageNumber != '99'">
            and t.image_id = #{imageNumber}
        </if>

        <if test="accountPeriod != null and accountPeriod != '' and accountPeriod != 'null' and accountPeriod != '99'">
            and t.account_period = #{accountPeriod}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '1'.toString()">
            and t.inaccount_status = #{inAccountStatus}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '0'.toString()">
            and (t.inaccount_status = '' or t.inaccount_status is null or t.inaccount_status = '0')
        </if>
        <if test="bzdh != null and bzdh != '' and bzdh != 'null' and badh != '99'">
            and t.bzdh = #{bzdh}
        </if>
        <if test="bzr != null and bzr != '' and bzr != 'null'">
            and t.bzr like concat('%',#{bzr},'%')
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode == '99'">
            and (t.comp_code in
            <foreach collection="companyCodes" index="index" item="companyCode" separator="," open="(" close=")">
                #{companyCode}
            </foreach>
            or t.comp_code is null or t.comp_code = ''
            )
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode != '88'">
            and t.comp_code = #{companyCode}
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode == '88'">
            and (t.comp_code = '' or t.comp_code is null)
        </if>
    </select>
    <!--销项票池查询-->
    <select id="listSaleInvoice" parameterType="java.util.Map"
            resultType="com.dxhy.extend.entity.ExtAddTaxInvoice" databaseId="mysql">
        select
        <include refid="sql_fields_added"/>
        ,t.incentive_flag incentiveFlag
        ,t.system_name systemName
        ,t.sn_voucher_number snVoucherNumber
        ,t.image_id imageNumber
        ,t.account_period accountPeriod
        ,t.posting_time postingTime
        ,t.inaccount_status inAccountStatus
        ,t.bzdh bzdh
        ,t.bzr bzr
        ,t.comp_code compCode
        from t_dx_sale_record_invoice t
        where 1 = 1
        <if test="cjksyf != null and cjksyf!= '' and cjjsyf != null and cjjsyf != ''">
            AND t.create_date between #{cjksyf} and #{cjjsyf}
        </if>
        <if test="kpksrq != null and kpksrq!= '' and kpjsrq != null and kpjsrq != ''">
            AND t.invoice_date between #{kpksrq} and #{kpjsrq}
        </if>
        <if test="keyWord != null and keyWord != '' and keyWord != 'null' ">
            and CONCAT(IFNULL(t.invoice_code,''),IFNULL(t.invoice_no,''),IFNULL(t.gf_name,''),IFNULL(t.gf_tax_no,''))
            like
            CONCAT('%',#{keyWord},'%')
        </if>
        <if test="sign != '88'">
            and t.xf_tax_no in
            <foreach collection="taxno" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        <if
                test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if
                test="invoiceStatus != null and invoiceStatus != '' and invoiceStatus != 'null' and invoiceStatus != '99'">
            and t.invoice_status = #{invoiceStatus}
        </if>
        <if test="qszt != null and qszt != '' and qszt != 'null' and qszt != '99'">
            and t.qs_status = #{qszt}
        </if>
        <if test="qsyf != null and qsyf != null and qsyf != '' and qsyf != ''">
            and DATE_FORMAT(t.qs_date,'%Y-%m') = #{qsyf}
        </if>
        <if test="qsr != null and qsr != '' and qsr != 'null' ">
            and t.qs_name like CONCAT(#{qsr},'%')
        </if>
        <if test="qsfs != null and qsfs != '' and qsfs != 'null' and qsfs != '99'">
            and t.qs_type = #{qsfs}
        </if>
        <if test="remark != null and remark != '' and remark != 'null' ">
            and t.remark like CONCAT(#{remark},'%')
        </if>
        <if test="listMark != null and listMark != '' and listMark != 'null' and listMark != '99'">
            and t.list_status = #{listMark}
        </if>
<!--        <if-->
<!--                test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99'">-->
<!--            and t.payment_status = #{inAccountStatus}-->
<!--        </if>-->
        <if test="inAccountMonth != null and inAccountMonth != null and inAccountMonth != '' and inAccountMonth != ''">
            and DATE_FORMAT(t.payment_date,'%Y-%m') = #{inAccountMonth}
        </if>
        <if test="incentiveFlag !=null and incentiveFlag !='' and incentiveFlag!= '99'">
            and t.incentive_flag like CONCAT('%',#{incentiveFlag},'%')
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='99'">
            and t.invoice_source = #{invoiceSource}
        </if>
        <if test="voucherNo != null and voucherNo != '' and voucherNo != 'null' and voucherNo != '99'">
            and t.voucher_no = #{voucherNo}
        </if>
        <if test="snVoucherNumber != null and snVoucherNumber != '' and snVoucherNumber != 'null' and snVoucherNumber != '99'">
            and t.sn_voucher_number = #{snVoucherNumber}
        </if>

        <if test="postingTimeStart != null and postingTimeStart != '' and postingTimeStart != 'null' and postingTimeStart != '99' and postingTimeEnd != null and postingTimeEnd != '' and postingTimeEnd != 'null' and postingTimeEnd != '99'">
            and t.posting_time between #{postingTimeStart} and #{postingTimeEnd}
        </if>

        <if test="imageNumber != null and imageNumber != '' and imageNumber != 'null' and imageNumber != '99'">
            and t.image_id = #{imageNumber}
        </if>

        <if test="accountPeriod != null and accountPeriod != '' and accountPeriod != 'null' and accountPeriod != '99'">
            and t.account_period = #{accountPeriod}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '1'.toString()">
            and t.inaccount_status = #{inAccountStatus}
        </if>
        <if test="inAccountStatus != null and inAccountStatus != '' and inAccountStatus != 'null' and inAccountStatus != '99' and inAccountStatus == '0'.toString()">
            and (t.inaccount_status = '' or t.inaccount_status is null or t.inaccount_status = '0')
        </if>
        <if test="bzdh != null and bzdh != '' and bzdh != 'null' and badh != '99'">
            and t.bzdh = #{bzdh}
        </if>
        <if test="bzr != null and bzr != '' and bzr != 'null'">
            and t.bzr like concat('%',#{bzr},'%')
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode == '99'">
            and (t.comp_code in
            <foreach collection="companyCodes" index="index" item="companyCode" separator="," open="(" close=")">
                #{companyCode}
            </foreach>
            or t.comp_code is null or t.comp_code = ''
            )
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode != '88'">
            and t.comp_code = #{companyCode}
        </if>
        <if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode != '99' and companyCode == '88'">
            and (t.comp_code = '' or t.comp_code is null)
        </if>
        GROUP BY t.uuid
        ORDER BY t.create_date DESC
    </select>
    <!--摊销记录查询-->
    <select id="listAmortizeRecord" parameterType="java.util.Map"
            resultType="com.dxhy.extend.entity.AmortizeRecordEntity" databaseId="mysql">
        SELECT amortize_document_number amortizeDocumentNumber,
               amortize_amount          amortizeAmount,
               remain_amortize_amount   remainAmortizeAmount,
               amortize_user            bxr
        FROM t_dx_amortize_batch
        WHERE invoice_code = #{invoiceCode}
          AND invoice_no = #{invoiceNo}
          AND status = '0'
        ORDER BY create_date DESC
    </select>
    <!--
     String[] titlelist = {"公司名称", "会计凭证号码", "会计年度",
                    "账期", "过账日期","报账单号","结算单","报账单状态","借贷标识","科目编码"
                    ,"科目描述","供应商名称","供应商编码","客户编码","客户名称","物料编码","数量","单位",
                    "税码","税率","本位币借方金额","本位币贷方金额","销售订单","销售订单行","矿别编号","矿别","最后接收时间"};
            String[] titleProp = {"companyName","belnr","gjahr",
                    "monat","budat","zbzdh","zjsdh","zbzdzt","zdrcrk","racct",
                    "txt50","zname","lifnr","kunnr","zname2","matnr","msl","runit",
                    "mwskz","kbetr","zhslj","zhsld","kdauf","kdpos","kbbh","ktype","lastReceiveTime"}
                    -->
    <select id="getPullRecord" parameterType="com.dxhy.extend.entity.PullRecordReq"
            resultType="com.dxhy.extend.entity.PullRecordModel">
        select vr.butxt companyName,vr.belnr, vr.gjahr,
        vr.monat,vr.budat,vr.zbzdh,vr.zjsdh,vr.zbzdzt,vri.zdrcrk,vri.racct,
        vri.txt50,vri.zname,vri.lifnr,vri.kunnr,vri.zname2,vri.matnr,vri.msl,vri.runit,
        vri.mwskz,vri.kbetr,vri.zhslj,vri.zhsld,vri.kdauf,vri.kdpos,vri.ktype,vr.create_time lastReceiveTime
        from
        voucher_record_item vri LEFT JOIN voucher_record vr on vri.relation_id = vr.id
         where 1=1
        <if test="companyName!=null and companyName != ''">
            and vr.butxt = #{companyName}
        </if>
        <if test ="orgCode !=null and orgCode.size>0">
            and vr.bukrs in
            <foreach collection="orgCode" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="companyCode !=null and companyCode !=''">
            and vr.bukrs = #{companyCode}
        </if>
        <if test ="accountPeriod !=null and accountPeriod !=''">
            and CONCAT_WS("-",vr.gjahr,vr.monat) = #{accountPeriod}
        </if>
        <if test="sm != null and sm !=''">
            and vri.mwskz = #{sm}
        </if>
        <if test="kmbm != null and kmbm !=''">
            and vri.racct = #{kmbm}
        </if>
        <if test="kmms !=null and kmms !=''" >
            and vri.txt50 = #{kmms}
        </if>
        <if test="supplierName !=null and supplierName !=''">
            and vri.zname1 = #{supplierName}
        </if>
        <if test="customerName!=null and customerName !=''">
            and vri.zname2 = #{customerName}
        </if>
        <if test = "accountStartDate !=null and accountStartDate!=''">
            and date_format(vr.budat,'%Y-%m-%d') between #{accountStartDate} and #{accountEndDate}
        </if>
    </select>

    <!--销项票池优惠政策查询-->
    <select id="listIncentiveFlag" resultType="java.lang.String">
        SELECT incentive_flag
        FROM t_dx_record_invoice_detail_sales
        WHERE incentive_flag != ''
        GROUP BY incentive_flag
    </select>
</mapper>
