<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LR  
    $Date: 2013-8-26 下午02:56:21  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        pb.prj_bp_id,
                        pb.bp_id,
                        pb.bp_code,
                        pb.bp_name,
                        pb.project_id,
                        pb.bp_category,
                        pb.bp_category_desc,
                        pb.bp_type,
                        pb.bp_type_desc,
                        pb.bp_class,
                        pb.bp_class_desc,
                        pb.contract_seq,
                        'PB' table_name,
                        DECODE(${@default_contract_seq},pb.contract_seq,'Y','N')check_flag
                    FROM
                        prj_project_bp_v pb
                    WHERE
                        pb.bp_category = 'GUARANTOR' AND
                        pb.project_id  = ${@project_id}
                    UNION ALL
                    SELECT
                        pah.prj_bp_id,
                        pah.bp_id,
                        pah.bp_code,
                        pah.bp_name,
                        pah.project_id,
                        pah.bp_category,
                        pah.bp_category_desc,
                        pah.bp_type,
                        pah.bp_type_desc,
                        pah.bp_class,
                        pah.bp_class_desc,
                        pah.contract_seq,
                        'PAH' table_name,
                        DECODE(${@default_contract_seq},pah.contract_seq,'Y','N')check_flag
                    FROM
                        prj_project_act_ctrler_hd_v pah
                    WHERE
                        pah.project_id = ${@project_id}
                    ) v #WHERE_CLAUSE#
                ORDER BY
                    check_flag DESC,
                    contract_seq
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                    IF ${@table_name} = 'PB' THEN
                        UPDATE
                            prj_project_bp pb
                        SET
                            pb.CONTRACT_SEQ     = ${../@contract_seq},
                            pb.LAST_UPDATED_BY  = ${/session/@user_id},
                            pb.LAST_UPDATE_DATE = sysdate
                        WHERE
                            pb.prj_bp_id   = ${@prj_bp_id} AND
                            ${@check_flag} = 'Y';
                    ELSE
                        UPDATE
                            prj_project_act_ctrler_hd ph
                        SET
                            ph.CONTRACT_SEQ     = ${../@contract_seq},
                            ph.LAST_UPDATED_BY  = ${/session/@user_id},
                            ph.LAST_UPDATE_DATE = sysdate
                        WHERE
                            ph.prj_bp_id   = ${@prj_bp_id} AND
                            ${@check_flag} = 'Y';
                    END IF;
                END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="bp_name" queryExpression="v.bp_name like ${@bp_name}"/>
        <bm:query-field name="contract_seq" queryExpression="v.contract_seq like ${@contract_seq}"/>
    </bm:query-fields>
</bm:model>
