<?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
            TO_CHAR(SUM(t1.principal),'FM999,999,990.00') sum_principal,
                    TO_CHAR(SUM(t1.net_interest),'FM999,999,990.00') sum_interest,
                    TO_CHAR(SUM(t1.due_amount),'FM999,999,990.00') sum_due_amount,
                    TO_CHAR(SUM(t1.vat_due_amount),'FM999,999,990.00') sum_vat_due_amount,
           TO_CHAR(SUM(t1.outstanding_principal),'FM999,999,999,990.00') sum_outstanding_principal
          from  ( select 
                    ccc.principal,
          ccc.net_interest,
          ccc.due_amount,
          ccc.vat_due_amount,
         (select nvl(sum(nvl(cf.net_principal,0)),0)
             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' AND
                    t.session_id    =${/session/@session_id}
                    ) t1
            
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
