<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: 王建文  
    $Date: 2017-3-6 下午7:49:17  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    (SELECT
                        ROUND(nvl(SUM(cc.principal),0),0)
                    FROM
                        con_contract_cashflow cc,
                        con_contract c
                    WHERE
                        cc.contract_id =c.contract_id AND
                        to_char(c.creation_date,'yyyy-mm')=to_char(sysdate,'yyyy-mm') 
                    ) put_total,
                    (SELECT
                        ROUND(nvl(SUM(cc.received_principal),0),0)
                    FROM
                        con_contract_cashflow cc,
                        con_contract c
                    WHERE
                        cc.contract_id =c.contract_id AND
                        to_char(c.creation_date,'yyyy-mm')=to_char(sysdate,'yyyy-mm') 
                    ) received_total,
                    ((SELECT
                        ROUND(nvl(SUM(cc.principal),0),0)
                    FROM
                        con_contract_cashflow cc,
                        con_contract c
                    WHERE
                        cc.contract_id =c.contract_id AND
                        to_char(c.creation_date,'yyyy-mm')=to_char(sysdate,'yyyy-mm') 
                    )-(SELECT
                        ROUND(nvl(SUM(cc.received_principal),0),0)
                    FROM
                        con_contract_cashflow cc,
                        con_contract c
                    WHERE
                        cc.contract_id =c.contract_id AND
                        to_char(c.creation_date,'yyyy-mm')=to_char(sysdate,'yyyy-mm') 
                    )) unrecevie_total
                FROM
                    dual
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="put_total" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PUT_TOTAL"/>
        <bm:field name="received_total" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RECEIVED_TOTAL"/>
        <bm:field name="unrecevie_total" databaseType="NUMBER" datatype="java.lang.Long" physicalName="UNRECEVIE_TOTAL"/>
    </bm:fields>
</bm:model>
