<?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="cn.superdesk.uniorder.dao.mapper.invoice.customer.InvoiceApplyMapperExScoreV2_1">


    <resultMap id="InvoiceApplyPageResultMap"
               type="cn.superdesk.uniorder.dto.vo.invoice.customer.InvoiceApplyCustomerPageVo">

        <id column="id" jdbcType="BIGINT" property="id"/>

        <result column="accounting_order_type" jdbcType="TINYINT" property="accountingOrderType"/>
        <result column="dim_create_by" jdbcType="TINYINT" property="dimCreateBy"/>
        <result column="accounting_order_id" jdbcType="BIGINT" property="accountingOrderId"/>
        <result column="accounting_order_sn" jdbcType="VARCHAR" property="accountingOrderSn"/>

        <result column="out_virt_names_str" jdbcType="VARCHAR" property="outVirtNamesStr"/>

        <result column="invoice_apply_sn" jdbcType="VARCHAR" property="invoiceApplySn"/>
        <result column="invoice_number" jdbcType="VARCHAR" property="invoiceNumber"/>
        <result column="invoice_title" jdbcType="VARCHAR" property="invoiceTitle"/>
        <result column="invoice_mode" jdbcType="VARCHAR" property="invoiceMode"/>
        <result column="invoice_title" jdbcType="VARCHAR" property="invoiceTitle"/>

        <result column="tax_rate" property="taxRate" jdbcType="VARCHAR"/>

        <!-- 发票申请部分 -->
        <result column="apply_user_id" jdbcType="BIGINT" property="applyUserId"/>
        <result column="apply_user_name" jdbcType="VARCHAR" property="applyUserName"/>
        <result column="apply_time" jdbcType="TIMESTAMP" property="applyTime"/>

        <!-- 发票申请审核部分 -->
        <result column="audit_user_id" jdbcType="BIGINT" property="auditUserId"/>
        <result column="audit_user_name" jdbcType="VARCHAR" property="auditUserName"/>
        <result column="audit_time" jdbcType="TIMESTAMP" property="auditTime"/>
        <result column="audit_status" jdbcType="TINYINT" property="auditStatus"/>

        <!-- 开票进展部分 -->
        <!-- inva.invoice_status,-->
        <!-- inva.invoice_progressing_user_id,-->
        <!-- inva.invoice_progressing_time,-->
        <result column="invoice_status" jdbcType="TINYINT" property="invoiceStatus"/>
        <result column="invoice_progressing_user_id" jdbcType="BIGINT" property="invoiceProgressingUserId"/>
        <result column="invoice_progressing_time" jdbcType="TIMESTAMP" property="invoiceProgressingTime"/>

        <!-- 发票登记部分 -->
        <result column="make_invoice_user_id" jdbcType="BIGINT" property="makeInvoiceUserId"/>
        <result column="make_invoice_user_name" jdbcType="VARCHAR" property="makeInvoiceUserName"/>
        <result column="make_invoice_status" jdbcType="TINYINT" property="makeInvoiceStatus"/>
        <result column="make_invoice_time" jdbcType="TIMESTAMP" property="makeInvoiceTime"/>

        <!-- 运营领票部分 -->
        <!-- inva.receive_invoice_status,-->
        <!-- inva.receive_invoice_user_id,-->
        <!-- inva.receive_invoice_time,-->
        <result column="receive_invoice_status" jdbcType="TINYINT" property="receiveInvoiceStatus"/>
        <result column="receive_invoice_user_id" jdbcType="BIGINT" property="receiveInvoiceUserId"/>
        <result column="receive_invoice_time" jdbcType="TIMESTAMP" property="receiveInvoiceTime"/>

        <!-- 寄票登记部分 -->
        <result column="mail_tick_user_id" jdbcType="BIGINT" property="mailTickUserId"/>
        <result column="mail_tick_user_name" jdbcType="TIMESTAMP" property="mailTickUserName"/>
        <result column="mail_tick_time" jdbcType="TIMESTAMP" property="mailTickTime"/>
        <result column="mail_tick_status" jdbcType="TINYINT" property="mailTickStatus"/>

        <result column="express_company_id" jdbcType="BIGINT" property="expressCompanyId"/>
        <result column="express_company_name" jdbcType="VARCHAR" property="expressCompanyName"/>
        <result column="express_no" jdbcType="VARCHAR" property="expressNo"/>

        <!-- 回款登记部分 -->
        <!-- inva.back_account_status,-->
        <!-- inva.back_account_mode_record,-->
        <!-- inva.back_account_user_id,-->
        <!-- inva.back_account_time,-->
        <result column="back_account_status" jdbcType="TINYINT" property="backAccountStatus"/>
        <result column="back_account_mode_record" jdbcType="TINYINT" property="backAccountModeRecord"/>
        <result column="back_account_user_id" jdbcType="BIGINT" property="backAccountUserId"/>
        <result column="back_account_time" jdbcType="TIMESTAMP" property="backAccountTime"/>

        <result column="sys_enterprise_ext_invoice_id" jdbcType="BIGINT" property="sysEnterpriseExtInvoiceId"/>
        <result column="sys_enterprise_ext_invoice_snapshot" jdbcType="LONGVARCHAR" property="sysEnterpriseExtInvoiceSnapshot"/>

        <result column="sys_org_id" jdbcType="BIGINT" property="sysOrgId" />
        <result column="sys_virt_id" jdbcType="BIGINT" property="sysVirtId" />
        <result column="out_org_id" jdbcType="BIGINT" property="outOrgId" />
        <result column="out_virt_id" jdbcType="BIGINT" property="outVirtId" />

        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="remark2" jdbcType="VARCHAR" property="remark2"/>

        <result column="need_revise_mark" jdbcType="INTEGER" property="needReviseMark" />

        <result column="attachment_upload_files_uids" jdbcType="VARCHAR" property="attachmentUploadFilesUids"/>

        <!--		<result column="unified_order_count_quantity" jdbcType="INTEGER" property="unifiedOrderCountQuantity"/>-->

        <!--		count(distinct invaxg.unified_order_id) as quantity_order,-->
        <!--		count(distinct invaxg.unified_order_credit_id) as quantity_order_credit,-->

        <!--		<result column="order_quantity" jdbcType="INTEGER" property="orderQuantity"/>-->
        <!--        <result column="credit_quantity" jdbcType="INTEGER" property="creditQuantity"/>-->

        <result column="accounting_order_quantity" jdbcType="INTEGER" property="accountingOrderQuantity"/>
        <result column="order_quantity" jdbcType="INTEGER" property="orderQuantity"/>
        <result column="goods_quantity" jdbcType="INTEGER" property="goodsQuantity"/>
        <result column="goods_item_quantity" jdbcType="INTEGER" property="goodsItemQuantity"/>
        <result column="credit_quantity" jdbcType="INTEGER" property="creditQuantity"/>

        <result column="order_amount" jdbcType="DECIMAL" property="orderAmount"/>
        <result column="goods_amount" jdbcType="DECIMAL" property="goodsAmount"/>
        <result column="goods_cost_amount" jdbcType="DECIMAL" property="goodsCostAmount"/>
        <result column="order_cost_amount" jdbcType="DECIMAL" property="orderCostAmount"/>

        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>

        <result column="source_from" jdbcType="VARCHAR" property="sourceFrom"/>
        <result column="service_name" jdbcType="VARCHAR" property="serviceName"/>

        <result column="invoice_apply_amount" jdbcType="DECIMAL" property="invoiceApplyAmount"/>
        <result column="free_amount" jdbcType="DECIMAL" property="freeAmount"/>
        <result column="un_accounting_amount" jdbcType="DECIMAL" property="unAccountingAmount"/>
        <result column="real_amount" jdbcType="DECIMAL" property="realAmount"/>
        <result column="no_back_money" jdbcType="DECIMAL" property="noBackMoney"/>

        <result column="max_back_time" jdbcType="TIMESTAMP" property="maxBackTime"/>

        <!-- group_concat(DISTINCT aucu.id) AS accounting_order_ids_str,-->
        <result column="accounting_order_ids_str" jdbcType="VARCHAR" property="accountingOrderIdsStr"/>
        <!-- group_concat(DISTINCT t6.accounting_order_sn) AS accounting_order_sns_str -->
        <result column="accounting_order_sns_str" jdbcType="VARCHAR" property="accountingOrderSnsStr"/>




        <result column="accounting_order_invoice_status" jdbcType="TINYINT" property="accountingOrderInvoiceStatus"/>

        <!--		<result column="accounting_order_sn" jdbcType="VARCHAR" property="accountingOrderSn"/>-->

        <!--		<result column="dz_money" jdbcType="DECIMAL" property="dzMoney"/>-->
        <!--		<result column="back_money" jdbcType="DECIMAL" property="backMoney"/>-->
        <!--		<result column="no_back_money" jdbcType="DECIMAL" property="noBackMoney"/>-->
        <!--		<result column="company_name" jdbcType="VARCHAR" property="companyName"/>-->


    </resultMap>

    <resultMap id="findViewHeadDataResultMap" type="cn.superdesk.uniorder.dto.vo.invoice.customer.InvoiceApplyCustomerHeadDataVoV2_1">

        <result column="invoice_apply_quantity" jdbcType="INTEGER" property="invoiceApplyQuantity"/>
        <result column="accounting_order_quantity" jdbcType="INTEGER" property="accountingOrderQuantity"/>
        <result column="order_quantity" jdbcType="INTEGER" property="orderQuantity"/>
        <result column="goods_quantity" jdbcType="INTEGER" property="goodsQuantity"/>
        <result column="goods_item_quantity" jdbcType="INTEGER" property="goodsItemQuantity"/>
        <result column="credit_quantity" jdbcType="INTEGER" property="creditQuantity"/>

        <result column="order_amount" jdbcType="DECIMAL" property="orderAmount"/>
        <result column="goods_amount" jdbcType="DECIMAL" property="orderCostAmount"/>
        <result column="goods_cost_amount" jdbcType="DECIMAL" property="goodsAmount"/>
        <result column="order_cost_amount" jdbcType="DECIMAL" property="goodsCostAmount"/>

        <result column="invoice_apply_amount" jdbcType="DECIMAL" property="invoiceApplyAmount"/>
        <result column="free_amount" jdbcType="DECIMAL" property="freeAmount"/>
        <result column="un_accounting_amount" jdbcType="DECIMAL" property="unAccountingAmount"/>
        <result column="real_amount" jdbcType="DECIMAL" property="realAmount"/>

    </resultMap>

    <sql id="findViewWhereIf">

        and inva.accounting_order_type = 2
        <!--
        and invaxg.accounting_order_type = 2
        -->
