<?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
                    ppb.bp_id,
                    ppb.bp_name,
                    SUM(bhrd.ref_n02) guarantor_sum_principal,
                    to_char(ROUND((SUM(bhrd.ref_n02) /
                    (SELECT
                        SUM(t.ref_n02)
                    FROM
                        bgfl_hls_report_data t
                    WHERE
                        t.function_code = 'HN2020' AND
                        t.session_id    = ${/session/@session_id}
                    )) * 100, 2),'FM990.00')
                    || '%' guarantor_sum_prin_percent,
                    SUM(bhrd.ref_n05) guarantor_rec_principal,
                    to_char(ROUND((SUM(bhrd.ref_n05) /
                    (SELECT
                        SUM(t.ref_n05)
                    FROM
                        bgfl_hls_report_data t
                    WHERE
                        t.function_code = 'HN2020' AND
                        t.session_id    = ${/session/@session_id}
                    )) * 100, 2),'FM990.00')
                    || '%' guarantor_rec_prin_percent
                FROM
                    prj_project_bp ppb,
                    bgfl_hls_report_data bhrd
                WHERE
                    ppb.bp_category    = 'GUARANTOR' AND
                    ppb.bp_type        = 'GUARANTOR' AND
                    --ppb.bp_class       = 'ORG' AND
                    ppb.project_id     = bhrd.ref_n01 AND
                    bhrd.function_code = 'HN2020' AND
                    bhrd.session_id    = ${/session/@session_id}
                GROUP BY
                    ppb.bp_id,
                    ppb.bp_name
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="guarantor_sum_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="guarantor_rec_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="bp_id"/>
        <bm:field name="bp_name"/>
        <bm:field name="guarantor_sum_prin_percent"/>
        <bm:field name="guarantor_rec_prin_percent"/>
    </bm:fields>
</bm:model>
