<?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.sign.dao.SignInvoiceDelDao">
    <resultMap id="BaseResultCountMap" type="com.dxhy.sign.model.QsInvoiceCount">
        <result column="sumTaxAmount" property="sumTaxAmount"/>
        <result column="sumInvoiceAmount" property="sumInvoiceAmount"/>
    </resultMap>

    <select id="selectDelfpList" parameterType="java.util.Map"
            resultType="com.dxhy.sign.entity.TDxInvoiceDel" databaseId="mysql">
        SELECT
        t.id,t.notes,t.qs_type,t.qs_date,t.user_name,t.invoice_code,t.invoice_no,t.uuid,t.invoice_date,t.invoice_type,t.invoice_amount,t.tax_amount
        ,t.scan_id,t.gf_name,t.xf_name,t.gf_tax_no,t.xf_tax_no,t.check_code,t.scan_date,t.total_amount
        FROM t_dx_invoice_del t
        WHERE t.user_account = #{userId} and t.company = #{company}

        <if test="gfsh != '99' and gfsh != null and gfsh != '' and gfsh != 'null'">
            and t.gf_tax_no = #{gfsh}
        </if>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="qsType != null and qsType != '' and qsType != 'null' ">
            and t.qs_type = #{qsType}
        </if>

        <if test="xfsh != null and xfsh != '' and xfsh != 'null' ">
            and t.xf_tax_no like concat(#{xfsh},'%')
        </if>
        <if test="createDateBegin != null and createDateBegin != '' and createDateBegin != 'null' ">
            <![CDATA[ AND t.scan_date >= #{createDateBegin} ]]>
        </if>
        <if test="createDateEnd != null and createDateEnd != '' and createDateEnd != 'null' ">
            <![CDATA[ AND t.scan_date <= #{createDateEnd} ]]>
        </if>

        ORDER BY t.invoice_serial_no desc
    </select>

    <select id="selectDelfpList" parameterType="java.util.Map"
            resultType="com.dxhy.sign.entity.TDxInvoiceDel" databaseId="oracle">
        SELECT
        t.id,t.notes,t.qs_type,t.qs_date,t.user_name,t.invoice_code,t.invoice_no,t.uuid,t.invoice_date,t.invoice_type,t.invoice_amount,t.tax_amount
        ,t.scan_id,t.gf_name,t.xf_name,t.gf_tax_no,t.xf_tax_no,t.check_code,t.scan_date,t.total_amount
        FROM t_dx_invoice_del t
        WHERE t.user_account = #{userId} and t.company = #{company}
        <if test="gfsh != null and gfsh != '' and gfsh != 'null' and gfsh != '99' ">
            and t.gf_tax_no = #{gfsh}
        </if>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="qsType != null and qsType != '' and qsType != 'null' ">
            and t.qs_type = #{qsType}
        </if>

        <if test="xfsh != null and xfsh != '' and xfsh != 'null' ">
            and t.xf_tax_no like concat(#{xfsh},'%')
        </if>
        <if test="createDateBegin != null and createDateBegin != '' and createDateBegin != 'null' ">
            <![CDATA[ AND to_char(t.scan_date, 'yyyy-MM-dd HH24:mm:dd') >= #{createDateBegin} ]]>
        </if>
        <if test="createDateEnd != null and createDateEnd != '' and createDateEnd != 'null' ">
            <![CDATA[ AND to_char(t.scan_date, 'yyyy-MM-dd HH24:mm:dd') <= #{createDateEnd} ]]>
        </if>

        ORDER BY t.invoice_serial_no desc
    </select>


    <select id="selectDelfpListCount" parameterType="java.util.Map"
            resultMap="BaseResultCountMap" databaseId="mysql">
        SELECT sum(t.invoice_amount) sumInvoiceAmount,
        sum(t.tax_amount) sumTaxAmount
        FROM t_dx_invoice_del t
        WHERE t.user_account = #{userId} and t.company = #{company}

        <if test="gfsh != '99' and gfsh != null and gfsh != '' and gfsh != 'null'">
            and t.gf_tax_no = #{gfsh}
        </if>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="qsType != null and qsType != '' and qsType != 'null' ">
            and t.qs_type = #{qsType}
        </if>

        <if test="xfsh != null and xfsh != '' and xfsh != 'null' ">
            and t.xf_tax_no like concat(#{xfsh},'%')
        </if>
        <if test="createDateBegin != null and createDateBegin != '' and createDateBegin != 'null' ">
            <![CDATA[ AND t.scan_date >= #{createDateBegin} ]]>
        </if>
        <if test="createDateEnd != null and createDateEnd != '' and createDateEnd != 'null' ">
            <![CDATA[ AND t.scan_date <= #{createDateEnd} ]]>
        </if>

    </select>

    <select id="selectDelfpListCount" parameterType="java.util.Map"
            resultMap="BaseResultCountMap" databaseId="oracle">
        SELECT sum(t.invoice_amount) sumInvoiceAmount,
        sum(t.tax_amount) sumTaxAmount
        FROM t_dx_invoice_del t
        WHERE t.user_account = #{userId} and t.company = #{company}
        <if test="gfsh != '99' and gfsh != null and gfsh != '' and gfsh != 'null'">
            and t.gf_tax_no = #{gfsh}
        </if>
        <if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' ">
            and t.invoice_type = #{invoiceType}
        </if>
        <if test="invoiceNo != null and invoiceNo != '' and invoiceNo != 'null' ">
            and t.invoice_no = #{invoiceNo}
        </if>
        <if test="qsType != null and qsType != '' and qsType != 'null' ">
            and t.qs_type = #{qsType}
        </if>

        <if test="xfsh != null and xfsh != '' and xfsh != 'null' ">
            and t.xf_tax_no like concat(#{xfsh},'%')
        </if>
        <if test="createDateBegin != null and createDateBegin != '' and createDateBegin != 'null' ">
            <![CDATA[ AND to_char(t.scan_date, 'yyyy-MM-dd HH24:mm:dd') >= #{createDateBegin} ]]>
        </if>
        <if test="createDateEnd != null and createDateEnd != '' and createDateEnd != 'null' ">
            <![CDATA[ AND to_char(t.scan_date, 'yyyy-MM-dd HH24:mm:dd') <= #{createDateEnd} ]]>
        </if>

    </select>
</mapper>
