<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
              SELECT c.contract_id,
                   ccc.cashflow_id,
                   c.contract_number,
                   to_char(ccc.due_date,'yyyy-mm-dd') due_date,
                   c.contract_name,
                   c.bp_id_tenant,
                   (select bp_id from sys_user where bp_category = 'AGENT' and user_id = c.OWNER_USER_ID) bp_id_agent,
                   (SELECT bp_name FROM hls_bp_master h WHERE c.bp_id_tenant = h.bp_id) bp_tenant_name,
                   ccc.times,
                   ccc.cf_item,
                   (SELECT description
                      FROM hls_cashflow_item
                     WHERE cf_item = ccc.cf_item) cf_item_desc,
                   c.pay_method,
                   (ccc.due_amount-nvl(ccc.received_amount,0)) due_amount,
                   (ccc.due_amount-nvl(ccc.received_amount,0)) manual_amount
              FROM con_contract c, con_contract_cashflow ccc
                #WHERE_CLAUSE#
                order by contract_id,times,cf_item desc
            ]]>
            </bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="pay_method" queryExpression="(c.pay_method = ${@pay_method})"/>
        <bm:query-field name="due_date_from" queryExpression="(ccc.due_date &gt;= to_date(${@due_date_from},'yyyy-mm-dd'))"/>
        <bm:query-field name="due_date_to" queryExpression="(ccc.due_date &lt;= to_date(${@due_date_to},'yyyy-mm-dd'))"/>
        <bm:query-field name="contract_id" queryExpression="(c.contract_id = ${@contract_id})"/>
        <bm:query-field name="cf_item" queryExpression="(ccc.cf_item = ${@cf_item})"/>
        <bm:query-field name="bp_id_tenant" queryExpression="(bp_id_tenant = ${@bp_id_tenant})"/>
        <bm:query-field name="bp_id_agent" queryExpression="(bp_id_agent = ${@bp_id_agent})"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter name="query"
                        expression="c.contract_id = ccc.contract_id and ccc.due_date &lt;= trunc(sysdate) and  c.data_class = 'NORMAL' and ccc.write_off_flag != 'FULL' and c.contract_status in ('SIGN','INCEPT') and ccc.cf_status = 'RELEASE' and ccc.cf_direction = 'INFLOW' and c.pay_method is not null and ccc.cf_item in (1,9)"/>
        <bm:data-filter name="query"
                        expression="not exists(select 1 from hls_ebank_batch_group g,hls_ebank_batch_ln l where g.status in ('NEW','DEAL') and g.group_id = l.group_id and l.cashflow_id = ccc.cashflow_id)"/>
    </bm:data-filters>
</bm:model>
