<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qm  
    $Date: 2014-4-21 上午10:00:36  
    $Revision: 1.0  
    $Purpose: 
-->
<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" alias="t1" baseTable="AST_CAR_INSURANCE">
    <bm:fields>
        <bm:field name="ast_car_insurance_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="AST_CAR_INSURANCE_ID" prompt="AST_CAR_INSURANCE.AST_CAR_INSURANCE_ID"/>
        <bm:field name="item_detail_id" databaseType="NUMBER" datatype="java.lang.Long" insertExpression="${/parameter/@item_detail_id}" physicalName="ITEM_DETAIL_ID" prompt="AST_CAR_INSURANCE.ITEM_DETAIL_ID"/>
        <bm:field name="bp_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID" prompt="AST_CAR_INSURANCE.BP_ID" required="true"/>
        <bm:field name="insurer_dis" expression="(select bp_name from hls_bp_master where bp_id = t1.bp_id)" forInsert="false" forUpdate="false"/>
        <bm:field name="insurance_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSURANCE_NUMBER" prompt="AST_CAR_INSURANCE.INSURANCE_NUMBER" required="true"/>
        <bm:field name="insurance_description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSURANCE_DESCRIPTION" prompt="AST_CAR_INSURANCE.INSURANCE_DESCRIPTION"/>
        <bm:field name="insure_date" databaseType="DATE" datatype="java.util.Date" physicalName="INSURE_DATE" prompt="AST_CAR_INSURANCE.INSURE_DATE"/>
        <bm:field name="insurance_date_from" databaseType="DATE" datatype="java.util.Date" physicalName="INSURANCE_DATE_FROM" prompt="AST_CAR_INSURANCE.INSURANCE_DATE_FROM" required="true"/>
        <bm:field name="insurance_date_to" databaseType="DATE" datatype="java.util.Date" physicalName="INSURANCE_DATE_TO" prompt="AST_CAR_INSURANCE.INSURANCE_DATE_TO" required="true"/>
        <bm:field name="insurance_year" databaseType="NUMBER" datatype="java.lang.Long" physicalName="INSURANCE_YEAR" prompt="AST_CAR_INSURANCE.INSURANCE_YEAR"/>
        <bm:field name="compulsory_insurance_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="COMPULSORY_INSURANCE_AMOUNT" prompt="AST_CAR_INSURANCE.COMPULSORY_INSURANCE_AMOUNT"/>
        <bm:field name="commercial_insurance_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="COMMERCIAL_INSURANCE_AMOUNT" prompt="AST_CAR_INSURANCE.COMMERCIAL_INSURANCE_AMOUNT"/>
        <bm:field name="others_insurance_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="OTHERS_INSURANCE_AMOUNT" prompt="AST_CAR_INSURANCE.OTHERS_INSURANCE_AMOUNT"/>
        <bm:field name="damage_insurance_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DAMAGE_INSURANCE_FLAG" prompt="AST_CAR_INSURANCE.DAMAGE_INSURANCE_FLAG"/>
        <bm:field name="third_party_insurance_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="THIRD_PARTY_INSURANCE_FLAG" prompt="AST_CAR_INSURANCE.THIRD_PARTY_INSURANCE_FLAG"/>
        <bm:field name="pilfer_insurance_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PILFER_INSURANCE_FLAG" prompt="AST_CAR_INSURANCE.PILFER_INSURANCE_FLAG"/>
        <bm:field name="basic_non_deductible_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BASIC_NON_DEDUCTIBLE_FLAG" prompt="AST_CAR_INSURANCE.BASIC_NON_DEDUCTIBLE_FLAG"/>
        <bm:field name="glass_insurance_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="GLASS_INSURANCE_FLAG" prompt="AST_CAR_INSURANCE.GLASS_INSURANCE_FLAG"/>
        <bm:field name="glass_insurance_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="GLASS_INSURANCE_AMOUNT" prompt="AST_CAR_INSURANCE.GLASS_INSURANCE_AMOUNT"/>
        <bm:field name="seat_insurance_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SEAT_INSURANCE_FLAG" prompt="AST_CAR_INSURANCE.SEAT_INSURANCE_FLAG"/>
        <bm:field name="seat_insurance_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="SEAT_INSURANCE_AMOUNT" prompt="AST_CAR_INSURANCE.SEAT_INSURANCE_AMOUNT"/>
        <bm:field name="combustion_insurance_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="COMBUSTION_INSURANCE_FLAG" prompt="AST_CAR_INSURANCE.COMBUSTION_INSURANCE_FLAG"/>
        <bm:field name="combustion_insurance_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="COMBUSTION_INSURANCE_AMOUNT" prompt="AST_CAR_INSURANCE.COMBUSTION_INSURANCE_AMOUNT"/>
        <bm:field name="add_non_deductible_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ADD_NON_DEDUCTIBLE_FLAG" prompt="AST_CAR_INSURANCE.ADD_NON_DEDUCTIBLE_FLAG"/>
        <bm:field name="compulsory_rebate_rate" databaseType="NUMBER" datatype="java.lang.Double" physicalName="COMPULSORY_REBATE_RATE"/>
        <bm:field name="combustion_rebate_rate" databaseType="NUMBER" datatype="java.lang.Double" physicalName="COMBUSTION_REBATE_RATE"/>
        <bm:field name="compulsory_rebate" databaseType="NUMBER" datatype="java.lang.Double" physicalName="COMPULSORY_REBATE"/>
        <bm:field name="combustion_rebate" databaseType="NUMBER" datatype="java.lang.Double" physicalName="COMBUSTION_REBATE"/>
        <bm:field name="insure_place" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSURE_PLACE"/>
        <bm:field name="insure_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSURE_NAME"/>
        <bm:field name="first_beneficiary" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FIRST_BENEFICIARY"/>
        <bm:field name="insurance_party" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSURANCE_PARTY"/>
        <bm:field name="damage_insurance_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="DAMAGE_INSURANCE_AMOUNT" prompt="AST_CAR_INSURANCE.DAMAGE_INSURANCE_AMOUNT"/>
        <bm:field name="third_party_insurance_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="THIRD_PARTY_INSURANCE_AMOUNT" prompt="AST_CAR_INSURANCE.THIRD_PARTY_INSURANCE_AMOUNT"/>
        <bm:field name="basic_non_deductible_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="BASIC_NON_DEDUCTIBLE_AMOUNT" prompt="AST_CAR_INSURANCE.BASIC_NON_DEDUCTIBLE_AMOUNT"/>
        <bm:field name="pilfer_insurance_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="PILFER_INSURANCE_AMOUNT" prompt="AST_CAR_INSURANCE.PILFER_INSURANCE_AMOUNT"/>
        <bm:field name="commercial_insurance_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="COMMERCIAL_INSURANCE_FLAG" prompt="AST_CAR_INSURANCE.COMMERCIAL_INSURANCE_FLAG"/>
        <bm:field name="document_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_STATUS" prompt="AST_CAR_INSURANCE.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.DOCUMENT_STATUS_DES"/>
        <bm:field name="payment_finish_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PAYMENT_FINISH_FLAG" prompt="AST_CAR_INSURANCE.PAYMENT_FINISH_FLAG"/>
        <bm:field name="insurance_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSURANCE_TYPE" prompt="AST_CAR_INSURANCE.INSURANCE_TYPE"/>
        <bm:field name="ref_v01"/>
        <bm:field name="travel_tax"/>
        <!-- COMPULSORY_REBATE_RATE      NUMBER,
  COMBUSTION_REBATE_RATE      NUMBER,
  COMPULSORY_REBATE           NUMBER,
  COMBUSTION_REBATE           NUMBER,
  INSURE_PLACE                VARCHAR2(200),
  INSURE_NAME                 VARCHAR2(30),
  FIRST_BENEFICIARY           VARCHAR2(30),
  INSURANCE_PARTY             VARCHAR2(200) -->
    </bm:fields>
    <e:exception-descriptor-config>
        <e:exception-descriptor exception="java.sql.SQLException" handleClass="leaf.database.SQLExceptionDescriptor">
            <e:error-message code="1" message="该保单号已经存在,请查证后输入"/>
        </e:exception-descriptor>
    </e:exception-descriptor-config>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk sequenceName="AST_CAR_INSURANCE_S"/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="ast_car_insurance_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field field="item_detail_id" queryOperator="="/>
        <bm:query-field field="ast_car_insurance_id" queryOperator="="/>
    </bm:query-fields>
    <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
                    WHERE
                        t.contract_id    =d.contract_id AND
                        d.ITEM_DETAIL_ID = ${/parameter/@item_detail_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_insurance_maintain, p_instance_id => NULL, p_user_id => ${/session/@user_id});
                    INSERT
                    INTO
                        AST_CAR_INSURANCE
                        (
                            AST_CAR_INSURANCE_ID,
                            ITEM_DETAIL_ID,
                            BP_ID,
                            INSURANCE_NUMBER,
                            INSURANCE_DESCRIPTION,
                            INSURE_DATE,
                            INSURANCE_DATE_FROM,
                            INSURANCE_DATE_TO,
                            INSURANCE_YEAR,
                            COMPULSORY_INSURANCE_AMOUNT,
                            COMMERCIAL_INSURANCE_AMOUNT,
                            OTHERS_INSURANCE_AMOUNT,
                            DAMAGE_INSURANCE_FLAG,
                            THIRD_PARTY_INSURANCE_FLAG,
                            PILFER_INSURANCE_FLAG,
                            BASIC_NON_DEDUCTIBLE_FLAG,
                            GLASS_INSURANCE_AMOUNT,
                            SEAT_INSURANCE_AMOUNT,
                            COMBUSTION_INSURANCE_AMOUNT,
                            ADD_NON_DEDUCTIBLE_FLAG,
                            COMPULSORY_REBATE_RATE,
                            COMBUSTION_REBATE_RATE,
                            COMPULSORY_REBATE,
                            COMBUSTION_REBATE,
                            INSURE_PLACE,
                            INSURE_NAME,
                            FIRST_BENEFICIARY,
                            INSURANCE_PARTY,
                            DAMAGE_INSURANCE_AMOUNT,
                            THIRD_PARTY_INSURANCE_AMOUNT,
                            BASIC_NON_DEDUCTIBLE_AMOUNT,
                            PILFER_INSURANCE_AMOUNT,
                            DOCUMENT_STATUS,
                            PAYMENT_FINISH_FLAG,
                            insurance_type,
                            ref_v01,
                            Travel_Tax,
                            CREATED_BY,
                            CREATION_DATE,
                            LAST_UPDATED_BY,
                            LAST_UPDATE_DATE
                        )
                        VALUES
                        (
                            AST_CAR_INSURANCE_S.NEXTVAL,
                            ${/parameter/@item_detail_id},
                            ${@bp_id},
                            ${@insurance_number},
                            ${@insurance_description},
                            to_date(${@insure_date},'yyyy-mm-dd'),
                            to_date(${@insurance_date_from},'yyyy-mm-dd'),
                            to_date(${@insurance_date_to},'yyyy-mm-dd'),
                            ${@insurance_year},
                            ${@compulsory_insurance_amount},
                            ${@commercial_insurance_amount},
                            ${@others_insurance_amount},
                            ${@damage_insurance_flag},
                            ${@third_party_insurance_flag},
                            ${@pilfer_insurance_flag},
                            ${@basic_non_deductible_flag},
                            ${@glass_insurance_amount},
                            ${@seat_insurance_amount},
                            ${@combustion_insurance_amount},
                            ${@add_non_deductible_flag},
                            ${@compulsory_rebate_rate},
                            ${@combustion_rebate_rate},
                            ${@compulsory_rebate},
                            ${@combustion_rebate},
                            ${@insure_place},
                            ${@insure_name},
                            ${@first_beneficiary},
                            ${@insurance_party},
                            ${@damage_insurance_amount},
                            ${@third_party_insurance_amount},
                            ${@basic_non_deductible_amount},
                            ${@pilfer_insurance_amount},
                            ${@document_status},
                            ${@payment_finish_flag},
                            ${@insurance_type},
                            ${@ref_v01},
                            ${@travel_tax},
                            ${/session/@user_id},
                            sysdate,
                            ${/session/@user_id},
                            sysdate
                        )
                        RETURNING AST_CAR_INSURANCE_ID
                    INTO
                        ${@ast_car_insurance_id};
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="delete">
            <bm:update-sql><![CDATA[
            begin
                delete from ast_car_insurance a
                where  
                   a.ast_car_insurance_id =${@ast_car_insurance_id};
        		delete from
				    ast_car_insurance_records t
				where 
				    t.ast_car_insurance_id =${@ast_car_insurance_id};
				    end;
        	]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
