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

    <resultMap id="BaseResultMap"
               type="com.dxhy.extend.model.ExtJxsemxbbRespVO">
        <result column="totalAmount" property="totalAmount"/>
        <result column="totalTax" property="totalTax"/>
        <result column="amount17" property="amount17"/>
        <result column="tax17" property="tax17"/>
        <result column="amount13" property="amount13"/>
        <result column="tax13" property="tax13"/>
        <result column="amount10" property="amount10"/>
        <result column="tax10" property="tax10"/>
        <result column="amount6" property="amount6"/>
        <result column="tax6" property="tax6"/>
        <result column="amount5" property="amount5"/>
        <result column="tax5" property="tax5"/>
        <result column="amount3" property="amount3"/>
        <result column="tax3" property="tax3"/>
    </resultMap>

    <resultMap id="nameResultMap"
               type="com.dxhy.extend.model.ExtJxsemxbbRespVO">
        <result column="gfmc" property="gfmc"/>
    </resultMap>

    <select id="selectname" parameterType="java.util.Map"
            resultMap="nameResultMap">
        select DISTINCT t.gf_name gfmc
        from t_dx_record_invoice t
        <if test="gfsh != null and gfsh != '' and gfsh != 'null' ">
            where t.gf_tax_no = #{gfsh}
        </if>
    </select>
    <select id="selectzp" parameterType="java.util.Map"
            resultMap="BaseResultMap">
        select
        sum(case WHEN b.tax_rate in("17","16","13","10","11","6","5","3") then t.invoice_amount else
        null end)
        totalAmount,
        sum(case WHEN b.tax_rate in("17","16","13","10","11","6","5","3") then t.tax_amount else null
        end) totalTax,
        sum(case WHEN b.tax_rate in("17","16") then t.invoice_amount else null end) amount17,
        sum(case WHEN b.tax_rate in("17","16") then t.tax_amount else null end) tax17,
        sum(case WHEN b.tax_rate in("13") then t.invoice_amount else null end) amount13,
        sum(case WHEN b.tax_rate in("13") then t.tax_amount else null end) tax13,
        sum(case WHEN b.tax_rate in("10","11") then t.invoice_amount else null end) amount10,
        sum(case WHEN b.tax_rate in("10","11") then t.tax_amount else null end) tax10,
        sum(case WHEN b.tax_rate in("6") then t.invoice_amount else null end) amount6,
        sum(case WHEN b.tax_rate in("6") then t.tax_amount else null end) tax6,
        sum(case WHEN b.tax_rate in("5") then t.invoice_amount else null end) amount5,
        sum(case WHEN b.tax_rate in("5") then t.tax_amount else null end) tax5,
        sum(case WHEN b.tax_rate in("3") then t.invoice_amount else null end) amount3,
        sum(case WHEN b.tax_rate in("3") then t.tax_amount else null end) tax3
        from t_dx_record_invoice t, t_dx_record_invoice_detail b
        where t.uuid = b.uuid
        and t.invoice_type in ('01','03','14')
        and t.invoice_amount > 0
        and t.invoice_status = '0'
        and t.rzh_yesorno = '1'
        <if test="gfsh != null and gfsh != '' and gfsh != 'null' ">
            and t.gf_tax_no = #{gfsh}
        </if>
        <if
                test="invoiceStatus != null and invoiceStatus != '' and invoiceStatus != 'null' ">
            and t.rzh_belong_date = #{skssq}
        </if>

    </select>


</mapper>
