<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:fields>
        <bm:field name="contract_number"/>
        <bm:field name="lease_execution_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="bp_code"/>
        <bm:field name="bp_name"/>
        <bm:field name="bp_agent_code"/>
        <bm:field name="bp_agent_name"/>
        <bm:field name="division"/>
        <bm:field name="division_n"/>
        <bm:field name="lease_channel"/>
        <bm:field name="lease_channel_n"/>
        <bm:field name="business_type"/>
        <bm:field name="business_type_n"/>
        <bm:field name="machine_number"/>
        <bm:field name="pattern"/>
        <bm:field name="equipment_number"/>
        <bm:field name="january_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="january_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="january_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="february_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="february_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="february_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="march_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="march_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="march_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="april_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="april_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="april_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="may_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="may_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="may_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="june_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="june_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="june_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="july_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="july_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="july_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="august_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="august_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="august_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="september_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="september_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="september_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="october_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="october_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="october_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="november_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="november_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="november_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="december_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="december_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="december_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="second_years_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="second_years_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="second_years_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="third_years_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="third_years_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="third_years_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="fourth_years_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="fourth_years_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="fourth_years_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="fifth_years_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="fifth_years_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="fifth_years_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="after_fifth_years_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="after_fifth_years_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="after_fifth_years_due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT *
  FROM (select c.contract_number,
               c.lease_execution_date,
       (select hb.bp_code
          from hls_bp_master hb
         where hb.bp_id = c.bp_id_tenant) bp_code,
       (select hb.bp_name
          from hls_bp_master hb
         where hb.bp_id = c.bp_id_tenant) bp_name,
       (select hb.bp_code
          from hls_bp_master hb
         where hb.bp_id = c.bp_id_agent_level1) bp_agent_code,
       (select hb.bp_name
          from hls_bp_master hb
         where hb.bp_id = c.bp_id_agent_level1) bp_agent_name,
       c.division,
       (SELECT hd.description
          FROM hls_division hd
         WHERE hd.division = c.division) AS division_n,
       c.lease_channel,
       (Select ch.description
          from hls_lease_channel ch
         Where ch.lease_channel = c.lease_channel) As lease_channel_n,
       c.business_type,
       (select bt.description
          from hls_business_type bt
         where bt.business_type = c.business_type) AS business_type_n,
       (select i.machine_number
          from con_contract_lease_item i
         WHERE i.contract_id = c.contract_id
           AND i.equipment_type = 'MAIN') machine_number,
       (select i.pattern
          from con_contract_lease_item i
         WHERE i.contract_id = c.contract_id
           AND i.equipment_type = 'MAIN') pattern,
       (select i.equipment_number
          from con_contract_lease_item i
         where i.contract_id = c.contract_id
           AND i.equipment_type = 'MAIN') equipment_number,
       (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '01'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') january_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '01'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') january_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '01'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) january_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '02'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') february_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '02'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') february_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '02'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) february_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '03'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') march_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '03'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') march_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '03'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) march_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '04'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') april_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '04'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') april_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '04'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) april_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '05'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') may_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '05'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') may_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '05'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) may_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '06'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') june_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '06'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') june_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '06'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) june_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '07'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') july_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '07'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') july_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '07'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) july_due_amount,
            (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '08'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') august_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '08'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') august_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '08'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) august_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '09'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') september_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '09'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') september_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '09'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) september_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '10'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') october_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '10'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') october_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '10'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) october_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '11'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') november_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '11'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') november_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '11'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) november_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '12'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') december_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
            and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '12'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE') december_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}
           and to_char(cc.calc_date, 'mm') = '12'
           and cc.cf_direction != 'NONCASH'
           and cc.cf_status = 'RELEASE'
           and cc.cf_item in(1,102,103,104)) december_due_amount,
           (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}+1) second_years_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
            and to_char(cc.calc_date, 'yyyy') = ${@select_year}+1) second_years_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and cc.cf_item in(1,102,103,104)
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}+1) second_years_due_amount,
         (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}+2) third_years_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
            and to_char(cc.calc_date, 'yyyy') = ${@select_year}+2) third_years_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and cc.cf_item in(1,102,103,104)
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}+2) third_years_due_amount,
         (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}+3) fourth_years_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
            and to_char(cc.calc_date, 'yyyy') = ${@select_year}+3) fourth_years_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and cc.cf_item in(1,102,103,104)
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}+3) fourth_years_due_amount,
         (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}+4) fifth_years_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
            and to_char(cc.calc_date, 'yyyy') = ${@select_year}+4) fifth_years_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and cc.cf_item in(1,102,103,104)
         and to_char(cc.calc_date, 'yyyy') = ${@select_year}+4) fifth_years_due_amount,
         (select nvl(sum(nvl(cc.principal,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and to_char(cc.calc_date, 'yyyy') >= ${@select_year}+5) after_fifth_years_principal,
           (select nvl(sum(nvl(cc.interest,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
            and to_char(cc.calc_date, 'yyyy') >= ${@select_year}+5) after_fifth_years_interest,
           (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and cc.cf_item in(1,102,103,104)
         and to_char(cc.calc_date, 'yyyy') >= ${@select_year}+5) after_fifth_years_due_amount
  from con_contract c
 where c.data_class = 'NORMAL'
 and (select nvl(sum(nvl(cc.due_amount,0)),0)
          from con_contract_cashflow cc
         where cc.contract_id = c.contract_id
         and cc.cf_direction != 'NONCASH'
         and cc.cf_status = 'RELEASE'
         and cc.cf_item in(1,102,103,104)
         and to_char(cc.calc_date, 'yyyy') = ${@select_year})!=0) t1

                #WHERE_CLAUSE#
                 #ORDER_BY_CLAUSE#
                ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field field="contract_number" queryOperator="like"/>
        <bm:query-field field="bp_agent_name" queryOperator="like"/>
        <bm:query-field name="lease_execution_date_from" queryExpression="t1.lease_execution_date &gt;= to_date(${@lease_execution_date_from},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="lease_execution_date_to" queryExpression="t1.lease_execution_date &lt;= to_date(${@lease_execution_date_to},&apos;yyyy-mm-dd&apos;)"/>
    </bm:query-fields>
</bm:model>
