<?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.core.job.dao.TDxRecordInvoiceDetailJobDao">


    <insert id="insertRecordInvoiceDetail" parameterType="com.dxhy.core.job.entity.TDxRecordInvoiceDetailJobEntity">
        insert into t_dx_record_invoice_detail(uuid,
                                               invoice_code,
                                               invoice_no,
                                               detail_no,
                                               goods_name,
                                               model,
                                               unit,
                                               num,
                                               unit_price,
                                               detail_amount,
                                               tax_rate,
                                               tax_amount)
        values (#{uuid},
                #{invoiceCode},
                #{invoiceNo},
                #{detailNo},
                #{goodsName},
                #{model},
                #{unit},
                #{num},
                #{unitPrice},
                #{detailAmount},
                #{taxRate},
                #{taxAmount})
    </insert>

    <delete id="delDetail" parameterType="java.lang.String">
        delete
        from t_dx_record_invoice_detail
        where uuid = #{uuid}
    </delete>

    <select id="getDetailCount" parameterType="java.lang.String" resultType="java.lang.Integer">
        select count(1)
        from t_dx_record_invoice_detail
        where uuid = #{uuid}
    </select>


    <delete id="delDetailJd" parameterType="java.lang.String">
        delete
        from t_dx_vehicle_sale_invoice
        where uuid = #{uuid}
    </delete>
    <delete id="delDetailJdSales" parameterType="java.lang.String">
        delete
        from t_dx_vehicle_sale_invoice_sales
        where uuid = #{uuid}
    </delete>

    <select id="getDetailJd" parameterType="java.lang.String" resultType="java.lang.Integer">
        select count(1)
        from t_dx_vehicle_sale_invoice
        where uuid = #{uuid}
    </select>
    <select id="getDetailJdSales" parameterType="java.lang.String" resultType="java.lang.Integer">
        select count(1)
        from t_dx_vehicle_sale_invoice_sales
        where uuid = #{uuid}
    </select>

    <delete id="delDetailTaxRate" parameterType="java.lang.String">
        delete
        from t_dx_record_invoice_statistics
        where
        invoice_no = #{invoiceNo}
        <if test="invoiceCode !=null and invoiceCode!=''">
            and  invoice_code = #{invoiceCode}
        </if>
    </delete>

    <select id="getTaxRate" parameterType="java.lang.String" resultType="java.lang.Integer">
        select count(1)
        from t_dx_record_invoice_statistics
        where invoice_code = #{invoiceCode}
          and invoice_no = #{invoiceNo}
    </select>

    <update id="updateDetailYesorno" parameterType="com.dxhy.core.job.entity.TDxRecordInvoiceJobEntity">
        update t_dx_record_invoice
        set detail_yesorno=#{invoiceInfo.detailYesorno}
        where uuid = #{invoiceInfo.uuid}
    </update>

    <update id="updateSaleDetailYesorno" parameterType="com.dxhy.core.job.entity.TDxSaleRecordInvoiceJobEntity">
        update t_dx_sale_record_invoice
        set detail_yesorno=#{invoiceInfo.detailYesorno}
        where uuid = #{invoiceInfo.uuid}
    </update>

</mapper>
