<?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.cf_item,
                        (SELECT
                            tp.description
                        FROM
                            hls_cashflow_item tp
                        WHERE
                            tp.cf_item = t.cf_item
                        ) cf_item_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,
                        t.outstanding_prin_tax_incld
                    FROM
                        con_contract_cashflow t
                    WHERE
                        t.contract_id     = ${@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.cf_item,
                    (SELECT
                        tp.description
                    FROM
                        hls_cashflow_item tp
                    WHERE
                        tp.cf_item = l.cf_item
                    ) cf_item_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,
                    l.outstanding_amount outstanding_prin_tax_incld
                FROM
                    con_contract_et_ln l,
                    con_contract_et_hd h
                WHERE
                    l.et_agreement_id = ${@et_agreement_id} AND
                    l.et_agreement_id = h.et_agreement_id AND
                    h.status         <>'APPROVED'
            ]]></bm:query-sql>
            <bm:parameters>
                <bm:parameter name="contract_id"/>
                <bm:parameter name="et_agreement_id"/>
            </bm:parameters>
        </bm:operation>
    </bm:operations>
</bm:model>
