<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wuyulun  
    $Date: 2015-7-15 下午4:05:25  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" rootpath="zj_wfl_45days">
    <bm:fields>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="bp_id_tenant_n" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="last_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="days" databaseType="NUMBER" datatype="java.lang.Long"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        *
                    FROM
                        (SELECT
                            b.contract_id ,
                            b.contract_number ,
                            b.bp_id_tenant ,
                            b.bp_id_tenant_n ,
                            MAX(a.due_date) last_date ,
                            MAX(a.due_date)-TRUNC(sysdate) days
                        FROM
                            con_contract_cashflow a,
                            con_contract_lv b
                        WHERE
                            a.contract_id     =b.contract_id AND
                            b.data_class      = 'NORMAL' AND
                            a.cf_type         =1 AND
                            b.contract_status = 'INCEPT'
                        GROUP BY
                            b.contract_id,
                            b.contract_number,
                            b.bp_id_tenant,
                            b.bp_id_tenant_n
                        )
                    WHERE
                        days <= 15
                    ) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:primary-key>
        <bm:pk-field name="contract_id"/>
    </bm:primary-key>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="exists (select 1 from sys_user_role_groups a where a.user_id=${/session/@user_id} and role_id in (160,1))"/>
    </bm:data-filters>
</bm:model>