<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang
    $Date: 2016-3-10 上午09:52: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
                    (SELECT
                        cc.contract_number
                    FROM
                        con_contract cc
                    WHERE
                        cc.contract_id = doc.contract_id
                    )
                    ||
                    (SELECT
                        ccc.bp_id_tenant_n
                    FROM
                        con_contract_lv ccc
                    WHERE
                        ccc.contract_id = doc.contract_id
                    )
                    || faa.file_type_code,
                    faa.file_name,
                    faa.file_path,
                    (SELECT
                        t.bp_id_tenant_n
                    FROM
                        con_contract_lv t
                    WHERE
                        t.contract_id = ${@contract_id}
                    ) bp_id_tenant_n,
                    (SELECT
                        t.contract_number
                    FROM
                        con_contract_lv t
                    WHERE
                        t.contract_id = ${@contract_id}
                    ) contract_number
                FROM
                    con_collection_tool doc,
                    fnd_atm_attachment_multi fam,
                    fnd_atm_attachment faa
                WHERE
                    doc.collection_id  = NVL(${@collection_id}, doc.collection_id) AND
                    doc.contract_id    = NVL(${@contract_id}, doc.contract_id) AND
                    fam.table_name     = 'CON_COLLECTION_TOOL' AND
                    fam.table_pk_value = doc.collection_id AND
                    fam.attachment_id  = faa.attachment_id
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="file_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_NAME"/>
        <bm:field name="file_path" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_PATH"/>
        <bm:field name="bp_id_tenant_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_ID_TENANT_N"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER"/>
    </bm:fields>
</bm:model>
