<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng
    $Date: 2018-10-16 18:24:26
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="DBLINK_SIMPLE_CONTRACT_FR_T">
    <bm:operations>
        <bm:operation name="execute">
            <bm:update-sql><![CDATA[
            begin
              -- Call the procedure
              ds_document_interface_pkg.create_simple_contract(p_dealer_cd => ${@dealer_cd},
                                                               p_chance_no => ${@chance_no},
                                                               p_machine_type => ${@machine_type},
                                                               p_success => ${@success},
                                                               p_msg => ${@msg},
                                                               p_user_id => ${/session/@user_id});
            end;
            ]]></bm:update-sql>
            <bm:parameters>
                <bm:parameter name="success" input="false" output="true" outputPath="@success"/>
                <bm:parameter name="msg" input="false" output="true" outputPath="@msg"/>
            </bm:parameters>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="dealer_cd"/>
        <bm:field name="chance_no"/>
        <bm:field name="cust_name"/>
        <bm:field name="company_name"/>
        <bm:field name="company_address"/>
        <bm:field name="company_legal"/>
        <bm:field name="har_address"/>
        <bm:field name="hand_phone"/>
        <bm:field name="brc_card_name"/>
        <bm:field name="brc_card_code"/>
        <bm:field name="brc_card_address"/>
        <bm:field name="gdc_cssi_tel"/>
        <bm:field name="gdc_card_name"/>
        <bm:field name="gdc_card_code"/>
        <bm:field name="gdc_card_address"/>
        <bm:field name="gdpoc_cssi_tel"/>
        <bm:field name="model_name"/>
        <bm:field name="f6020_r"/>
        <bm:field name="f6020_l"/>
        <bm:field name="f2060_r"/>
        <bm:field name="f4010_r"/>
        <bm:field name="f4040_r"/>
        <bm:field name="f5120_r"/>
        <bm:field name="f3010_r"/>
        <bm:field name="dcfl_cycle_code"/>
        <bm:field name="dcfl_code"/>
        <bm:field name="machine_type"/>
        <bm:field name="unique_code"/>
        <bm:field name="machine_type_n"  expression="decode(machine_type,'01','挖掘机','02','装载机','10','OEM','')"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:query-fields>
        <bm:query-field field="dealer_cd" queryOperator="="/>
        <bm:query-field field="chance_no" queryOperator="="/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter name="user_id" expression=" (exists (select 1 from aut_owner_user_authorize a1,(SELECT m.bp_id,m.bp_funnel_id,u.user_id FROM hls_bp_master m, sys_user u
                  WHERE  m.bp_id = u.bp_id AND u.bp_category = 'AGENT') a2 where  a1.owner_user_id = a2.user_id and a1.trx_category = 'CONTRACT'
                    and a1.authorized_user_id = ${/session/@user_id} and a2.bp_funnel_id = t1.dealer_cd) or (SELECT u.bp_category FROM sys_user u  WHERE u.user_id = ${/session/@user_id}) = 'EMPLOYEE')"/>
    </bm:data-filters>
</bm:model>
