<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:fields>
        <bm:field name="attachment_id"/>
        <bm:field name="file_name"/>
        <bm:field name="file_path"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
select fa.file_name,fa.file_path,fa.attachment_id
                   from prj_cdd_item pi,PRJ_CDD_ITEM_CHECK pc,fnd_atm_attachment_multi fm,fnd_atm_attachment fa
                  where pc.cdd_item_id = pi.cdd_item_id
                   and fm.table_pk_value = pc.check_id
                   and fm.attachment_id = fa.attachment_id
                   and fm.table_name = 'CON_CONTRACT'
                   and pi.cdd_item in
                        (select decode(cf.templet_code,
                                'LEASE_CONTRACT_MASTER_OEC','CONTRACT',
                                'LEASE_REQUEST_OEC','LEASE_ITEM_REQ',
                                'LEASE_INFO_OEC','TN_GU_INFO',
                                'LEASE_SURE_PER_OEC','GUARANTEE_LETTER_OEC',
                                'LEASE_SURE_SEL_OEC','S_GUARANTEE_LETTER_OEC',
                                'LEASE_CHECK_OEC','CHECK_INFO',
                                'LEASE_SURE_PAR_OEC','SPOUSE_COMMITMENT',
                                'LEASE_SALE_RL_OEC','PUR_CONTRACT',
                                'LEASE_SALE_YL_OEC','PUR_CONTRACT',
                                'LEASE_SURE_BUS_OEC','GUARANTEE_LETTER_OEC',
                                'R_LEASE_CONTRACT_MASTER_OEC','CONTRACT',
                                'R_LEASE_REQUEST_OEC','LEASE_ITEM_REQ',
                                'R_LEASE_INFO_OEC','TN_GU_INFO',
                                'R_LEASE_SURE_PER_OEC','GUARANTEE_LETTER_OEC',
                                'R_LEASE_SURE_SEL_OEC','S_GUARANTEE_LETTER_OEC',
                                'R_LEASE_SURE_BUS_OEC','GUARANTEE_LETTER_OEC',
                                'R_LEASE_CHECK_OEC','CHECK_INFO',
                                'R_LEASE_SURE_PAR_OEC','SPOUSE_COMMITMENT',
                                'R_LEASE_SALE_OEC','PUR_CONTRACT',
                                'S_LEASE_CONTRACT_MASTER_B_OEC','CONTRACT',
                                'S_LEASE_PAY_OEC','CASHFLOW_INFO',
                                'S_LEASE_CHECK_OEC','CHECK_INFO',
                                'S_LEASE_SURE_PER_OEC','GUARANTEE_LETTER_OEC',
                                'S_LEASE_SURE_PAR_OEC','SPOUSE_COMMITMENT',
                                'S_LEASE_SURE_F_OEC','S_GUARANTEE_LETTER_OEC',
                                'S_LEASE_SURE_BUS_OEC','GUARANTEE_LETTER_OEC',
                                'S_LEASE_ORDER_OEC','ITEM_TRAN_NOTICE',
                                'S_LEASE_PAY_REQ_OEC','PAYMENT_REQ',
                                'S_LEASE_MOR_OEC','MORT_CONTRACT',
                                'FINANCE_LEASE_CONTRACT_TJ_S_E',  --update by xsh35973 铁甲电子签约
                                'FINANCE_LEASE_CONTRACT_TJ_S_E',
                                'FINANCE_LEASE_CONTRACT_TJ_E',
                                'FINANCE_LEASE_CONTRACT_TJ_E',
                                'CON_COLLECTION_PAYMENT_TJ_E',
                                'CON_COLLECTION_PAYMENT_TJ_E',
                                'CON_CONTRACT_MORTGAGE_TJ_E',
                                'CON_CONTRACT_MORTGAGE_TJ_E',
                                'PERSONAL_CREDIT',
                                'PERSONAL_CREDIT',
                                'FINANCE_LEASE_CONTRACT_TJ_FR_E',
                                'FINANCE_LEASE_CONTRACT_TJ_FR_E',
                                'CON_GUR_NP',
                                'CON_GUR_NP',
                                'FINANCE_LEASE_CONTRACT_FR_KJ_E','FINANCE_LEASE_CONTRACT_FR_KJ_E',--update by gzj 北京卡家电子签约
                                'FINANCE_LEASE_CONTRACT_KJ_FR_E','FINANCE_LEASE_CONTRACT_KJ_FR_E',
                                'FINANCE_LEASE_CONTRACT_KJ_S_E','FINANCE_LEASE_CONTRACT_KJ_S_E',
                                'FINANCE_LEASE_CONTRACT_KJ_E','FINANCE_LEASE_CONTRACT_KJ_E',
                                'CSH_PAYMENT_REQ_KJ_1_E','CSH_PAYMENT_REQ_KJ_1_E',
                                'CON_CONTRACT_MORTGAGE_KJ_E','CON_CONTRACT_MORTGAGE_KJ_E',
                                'LEASE_CONTRACT_PAR_KJ_E','LEASE_CONTRACT_PAR_KJ_E',
                                'LEASE_CONTRACT_PAR_KJ_1_E','LEASE_CONTRACT_PAR_KJ_1_E',
                                'CON_COLLECTION_PAYMENT_KJ_E','CON_COLLECTION_PAYMENT_KJ_E',
                                --博雷顿
                                'PERSONAL_CREDIT_BLD_E',
                                'CREDIT_AUTHOR',
                                'ENTERPRISE_CREDIT_BLD_E',
                                'CREDIT_AUTHOR',
                                'PERSONAL_CREDIT_GUTA_BLD_E',
                                'CREDIT_AUTHOR',
                                'ENTERPRISE_CREDIT_GUTA_BLD_E',
                                'CREDIT_AUTHOR',
                                'ACCEPTANCE_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'PAR_TENANT_BLD_E',
                                'SPOUSE_COMMITMENT',
                                'PAR_GUTA_BLD_E',
                                'SPOUSE_COMMITMENT',
                                'SURE_LEASE_GR_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'SURE_LEASE_FR_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'PROOF_RECEIPT_LEASE_BLD_E',
                                'CHECK_INFO',
                                'LEASE_SALE_BLD_E',
                                'PUR_CONTRACT',
                                'FINANCE_LEASE_CONTRACT_BLD_E',
                                'CONTRACT',
                                'SURE_LEASEBACK_GR_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'SURE_LEASEBACK_FR_BLD_E',
                                'GUARANTEE_LETTER_OEC',
                                'PROOF_RECEIPT_LEASEBACK_BLD_E',
                                'CHECK_INFO',
                                'LEASE_ORDER_LEASEBACK_BLD_E',
                                'ITEM_TRAN_NOTICE',
                                'CON_CONTRACT_MORTGAGE_BLD_E',
                                'MORT_CONTRACT',
                                'CON_CONTRACT_LEASEBACK_BLD_E',
                                'CONTRACT'
                                )
                    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 = ${@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 = cs.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 = cs.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 = cs.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 = cs.contract_id)))
                    and pi.cdd_list_id =
                        (select cc.cdd_list_id
                           from con_contract cc
                          where cc.contract_id = ${@contract_id}
                            and cc.data_class = 'NORMAL')
                    order by pi.order_seq
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
