<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:fields>
        <bm:field name="file_name"/>
        <bm:field name="file_path"/>
        <bm:field name="file_size"/>
        <bm:field name="order_seq"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
select fa.file_name, fa.file_path, fa.file_size, ct.order_seq
  from fnd_atm_attachment       fa,
       fnd_atm_attachment_multi fm,
       con_contract_content     cc,
       con_clause_templet       ct
 where fa.attachment_id = fm.attachment_id
   and fm.table_name = 'CON_CONTRACT_CONTENT'
   and cc.contract_id = ${@contract_id}
   and cc.content_id = fm.table_pk_value
   and cc.templet_id = ct.templet_id
   and fm.table_pk_value = cc.content_id
   and ct.templet_code in
       (select cf.templet_code
          from con_ele_signer_file cf, con_contract_ele_signer cs
         where cf.con_ele_signer_id = cs.con_ele_signer_id
           and cs.contract_id = cc.contract_id
           and ((('AGENT' not in(select cb.bp_category
                     from con_contract_bp cb, hls_bp_master hm
                    where cb.bp_id = hm.bp_id
                      and hm.social_code = ${@id_no}
                      and cb.contract_id = cc.contract_id)or
               not exists(select 1
                     from con_contract_bp cb, hls_bp_master hm
                    where cb.bp_id = hm.bp_id
                      and hm.social_code = ${@id_no}
                      and cb.contract_id = cc.contract_id)) and
               exists (select 1
                          from hls_doc_file_templet_signer hs,
                               con_clause_templet          ct,
                               hls_doc_file_templet        ht
                         where hs.templet_id = ht.templet_id
                           and ht.templet_code = ct.templet_code
                           and ct.templet_id = cf.templet_id
                           and hs.enable_flag = 'Y'
                           and hs.signer_category not in
                               ('AGENCY_STORE_SEAL',
                                'AGENCY_STORE_SIGN',
                                'HONGLING_SEAL',
                                'HONGLING_SIGN',
                                'MAN_FACTURER_SEAL',
                                'MAN_FACTURER_SIGN',
                                'SUPPLIER_SEAL',
                                'SUPPLIER_SIGN',
                                'LEASE_SUPPLIER_SEAL',
                                'LEASE_SUPPLIER_SIGN'))) or
               'AGENT' in (select cb.bp_category
                   from con_contract_bp cb, hls_bp_master hm
                  where cb.bp_id = hm.bp_id
                    and hm.social_code = ${@id_no}
                    and cb.contract_id = cc.contract_id)
               or
              'VENDER' in (select cb.bp_category
                  from con_contract_bp cb, hls_bp_master hm
                 where cb.bp_id = hm.bp_id
                   and hm.social_code = ${@id_no}
                   and cb.contract_id = cc.contract_id)))
                order by ct.order_seq
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
