<?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.ExtRecordInvoiceDao">
    <!-- 自定义底账表结果集映射-->
    <resultMap id="recordInvoiceMap" type="com.dxhy.extend.entity.ExtRecordInvoiceEntity">
        <id property="id" column="id"></id>
        <result property="cutApproveDate" column="lastdate"/>
        <result property="invoiceType" column="invoice_type"/>
        <result property="invoiceCode" column="invoice_code"/>
        <result property="invoiceNo" column="invoice_no"/>
        <result property="invoiceDate" column="invoice_date"/>
        <result property="gfName" column="gf_name"/>
        <result property="xfName" column="xf_name"/>
        <result property="gfTaxNo" column="gf_tax_no"/>
        <result property="taxAmount" column="taxAmount"/>
        <result property="invoiceAmount" column="invoiceamount"/>
        <result property="dkse" column="dkse"/>
    </resultMap>
    <select id="queryInvoice" resultMap="recordInvoiceMap" databaseId="mysql">
        SELECT
        t.invoice_type,
        t.gf_tax_no,
        DATE_FORMAT(DATE_ADD(t.invoice_date, INTERVAL 360 DAY), '%Y%m') AS lastdate,
        t.invoice_code,
        t.invoice_no,
        DATE_FORMAT(t.invoice_date , '%Y-%m-%d') invoice_date,
        t.gf_name,
        t.xf_name,
        t.invoice_amount AS invoiceAmount,
        t.tax_amount AS taxAmount ,
        t.dk_tax_amount dkse
        FROM
        t_dx_record_invoice t
        LEFT JOIN t_dx_tax_current tdtc ON t.gf_tax_no = tdtc.taxno
        WHERE
        (t.rzh_belong_date IS NULL OR t.rzh_belong_date = '')
        AND t.invoice_amount > 0
        AND invoice_status = 0
        AND t.rzh_yesorno = 0
        AND t.invoice_type IN ("01", "03", "14")
        AND t.confirm_date IS NULL
        AND t.rzh_date IS NULL
        AND t.tax_amount >= 0
        AND period_add(tdtc.current_tax_period, 1 ) >= DATE_FORMAT(DATE_ADD(invoice_date, INTERVAL 360
        DAY), '%Y%m')
        AND DATE_FORMAT(invoice_date, '%Y%m%d') >= tdtc.select_start_date
        AND t.gf_tax_no IN
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        ORDER BY
        t.invoice_date ASC
    </select>


    <select id="queryInvoice" resultMap="recordInvoiceMap" databaseId="oracle">
        SELECT
        t.invoice_type,
        t.gf_tax_no,
        to_char(t.invoice_date + 360, 'yyyyMM') lastdate,
        t.invoice_code,
        t.invoice_no,
        to_char(t.invoice_date , 'yyyy-MM-dd') invoice_date,
        t.gf_name,
        t.xf_name,
        t.invoice_amount invoiceAmount,
        t.tax_amount taxAmount ,
        t.dk_tax_amount dkse
        FROM
        t_dx_record_invoice t
        LEFT JOIN t_dx_tax_current tdtc ON t.gf_tax_no = tdtc.taxno
        WHERE
        (t.rzh_belong_date IS NULL OR t.rzh_belong_date = '')
        AND t.invoice_amount > 0
        AND invoice_status = 0
        AND t.rzh_yesorno = 0
        AND t.invoice_type IN ('01', '03', '14')
        AND t.confirm_date IS NULL
        AND t.rzh_date IS NULL
        AND t.tax_amount >= 0
        AND add_months(to_date(tdtc.current_tax_period,'yyyyMM'), 1) >= to_date(to_char(invoice_date +
        360,
        'yyyyMM'),'yyyyMM')
        AND to_char(invoice_date, 'yyyyMMdd') >= tdtc.select_start_date
        AND t.gf_tax_no IN
        <foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        ORDER BY
        t.invoice_date ASC
    </select>

</mapper>
