<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-9-10 下午04:29:30  
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    t1.contract_id,
                    t1.contract_number,
                    decode(d.province_name,d.city_name,d.province_name,d.province_name||d.city_name) 
                    || d.district_name
                    || d.address default_address,
                    d.bp_name,
                    d.bp_name_sp,
                    (SELECT
                        av.province_name
                        || av.city_name
                        || av.district_name
                        || av.address
                    FROM
                        hls_bp_master_address_v av
                    WHERE
                        av.bp_id        = cb.bp_id AND
                        av.address_type = 'MAIN_AGENCY_ADRESS' AND
                        rownum          =1
                    ) main_agency_address,
                    '' full_name,
                    
                    to_char(t1.lease_item_amount,'FM99,999,999,999,990.00') lease_item_amount,
                    change_number_to_rmb(t1.lease_item_amount) lease_item_amount_rmb,
                    to_char(t1.finance_amount,'FM99,999,999,999,990.00') finance_amount,
                    change_number_to_rmb(t1.finance_amount) finance_amount_rmb,
                    (select count(*) from CON_CONTRACT_CASHFLOW_V t where t.contract_id = t1.contract_id  and cf_direction ='OUTFLOW' and cf_item =0 and cf_type=0 ) pay_times,
                    t1.bp_id_tenant,
                    (select t.bp_name from hls_bp_master t where t.bp_id = t1.bp_id_tenant ) t_name,
                    (select t.mobil from exp_employees t where t.employee_id =t1.employee_id ) mobil_phone,
                    (select t.name from exp_employees t where t.employee_id =t1.employee_id ) employee_name,
                    con_contract_content_pkg.get_common_content_number(${@contract_id},'ORG','FIN') fin_content_number,
                    con_contract_content_pkg.get_common_content_number(${@contract_id},'ORG','OWN') purchase_order_no,
                    con_contract_content_pkg.get_common_content_number(${@contract_id},'ORG','PUR') pur_ord_no
                FROM
                    con_contract_v t1,
                    con_contract_bp cb,
                    hls_bp_master_all_data_v d
                WHERE
                    t1.contract_id = cb.contract_id AND
                    cb.bp_id       = d.bp_id AND
                    t1.contract_id =${@contract_id}
                    and cb.bp_id = ${@bp_id}
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID" required="true"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER" required="true"/>
        <bm:field name="default_address" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DEFAULT_ADDRESS"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_NAME"/>
        <bm:field name="bp_name_sp" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_NAME_SP"/>
        <bm:field name="main_agency_address" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="MAIN_AGENCY_ADDRESS"/>
        <bm:field name="full_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FULL_NAME"/>
        <bm:field name="lease_item_amount" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="lease_item_amount_rmb" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="pay_times" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="purchase_order_no" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="bp_id_tenant" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="finance_amount" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="finance_amount_rmb" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="t_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="T_NAME"/>
        <bm:field name="mobil_phone" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="employee_name" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="fin_content_number" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="pur_ord_no" databaseType="VARCHAR2" datatype="java.lang.String"/>
    </bm:fields>
</bm:model>
