<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2013-9-9 下午03:33:56  
    $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 bp.bp_name,
		       bp.bp_id,
		       con.contract_number,
		       cf.times,
		       nvl(cf.due_amount,0)due_amount,
		       cf.due_date,
		       nvl(cf.principal,0) principal,
		       nvl(cf.interest,0) interest,
		       (SELECT write_off_date FROM csh_write_off WHERE cashflow_id = cf.cashflow_id AND reversed_flag = 'N' AND ROWNUM = 1)write_off_date,
		       (SELECT SUM(write_off_due_amount) FROM csh_write_off WHERE cashflow_id = cf.cashflow_id AND reversed_flag = 'N')write_off_due_amount,
		       (SELECT SUM(write_off_principal) FROM csh_write_off WHERE cashflow_id = cf.cashflow_id AND reversed_flag = 'N')write_off_principal,
		       (SELECT SUM(write_off_interest) FROM csh_write_off WHERE cashflow_id = cf.cashflow_id AND reversed_flag = 'N')write_off_interest,
		       con.contract_id
		  FROM con_contract_cashflow cf,
		       con_contract          con,
		       hls_bp_master         bp
		 WHERE con.contract_id = cf.contract_id
		       AND con.bp_id_tenant = bp.bp_id
		       AND cf.cf_item = 1
		       AND cf.cf_type = 1
		       AND con.contract_id = ${@contract_id}
		 ORDER BY cf.times ASC
		]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="bp_name"/>
        <bm:field name="contract_number"/>
        <bm:field name="times"/>
        <bm:field name="due_amount"/>
        <bm:field name="due_date" databaseType="Date" datatype="java.util.Date"/>
        <bm:field name="principal"/>
        <bm:field name="interest"/>
        <bm:field name="write_off_date" databaseType="Date" datatype="java.util.Date"/>
        <bm:field name="write_off_due_amount"/>
        <bm:field name="write_off_principal"/>
        <bm:field name="write_off_interest"/>
    </bm:fields>
</bm:model>
