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

    <resultMap id="reportResultMap" type="com.dxhy.extend.model.ExtReportStatisticsVo">
        <result column="totalCount" property="totalCount"/>
        <result column="totalAmount" property="totalAmount"/>
        <result column="totalTax" property="totalTax"/>
    </resultMap>

    <select id="getResult" resultMap="reportResultMap">
        select count(1) totalCount, ifnull(sum(invoice_amount), 0) totalAmount,
        ifnull(sum(dk_tax_amount), 0) totalTax
        FROM t_dx_record_invoice
        WHERE valid='1'
        and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and lq_tdyslxDm='08'))
        AND invoice_status='0'
        AND rzh_yesorno='1'
        <if test="skssq !=null and skssq != ''">
            and rzh_belong_date = #{skssq}
        </if>
        and gf_tax_no = #{gfsh}
    </select>
    <select id="getResult" resultMap="reportResultMap" databaseId="oracle">
        select count(1) totalCount, nvl(sum(invoice_amount), 0) totalAmount, nvl(sum(dk_tax_amount), 0)
        totalTax
        FROM t_dx_record_invoice
        WHERE valid='1' and invoice_type in ('01','03','08','14') AND invoice_status='0' AND
        rzh_yesorno='1'
        <if test="skssq !=null and skssq != ''">
            and rzh_belong_date = #{skssq}
        </if>
        and gf_tax_no = #{gfsh}
    </select>

    <select id="getTotal" resultType="com.dxhy.extend.model.ExtCustomsStatisticsVo">
        select count(1) customsCount, ifnull(sum(yx_tax_amount), 0) customsTax
        FROM t_dx_customs_record
        WHERE data_type = '17' AND glzt='0' AND rzh_yesorno='1'
        <if test="skssq !=null and skssq != ''">
            and rzh_belong_date = #{skssq}
        </if>
        and gf_tax_no = #{gfsh}
    </select>
    <select id="getTotal" resultType="com.dxhy.extend.model.ExtCustomsStatisticsVo"
            databaseId="oracle">
        select count(1) customsCount,nvl(sum(yx_tax_amount), 0) customsTax
        FROM t_dx_customs_record
        WHERE data_type = '17' AND glzt='0' AND rzh_yesorno='1'
        <if test="skssq !=null and skssq != ''">
            and rzh_belong_date = #{skssq}
        </if>
        and gf_tax_no = #{gfsh}
    </select>

    <select id="getTotalOutTax" resultType="Double" databaseId="mysql">
        SELECT ifnull(sum(out_tax_amount), 0) FROM t_dx_record_invoice
        WHERE valid='1'
        and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and lq_tdyslxDm='08'))
        AND invoice_status='0'
        AND rzh_yesorno='1'
        AND out_status in ('1','2')
        <if test="skssq !=null and skssq != ''">
            and out_belong_date = #{skssq}
        </if>
        and gf_tax_no = #{gfsh}
    </select>

    <select id="getOutTaxDetail" resultType="com.dxhy.extend.model.ExtDailyReportVo"
            databaseId="mysql">
        SELECT
        out_reason rzhDate,
        ifnull(sum(out_tax_amount), 0) tax
        FROM t_dx_record_invoice
        WHERE valid='1'
        and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and lq_tdyslxDm='08'))
        AND invoice_status='0'
        AND rzh_yesorno='1'
        AND out_status in ('1','2')
        <if test="skssq !=null and skssq != ''">
            and out_belong_date = #{skssq}
        </if>
        and gf_tax_no = #{gfsh}
        GROUP BY out_reason
        ORDER BY out_reason ASC
    </select>

    <select id="getTotalOutTax" resultType="Double" databaseId="oracle">
        SELECT nvl(sum(out_tax_amount), 0) FROM t_dx_record_invoice
        WHERE valid='1' and invoice_type in ('01','03','08','14') AND invoice_status='0' AND
        rzh_yesorno='1' AND
        out_status in ('1','2')
        <if test="skssq !=null and skssq != ''">
            and out_belong_date = #{skssq}
        </if>
        and gf_tax_no = #{gfsh}
    </select>

    <select id="getOutTaxDetail" resultType="com.dxhy.extend.model.ExtDailyReportVo"
            databaseId="oracle">
        SELECT
        out_reason rzhDate,
        nvl(sum(out_tax_amount), 0) tax
        FROM t_dx_record_invoice
        WHERE valid='1' and invoice_type in ('01','03','08','14') AND invoice_status='0' AND
        rzh_yesorno='1' AND
        out_status in ('1','2')
        <if test="skssq !=null and skssq != ''">
            and out_belong_date = #{skssq}
        </if>
        and gf_tax_no = #{gfsh}
        GROUP BY out_reason
        ORDER BY out_reason ASC
    </select>
</mapper>
