<?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.contract_id,t1.times desc">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
            select * from (
                select (select h.bp_name
          from hls_bp_master h
         where h.bp_id = cc.bp_id_agent_level1) bp_agent_name,
       (select h.bp_name
          from hls_bp_master h
         where h.bp_id = cc.bp_id_tenant) bp_name,
       cc. contract_number,
       t.times,
       t.cf_item,
       (select cf.description
          from hls_cashflow_item cf
         where t.cf_item = cf.cf_item) cf_item_n,
       t.due_date,
       to_number(decode(t.cf_item, '9', nvl(t.due_amount, 0), nvl(t.due_amount, 0))) due_amount,
       to_number(decode(t.cf_item, '9', 0, nvl(t.principal, 0))) principal,
       to_number(decode(t.cf_item, '9', 0, nvl(t.interest, 0))) interest,
       to_number(decode(t.cf_item, '9', 0, nvl(t.received_amount, 0))) received_amount,
       to_number(decode(t.cf_item, '9', 0, nvl(t.received_principal, 0))) received_principal,
       to_number(decode(t.cf_item, '9', 0, nvl(t.received_interest, 0))) received_interest,
       to_number(decode(t.cf_item, '9', nvl(t.received_amount, 0), null)) received_amount_penalty,
       t.contract_id,
       cc.lease_execution_date,
       case when t.cf_item in (1,9,8) and t.due_date < sysdate and t.write_off_flag <>'FULL'
              then '逾期'
              else '' end delay_yn,
       case when t.cf_item in (1,8) and t.due_date < sysdate and t.write_off_flag <>'FULL'
              then to_date(to_char(sysdate,'yyyymmdd'),'yyyymmdd') - t.due_date
              else 0 end delay_dd
  from con_contract_cashflow t, con_contract cc
 where cc.contract_id = t.contract_id
   and cc.data_class = 'NORMAL'
   and cc.contract_status not in ('CANCEL', 'NEW')
   and t.cf_status = 'RELEASE'
   and t.cf_direction = 'INFLOW'
                    ) t1 #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:fields>
        <bm:field name="bp_agent_name"/>
        <bm:field name="bp_name"/>
        <bm:field name="contract_number"/>
        <bm:field name="times"/>
        <bm:field name="cf_item"/>
        <bm:field name="cf_item_n"/>
        <bm:field name="due_date" databaseType="DATE" datatype="java.util.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="received_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="received_interest" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="received_amount_penalty" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="lease_execution_date" databaseType="DATE" datatype="java.util.Date"/>
        <bm:field name="delay_yn" />
        <bm:field name="delay_dd" databaseType="NUMBER" />
    </bm:fields>
    <bm:query-fields>
        <bm:query-field field="contract_number" queryOperator="like"/>
        <bm:query-field field="bp_name" queryOperator="like"/>
        <bm:query-field field="bp_agent_name" queryOperator="="/>
        <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>