<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:fields>
        <bm:field name="times"/>
        <bm:field name="due_year"/>
        <bm:field name="due_date"/>
        <bm:field name="cf_item"/>
        <bm:field name="due_amount"/>
        <bm:field name="received_amount"/>
        <bm:field name="cf_status"/>
        <bm:field name="cf_status_n"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                  select cc.times, --期数
                         to_char(cc.due_date, 'YYYY') due_year, --支付年
                         to_char(cc.due_date, 'MM-dd') due_date, --支付日期
                         (select h.description  from hls_cashflow_item h
                         where h.cf_item = cc.cf_item
                         and h.enabled_flag = 'Y'
                         and rownum =1) cf_item, --项目
                         to_char(nvl(cc.due_amount, 0),
                                 'FM9,999,999,999,990.00') due_amount, --应付金额
                         to_char(nvl(cc.due_amount, 0)-nvl(cc.received_amount, 0),
                                 'FM9,999,999,999,990.00') received_amount, --已付金额
                          (case
                           when cc.write_off_flag = 'FULL' then
                            'PAID'
                           when cc.overdue_status = 'Y' then
                            'OVERDUE'
                           else
                            'TOPAY'
                         end) as cf_status,
                         (case
                           when cc.write_off_flag = 'FULL' then
                            '已支付'
                           when cc.overdue_status = 'Y' then
                            '已逾期'
                           else
                            '待支付'
                         end) as cf_status_n --支付状态
                    from con_contract_cashflow cc
                    where cc.contract_id = ${@contract_id}
                    and ((cc.cf_type = 1 and cc.cf_item in (1,200,250)) or (cc.cf_item = 11 and cc.cf_type =11)
                    or (cc.cf_item = 8 and cc.cf_type = 8) or (cc.cf_item = 9 and cc.cf_type = 9))
                    and cc.cf_direction = 'INFLOW'
                    and cc.cf_status = 'RELEASE'
                    order by cc.cf_item,cc.times
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
