<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
               SELECT fam.table_name,
                      fam.table_pk_value,
                      fam.record_id,
                      faa.attachment_id,
                      faa.file_name,
                      faa.file_path
               FROM prj_cdd_item_doc_ref      doc,
                    fnd_atm_attachment_multi  fam,
                    fnd_atm_attachment        faa,
                    prj_cdd_item_check        pck,
                    prj_cdd_item_list_grp_tab lgt,
                    prj_cdd_item_tab_group    tg,
                    prj_cdd_item              pci
               WHERE doc.document_id = ${@table_pk_value}
                 AND doc.document_table = ${@table_name}
                 AND fam.table_name = 'PRJ_CDD_ITEM_CHECK'
                 AND fam.table_pk_value = TO_CHAR(doc.check_id)
                 AND fam.attachment_id = faa.attachment_id
                 and lgt.tab_group_id = tg.tab_group_id
                 and lgt.cdd_list_id = pci.cdd_list_id
                 and pci.cdd_item_id = lgt.cdd_item_id
                 and pci.cdd_list_id = ${@cdd_list_id}
                 AND lgt.cdd_list_id = pci.cdd_list_id
                 and pck.check_id=doc.check_id
                 and pci.cdd_item_id =  pck.cdd_item_id
                 and tg.tab_group=${@group_code}
             union all
               SELECT fam.table_name,
                      fam.table_pk_value,
                      fam.record_id,
                      faa.attachment_id,
                      faa.file_name,
                      faa.file_path
               FROM
                    fnd_atm_attachment_multi  fam,
                    fnd_atm_attachment        faa,
                    con_contract_content ccc

               WHERE
                  fam.table_name = 'CON_CONTRACT'
                 AND fam.table_pk_value = ccc.check_id
                 AND fam.attachment_id = faa.attachment_id
                 and ccc.contract_id=${@table_pk_value}
                 and nvl(${@ele_flag},'N')='Y'
                  and  ccc.check_id is not null

            ]]></bm:query-sql>
            <bm:parameters>
                <bm:parameter name="table_pk_value"/>
                <bm:parameter name="table_name"/>
                <bm:parameter name="cdd_list_id"/>
                <bm:parameter name="group_code"/>
                <bm:parameter name="@ele_flag"/>
            </bm:parameters>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="table_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TABLE_NAME" required="true"/>
        <bm:field name="table_pk_value" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TABLE_PK_VALUE" required="true"/>
        <bm:field name="record_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="RECORD_ID" required="true"/>
        <bm:field name="attachment_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="ATTACHMENT_ID" required="true"/>
        <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:fields>
</bm:model>
