<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm  
    $Date: 2013-7-15 下午7:59:08  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
            select * from (
                SELECT
                    t.times,
                    t.cf_type,
                    (SELECT tp.description FROM hls_cashflow_type tp WHERE tp.cf_type = t.cf_type
                    ) cf_type_dis,
                    t.due_amount,
                    t.received_amount,
                     to_char(t.due_date,'yyyy-mm-dd') due_date,
                    t.principal - NVL(t.received_principal, 0) principal,
                    t.interest - NVL(t.received_interest, 0) interest,
                    t.cf_status,
                    (SELECT
                        v.code_value_name
                    FROM
                        sys_code_values_v v
                    WHERE
                        v.code       = 'HLS005_CF_STATUS' AND
                        v.code_value = t.cf_status
                    ) cf_status_dis
                FROM
                    con_contract_cashflow t
                WHERE
                    (t.contract_id     = ${@contract_id}
                    or exists (
 		select 1 from con_contract_et_hd where et_agreement_id = ${@et_agreement_id} and contract_id = t.contract_id))
                     AND
                    t.write_off_flag <> 'FULL'
                    and t.cf_direction='INFLOW'
                order by  t.times,t.cf_type
                    )
                UNION ALL
                SELECT
                    l.times,
                    l.cf_type,
                    (SELECT tp.description FROM hls_cashflow_type tp WHERE tp.cf_type = l.cf_type
                    ) cf_type_dis,
                    l.due_amount,
                    NULL received_amount,
                    to_char(l.due_date,'yyyy-mm-dd') due_date,
                    l.principal,
                    l.interest,
                    l.cf_status,
                    (SELECT
                        v.code_value_name
                    FROM
                        sys_code_values_v v
                    WHERE
                        v.code       = 'HLS005_CF_STATUS' AND
                        v.code_value = l.cf_status
                    ) cf_status_dis
                FROM
                    con_contract_et_ln l
                WHERE
                    l.et_agreement_id = ${@et_agreement_id}
            ]]></bm:query-sql>
            <bm:parameters>
                <bm:parameter name="contract_id"/>
                <bm:parameter name="et_agreement_id"/>
            </bm:parameters>
        </bm:operation>
    </bm:operations>
</bm:model>
