<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm
    $Date: 2013-12-28 下午1:31:12
    $Revision: 1.0
    $Purpose:
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="CON_UNEARNED_FINANCE_INCOME">
    <bm:fields>
        <bm:field name="seq" databaseType="NUMBER" datatype="java.lang.Long" expression="(row_number() over(order by t1.contract_id))"/>
        <bm:field name="record_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RECORD_ID" prompt="CON_UNEARNED_FINANCE_INCOME.RECORD_ID"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="COMPANY_ID" prompt="CON_UNEARNED_FINANCE_INCOME.COMPANY_ID"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="CON_UNEARNED_FINANCE_INCOME.CONTRACT_ID"/>
        <bm:field name="internal_period_num" databaseType="NUMBER" datatype="java.lang.Long" physicalName="INTERNAL_PERIOD_NUM" prompt="CON_UNEARNED_FINANCE_INCOME.INTERNAL_PERIOD_NUM"/>
        <bm:field name="cf_item" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CF_ITEM" prompt="CON_UNEARNED_FINANCE_INCOME.CF_ITEM"/>
        <bm:field name="seq_in_period" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SEQ_IN_PERIOD" prompt="CON_UNEARNED_FINANCE_INCOME.SEQ_IN_PERIOD"/>
        <bm:field name="unearned_finance_income" databaseType="NUMBER" datatype="java.lang.Double" physicalName="UNEARNED_FINANCE_INCOME" prompt="CON_UNEARNED_FINANCE_INCOME.UNEARNED_FINANCE_INCOME"/>
        <bm:field name="financing_cost" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FINANCING_COST" prompt="CON_UNEARNED_FINANCE_INCOME.FINANCING_COST"/>
        <bm:field name="main_business_income" databaseType="NUMBER" datatype="java.lang.Long" physicalName="MAIN_BUSINESS_INCOME" prompt="CON_UNEARNED_FINANCE_INCOME.MAIN_BUSINESS_INCOME"/>
        <bm:field name="main_business_cost" databaseType="NUMBER" datatype="java.lang.Long" physicalName="MAIN_BUSINESS_COST" prompt="CON_UNEARNED_FINANCE_INCOME.MAIN_BUSINESS_COST"/>
        <bm:field name="unearned_finance_income_balanc" databaseType="NUMBER" datatype="java.lang.Long" physicalName="UNEARNED_FINANCE_INCOME_BALANC" prompt="CON_UNEARNED_FINANCE_INCOME.UNEARNED_FINANCE_INCOME_BALANC"/>
        <bm:field name="finance_income_recognized" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FINANCE_INCOME_RECOGNIZED" prompt="CON_UNEARNED_FINANCE_INCOME.FINANCE_INCOME_RECOGNIZED"/>
        <bm:field name="weight_factor" databaseType="NUMBER" datatype="java.lang.Long" physicalName="WEIGHT_FACTOR" prompt="CON_UNEARNED_FINANCE_INCOME.WEIGHT_FACTOR"/>
        <bm:field name="total_weight" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TOTAL_WEIGHT" prompt="CON_UNEARNED_FINANCE_INCOME.TOTAL_WEIGHT"/>
        <bm:field name="factor_days" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_DAYS" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_DAYS"/>
        <bm:field name="factor_outstanding_principal" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_OUTSTANDING_PRINCIPAL" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_OUTSTANDING_PRINCIPAL"/>
        <bm:field name="factor_interest_accrual_balanc" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_INTEREST_ACCRUAL_BALANC" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_INTEREST_ACCRUAL_BALANC"/>
        <bm:field name="factor_reserved1" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_RESERVED1" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_RESERVED1"/>
        <bm:field name="factor_reserved2" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_RESERVED2" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_RESERVED2"/>
        <bm:field name="factor_reserved3" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FACTOR_RESERVED3" prompt="CON_UNEARNED_FINANCE_INCOME.FACTOR_RESERVED3"/>
        <bm:field name="cashflow_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CASHFLOW_ID" prompt="CON_UNEARNED_FINANCE_INCOME.CASHFLOW_ID"/>
        <bm:field name="times" databaseType="NUMBER" datatype="java.lang.Long" physicalName="TIMES" prompt="CON_UNEARNED_FINANCE_INCOME.TIMES"/>
        <bm:field name="cf_type" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CF_TYPE" prompt="CON_UNEARNED_FINANCE_INCOME.CF_TYPE"/>
        <bm:field name="calc_start_date" databaseType="DATE" datatype="java.util.Date" physicalName="CALC_START_DATE" prompt="CON_UNEARNED_FINANCE_INCOME.CALC_START_DATE"/>
        <bm:field name="calc_end_date" databaseType="DATE" datatype="java.util.Date" physicalName="CALC_END_DATE" prompt="CON_UNEARNED_FINANCE_INCOME.CALC_END_DATE"/>
        <bm:field name="project_name" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select p.project_name from prj_project p ,con_contract c where c.contract_id = t1.contract_id and p.project_id = c.project_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="finance_amount" databaseType="NUMBER" datatype="java.lang.Double" expression="(select c.finance_amount from con_contract c where c.contract_id = t1.contract_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="period" databaseType="VARCHAR2" datatype="java.lang.String" expression="((CASE WHEN t1.cf_item = 8 THEN (SELECT to_char(cf1.due_date,&apos;yyyy/mm/dd&apos;) FROM con_contract_cashflow cf1 WHERE cf1.contract_id = t1.contract_id  AND cf1.cf_item = t1.cf_item)|| '-' ||(SELECT    TO_CHAR(cf.due_date, &apos;yyyy/mm/dd&apos;)  FROM con_contract_cashflow cf  WHERE   cf.cashflow_id = t1.cashflow_id) ELSE ( (SELECT to_char(cf1.due_date,&apos;yyyy/mm/dd&apos;) FROM con_contract_cashflow cf1 WHERE cf1.contract_id = t1.contract_id   AND cf1.cf_item = t1.cf_item AND cf1.times = (SELECT cf.times - 1  FROM con_contract_cashflow cf  WHERE cf.cashflow_id = t1.cashflow_id)) || nvl2((Select to_char(cf1.due_date, 'yyyy/mm/dd') From con_contract_cashflow cf1 Where cf1.contract_id = t1.contract_id And cf1.cf_item = t1.cf_item And cf1.times = (Select cf.times - 1 From con_contract_cashflow cf Where cf.cashflow_id = t1.cashflow_id)), '-', '') || (SELECT TO_CHAR(cf.due_date -1, &apos;yyyy/mm/dd&apos;)  FROM con_contract_cashflow cf  WHERE cf.cashflow_id = t1.cashflow_id))END))" forInsert="false" forUpdate="false"/>
        <bm:field name="interest" databaseType="NUMBER" datatype="java.lang.Double" expression="(select c.interest from con_contract_cashflow c where c.cashflow_id = t1.cashflow_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="int_rate_implicit" databaseType="NUMBER" datatype="java.lang.Double" expression="round((select c.int_rate from con_contract c where c.contract_id = t1.contract_id),4)" forInsert="false" forUpdate="false"/>
        <bm:field name="calc_period" databaseType="VARCHAR2" datatype="java.lang.String" expression="(to_char(t1.calc_start_date,&apos;yyyy/mm/dd&apos;)||&apos;-&apos;||to_char(t1.calc_end_date,&apos;yyyy/mm/dd&apos;))" forInsert="false" forUpdate="false"/>
        <bm:field name="calc_date_count" databaseType="NUMBER" datatype="java.lang.Long" expression="(t1.calc_end_date-t1.calc_start_date+1)" forInsert="false" forUpdate="false"/>
        <bm:field name="vat_unearned_finance_income" databaseType="NUMBER" datatype="java.lang.Double" expression="(t1.unearned_finance_income*(select decode(t.tax_type_id,1,1,1+(select c.tax_type_rate   from fnd_tax_type_codes c  where c.tax_type_id = t.tax_type_id))  from con_contract t           where t.contract_id = t1.contract_id))" forInsert="false" forUpdate="false"/>
        <bm:field name="current_month_vat_income" databaseType="NUMBER" datatype="java.lang.Double" expression="ROUND((select sum(t.unearned_finance_income*(select decode(t.tax_type_id,                        1,                        1,                        1+(select c.tax_type_rate                           from fnd_tax_type_codes c                          where c.tax_type_id = t.tax_type_id))            from con_contract t           where t.contract_id = t1.contract_id)) from con_unearned_finance_income t where t.contract_id =t1.contract_id and t.internal_period_num =${@internal_period_num} ),(select c.PRECISION from gld_currency c,con_contract ct where c.currency_code = ct.currency and ct.contract_id = t1.contract_id))" forInsert="false" forUpdate="false"/>
        <bm:field name="current_month_income" databaseType="NUMBER" datatype="java.lang.Double" expression="(select sum(t.unearned_finance_income) from con_unearned_finance_income t where t.contract_id =t1.contract_id and t.internal_period_num =${@internal_period_num})" forInsert="false" forUpdate="false"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select t.contract_number from con_contract t where t.contract_id =t1.contract_id )" forInsert="false" forUpdate="false"/>
        <bm:field name="contract_name" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select t.contract_name from con_contract t where t.contract_id =t1.contract_id )" forInsert="false" forUpdate="false"/>
        <bm:field name="adjustvat"/>
        <bm:field name="adjustvat13"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="record_id"/>
    </bm:primary-key>
      <bm:operations>
            <bm:operation name="query">
                <bm:query-sql><![CDATA[
            select * from(
                SELECT (row_number() over(order by t1.contract_id)) AS seq,
                       t1.RECORD_ID,
                       t1.COMPANY_ID,
                       t1.CONTRACT_ID,
                       t1.INTERNAL_PERIOD_NUM,
                       t1.CF_ITEM,
                       t1.SEQ_IN_PERIOD,
                       t1.UNEARNED_FINANCE_INCOME,
                       t1.FINANCING_COST,
                       t1.MAIN_BUSINESS_INCOME,
                       t1.MAIN_BUSINESS_COST,
                       t1.UNEARNED_FINANCE_INCOME_BALANC,
                       t1.FINANCE_INCOME_RECOGNIZED,
                       t1.WEIGHT_FACTOR,
                       t1.TOTAL_WEIGHT,
                       t1.FACTOR_DAYS,
                       t1.FACTOR_OUTSTANDING_PRINCIPAL,
                       t1.FACTOR_INTEREST_ACCRUAL_BALANC,
                       t1.FACTOR_RESERVED1,
                       t1.FACTOR_RESERVED2,
                       t1.FACTOR_RESERVED3,
                       t1.CASHFLOW_ID,
                       t1.TIMES,
                       t1.CF_TYPE,
                       t1.CALC_START_DATE,
                       t1.CALC_END_DATE,
                       (select p.project_name
                          from prj_project p, con_contract c
                         where c.contract_id = t1.contract_id
                           and p.project_id = c.project_id) AS project_name,
                       (select c.finance_amount
                          from con_contract c
                         where c.contract_id = t1.contract_id) AS finance_amount,
                       ((CASE
                         WHEN t1.cf_item = 8 THEN
                          (SELECT to_char(cf1.due_date, 'yyyy/mm/dd')
                             FROM con_contract_cashflow cf1
                            WHERE cf1.contract_id = t1.contract_id
                              AND cf1.cf_item = t1.cf_item) || '-' ||
                          (SELECT TO_CHAR(cf.due_date, 'yyyy/mm/dd')
                             FROM con_contract_cashflow cf
                            WHERE cf.cashflow_id = t1.cashflow_id)
                         ELSE
                          ((SELECT to_char(cf1.due_date, 'yyyy/mm/dd')
                              FROM con_contract_cashflow cf1
                             WHERE cf1.contract_id = t1.contract_id
                               AND cf1.cf_item = t1.cf_item
                               AND cf1.times =
                                   (SELECT cf.times - 1
                                      FROM con_contract_cashflow cf
                                     WHERE cf.cashflow_id = t1.cashflow_id)) ||
                          nvl2((Select to_char(cf1.due_date, 'yyyy/mm/dd')
                                  From con_contract_cashflow cf1
                                 Where cf1.contract_id = t1.contract_id
                                   And cf1.cf_item = t1.cf_item
                                   And cf1.times =
                                       (Select cf.times - 1
                                          From con_contract_cashflow cf
                                         Where cf.cashflow_id = t1.cashflow_id)),
                                '-',
                                '') ||
                          (SELECT TO_CHAR(cf.due_date - 1, 'yyyy/mm/dd')
                              FROM con_contract_cashflow cf
                             WHERE cf.cashflow_id = t1.cashflow_id))
                       END)) AS period,
                       (select c.interest
                          from con_contract_cashflow c
                         where c.cashflow_id = t1.cashflow_id) AS interest,
                       round((select c.int_rate
                               from con_contract c
                              where c.contract_id = t1.contract_id),
                             4) AS int_rate_implicit,
                       (to_char(t1.calc_start_date, 'yyyy/mm/dd') || '-' ||
                       to_char(t1.calc_end_date, 'yyyy/mm/dd')) AS calc_period,
                       (t1.calc_end_date - t1.calc_start_date + 1) AS calc_date_count,
                       (t1.unearned_finance_income *
                       (select decode(t.tax_type_id,
                                       1,
                                       1,
                                       1 + (select c.tax_type_rate
                                              from fnd_tax_type_codes c
                                             where c.tax_type_id = t.tax_type_id))
                           from con_contract t
                          where t.contract_id = t1.contract_id)) AS vat_unearned_finance_income,
                       ROUND((select sum(t.unearned_finance_income *
                                        (select decode(t.tax_type_id,
                                                       1,
                                                       1,
                                                       1 +
                                                       (select c.tax_type_rate
                                                          from fnd_tax_type_codes c
                                                         where c.tax_type_id = t.tax_type_id))
                                           from con_contract t
                                          where t.contract_id = t1.contract_id))
                               from con_unearned_finance_income t
                              where t.contract_id = t1.contract_id
                                and t.internal_period_num = ${@internal_period_num}),
                             (select c.PRECISION
                                from gld_currency c, con_contract ct
                               where c.currency_code = ct.currency
                                 and ct.contract_id = t1.contract_id)) AS current_month_vat_income,
                       (select sum(t.unearned_finance_income)
                          from con_unearned_finance_income t
                         where t.contract_id = t1.contract_id
                           and t.internal_period_num = ${@internal_period_num}) AS current_month_income,
                       (select t.contract_number
                          from con_contract t
                         where t.contract_id = t1.contract_id) AS contract_number,
                       (select t.contract_name
                          from con_contract t
                         where t.contract_id = t1.contract_id) AS contract_name,
                       t1.adjustvat,
                       t1.adjustvat13
                  FROM CON_UNEARNED_FINANCE_INCOME t1
                 WHERE t1.internal_period_num = ${@internal_period_num}
                   and exists (Select 1
                          From con_contract cc
                         Where t1.contract_id = cc.contract_id
                           And cc.data_class = 'NORMAL'
                           And t1.cf_item In (1, 8)
                           And ((t1.cf_item = 1 And
                               cc.contract_status In
                               ('TERMINATE', 'INCEPT', 'ETING', 'REPURING')) Or
                               (t1.cf_item = 8 And
                               cc.contract_status In ('TERMINATE', 'INCEPT'))))
                   and exists (select 1
                          from con_contract_cashflow c
                         where c.cashflow_id = t1.cashflow_id
                           and c.interest is not null)
                   AND to_char(t1.calc_end_date, 'yyyy-mm-dd') = ${@calc_end_date}
                   AND t1.cashflow_id in
                       (select cw.cashflow_id
                          from con_contract_cashflow cw
                         where cw.cf_direction not in ('NONCASH'))
               union
                SELECT (row_number() over(order by t1.contract_id)) AS seq,
                                      t1.RECORD_ID,
                                      t1.COMPANY_ID,
                                      t1.CONTRACT_ID,
                                      t1.INTERNAL_PERIOD_NUM,
                                      t1.CF_ITEM,
                                      t1.SEQ_IN_PERIOD,
                                      t1.UNEARNED_FINANCE_INCOME,
                                      t1.FINANCING_COST,
                                      t1.MAIN_BUSINESS_INCOME,
                                      t1.MAIN_BUSINESS_COST,
                                      t1.UNEARNED_FINANCE_INCOME_BALANC,
                                      t1.FINANCE_INCOME_RECOGNIZED,
                                      t1.WEIGHT_FACTOR,
                                      t1.TOTAL_WEIGHT,
                                      t1.FACTOR_DAYS,
                                      t1.FACTOR_OUTSTANDING_PRINCIPAL,
                                      t1.FACTOR_INTEREST_ACCRUAL_BALANC,
                                      t1.FACTOR_RESERVED1,
                                      t1.FACTOR_RESERVED2,
                                      t1.FACTOR_RESERVED3,
                                      t1.CASHFLOW_ID,
                                      t1.TIMES,
                                      t1.CF_TYPE,
                                      t1.CALC_START_DATE,
                                      t1.CALC_END_DATE,
                                      (select p.project_name
                                         from prj_project p, con_contract c
                                        where c.contract_id = t1.contract_id
                                          and p.project_id = c.project_id) AS project_name,
                                      (select c.finance_amount
                                         from con_contract c
                                        where c.contract_id = t1.contract_id) AS finance_amount,
                                      ((CASE
                                        WHEN t1.cf_item = 8 THEN
                                         (SELECT to_char(cf1.due_date, 'yyyy/mm/dd')
                                            FROM con_contract_cashflow cf1
                                           WHERE cf1.contract_id = t1.contract_id
                                             AND cf1.cf_item = t1.cf_item) || '-' ||
                                         (SELECT TO_CHAR(cf.due_date, 'yyyy/mm/dd')
                                            FROM con_contract_cashflow cf
                                           WHERE cf.cashflow_id = t1.cashflow_id)
                                        ELSE
                                         ((SELECT to_char(cf1.due_date, 'yyyy/mm/dd')
                                             FROM con_contract_cashflow cf1
                                            WHERE cf1.contract_id = t1.contract_id
                                              AND cf1.cf_item = t1.cf_item
                                              AND cf1.times =
                                                  (SELECT cf.times - 1
                                                     FROM con_contract_cashflow cf
                                                    WHERE cf.cashflow_id = t1.cashflow_id)) ||
                                         nvl2((Select to_char(cf1.due_date, 'yyyy/mm/dd')
                                                 From con_contract_cashflow cf1
                                                Where cf1.contract_id = t1.contract_id
                                                  And cf1.cf_item = t1.cf_item
                                                  And cf1.times =
                                                      (Select cf.times - 1
                                                         From con_contract_cashflow cf
                                                        Where cf.cashflow_id = t1.cashflow_id)),
                                               '-',
                                               '') ||
                                         (SELECT TO_CHAR(cf.due_date - 1, 'yyyy/mm/dd')
                                             FROM con_contract_cashflow cf
                                            WHERE cf.cashflow_id = t1.cashflow_id))
                                      END)) AS period,
                                      (select c.interest
                                         from con_contract_cashflow c
                                        where c.cashflow_id = t1.cashflow_id) AS interest,
                                      round((select c.int_rate
                                              from con_contract c
                                             where c.contract_id = t1.contract_id),
                                            4) AS int_rate_implicit,
                                      (to_char(t1.calc_start_date, 'yyyy/mm/dd') || '-' ||
                                      to_char(t1.calc_end_date, 'yyyy/mm/dd')) AS calc_period,
                                      (t1.calc_end_date - t1.calc_start_date + 1) AS calc_date_count,
                                      (t1.unearned_finance_income *
                                      (select decode(t.tax_type_id,
                                                      1,
                                                      1,
                                                      1 + (select c.tax_type_rate
                                                             from fnd_tax_type_codes c
                                                            where c.tax_type_id = t.tax_type_id))
                                          from con_contract t
                                         where t.contract_id = t1.contract_id)) AS vat_unearned_finance_income,
                                      ROUND((select sum(t.unearned_finance_income *
                                                       (select decode(t.tax_type_id,
                                                                      1,
                                                                      1,
                                                                      1 +
                                                                      (select c.tax_type_rate
                                                                         from fnd_tax_type_codes c
                                                                        where c.tax_type_id = t.tax_type_id))
                                                          from con_contract t
                                                         where t.contract_id = t1.contract_id))
                                              from con_unearned_finance_income t
                                             where t.contract_id = t1.contract_id
                                               and t.internal_period_num = ${@internal_period_num}),
                                            (select c.PRECISION
                                               from gld_currency c, con_contract ct
                                              where c.currency_code = ct.currency
                                                and ct.contract_id = t1.contract_id)) AS current_month_vat_income,
                                      (select sum(t.unearned_finance_income)
                                         from con_unearned_finance_income t
                                        where t.contract_id = t1.contract_id
                                          and t.internal_period_num = ${@internal_period_num}) AS current_month_income,
                                      (select t.contract_number
                                         from con_contract t
                                        where t.contract_id = t1.contract_id) AS contract_number,
                                      (select t.contract_name
                                         from con_contract t
                                        where t.contract_id = t1.contract_id) AS contract_name,
                                      t1.adjustvat,
                                      t1.adjustvat13
                                 FROM CON_UNEARNED_FINANCE_INCOME t1
                                  WHERE t1.internal_period_num <> ${@internal_period_num}
                                  and exists (Select 1
                                            From con_contract cc
                                           Where t1.contract_id = cc.contract_id
                                             And cc.data_class = 'NORMAL'
                                             And t1.cf_item In (1, 8)
                                             And cc.contract_status In  ('INCEPT'))
                                     and (select sum(nvl(ccc.due_amount, 0) - nvl(ccc.received_amount, 0))
                                                from con_contract_cashflow ccc
                                               where ccc.contract_id = t1.contract_id
                                                 and ccc.cf_status = 'RELEASE'
                                                 and ccc.cf_direction = 'INFLOW'
                                                 and ccc.cf_item in (1, 2, 8, 9)) = 0
									and t1.cashflow_id in
                                            (select cw.cashflow_id
                                               from con_contract_cashflow cw
                                              where cw.cf_direction not in ('NONCASH'))) t1  #WHERE_CLAUSE#
     	       ]]></bm:query-sql>
             </bm:operation>
      </bm:operations>
    <bm:query-fields>
        <bm:query-field field="company_id" queryOperator="="/>
        <bm:query-field  field="finance_income_recognized" queryExpression="t1.finance_income_recognized=${@finance_income_recognized}"/>
    </bm:query-fields>
    <!--<bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="(t1.internal_period_num = ${@internal_period_num} or (t1.internal_period_num > ${@internal_period_num} and exists(select 1 from con_contract_cashflow ccc where ccc.cashflow_id = t1.cashflow_id and ccc.cf_status='RELEASE' and ccc.write_off_flag = 'FULL' and to_char(ccc.full_write_off_date, 'yyyy-mm') = to_char(to_date(${@calc_end_date},'yyyy-mm-dd'),'yyyy-mm') and trunc(ccc.due_date) > trunc(to_date(${@calc_end_date},&apos;yyyy-mm-dd&apos;))) and  (select sum(nvl(ccc.due_amount, 0) - nvl(ccc.received_amount, 0)) from con_contract_cashflow ccc where ccc.contract_id = t1.contract_id and ccc.cf_status = 'RELEASE' and ccc.cf_direction = 'INFLOW' and ccc.cf_item in (1, 2, 8, 9)) = 0 and exists (Select 1  From con_contract cc  Where t1.contract_id = cc.contract_id  And cc.data_class = 'NORMAL' and cc.contract_status In ('INCEPT')))) and exists (Select 1 From con_contract cc Where t1.contract_id = cc.contract_id And cc.data_class = &apos;NORMAL&apos; And t1.cf_item In (1, 8) And ((t1.cf_item = 1 And cc.contract_status In (&apos;TERMINATE&apos;, &apos;INCEPT&apos;, &apos;ETING&apos;, &apos;REPURING&apos;)) Or (t1.cf_item = 8 And cc.contract_status In (&apos;TERMINATE&apos;, &apos;INCEPT&apos;))) ) and exists (select 1 from con_contract_cashflow c where c.cashflow_id = t1.cashflow_id and c.interest is not null)"/>
        <bm:data-filter enforceOperations="query" expression="(to_char(t1.calc_end_date,&apos;yyyy-mm-dd&apos;) = ${@calc_end_date} or (to_char(t1.calc_end_date,&apos;yyyy-mm-dd&apos;) > ${@calc_end_date} and exists (select 1 from con_contract_cashflow ccc where ccc.cashflow_id = t1.cashflow_id and ccc.cf_status='RELEASE' and ccc.write_off_flag = 'FULL' and to_char(ccc.full_write_off_date, 'yyyy-mm') = to_char(to_date(${@calc_end_date},'yyyy-mm-dd'),'yyyy-mm') and trunc(ccc.due_date) > trunc(to_date(${@calc_end_date},&apos;yyyy-mm-dd&apos;)))and  (select sum(nvl(ccc.due_amount, 0) - nvl(ccc.received_amount, 0)) from con_contract_cashflow ccc where ccc.contract_id = t1.contract_id and ccc.cf_status = 'RELEASE' and ccc.cf_direction = 'INFLOW' and ccc.cf_item in (1, 2, 8, 9)) = 0 and exists (Select 1  From con_contract cc  Where t1.contract_id = cc.contract_id  And cc.data_class = 'NORMAL' and cc.contract_status In ('INCEPT'))))"/>
        <bm:data-filter enforceOperations="query" expression="t1.cashflow_id in (select cw.cashflow_id from con_contract_cashflow cw where cw.cf_direction not in ('NONCASH'))"/>
    </bm:data-filters>-->
</bm:model>
