<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:e="leaf.service.exception" xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" baseTable="tre_funds_reservation">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        pp.virtual_con_number document_number,
                        pp.project_id,
                        pp. virtual_con_name document_name,
                        pp.bp_id_tenant_n bp_name,
                        r.reservation_id,
                        r.reserve_amount,
                        r.paid_date,
                        r.reserve_note,
                        r.status,
                        (SELECT
                            fd.description_text
                        FROM
                            sys_codes sc,
                            sys_code_values scv,
                            fnd_descriptions fd
                        WHERE
                            sc.code           = 'RESERVE_STATUS' AND
                            sc.code_id        = scv.code_id AND
                            scv.code_value    = r.status AND
                            fd.description_id = scv.code_value_name_id AND
                            fd.language       = 'ZHS'
                        ) status_n,
                        r.description,
                        r.creation_date
                    FROM
                        prj_project_virtual_con_lv pp,
                        tre_funds_reservation r
                    WHERE
                        pp.project_id = r.project_id AND
                        pp.project_id = ${/parameter/@project_id} AND
                        r.status      = NVL(${/parameter/@status},r.status)
                    UNION
                    SELECT
                        pp.project_number document_number,
                        pp.project_id,
                        pp.project_name document_name,
                        pp.bp_name,
                        r.reservation_id,
                        r.reserve_amount,
                        r.paid_date,
                        r.reserve_note,
                        r.status,
                        (SELECT
                            fd.description_text
                        FROM
                            sys_codes sc,
                            sys_code_values scv,
                            fnd_descriptions fd
                        WHERE
                            sc.code           = 'RESERVE_STATUS' AND
                            sc.code_id        = scv.code_id AND
                            scv.code_value    = r.status AND
                            fd.description_id = scv.code_value_name_id AND
                            fd.language       = 'ZHS'
                        ) status_n,
                        r.description,
                        r.creation_date
                    FROM
                        prj_project_lv pp,
                        tre_funds_reservation r
                    WHERE
                        pp.project_id = r.project_id AND
                        pp.project_id = ${/parameter/@project_id} AND
                        r.status      = NVL(${/parameter/@status},r.status) AND
                        pp.data_class = 'NORMAL' AND
                        NOT EXISTS
                        (SELECT 1 FROM prj_project pp1 WHERE pp1.ref_project_id = pp.project_id
                        )
                    ) tt
                ORDER BY
                    tt.creation_date
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:query-sql><![CDATA[
                BEGIN
                    tre510_save_pkg.reserve_submit(p_reservation_id => ${@reservation_id},
                    						p_project_id => ${@project_id}, 
                                            p_company_id => ${/session/@company_id}, 
                                            p_user_id => ${/session/@user_id});
                END;
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="delete">
            <bm:update-sql><![CDATA[
                begin
                tre510_save_pkg.tre_funds_reservation_delete(p_reservation_id => ${@reservation_id},
                                         p_user_id       => ${/session/@user_id});
                end;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <!-- <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" forInsert="false" forUpdate="false" physicalName="CONTRACT_ID"/> -->
        <bm:field name="reservation_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RESERVATION_ID"/>
        <!-- <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false" physicalName="CONTRACT_NUMBER"/> -->
        <!-- <bm:field name="contract_name" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false" physicalName="CONTRACT_NAME"/> -->
        <!-- <bm:field name="bp_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID"/> -->
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false" physicalName="BP_NAME"/>
        <bm:field name="reserve_amount" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RESERVE_AMOUNT"/>
        <bm:field name="paid_date" databaseType="DATE" datatype="java.util.Date" physicalName="PAID_DATE"/>
        <bm:field name="status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="STATUS"/>
        <bm:field name="status_n" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false" physicalName="STATUS_N"/>
        <!-- <bm:field name="confirm_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONFIRM_STATUS"/> -->
        <!-- <bm:field name="confirm_status_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONFIRM_STATUS_DESC"/> -->
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION"/>
        <bm:field name="document_number" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false"/>
        <bm:field name="document_name" databaseType="VARCHAR2" datatype="java.lang.String" forInsert="false" forUpdate="false"/>
        <bm:field name="project_id"/>
        <bm:field name="reserve_note"/>
    </bm:fields>
    <bm:primary-key>
        <bm:pk-field name="reservation_id"/>
    </bm:primary-key>
    <bm:features>
        <o:sequence-pk/>
        <f:standard-who/>
    </bm:features>
</bm:model>
