<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:s="leaf.plugin.script" xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false" defaultOrderBy="t1.times">
    <bm:fields>
        <bm:field name="contract_id"/>
        <bm:field name="lease_channel"/>
        <bm:field name="contract_number"/>
        <bm:field name="bp_name"/>
        <bm:field name="colour_scheme"/>
        <bm:field name="cf_direction"/>
        <bm:field name="times" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="cf_item"/>
        <bm:field name="cf_item_n"/>
        <bm:field name="calc_date"/>
        <bm:field name="due_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="received_amount" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="outstanding_prin_tax_incld" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="total_rental"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
          select t1.cashflow_id,
                       t1.contract_id,
                       (Select ch.description
                          from hls_lease_channel ch
                         Where ch.lease_channel = (select c.lease_channel
                                                    from con_contract c
                                                    where c.contract_id = t1.contract_id)) As lease_channel,
                       (select c.contract_number
                          from con_contract c
                         where c.contract_id = t1.contract_id) contract_number,
                       (select c.total_rental
                          from con_contract c
                         where c.contract_id = t1.contract_id) total_rental,
                       (select h.bp_name
                          from hls_bp_master h
                         where h.bp_id = (select c.bp_id_tenant
                                            from con_contract c
                                           where c.contract_id = t1.contract_id)) bp_name,
                       t1.colour_scheme,
                       (select v.code_value_name
                          from sys_code_values_v v
                         where v.code = 'CF_DIRECTION'
                           and v.code_value = t1.cf_direction) cf_direction,
                       t1.times,
                       t1.cf_item,
                       cf.description as cf_item_n,
                       to_char(t1.calc_date,'yyyy/mm/dd') calc_date,
                       t1.due_amount,
                       t1.principal,
                       t1.interest,
                       t1.received_amount,
                       t1.outstanding_prin_tax_incld
                  from con_contract_cashflow t1,
                       hls_cashflow_item     cf,
                       hls_cashflow_type     cft

                #WHERE_CLAUSE#
                 #ORDER_BY_CLAUSE#
                ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <s:bm-script><![CDATA[
            var cx = Packages.leaf.javascript.Context.getCurrentContext();
            Packages.leaf.plugin.script.engine.ScriptImportor.defineExternScript(cx, this, $ctx.getData(), "aut_authority_bm_validate.js");
        ]]></s:bm-script>
    <bm:data-filters>
        <bm:data-filter name="join" expression="t1.cf_item = cf.cf_item
                   and t1.cf_type = cft.cf_type
                   and t1.times &gt; 0
                   and t1.cf_item in(1,3,8,102,103,104)"/>
        <bm:data-filter expression="t1.contract_id = ${@contract_id}" name="contract_id"/>
    </bm:data-filters>
</bm:model>
