<?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 t.loan_contract_id,
       t.loan_contract_number,
       t.loan_contract_name,
       t.loan_amount,
       t.company_id,
       (select v.code_value_name
          from sys_code_values_v v
         where v.code = 'YES_NO'
           and v.code_value = t.external_debt_cir_flag) external_debt_cir_flag_n,
       (select nvl(sum(tl.repayment_amount), 0)
          from tre_loan_contract_repayment tl
         where tl.loan_contract_id(+) = t.loan_contract_id
           and tl.repayment_type in ('CAPITAL', 'CAPITAL_INT', 'INTEREST')) total_repayment_amount
  from tre_loan_contract t
 where t.external_debt_flag = 'Y'
 and t.company_id=${@company_id}]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
