<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: DJ  
    $Date: 2013-11-4 下午1:33:14  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="TRE_LOAN_CON_REPAYMENT_BANK_LV" needAccessControl="false">
    <bm:fields>
        <bm:field name="repayment_bank_id"/>
        <bm:field name="tre_date"/>
        <bm:field name="bank_account_id"/>
        <bm:field name="bank_account_id_n"/>
        <bm:field name="bank_account_code"/>
        <bm:field name="bank_account_num"/>
        <bm:field name="bank_account_name"/>
        <bm:field name="loan_contract_id"/>
        <bm:field name="batch_id"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                 SELECT
                        t1.repayment_bank_id,
                        t1.tre_date,
                        t1.bank_account_id,
                        t1.bank_account_id_n,
                        t1.bank_account_code,
                        t1.bank_account_num,
                        t1.bank_account_name,
                        t1.loan_contract_id,
                        t1.batch_id
                    FROM
                        tre_loan_con_repayment_bank_lv t1
                    WHERE
                        t1.batch_id = ${/parameter/@batch_id}
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
                BEGIN
                    IF ${/parameter/@batch_id} IS NOT NULL THEN
                        UPDATE
                            tre_loan_con_repayment_bank
                        SET
                            tre_date          = to_date(${@tre_date},'yyyy-mm-dd'),
                            bank_account_id   = ${@bank_account_id},
                            bank_account_code = ${@bank_account_code},
                            bank_account_num  = ${@bank_account_num},
                            bank_account_name = ${@bank_account_name}
                        WHERE
                            batch_id = ${/parameter/@batch_id};
                    ELSE
                        INSERT
                        INTO
                            tre_loan_con_repayment_bank
                            (
                                repayment_bank_id,
                                batch_id,
                                tre_date,
                                bank_account_id,
                                bank_account_code,
                                bank_account_num,
                                bank_account_name,
                                creation_date,
                                created_by,
                                last_update_date,
                                last_updated_by,
                                loan_contract_id
                            )
                            VALUES
                            (
                                tre_loan_con_repayment_bank_s.nextval,
                                ${@batch_id},
                                ${@tre_date},
                                ${@bank_account_id},
                                ${@bank_account_code},
                                ${@bank_account_num},
                                ${@bank_account_name},
                                sysdate,
                                ${/session/@user_id},
                                sysdate,
                                ${/session/@user_id},
                                ${@loan_contract_id}
                            ) ;
                    END IF;
                END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
