<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="BGFL_EXTERNAL_DEBT_QUOTA_HD">
    <bm:fields>
        <bm:field name="hd_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="HD_ID" prompt="BGFL_EXTERNAL_DEBT_QUOTA_HD.HD_ID"/>
        <bm:field name="company_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="COMPANY_ID" prompt="BGFL_EXTERNAL_DEBT_QUOTA_HD.COMPANY_ID"/>
        <bm:field name="company_code" expression="(select fc.company_code from fnd_companies fc where fc.company_id=t1.company_id)"/>
        <bm:field name="company_name" expression="(select fc.company_short_name from fnd_companies fc where fc.company_id=t1.company_id)"/>
        <bm:field name="inflow_quota" databaseType="NUMBER" datatype="java.lang.Long" physicalName="INFLOW_QUOTA" prompt="BGFL_EXTERNAL_DEBT_QUOTA_HD.INFLOW_QUOTA"/>
        <bm:field name="available_quota" databaseType="NUMBER" datatype="java.lang.Long" physicalName="AVAILABLE_QUOTA" prompt="BGFL_EXTERNAL_DEBT_QUOTA_HD.AVAILABLE_QUOTA"/>
        <bm:field name="used_quota" databaseType="NUMBER" datatype="java.lang.Long" physicalName="USED_QUOTA" prompt="BGFL_EXTERNAL_DEBT_QUOTA_HD.USED_QUOTA"/>
        <!-- <bm:field name="enabled_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="ENABLED_FLAG" prompt="BGFL_EXTERNAL_DEBT_QUOTA_HD.ENABLED_FLAG"/> -->
        <bm:field name="description" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DESCRIPTION" prompt="BGFL_EXTERNAL_DEBT_QUOTA_HD.DESCRIPTION"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="company_name" queryExpression="company_id = ${@company_id}"/>
        <bm:query-field name="inflow_quota_from" queryExpression="inflow_quota &gt;=${@inflow_quota_from}"/>
        <bm:query-field name="inflow_quota_to" queryExpression="inflow_quota &lt;=${@inflow_quota_to}"/>
        <!-- <bm:query-field name="enabled_flag_desc" queryExpression="enabled_flag = ${@enabled_flag}"/> -->
        <bm:query-field name="available_quota_from" queryExpression="available_quota &gt;=${@available_quota_from}"/>
        <bm:query-field name="available_quota_to" queryExpression="available_quota &lt;=${@available_quota_to}"/>
        <bm:query-field name="used_quota_from" queryExpression="used_quota &gt;=${@used_quota_from}"/>
        <bm:query-field name="used_quota_to" queryExpression="used_quota &lt;=${@used_quota_to}"/>
    </bm:query-fields>
    <bm:operations>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
    			begin
    				bgfl_external_debt_quota_pkg.external_debt_quota_hd_insert(p_company_id      =>${@company_id},
                                          									   p_inflow_quota    =>${@inflow_quota},
                                          									   p_available_quota =>${@available_quota},
                                         									   p_used_quota      =>${@used_quota},
                                          									   p_description     =>${@description},
                                          									   p_user_id         =>${/session/@user_id});
    			end;
    		]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
    			begin
    				bgfl_external_debt_quota_pkg.external_debt_quota_hd_update(p_hd_id           =>${@hd_id},
    																		   p_inflow_quota    =>${@inflow_quota},
                                          									   p_description     =>${@description},
                                          									   p_user_id         =>${/session/@user_id});
    			end;
    		]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <!-- <e:exception-descriptor-config xmlns:e="leaf.service.exception" >
    	<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:model>
