<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qm  
    $Date: 2014-4-21 下午2:44:35  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="AST_CAR_INSURANCE_RECORDS">
    <bm:fields>
        <bm:field name="ast_car_insurance_records_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="AST_CAR_INSURANCE_RECORDS_ID" prompt="AST_CAR_INSURANCE_RECORDS.AST_CAR_INSURANCE_RECORDS_ID"/>
        <bm:field name="ast_car_insurance_id" databaseType="NUMBER" datatype="java.lang.Long" insertExpression="${../../@ast_car_insurance_id}" physicalName="AST_CAR_INSURANCE_ID" prompt="AST_CAR_INSURANCE_RECORDS.AST_CAR_INSURANCE_ID"/>
        <bm:field name="record_date" databaseType="DATE" datatype="java.util.Date" physicalName="RECORD_DATE" prompt="AST_CAR_INSURANCE_RECORDS.RECORD_DATE" required="true"/>
        <bm:field name="insurance_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSURANCE_TYPE" prompt="AST_CAR_INSURANCE_RECORDS.INSURANCE_TYPE"/>
        <bm:field name="record_description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="RECORD_DESCRIPTION" prompt="AST_CAR_INSURANCE_RECORDS.RECORD_DESCRIPTION"/>
        <bm:field name="settle_claim_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="SETTLE_CLAIM_AMOUNT" prompt="AST_CAR_INSURANCE_RECORDS.SETTLE_CLAIM_AMOUNT"/>
        <bm:field name="report_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REPORT_NUMBER" prompt="AST_CAR_INSURANCE_RECORDS.REPORT_NUMBER"/>
        <bm:field name="damage_serious_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DAMAGE_SERIOUS_FLAG" prompt="AST_CAR_INSURANCE_RECORDS.DAMAGE_SERIOUS_FLAG"/>
        <bm:field name="damage_level_description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DAMAGE_LEVEL_DESCRIPTION" prompt="AST_CAR_INSURANCE_RECORDS.DAMAGE_LEVEL_DESCRIPTION"/>
        <bm:field name="document_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_STATUS" prompt="AST_CAR_INSURANCE_RECORDS.DOCUMENT_STATUS"/>
        <bm:field name="document_status_des" databaseType="VARCHAR2" datatype="java.lang.String" expression="(select v.code_value_name from sys_code_values_v v where v.code=&apos;AST_INSURANCE_DOCUMENT_STATUS&apos; and t1.document_status=v.code_value)" forInsert="false" physicalName="DOCUMENT_STATUS_DES" prompt="AST_CAR_INSURANCE_RECORDS.DOCUMENT_STATUS_DES"/>
        <bm:field name="payment_finish_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PAYMENT_FINISH_FLAG" prompt="AST_CAR_INSURANCE_RECORDS.PAYMENT_FINISH_FLAG"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk sequenceName="AST_CAR_INSURANCE_RECORDS_S"/>
    </bm:features>
    <bm:operations>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
            DECLARE
                v_con_contract con_contract%rowtype;
            BEGIN
                SELECT
                    t.*
                INTO
                    v_con_contract
                FROM
                    con_contract t,
                    con_contract_item_detail d,
                    AST_CAR_INSURANCE t1
                WHERE
                    t.contract_id           =d.contract_id AND
                    d.ITEM_DETAIL_ID        = t1.ITEM_DETAIL_ID AND
                    t1.AST_CAR_INSURANCE_ID = ${../../@ast_car_insurance_id};
                yonda_doc_history_pkg.yonda_insert_doc_status(p_document_id => v_con_contract.contract_id, p_document_type => v_con_contract.document_type, p_document_category => v_con_contract.document_category, p_doc_status => yonda_doc_history_pkg.yonda_con_accident_maintain, p_instance_id => NULL, p_user_id => ${/session/@user_id});
                INSERT
                INTO
                    AST_CAR_INSURANCE_RECORDS
                    (
                        AST_CAR_INSURANCE_RECORDS_ID,
                        AST_CAR_INSURANCE_ID,
                        RECORD_DATE,
                        INSURANCE_TYPE,
                        RECORD_DESCRIPTION,
                        SETTLE_CLAIM_AMOUNT,
                        REPORT_NUMBER,
                        DAMAGE_SERIOUS_FLAG,
                        DAMAGE_LEVEL_DESCRIPTION,
                        DOCUMENT_STATUS,
                        PAYMENT_FINISH_FLAG,
                        CREATED_BY,
                        CREATION_DATE,
                        LAST_UPDATED_BY,
                        LAST_UPDATE_DATE
                    )
                    VALUES
                    (
                        AST_CAR_INSURANCE_RECORDS_S.NEXTVAL,
                        ${../../@ast_car_insurance_id},
                        to_date(${@record_date},'yyyy-mm-dd'),
                        ${@insurance_type},
                        ${@record_description},
                        ${@settle_claim_amount},
                        ${@report_number},
                        ${@damage_serious_flag},
                        ${@damage_level_description},
                        ${@document_status},
                        ${@payment_finish_flag},
                        ${/session/@user_id},
                        sysdate,
                        ${/session/@user_id},
                        sysdate
                    )
                    RETURNING AST_CAR_INSURANCE_RECORDS_ID
                INTO
                    ${@ast_car_insurance_records_id};
            END;
        ]]></bm:update-sql>
            <bm:parameters>
                <bm:parameter name="ast_car_insurance_records_id" input="false" output="true"/>
            </bm:parameters>
        </bm:operation>
    </bm:operations>
    <bm:primary-key>
        <bm:pk-field name="ast_car_insurance_records_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field field="ast_car_insurance_id" queryOperator="="/>
        <bm:query-field field="ast_car_insurance_records_id" queryOperator="="/>
    </bm:query-fields>
</bm:model>
