<?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
                    tfr.reservation_id,
                    tfr.reserve_amount,
                    to_char(tfr.paid_date,'YYYY-MM-DD') paid_date,
                    tfr.description,
                    tfr.reserve_note,
                    pp.virtual_con_number document_number,
                    pp.virtual_con_name document_name,
                    to_char(pp.inception_of_lease,'YYYY-MM-DD') inception_of_lease,
                    pp.finance_amount,
                    pp.bp_id_tenant_n||
                    (select '、'||ppb.bp_name from prj_project_bp ppb
                    where ppb.project_id=pp.project_id
                    and ppb.bp_category='TENANT'
                    and ppb.bp_type='TENANT_SEC') bp_name,
                    to_char(tfr.creation_date,'YYYY-MM-DD') creation_date,
                    (select v.description from exp_org_unit_vl v
                    where v.unit_code=
                    sdic_workflow_assign_pkg.get_unit_code(p_user_id => tfr.created_by)) unit_name
                FROM
                    tre_funds_reservation tfr,
                    prj_project_virtual_con_lv pp
                WHERE
                    tfr.project_id   = pp.project_id AND
                    tfr.reservation_id=${@reservation_id}
                union
                    SELECT
                    tfr.reservation_id,
                    tfr.reserve_amount,
                    to_char(tfr.paid_date,'YYYY-MM-DD') paid_date,
                    tfr.description,
                    tfr.reserve_note,
                    pp.project_number document_number,
                    pp.project_name document_name,
                    to_char(pp.inception_of_lease,'YYYY-MM-DD') inception_of_lease,
                    pp.finance_amount,
                    pp.bp_name||
                    (select '、'||ppb.bp_name from prj_project_bp ppb
                    where ppb.project_id=pp.project_id
                    and ppb.bp_category='TENANT'
                    and ppb.bp_type='TENANT_SEC'),
                    to_char(tfr.creation_date,'YYYY-MM-DD') creation_date,
                    (select v.description from exp_org_unit_vl v
                    where v.unit_code=
                    sdic_workflow_assign_pkg.get_unit_code(p_user_id => tfr.created_by)) unit_name
                FROM
                    tre_funds_reservation tfr,
                    prj_project_lv pp
                WHERE
                    tfr.project_id   = pp.project_id
                    and pp.data_class='NORMAL' AND
                    tfr.reservation_id=${@reservation_id}
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
