<?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 t1.*,
       to_char(sum_principal_num + sum_interest_num + sum_lease_charge_num,'FM999,999,999,990.00') sum_due_amount
  from (SELECT ccc.contract_id,
               SUM(ccc.net_principal) sum_principal_num,
               SUM(ccc.net_interest) sum_interest_num,
               TO_CHAR(SUM(ccc.net_principal), 'FM999,999,999,990.00') sum_principal,
               TO_CHAR(SUM(ccc.net_interest), 'FM999,999,999,990.00') sum_interest,
               TO_CHAR(SUM(ccc.due_amount), 'FM999,999,999,990.00') sum_rental,
               nvl((select sum(nvl(t.due_amount, 0))
                     from con_contract_cashflow t
                    where t.contract_id = ccc.contract_id
                      and t.cf_item = 3),
                   0) sum_lease_charge_num,
               to_char(nvl((select sum(nvl(t.due_amount, 0))
                             from con_contract_cashflow t
                            where t.contract_id = ccc.contract_id
                              and t.cf_item = 3),
                           0),
                       'FM999,999,999,990.00') sum_lease_charge
          FROM con_contract_cashflow ccc
         WHERE ccc.cf_item = 1
           AND ccc.cf_direction = 'INFLOW'
           AND ccc.cf_status = 'RELEASE'
         GROUP BY ccc.contract_id) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
