<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm  
    $Date: 2013-10-29 下午4:08:06  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="PRJ_BP_GUAR_ANALYSIS_LV">
    <!-- <bm:fields>
        <bm:field name="record_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RECORD_ID" prompt="PRJ_BP_GUAR_ANALYSIS_LV.RECORD_ID"/>
        <bm:field name="prj_bp_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PRJ_BP_ID" prompt="PRJ_BP_GUAR_ANALYSIS_LV.PRJ_BP_ID"/>
        <bm:field name="bp_seq" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_SEQ" prompt="PRJ_BP_GUAR_ANALYSIS_LV.BP_SEQ"/>
        <bm:field name="prj_bp_id_c" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PRJ_BP_ID_C" prompt="PRJ_BP_GUAR_ANALYSIS_LV.PRJ_BP_ID_C"/>
        <bm:field name="prj_bp_id_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="PRJ_BP_ID_N" prompt="PRJ_BP_GUAR_ANALYSIS_LV.PRJ_BP_ID_N"/>
        <bm:field name="warrantee" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="WARRANTEE" prompt="PRJ_BP_GUAR_ANALYSIS_LV.WARRANTEE"/>
        <bm:field name="amount_of_guant" databaseType="NUMBER" datatype="java.lang.Long" physicalName="AMOUNT_OF_GUANT" prompt="PRJ_BP_GUAR_ANALYSIS_LV.AMOUNT_OF_GUANT"/>
        <bm:field name="start_date_guant" databaseType="DATE" datatype="java.util.Date" physicalName="START_DATE_GUANT" prompt="PRJ_BP_GUAR_ANALYSIS_LV.START_DATE_GUANT"/>
        <bm:field name="end_date_guant" databaseType="DATE" datatype="java.util.Date" physicalName="END_DATE_GUANT" prompt="PRJ_BP_GUAR_ANALYSIS_LV.END_DATE_GUANT"/>
        <bm:field name="type_guant" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TYPE_GUANT" prompt="PRJ_BP_GUAR_ANALYSIS_LV.TYPE_GUANT"/>
        <bm:field name="reason_guant" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REASON_GUANT" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REASON_GUANT"/>
        <bm:field name="counter_guant_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="COUNTER_GUANT_FLAG" prompt="PRJ_BP_GUAR_ANALYSIS_LV.COUNTER_GUANT_FLAG"/>
        <bm:field name="mutual_guant_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="MUTUAL_GUANT_FLAG" prompt="PRJ_BP_GUAR_ANALYSIS_LV.MUTUAL_GUANT_FLAG"/>
        <bm:field name="ref_v01" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V01" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_V01"/>
        <bm:field name="ref_v02" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V02" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_V02"/>
        <bm:field name="ref_v03" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V03" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_V03"/>
        <bm:field name="ref_v04" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V04" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_V04"/>
        <bm:field name="ref_v05" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="REF_V05" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_V05"/>
        <bm:field name="ref_n01" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N01" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_N01"/>
        <bm:field name="ref_n02" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N02" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_N02"/>
        <bm:field name="ref_n03" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N03" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_N03"/>
        <bm:field name="ref_n04" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N04" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_N04"/>
        <bm:field name="ref_n05" databaseType="NUMBER" datatype="java.lang.Long" physicalName="REF_N05" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_N05"/>
        <bm:field name="ref_d01" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D01" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_D01"/>
        <bm:field name="ref_d02" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D02" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_D02"/>
        <bm:field name="ref_d03" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D03" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_D03"/>
        <bm:field name="ref_d04" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D04" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_D04"/>
        <bm:field name="ref_d05" databaseType="DATE" datatype="java.util.Date" physicalName="REF_D05" prompt="PRJ_BP_GUAR_ANALYSIS_LV.REF_D05"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:data-filters>
        <bm:data-filter name="prj_bp_id" enforceOperations="query" expression="exists ( select 1 from PRJ_PROJECT_BP b where b.project_id =${@project_id} and b.prj_bp_id = t1.prj_bp_id)"/>
    </bm:data-filters> -->
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                select t1.PRJ_BP_ID,
    t1.WARRANTEE,
    to_char(t1.AMOUNT_OF_GUANT,'FM99,999,999,990.00') AMOUNT_OF_GUANT,
    to_char(t1.START_DATE_GUANT,'yyyy-mm-dd') START_DATE_GUANT,
    to_char(t1.END_DATE_GUANT,'yyyy-mm-dd') END_DATE_GUANT,
    t1.TYPE_GUANT,
    t1.REASON_GUANT,
    CASE WHEN t1.COUNTER_GUANT_FLAG = 'Y' AND t1.MUTUAL_GUANT_FLAG = 'Y'  THEN '反担保/互保'
         WHEN t1.COUNTER_GUANT_FLAG = 'Y'   THEN '反担保'
         WHEN  t1.MUTUAL_GUANT_FLAG = 'Y'  THEN '互保'
        ELSE NULL END GUANT_FLAG
    
  from PRJ_BP_GUAR_ANALYSIS_LV t1
 where exists (select 1
          from PRJ_PROJECT_BP b
         where b.project_id = ${@project_id}
           and b.prj_bp_id = t1.prj_bp_id)
union all
select t1.PRJ_BP_ID,
    '合计' WARRANTEE,
    to_char(sum(t1.AMOUNT_OF_GUANT),'FM99,999,999,990.00'),
    '' START_DATE_GUANT,
    '' END_DATE_GUANT,
    '' TYPE_GUANT,
    '' REASON_GUANT,
    null GUANT_FLAG
  from PRJ_BP_GUAR_ANALYSIS_LV t1
 where exists (select 1
          from PRJ_PROJECT_BP b
         where b.project_id = ${@project_id}
           and b.prj_bp_id = t1.prj_bp_id)
 group by t1.prj_bp_id

            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