<!--        <if test="timeField != null and timeField != '' and startTime != null and startTime != '' and endTime != null and endTime != ''">-->
<!--            and TO_DAYS(inva.${timeField}) &gt;= TO_DAYS(#{startTime,jdbcType=VARCHAR})-->
<!--            and TO_DAYS(inva.${timeField}) &lt;= TO_DAYS(#{endTime,jdbcType=VARCHAR})-->
<!--        </if>-->

        <if test="applyTimeStart != null and applyTimeStart != '' and applyTimeEnd != null and applyTimeEnd !=''">
            and TO_DAYS(inva.apply_time) &gt;= TO_DAYS(#{applyTimeStart,jdbcType=VARCHAR})
            and TO_DAYS(inva.apply_time) &lt;= TO_DAYS(#{applyTimeEnd,jdbcType=VARCHAR})
        </if>
        <if test="makeInvoiceTimeStart != null and makeInvoiceTimeStart != '' and makeInvoiceTimeEnd != null and makeInvoiceTimeEnd !=''">
            and TO_DAYS(inva.make_invoice_time) &gt;= TO_DAYS(#{makeInvoiceTimeStart,jdbcType=VARCHAR})
            and TO_DAYS(inva.make_invoice_time) &lt;= TO_DAYS(#{makeInvoiceTimeEnd,jdbcType=VARCHAR})
        </if>
        <if test="receiveInvoiceTimeStart != null and receiveInvoiceTimeStart != '' and receiveInvoiceTimeEnd != null and receiveInvoiceTimeEnd !=''">
            and TO_DAYS(inva.receive_invoice_time) &gt;= TO_DAYS(#{receiveInvoiceTimeStart,jdbcType=VARCHAR})
            and TO_DAYS(inva.receive_invoice_time) &lt;= TO_DAYS(#{receiveInvoiceTimeEnd,jdbcType=VARCHAR})
        </if>
        <if test="mailTickTimeStart != null and mailTickTimeStart != '' and mailTickTimeEnd != null and mailTickTimeEnd !=''">
            and TO_DAYS(inva.mail_tick_time) &gt;= TO_DAYS(#{mailTickTimeStart,jdbcType=VARCHAR})
            and TO_DAYS(inva.mail_tick_time) &lt;= TO_DAYS(#{mailTickTimeEnd,jdbcType=VARCHAR})
        </if>
        <if test="backAccountTimeStart != null and backAccountTimeStart != '' and backAccountTimeEnd != null and backAccountTimeEnd !=''">
            and TO_DAYS(inva.back_account_time) &gt;= TO_DAYS(#{backAccountTimeStart,jdbcType=VARCHAR})
            and TO_DAYS(inva.back_account_time) &lt;= TO_DAYS(#{backAccountTimeEnd,jdbcType=VARCHAR})
        </if>

        <if test="applyUserId != null and applyUserId != ''">
            and inva.apply_user_id = #{applyUserId,jdbcType=BIGINT}
        </if>
        <if test="makeInvoiceUserId != null and makeInvoiceUserId != ''">
            and inva.make_invoice_user_id = #{makeInvoiceUserId,jdbcType=BIGINT}
        </if>
        <if test="receiveInvoiceUserId != null and receiveInvoiceUserId != ''">
            and inva.receive_invoice_user_id = #{receiveInvoiceUserId,jdbcType=BIGINT}
        </if>
        <if test="mailTickUserId != null and mailTickUserId != ''">
            and inva.mail_tick_user_id = #{mailTickUserId,jdbcType=BIGINT}
        </if>
        <if test="backAccountUserId != null and backAccountUserId != ''">
            and inva.back_account_user_id = #{backAccountUserId,jdbcType=BIGINT}
        </if>


        <!-- 发票登记部分 - 填写税局发票号 -->
<!--        <if test="keywordsField != null and keywordsField != '' and keywordsField == 'invoice_number' and keywords != null and keywords != ''">-->
<!--            and inva.invoice_number like CONCAT(CONCAT('%',#{keywords,jdbcType=VARCHAR}),'%')-->
<!--        </if>-->


        <!-- 2.5.3.1 对账单编号 -->
        <if test="accountingOrderSn != null and accountingOrderSn != ''">
            and inva.accounting_order_sn = #{accountingOrderSn,jdbcType=VARCHAR}
        </if>

        <!-- 2.5.3.2 开票申请编号 -->
        <if test="invoiceApplySn != null and invoiceApplySn != ''">
            and inva.invoice_apply_sn = #{invoiceApplySn,jdbcType=VARCHAR}
        </if>

        <if test="accountingOrderInvoiceStatus != null">
            and ascu.invoice_status = #{accountingOrderInvoiceStatus,jdbcType=TINYINT}
        </if>



        <!-- 2.5.3.3 企业名称/发票号/申请人/开票人 -->
        <if test="outVirtId != null and outVirtId != ''">
            and inva.out_virt_id = #{outVirtId,jdbcType=BIGINT}
        </if>
        <!--
        <if test="invoiceNumber != null and invoiceNumber != ''">
            and inva.invoice_number like CONCAT(CONCAT('%',#{invoiceNumber}),'%')
        </if>
        -->
        <if test="invoiceNumber != null and invoiceNumber != ''">
            and FIND_IN_SET(#{invoiceNumber},inva.invoice_number)
        </if>




        <!-- 发票登记部分 - 开票申请编号 -->
<!--        <if test="keywordsField != null and keywordsField != '' and keywordsField == 'invoice_apply_sn' and keywords != null and keywords != ''">-->
<!--            and inva.invoice_apply_sn like CONCAT(CONCAT('%',#{keywords,jdbcType=VARCHAR}),'%')-->
<!--        </if>-->
<!--        <if test="keywordsField != null and keywordsField != '' and keywordsField == 'accountingOrderSn' and keywords != null and keywords != ''">-->
<!--            and ascu.accounting_order_sn like CONCAT(CONCAT('%',#{keywords,jdbcType=VARCHAR}),'%')-->
<!--        </if>-->

<!--        <if test="keywordsField != null and keywordsField != '' and keywordsField == 'apply_user_name' and keywords != null and keywords != ''">-->
<!--            and t2.fullname like CONCAT(CONCAT('%',#{keywords,jdbcType=VARCHAR}),'%')-->
<!--        </if>-->
<!--        <if test="keywordsField != null and keywordsField != '' and keywordsField == 'audit_user_name' and keywords != null and keywords != ''">-->
<!--            and t3.fullname like CONCAT(CONCAT('%',#{keywords,jdbcType=VARCHAR}),'%')-->
<!--        </if>-->
<!--        <if test="keywordsField != null and keywordsField != '' and keywordsField == 'company_name' and keywords != null and keywords != ''">-->
<!--            and t10.enterprise_name like CONCAT(CONCAT('%',#{keywords,jdbcType=VARCHAR}),'%')-->
<!--        </if>-->
<!--        <if test="companyName != null and companyName != '' ">-->
<!--            and t10.enterprise_name like CONCAT(CONCAT('%',#{companyName,jdbcType=VARCHAR}),'%')-->
<!--        </if>-->
        <if test="invoiceTitle != null and invoiceTitle != '' ">
            and inva.invoice_title like CONCAT(CONCAT('%',#{invoiceTitle,jdbcType=VARCHAR}),'%')
        </if>


        <!-- 发票申请审核部分 -->
        <if test="auditStatus != null">
            and inva.audit_status = #{auditStatus,jdbcType=TINYINT}
        </if>

        <!-- 2.5.3.4 申请状态 开票进展部分 -->
        <if test="invoiceProgressingStatus != null">
            and inva.invoice_status = #{invoiceProgressingStatus,jdbcType=TINYINT}
        </if>
        <if test="invoiceProgressingStatusSelected != null and invoiceProgressingStatusSelected.size > 0">
            and inva.invoice_status IN
            <foreach close=")" collection="invoiceProgressingStatusSelected" index="index" item="item" open="(" separator=",">
                #{item}
            </foreach>
        </if>


        <!-- 2.5.3.7 开票状态 开票登记部分 -->
        <if test="makeInvoiceStatus != null">
            and inva.make_invoice_status = #{makeInvoiceStatus,jdbcType=TINYINT}
        </if>
        <if test="makeInvoiceStatusSelected != null and makeInvoiceStatusSelected.size > 0">
            and inva.make_invoice_status IN
            <foreach close=")" collection="makeInvoiceStatusSelected" index="index" item="item" open="(" separator=",">
                #{item}
            </foreach>
        </if>

        <!-- 运营领票部分 -->
        <if test="receiveInvoiceStatus != null">
            and inva.receive_invoice_status = #{receiveInvoiceStatus,jdbcType=TINYINT}
        </if>
        <if test="receiveInvoiceStatusSelected != null and receiveInvoiceStatusSelected.size > 0">
            and inva.receive_invoice_status IN
            <foreach close=")" collection="receiveInvoiceStatusSelected" index="index" item="item" open="(" separator=",">
                #{item}
            </foreach>
        </if>

        <!-- 寄票登记部分 -->
        <if test="mailTickStatus != null">
            and inva.mail_tick_status = #{mailTickStatus,jdbcType=TINYINT}
        </if>
        <if test="mailTickStatusSelected != null and mailTickStatusSelected.size > 0">
            and inva.mail_tick_status IN
            <foreach close=")" collection="mailTickStatusSelected" index="index" item="item" open="(" separator=",">
                #{item}
            </foreach>
        </if>

        <!-- 回款登记部分 -->
        <if test="backAccountStatus != null">
            and inva.back_account_status = #{backAccountStatus,jdbcType=TINYINT}
        </if>
        <if test="backAccountStatusSelected != null and backAccountStatusSelected.size > 0">
            and inva.back_account_status IN
            <foreach close=")" collection="backAccountStatusSelected" index="index" item="item" open="(" separator=",">
                #{item}
            </foreach>
        </if>

        <!-- 2.5.3.5 发票种类-单选 -->
        <if test="invoiceTypeId != null and invoiceTypeId != ''">
            and inva.invoice_type = #{invoiceTypeId,jdbcType=BIGINT}
        </if>

        <!-- 2.5.3.6 开票方式-单选 -->
        <if test="invoiceMode != null and invoiceMode != ''">
            and inva.invoice_mode = #{invoiceMode,jdbcType=VARCHAR}
        </if>

        <!-- 2.5.3.5 发票种类-单选 -->
        <if test="invoiceTypeIdsSelected != null and invoiceTypeIdsSelected.size > 0">
            and inva.invoice_type IN
            <foreach close=")" collection="invoiceTypeIdsSelected" index="index" item="invoiceTypeId" open="(" separator=",">
                #{invoiceTypeId}
            </foreach>
        </if>

        <!-- 2.5.3.6 开票方式-单选 -->
        <if test="invoiceModesSelected != null and invoiceModesSelected.size > 0">
            and inva.invoice_mode IN
            <foreach close=")" collection="invoiceModesSelected" index="index" item="invoiceMode" open="(" separator=",">
                #{invoiceMode}
            </foreach>
        </if>

<!--        <if test="purchaser != null">-->
<!--            AND EXISTS (-->
<!--            SELECT 1-->
<!--            from-->
<!--            sys_oder_user sou1-->
<!--            WHERE-->
<!--            sou1.user_id = uo.purchase_user_id-->
<!--            AND sou1.realname = #{purchaser,jdbcType=VARCHAR}-->
<!--            )-->
<!--        </if>-->

        <if test="sourceFromsSelected != null and sourceFromsSelected != '' and sourceFromsSelected.size > 0">
            and inva.source_from in
            <foreach collection="sourceFromsSelected" index="index" item="source_from" open="(" close=")" separator=",">
                #{source_from}
            </foreach>
        </if>

        <if test="serviceNosSelected != null and serviceNosSelected != '' and serviceNosSelected.size > 0">
            and inva.service_no in
            <foreach collection="serviceNosSelected" index="index" item="service_no" open="(" close=")" separator=",">
                #{service_no}
            </foreach>
        </if>



        <if test="id != null">
            and inva.id = #{id,jdbcType=BIGINT}
        </if>

<!--        <if test="accountingOrderSn != null and accountingOrderSn != ''">-->
<!--            and ascu.accounting_order_sn = #{accountingOrderSn,jdbcType=VARCHAR}-->
<!--        </if>-->

        <if test="ids != null and ids.size > 0">
            and inva.id in
            <foreach collection="ids" index="index" item="id" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>

<!--        <if test="outVirtIds != null and outVirtIds != ''">-->
<!--            and t10.enterprise_id in-->
<!--            <foreach collection="outVirtIds" index="index" item="pid" open="(" close=")" separator=",">-->
<!--                #{pid}-->
<!--            </foreach>-->
<!--        </if>-->

    </sql>

    <!-- 积分结算 发票申请管理 List & Head start -->

    <select id="findViewByPage"
            parameterType="cn.superdesk.uniorder.dto.param.invoice.customer.InvoiceApplyCustomerQueryCriteria"
            resultMap="InvoiceApplyPageResultMap">

        SELECT

            inva.id,
            inva.accounting_order_type,
            inva.dim_create_by,
            inva.accounting_order_id,
            inva.accounting_order_sn,

    --         group_concat(DISTINCT t10.enterprise_name) AS out_virt_names_str,

            inva.invoice_apply_sn,

            inva.invoice_number,
            inva.invoice_title,
            inva.invoice_type,
            inva.invoice_mode,
            inva.tax_rate,

            <!-- 发票申请部分 -->
            inva.apply_user_id,
    --         t2.fullname AS apply_user_name,
            inva.apply_time,

            <!-- 发票申请审核部分 -->
            inva.audit_user_id,
    --         t3.fullname AS audit_user_name,
            inva.audit_status,
            inva.audit_time,

            <!-- 开票进展部分 -->
            inva.invoice_status,
            inva.invoice_progressing_user_id,
            inva.invoice_progressing_time,

            <!-- 发票登记部分 -->
            inva.make_invoice_user_id,
    --         t4.fullname AS make_invoice_user_name,
            inva.make_invoice_time,
            inva.make_invoice_status,

            <!-- 运营领票部分 -->
            inva.receive_invoice_status,
            inva.receive_invoice_user_id,
            inva.receive_invoice_time,

            <!-- 寄票登记部分 -->
            inva.mail_tick_user_id,
    --         t5.fullname AS mail_tick_user_name,
            inva.mail_tick_status,
            inva.mail_tick_time,

            inva.express_company_id,
            inva.express_no,
    --         t9.company_name as express_company_name,

            <!-- 回款登记部分 -->
            inva.back_account_status,
            inva.back_account_mode_record,
            inva.back_account_user_id,
            inva.back_account_time,

            <!-- 企业信息扩展-发票抬头信息 -->
            inva.sys_enterprise_ext_invoice_id,
            inva.sys_enterprise_ext_invoice_snapshot,

            inva.sys_org_id,
            inva.sys_virt_id,
            inva.out_org_id,
            inva.out_virt_id,

            inva.remark,
            inva.remark2,

            inva.need_revise_mark,

            inva.attachment_upload_files_uids,

            inva.relation_mode,
            inva.error_check_relation_01,
            inva.error_check_relation_02,

            inva.accounting_order_quantity,
            inva.order_quantity,
            inva.goods_quantity,
            inva.goods_item_quantity,
            inva.credit_quantity,

            inva.order_amount,
            inva.goods_amount,
            inva.goods_cost_amount,
            inva.order_cost_amount,

            inva.update_time,
            inva.update_user_id,

            inva.service_no,
            inva.source_from,

            <!--
            count(distinct invaxg.unified_order_credit_id) as credit_quantity,
            -->

            inva.invoice_apply_amount,
            inva.free_amount,
            inva.un_accounting_amount,
            inva.real_amount,
            inva.no_check_count as no_back_money

        <!--
        MAX(invaxg.back_time) AS max_back_time
        -->

        <!--
        group_concat(DISTINCT ascu.id) AS accounting_order_ids_str,
        group_concat(DISTINCT ascu.accounting_order_sn) AS accounting_order_sns_str
        -->

        FROM
            invoice_apply inva

        <!--
        LEFT JOIN invoice_apply_x_goods invaxg ON inva.id = invaxg.invoice_apply_id

        LEFT JOIN accounting_score_customer ascu ON invaxg.accounting_order_id = ascu.id
        LEFT JOIN unified_order uo on invaxg.unified_order_id = uo.id
        LEFT JOIN unified_order_goods uog on invaxg.unified_order_goods_id = uog.id
        LEFT JOIN unified_order_credit uoc on invaxg.unified_order_credit_id = uoc.id

        LEFT JOIN express_company t9 ON inva.express_company_id = t9.id
        LEFT JOIN sys_enterprise t10 ON ascu.enterprise_id = t10.enterprise_id

        LEFT JOIN sys_user t2 ON inva.apply_user_id = t2.id
        LEFT JOIN sys_user t3 ON inva.audit_user_id = t3.id
        LEFT JOIN sys_user t4 ON inva.make_invoice_user_id = t4.id
        LEFT JOIN sys_user t5 ON inva.mail_tick_user_id = t5.id
        LEFT JOIN sys_user su1 ON uo.purchase_user_id = su1.id
        -->


        <where>

            <!-- 积分订单 -->
            and inva.accounting_order_type = 2
            <!--
            and invaxg.accounting_order_type = 2
            -->
            <include refid="findViewWhereIf"></include>
        </where>

        GROUP BY inva.id
        order by inva.apply_time DESC
    </select>


    <select id="findViewHeadData"
            parameterType="cn.superdesk.uniorder.dto.param.invoice.customer.InvoiceApplyCustomerQueryCriteria"
            resultMap="findViewHeadDataResultMap">

        SELECT
            count(inva.id) AS invoice_apply_quantity,
            SUM(inva.accounting_order_quantity) AS accounting_order_quantity,
            SUM(inva.order_quantity) AS order_quantity,
            SUM(inva.goods_quantity) AS goods_quantity,
            SUM(inva.goods_item_quantity) AS goods_item_quantity,
            SUM(inva.credit_quantity) AS credit_quantity,

            SUM(inva.order_amount) as order_amount,
            SUM(inva.goods_amount) as goods_amount,
            SUM(inva.goods_cost_amount) as goods_cost_amount,
            SUM(inva.order_cost_amount) as order_cost_amount,

            SUM(inva.invoice_apply_amount) as invoice_apply_amount,
            SUM(inva.free_amount) as free_amount,
            SUM(inva.un_accounting_amount) as un_accounting_amount,
            SUM(inva.real_amount) as real_amount
        FROM
            invoice_apply inva
            <!--
            LEFT JOIN invoice_apply_x_goods invaxg ON inva.id = invaxg.invoice_apply_id

            LEFT JOIN accounting_score_customer ascu ON invaxg.accounting_order_id = ascu.id
            LEFT JOIN unified_order uo on invaxg.unified_order_id = uo.id
            LEFT JOIN unified_order_goods uog on invaxg.unified_order_goods_id = uog.id
            LEFT JOIN unified_order_credit uoc on invaxg.unified_order_credit_id = uoc.id

            LEFT JOIN express_company t9 ON inva.express_company_id = t9.id
            LEFT JOIN sys_enterprise t10 ON ascu.enterprise_id = t10.enterprise_id

            LEFT JOIN sys_user t2 ON inva.apply_user_id = t2.id
            LEFT JOIN sys_user t3 ON inva.audit_user_id = t3.id
            LEFT JOIN sys_user t4 ON inva.make_invoice_user_id = t4.id
            LEFT JOIN sys_user t5 ON inva.mail_tick_user_id = t5.id
            LEFT JOIN sys_user su1 ON uo.purchase_user_id = su1.id
            -->
        <where>
            <include refid="findViewWhereIf"></include>
        </where>

    </select>
    <!-- 积分结算 发票申请管理 List & Head   end -->

    <!-- 积分结算 发票管理 List & Head start -->

    <select id="findInvoiceListByPageV2_1"
            parameterType="cn.superdesk.uniorder.dto.param.invoice.customer.InvoiceApplyCustomerQueryCriteria"
            resultMap="InvoiceApplyPageResultMap">

        SELECT

            inva.id,
            inva.accounting_order_type,
            inva.dim_create_by,
            inva.accounting_order_id,
            inva.accounting_order_sn,

            inva.invoice_apply_sn,

            inva.invoice_number,
            inva.invoice_title,
            inva.invoice_type,
            inva.invoice_mode,
            inva.tax_rate,

            <!-- 发票申请部分 -->
            inva.apply_user_id,
            inva.apply_time,

            <!-- 发票申请审核部分 -->
            inva.audit_user_id,
            inva.audit_status,
            inva.audit_time,

            <!-- 开票进展部分 -->
            inva.invoice_status,
            inva.invoice_progressing_user_id,
            inva.invoice_progressing_time,

            <!-- 发票登记部分 -->
            inva.make_invoice_user_id,
            inva.make_invoice_time,
            inva.make_invoice_status,

            <!-- 运营领票部分 -->
            inva.receive_invoice_status,
            inva.receive_invoice_user_id,
            inva.receive_invoice_time,

            <!-- 寄票登记部分 -->
            inva.mail_tick_user_id,
            inva.mail_tick_status,
            inva.mail_tick_time,

            inva.express_company_id,
            inva.express_no,
            --         t9.company_name as express_company_name,

            <!-- 回款登记部分 -->
            inva.back_account_status,
            inva.back_account_mode_record,
            inva.back_account_user_id,
            inva.back_account_time,

            <!-- 企业信息扩展-发票抬头信息 -->
            inva.sys_enterprise_ext_invoice_id,
            inva.sys_enterprise_ext_invoice_snapshot,

            inva.sys_org_id,
            inva.sys_virt_id,
            inva.out_org_id,
            inva.out_virt_id,

            inva.remark,
            inva.remark2,

            inva.need_revise_mark,

            inva.attachment_upload_files_uids,

            inva.relation_mode,
            inva.error_check_relation_01,
            inva.error_check_relation_02,

            inva.accounting_order_quantity,
            inva.order_quantity,
            inva.goods_quantity,
            inva.goods_item_quantity,
            inva.credit_quantity,

            inva.order_amount,
            inva.goods_amount,
            inva.goods_cost_amount,
            inva.order_cost_amount,

            inva.update_time,
            inva.update_user_id,

            inva.service_no,
            inva.source_from,

            inva.invoice_apply_amount,
            inva.free_amount,
            inva.un_accounting_amount,
            inva.real_amount,
            inva.no_check_count as no_back_money,

            ascu.invoice_status as accounting_order_invoice_status


        FROM
            invoice_apply inva
            LEFT JOIN accounting_score_customer ascu ON inva.accounting_order_id = ascu.id
        <!--
        LEFT JOIN invoice_apply_x_goods invaxg ON inva.id = invaxg.invoice_apply_id

        LEFT JOIN accounting_score_customer ascu ON invaxg.accounting_order_id = ascu.id
        LEFT JOIN unified_order uo on invaxg.unified_order_id = uo.id
        LEFT JOIN unified_order_goods uog on invaxg.unified_order_goods_id = uog.id
        LEFT JOIN unified_order_credit uoc on invaxg.unified_order_credit_id = uoc.id

        LEFT JOIN express_company t9 ON inva.express_company_id = t9.id
        LEFT JOIN sys_enterprise t10 ON ascu.enterprise_id = t10.enterprise_id

        LEFT JOIN sys_user t2 ON inva.apply_user_id = t2.id
        LEFT JOIN sys_user t3 ON inva.audit_user_id = t3.id
        LEFT JOIN sys_user t4 ON inva.make_invoice_user_id = t4.id
        LEFT JOIN sys_user t5 ON inva.mail_tick_user_id = t5.id
        LEFT JOIN sys_user su1 ON uo.purchase_user_id = su1.id
        -->


        <where>

            <!-- 积分订单 -->
            and inva.accounting_order_type = 2
            <!--
            and invaxg.accounting_order_type = 2
            -->
            <include refid="findViewWhereIf"></include>
        </where>

        GROUP BY inva.id
        order by ascu.create_time DESC,inva.apply_time DESC
    </select>



    <select id="findInvoiceHeadDataV2_1"
            parameterType="cn.superdesk.uniorder.dto.param.invoice.customer.InvoiceApplyCustomerQueryCriteria"
            resultMap="findViewHeadDataResultMap">

        SELECT
            count(inva.id) AS invoice_apply_quantity,
            SUM(inva.accounting_order_quantity) AS accounting_order_quantity,
            SUM(inva.order_quantity) AS order_quantity,
            SUM(inva.goods_quantity) AS goods_quantity,
            SUM(inva.goods_item_quantity) AS goods_item_quantity,
            SUM(inva.credit_quantity) AS credit_quantity,

            SUM(inva.order_amount) as order_amount,
            SUM(inva.goods_amount) as goods_amount,
            SUM(inva.goods_cost_amount) as goods_cost_amount,
            SUM(inva.order_cost_amount) as order_cost_amount,

            SUM(inva.invoice_apply_amount) as invoice_apply_amount,
            SUM(inva.free_amount) as free_amount,
            SUM(inva.un_accounting_amount) as un_accounting_amount,
            SUM(inva.real_amount) as real_amount
        FROM
            invoice_apply inva
            LEFT JOIN accounting_score_customer ascu ON inva.accounting_order_id = ascu.id
        <!--
        LEFT JOIN invoice_apply_x_goods invaxg ON inva.id = invaxg.invoice_apply_id


        LEFT JOIN unified_order uo on invaxg.unified_order_id = uo.id
        LEFT JOIN unified_order_goods uog on invaxg.unified_order_goods_id = uog.id
        LEFT JOIN unified_order_credit uoc on invaxg.unified_order_credit_id = uoc.id

        LEFT JOIN express_company t9 ON inva.express_company_id = t9.id
        LEFT JOIN sys_enterprise t10 ON ascu.enterprise_id = t10.enterprise_id

        LEFT JOIN sys_user t2 ON inva.apply_user_id = t2.id
        LEFT JOIN sys_user t3 ON inva.audit_user_id = t3.id
        LEFT JOIN sys_user t4 ON inva.make_invoice_user_id = t4.id
        LEFT JOIN sys_user t5 ON inva.mail_tick_user_id = t5.id
        LEFT JOIN sys_user su1 ON uo.purchase_user_id = su1.id
        -->
        <where>
            <include refid="findViewWhereIf"></include>
        </where>

    </select>

    <!-- 积分结算 发票管理 List & Head   end -->
</mapper>
