<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Icon  
    $Date: 2014-10-16 下午7:50:10  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="AST_CAR_DISPATCH_V">
    <bm:fields>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" prompt="AST_CAR_DISPATCH_V.CONTRACT_ID"/>
        <bm:field name="contract_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NAME" prompt="AST_CAR_DISPATCH_V.CONTRACT_NAME"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER" prompt="AST_CAR_DISPATCH_V.CONTRACT_NUMBER"/>
        <bm:field name="bp_id_tenant" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID_TENANT" prompt="AST_CAR_DISPATCH_V.BP_ID_TENANT"/>
        <bm:field name="bp_id_tenant_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_ID_TENANT_N" prompt="AST_CAR_DISPATCH_V.BP_ID_TENANT_N"/>
        <bm:field name="lease_start_date" databaseType="DATE" datatype="java.util.Date" physicalName="LEASE_START_DATE" prompt="AST_CAR_DISPATCH_V.LEASE_START_DATE"/>
        <bm:field name="project_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PROJECT_NUMBER" prompt="AST_CAR_DISPATCH_V.PROJECT_NUMBER"/>
        <bm:field name="contract_status" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_STATUS" prompt="AST_CAR_DISPATCH_V.CONTRACT_STATUS"/>
        <bm:field name="contract_status_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_STATUS_N" prompt="AST_CAR_DISPATCH_V.CONTRACT_STATUS_N"/>
        <bm:field name="document_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_TYPE" prompt="AST_CAR_DISPATCH_V.DOCUMENT_TYPE"/>
        <bm:field name="document_type_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DOCUMENT_TYPE_N" prompt="AST_CAR_DISPATCH_V.DOCUMENT_TYPE_N"/>
        <bm:field name="gps_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="GPS_FLAG" prompt="AST_CAR_DISPATCH_V.GPS_FLAG"/>
        <bm:field name="insurance_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="INSURANCE_FLAG" prompt="AST_CAR_DISPATCH_V.INSURANCE_FLAG"/>
        <bm:field name="mortgage_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="MORTGAGE_FLAG" prompt="AST_CAR_DISPATCH_V.MORTGAGE_FLAG"/>
        <bm:field name="license_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LICENSE_TYPE" prompt="AST_CAR_DISPATCH_V.LICENSE_TYPE"/>
        <bm:field name="license_type_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LICENSE_TYPE_N" prompt="AST_CAR_DISPATCH_V.LICENSE_TYPE_N"/>
        <bm:field name="can_dispatch_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CAN_DISPATCH_FLAG" prompt="AST_CAR_DISPATCH_V.CAN_DISPATCH_FLAG"/>
        <bm:field name="can_dispatch_flag_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CAN_DISPATCH_FLAG_N" prompt="AST_CAR_DISPATCH_V.CAN_DISPATCH_FLAG_N"/>
        <bm:field name="license_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="LICENSE_FLAG" prompt="AST_CAR_DISPATCH_V.LICENSE_FLAG"/>
        <bm:field name="spv_company_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SPV_COMPANY_CODE" prompt="AST_CAR_DISPATCH_V.SPV_COMPANY_CODE"/>
        <bm:field name="spv_company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SPV_COMPANY_ID" prompt="AST_CAR_DISPATCH_V.SPV_COMPANY_ID"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        a.*,
                        'Y' can_dispatch_flag_n
                    FROM
                        AST_CAR_DISPATCH_V a
                    WHERE
                         a.license_flag='Y'
                    UNION
                    SELECT
                        a.*,
                        'N' can_dispatch_flag_n
                    FROM
                        AST_CAR_DISPATCH_V a
                    WHERE
                        NOT EXISTS
                        (SELECT
                            1
                        FROM
                            AST_CAR_DISPATCH_V b
                        WHERE
                            a.contract_id   =b.contract_id AND
                            b.license_flag='Y'
                        )
                    ) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="contract_id" queryExpression="t1.contract_id = ${@contract_id}"/>
        <bm:query-field name="contract_number" queryExpression="t1.contract_number like ${@contract_number}"/>
        <bm:query-field name="contract_name" queryExpression="t1.contract_name like ${@contract_name}"/>
        <bm:query-field name="bp_id_tenant" queryExpression="t1.bp_id_tenant = ${@bp_id_tenant}"/>
        <bm:query-field name="bp_id_tenant_n" queryExpression="t1.bp_id_tenant_n like ${@bp_id_tenant_n}"/>
        <bm:query-field name="lease_date_from" queryExpression="t1.lease_start_date &gt;= ${@lease_date_from}"/>
        <bm:query-field name="lease_date_to" queryExpression="t1.lease_start_date &lt;= ${@lease_date_to}"/>
        <bm:query-field name="gps_flag" queryExpression="t1.gps_flag = ${@gps_flag}"/>
        <bm:query-field name="insurance_flag" queryExpression="t1.insurance_flag = ${@insurance_flag}"/>
        <bm:query-field name="license_flag" queryExpression="t1.license_flag = ${@license_flag}"/>
        <bm:query-field name="mortgage_flag" queryExpression="t1.mortgage_flag = ${@mortgage_flag}"/>
        <bm:query-field name="can_dispatch_flag_n" queryExpression="t1.can_dispatch_flag_n = ${@can_dispatch_flag_n}"/>
        <bm:query-field name="license_type" queryExpression="t1.license_type = ${@license_type}"/>
        <bm:query-field name="can_dispatch_flag" queryExpression="t1.can_dispatch_flag = ${@can_dispatch_flag}"/>
    </bm:query-fields>
</bm:model>
