<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:f="leaf.database.features" xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="CONTRACT_INSURANCE_TEMP" needAccessControl="false">
    <bm:fields>
        <bm:field name="record_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RECORD_ID" prompt="CONTRACT_INSURANCE_TEMP.RECORD_ID"/>
        <bm:field name="batch_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BATCH_ID" prompt="CONTRACT_INSURANCE_TEMP.BATCH_ID"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER" prompt="CONTRACT_INSURANCE_TEMP.CONTRACT_NUMBER"/>
        <bm:field name="insurance_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSURANCE_NUMBER" prompt="CONTRACT_INSURANCE_TEMP.INSURANCE_NUMBER"/>
        <bm:field name="pattern" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="pattern" prompt="CONTRACT_INSURANCE_TEMP.pattern"/>
        <bm:field name="model_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="MODEL_NUMBER" prompt="CONTRACT_INSURANCE_TEMP.MODEL_NUMBER"/>
        <bm:field name="engine_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ENGINE_NUMBER" prompt="CONTRACT_INSURANCE_TEMP.ENGINE_NUMBER"/>
        <bm:field name="real_insurance_date"  prompt="CONTRACT_INSURANCE_TEMP.REAL_INSURANCE_DATE"/>
        <bm:field name="insurance_end_date"  prompt="CONTRACT_INSURANCE_TEMP.INSURANCE_END_DATE"/>
        <bm:field name="ins_company"  />
        <bm:field name="err_message" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ERR_MESSAGE" prompt="CONTRACT_INSURANCE_TEMP.ERR_MESSAGE"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="record_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field name="batch_id" queryExpression="t1.batch_id=${@batch_id}"/>
    </bm:query-fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
               Select t1.record_id,
               t1.batch_id,
               t1.contract_number,
               t1.insurance_number,
               t1.pattern,
               t1.model_number,
               t1.engine_number,
               to_char(t1.real_insurance_date,'yyyy-mm-dd') real_insurance_date,
               to_char(t1.insurance_end_date ,'yyyy-mm-dd') insurance_end_date,
               t1.ins_company,
               t1.err_message
          From CONTRACT_INSURANCE_TEMP t1
          Where t1.batch_id =${@batch_id}
         Order By decode(t1.err_message, Null, 2, 1),contract_number asc
         ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            begin
             contract_insurance_pkg.save_data
                    (
                        p_batch_id=>${@batch_id},
                        p_user_id=>${/session/@user_id},
                        p_company_id =>${/session/@company_id}
                    );
             end;
         ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
            begin
             contract_insurance_pkg.save_insurance_data(
                                p_contract_id         =>${@contract_id},
                                p_insurance_number    =>${@insurance_number},
                                p_insurance_fee       =>${@insurance_fee},
                                p_insurance_rate      =>${@insurance_rate},
                                p_real_insurance_date =>to_date(${@real_insurance_date},'yyyy-mm-dd'),
                                p_insurance_end_date  =>to_date(${@insurance_end_date},'yyyy-mm-dd'),
                                p_ins_company         =>${@ins_company},
                                p_user_id             =>${/session/@user_id}
                                );
             end;
         ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
