<?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
                    *
                FROM
                    (SELECT
                        t.session_id,
					(select count(1) from con_contract cc1 where
            cc1.project_id=pp.project_id
            and cc1.data_class='NORMAL'
            AND CC1.CONTRACT_STATUS NOT IN('CANCEL')
            AND to_number(substr(cc1.contract_number,instr(cc1.contract_number,'-')+1,2))<=
            to_number(substr(cc.contract_number,instr(cc.contract_number,'-')+1,2))) order_seq,
						
                        --t.order_seq,
                        ccc.times,
                        TO_CHAR(ccc.principal,'FM999,999,990.00') principal,
                        TO_CHAR(ccc.net_interest,'FM999,999,990.00') interest,
                        TO_CHAR(ccc.due_amount,'FM999,999,990.00') due_amount,
                        TO_CHAR(ccc.vat_due_amount,'FM999,999,990.00') vat_due_amount,
                        TO_CHAR(ccc.due_date,'YYYY-MM-DD') due_date,
                         (select TO_CHAR(nvl(sum(nvl(cf.net_principal,0)),0),'FM999,999,999,990.00')  
						 from con_contract_cashflow cf 
                        where cf.contract_id=cc.contract_id
                        and cf.cf_item=1
                        and cf.times>ccc.times
                       ) outstanding_principal
                    FROM
                        prj_project pp,
                        con_contract cc,
                        con_contract_cashflow ccc,
                        sdic_batch_csh_accounts t
                    WHERE
                        pp.project_id   = cc.project_id AND
                        cc.contract_id  = ccc.contract_id AND
                        ccc.cashflow_id = t.cashflow_id AND
                        cc.data_class   = 'NORMAL'
                    ) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="delete">
            <bm:update-sql><![CDATA[
            delete from sdic_batch_csh_accounts t where t.session_id=${/session/@session_id}
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
            begin
            sdic_virtual_con_content_pkg.sdic_csh_accounts_ins(p_session_id  =>${/session/@session_id},
                                  p_cashflow_id =>${@cashflow_id},
                                  p_times       =>${@times},
                                  p_user_id     =>${/session/@user_id});
            end;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.session_id=${/session/@session_id}"/>
        <!-- <bm:data-filter enforceOperations="query" expression="rownum=1"  /> -->
    </bm:data-filters>
</bm:model>
