<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Feng  
    $Date: 2014-5-16 下午3:48:54  
    $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_GPS" defaultOrderBy="t1.enabled_flag desc,t1.ast_car_gps_id desc">
    <bm:fields>
        <bm:field name="ast_car_gps_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="AST_CAR_GPS_ID" prompt="AST_CAR_GPS.AST_CAR_GPS_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_GPS.ITEM_DETAIL_ID"/>
        <bm:field name="imei" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="IMEI" prompt="AST_CAR_GPS.IMEI"/>
        <bm:field name="install_date" databaseType="DATE" datatype="java.util.Date" physicalName="INSTALL_DATE" prompt="AST_CAR_GPS.INSTALL_DATE"/>
        <bm:field name="gps_provider" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="GPS_PROVIDER" prompt="AST_CAR_GPS.GPS_PROVIDER"/>
        <bm:field name="gps_provider_desc" forInsert="false" forUpdate="false"/>
        <bm:field name="procurement_price" databaseType="NUMBER" datatype="java.lang.Double" physicalName="PROCUREMENT_PRICE" prompt="AST_CAR_GPS.PROCUREMENT_PRICE"/>
        <bm:field name="install_fee" databaseType="NUMBER" datatype="java.lang.Double" physicalName="INSTALL_FEE" prompt="AST_CAR_GPS.INSTALL_FEE"/>
        <bm:field name="gps_fee" databaseType="NUMBER" datatype="java.lang.Double" physicalName="GPS_FEE" prompt="AST_CAR_GPS.GPS_FEE"/>
        <bm:field name="remove_date" databaseType="DATE" datatype="java.util.Date" physicalName="REMOVE_DATE" prompt="AST_CAR_GPS.REMOVE_DATE"/>
        <bm:field name="gps_fee_back" databaseType="NUMBER" datatype="java.lang.Double" physicalName="GPS_FEE_BACK" prompt="AST_CAR_GPS.GPS_FEE_BACK"/>
        <bm:field name="arrange_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ARRANGE_FLAG" prompt="AST_CAR_GPS.ARRANGE_FLAG"/>
        <bm:field name="enabled_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ENABLED_FLAG" prompt="AST_CAR_GPS.ENABLED_FLAG"/>
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION" prompt="AST_CAR_GPS.DESCRIPTION"/>
        <bm:field name="contactor" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTACTOR" prompt="AST_CAR_GPS.CONTACTOR"/>
        <bm:field name="phone" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PHONE" prompt="AST_CAR_GPS.PHONE"/>
        <bm:field name="install_address" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSTALL_ADDRESS" prompt="AST_CAR_GPS.INSTALL_ADDRESS"/>
        <bm:field name="install_location" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSTALL_LOCATION" prompt="AST_CAR_GPS.INSTALL_LOCATION"/>
        <bm:field name="employee_id"/>
        <bm:field name="financial_manager_name"/>
        <bm:field name="owner_user_tel"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk sequenceName="AST_CAR_GPS_S"/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="ast_car_gps_id"/>
    </bm:primary-key>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
        		SELECT * FROM
        		(SELECT
        		    acg.*,
        		    (select t.bp_name from hls_bp_master t where t.bp_id=acg.gps_provider ) gps_provider_desc,
        		    c.employee_id,
        		    (SELECT ee.description FROM SYS_USER ee WHERE ee.user_id = c.owner_user_id
        		    ) financial_manager_name,
        		    c.owner_user_tel
        		FROM
        		    ast_car_gps acg,
        		    con_contract_item_detail cid,
        		    con_contract_lease_item cli,
        		    con_contract c
        		WHERE
        		    acg.item_detail_id         = cid.item_detail_id AND
        		    cid.contract_lease_item_id = cli.contract_lease_item_id AND
        		    cli.contract_id            = c.contract_id
        		) t1 #WHERE_CLAUSE#
    		 		]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
                BEGIN
                    ast_car_pkg.insert_ast_car_gps(p_item_detail_id =>${/parameter/@item_detail_id},
                               p_imei =>${@imei},
                               p_install_date =>${@install_date},
                               p_gps_provider =>${@gps_provider},
                               p_procurement_price =>${@procurement_price},
                               p_install_fee =>${@install_fee},
                               p_gps_fee =>${@gps_fee},
                               p_remove_date =>${@remove_date},
                               p_gps_fee_back =>${@gps_fee_back},
                               p_arrange_flag =>${@arrange_flag},
                               p_enabled_flag =>${@enabled_flag},
                               p_description  =>${@description},
                               p_contactor =>${@contactor},
                               p_phone =>${@phone},
                               p_install_address =>${@install_address},
                               p_install_location =>${@install_location},
                               p_user_id   =>${/session/@user_id});
                    COMMIT;           
                END;
            ]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN
                    ast_car_pkg.update_ast_car_gps(p_ast_car_gps_id =>${@ast_car_gps_id},
                    		   p_item_detail_id =>${/parameter/@item_detail_id},
                    		   p_imei =>${@imei},
                               p_install_date =>${@install_date},
                               p_gps_provider =>${@gps_provider},
                               p_procurement_price =>${@procurement_price},
                               p_install_fee =>${@install_fee},
                               p_gps_fee =>${@gps_fee},
                               p_remove_date =>${@remove_date},
                               p_gps_fee_back =>${@gps_fee_back},
                               p_arrange_flag =>${@arrange_flag},
                               p_enabled_flag =>${@enabled_flag},
                               p_description  =>${@description},	
                               p_contactor =>${@contactor},
                               p_phone =>${@phone},
                               p_install_address =>${@install_address},
                               p_install_location =>${@install_location},
                               p_user_id   =>${/session/@user_id});
                    COMMIT;           
                END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field field="item_detail_id" queryOperator="="/>
    </bm:query-fields>
</bm:model>
