<?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.ExtSaleSignDao">

    <select id="querySaleSign" parameterType="java.util.Map"
            resultType="com.dxhy.extend.entity.ExtSaleSignModel" databaseId="mysql">
        SELECT
        DATE_FORMAT( qs_date, '%Y-%m-%d' ) qsDate,
        system_name,
        count( 1 ) invoiceNum,
        sum( invoice_amount ) invoiceAmount,
        sum( tax_amount ) taxAmount,
        qs_status
        FROM
        t_dx_sale_record_invoice
        WHERE
        1=1
        AND xf_tax_no IN
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="beginDate != null and beginDate!= '' and endDate != null and endDate != ''">
            and qs_date BETWEEN #{beginDate} and #{endDate}
        </if>
        GROUP BY
        DATE_FORMAT( qs_date, '%Y-%m-%d' ),
        system_name,
        qs_status
        ORDER BY
        qs_date DESC
    </select>


    <select id="querySaleSignDetail" resultType="com.dxhy.extend.entity.ExtSaleSignDetailModel">
        select * from t_dx_sale_record_invoice where xf_tax_no IN
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and DATE_FORMAT( qs_date, '%Y-%m-%d' )=#{qsDate}
        <if test="systemName!=null and systemName!='null' and systemName!=''">
            and system_name =#{systemName}
        </if>
    </select>

    <resultMap id="SignHjResultMap"
               type="com.dxhy.extend.entity.ExtAddTaxInvoice">
        <result column="hjsl" property="id"/>
        <result column="hjje" property="invoiceAmount"/>
        <result column="hjse" property="taxAmount"/>
    </resultMap>
    <select id="selectAddTaxHj" parameterType="java.util.Map"
            resultMap="SignHjResultMap" databaseId="mysql">
        select count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
        from t_dx_sale_record_invoice t where t.xf_tax_no IN
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="beginDate != null and beginDate!= '' and endDate != null and endDate != ''">
            and t.qs_date BETWEEN #{beginDate} and #{endDate}
        </if>
        <if test="invoiceDateStart != null and invoiceDateStart!= '' and invoiceDateEnd != null and invoiceDateEnd != ''">
            and t.invoice_date BETWEEN #{invoiceDateStart} and #{invoiceDateEnd}
        </if>
        <if test="searchKey != null and searchKey != '' and searchKey != 'null' ">
            and CONCAT(IFNULL(t.invoice_code,''),IFNULL(t.invoice_no,''),IFNULL(t.gf_name,''),IFNULL(t.gf_tax_no,''))
            like
            CONCAT('%',#{searchKey},'%')
        </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="qsfs != null and qsfs != '' and qsfs != 'null' and qsfs != '99'">
            and t.qs_type = #{qsfs}
        </if>
        <if test="listStatus != null and listStatus != '' and listStatus != 'null' and listStatus != '99'">
            and t.list_status=#{listStatus}
        </if>
        <if test="incentiveFlag != null and incentiveFlag != '' and incentiveFlag != 'null' and incentiveFlag != '99'">
            and t.incentive_flag=#{incentiveFlag}
        </if>
        <if test="remark != null and remark != '' and remark != 'null' and remark != '99'">
            and t.remark=#{remark}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='99'">
            and t.invoice_source = #{invoiceSource}
        </if>
    </select>

    <select id="querySaleSignInvoice" resultType="com.dxhy.extend.entity.ExtSaleSignInvoiceModel">
        select * from t_dx_sale_record_invoice t where t.xf_tax_no IN
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="beginDate != null and beginDate!= '' and endDate != null and endDate != ''">
            and t.qs_date BETWEEN #{beginDate} and #{endDate}
        </if>
        <if test="invoiceDateStart != null and invoiceDateStart!= '' and invoiceDateEnd != null and invoiceDateEnd != ''">
            and t.invoice_date BETWEEN #{invoiceDateStart} and #{invoiceDateEnd}
        </if>
        <if test="searchKey != null and searchKey != '' and searchKey != 'null' ">
            and CONCAT(IFNULL(t.invoice_code,''),IFNULL(t.invoice_no,''),IFNULL(t.gf_name,'')) like
            CONCAT('%',#{searchKey},'%')
        </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="qsfs != null and qsfs != '' and qsfs != 'null' and qsfs != '99'">
            and t.qs_type = #{qsfs}
        </if>
        <if test="listMark != null and listMark != '' and listMark != 'null' and listMark != '99'">
            and t.list_status=#{listMark}
        </if>
        <if test="incentiveFlag != null and incentiveFlag != '' and incentiveFlag != 'null' and incentiveFlag != '99'">
            and t.incentive_flag like CONCAT('%',#{incentiveFlag},'%')
        </if>
        <if test="remark != null and remark != '' and remark != 'null' and remark != '99'">
            and t.remark=#{remark}
        </if>
        <if test="invoiceSource!=null and invoiceSource!='' and invoiceSource!='99'">
            and t.invoice_source = #{invoiceSource}
        </if>
    </select>
</mapper>
