<?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')=to_char(sysdate,'yyyy')) year_count,
                        
  (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='01') jan_count, 
   (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='02') feb_count,
   (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='03') mar_count,  
   (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='04') apr_count, 
   (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='05') may_count,  
   (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='06') jun_count, 
   (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='07') jul_count,  
   (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='08') aug_count, 
    (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='09') sep_count,  
    (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='10') oct_count, 
    (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='11') nov_count,
   (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')=to_char(sysdate,'yyyy') and
                        to_char(c.creation_date,'mm')='12') dec_count          
                        
                        from dual
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="year_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="YEAR_COUNT"/>
        <bm:field name="jan_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="JAN_COUNT"/>
        <bm:field name="feb_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FEB_COUNT"/>
        <bm:field name="mar_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="MAR_COUNT"/>
        <bm:field name="apr_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="APR_COUNT"/>
        <bm:field name="may_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="MAY_COUNT"/>
        <bm:field name="jun_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="JUN_COUNT"/>
        <bm:field name="jul_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="JUL_COUNT"/>
        <bm:field name="aug_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="AUG_COUNT"/>
        <bm:field name="sep_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SEP_COUNT"/>
        <bm:field name="oct_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="OCT_COUNT"/>
        <bm:field name="nov_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="NOV_COUNT"/>
        <bm:field name="dec_count" databaseType="NUMBER" datatype="java.lang.Long" physicalName="DEC_COUNT"/>
    </bm:fields>
</bm:model>
