<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2018/6/25 13:13
    $Revision: 1.0 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
             Select t1.*
              From (Select tc.assets_id,
                           (Select a.assets_number
                              From tre_assets_contract a
                             Where a.assets_id = tc.assets_id) assets_number,
                           tc.contract_id,
                           tc.loan_contract_id,
                           tc.mark_status,
                           (Select v.code_value_name
                              From sys_code_values_v v
                             Where v.code = 'TRE_ASSETS_MARK_STATUS'
                               And v.code_value = tc.mark_status) mark_status_n,
                           tc.mark_time,
                           (Select bp.bp_name
                              From hls_bp_master bp
                             Where bp.bp_id = cc.bp_id_tenant) bp_name,
                           (Select Sum(nvl(ccc.due_amount, 0))
                              From con_contract_cashflow ccc
                             Where ccc.contract_id = tc.contract_id
                               And ccc.cf_item = 1
                               And ccc.cf_direction = 'INFLOW'
                               And ccc.cf_status = 'RELEASE') total_rent,
                           cc.contract_status,
                           (Select v.code_value_name
                              From sys_code_values_v v
                             Where v.code = 'CON500_CONTRACT_STATUS'
                               And v.code_value = cc.contract_status) As contract_status_n,
                           cc.contract_number,
                           cc.contract_name
                      From tre_assets_contract_ln tc, con_contract cc
                     Where tc.contract_id(+) = cc.contract_id
                       and cc.data_class = 'NORMAL'
                       And cc.contract_status In ('INCEPT', 'PENDING')) t1

                  #WHERE_CLAUSE#

]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="assets_id"/>
        <bm:field name="assets_number"/>
        <bm:field name="contract_id"/>
        <bm:field name="loan_contract_id"/>
        <bm:field name="mark_status"/>
        <bm:field name="mark_time"/>
        <bm:field name="bp_name"/>
        <bm:field name="total_rent"/>
        <bm:field name="contract_status"/>
        <bm:field name="contract_status_n"/>
        <bm:field name="contract_number"/>
        <bm:field name="contract_name"/>
        <bm:field name="mark_status_n"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/>
        <bm:query-field name="contract_name" queryExpression="t1.contract_name  like ${@contract_name}"/>
        <bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/>
        <bm:query-field name="mark_status"
                        queryExpression="t1.mark_status =  ${@mark_status}"/>
    </bm:query-fields>
</bm:model>