<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        b.contract_number,
                        b.search_term_1,
                        b.contract_status,
                        (SELECT
                            v.code_value_name
                        FROM
                            sys_code_values_v v
                        WHERE
                            v.code       = 'CON500_CONTRACT_STATUS' AND
                            v.code_value = b.contract_status
                        ) AS contract_status_n,
                        a.internal_period_num,
                        TO_CHAR(a.calc_start_date,'YYYY-MM-DD') calc_start_date,
                        TO_CHAR(a.calc_end_date,'YYYY-MM-DD') calc_end_date,
                        a.times,
                        a.unearned_finance_income,
                        a.finance_income_recognized,
                        b.vat_flag,
                        b.business_type,
                        b.business_type_n,
                        b.legal_status_n,
               			b.fin_income_suspend_flag
                    FROM
                        con_unearned_finance_income a,
                        con_contract_lv b
                    WHERE
                        a.company_id               =${/session/@company_id} AND
                        a.contract_id              = b.contract_id AND
                        a.unearned_finance_income IS NOT NULL AND
                        b.data_class               = 'NORMAL'
                    ORDER BY
                        contract_number,
                        internal_period_num,
                        calc_start_date
                    ) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="contract_number" queryExpression="contract_number like ${@contract_number}"/>
        <bm:query-field name="search_term_1" queryExpression="search_term_1 like ${@search_term_1}"/>
        <bm:query-field name="internal_period_num" queryExpression="internal_period_num like ${@internal_period_num}"/>
        <bm:query-field name="calc_start_date" queryExpression="calc_start_date &gt;= ${@calc_start_date}"/>
        <bm:query-field name="calc_end_date" queryExpression="calc_end_date &lt;= ${@calc_end_date}"/>
    </bm:query-fields>
</bm:model>
