<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: 26887cz
    $Date: 2021年8月2日15:40:53
    $Revision: 1.0
    $Purpose: 保证金划转复核
-->
<bm:model xmlns:o="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1" baseTable="CSH_TRANSACTION_CONTEMP">
    <bm:fields>
        <bm:field name="contemp_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTEMP_ID"/>
        <bm:field name="bp_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID"/>
        <bm:field name="batch_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BATCH_ID"/>
        <bm:field name="source_contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SOURCE_CONTRACT_ID"/>
        <bm:field name="contract_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CONTRACT_ID"/>
        <bm:field name="contract_number" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CONTRACT_NUMBER" forInsert="false" forUpdate="false"/>
        <bm:field name="je_date" databaseType="DATE" datatype="java.util.Date" physicalName="JE_DATE"/>
        <bm:field name="deposit_trans_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DEPOSIT_TRANS_TYPE"/>
        <bm:field name="deposit_trans_type_desc" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DEPOSIT_TRANS_TYPE_DESC" forInsert="false" forUpdate="false"/>
        <bm:field name="source_trans_type" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SOURCE_TRANS_TYPE"/>
        <bm:field name="deposit_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="DEPOSIT_AMOUNT"/>
        <bm:field name="deposit_info" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="DEPOSIT_INFO"/>
        <bm:field name="bp_id_agent_level1" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID_AGENT_LEVEL1" forInsert="false" forUpdate="false"/>
        <bm:field name="bp_id_agent_level1_n" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_ID_AGENT_LEVEL1_N" forInsert="false" forUpdate="false"/>
        <bm:field name="bp_id_tenant" databaseType="NUMBER" datatype="java.lang.Long" physicalName="BP_ID_TENANT" forInsert="false" forUpdate="false"/>
        <bm:field name="bp_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="BP_NAME" forInsert="false" forUpdate="false"/>
        <bm:field name="file_num" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FILE_NUM" forInsert="false" forUpdate="false"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
        <o:sequence-pk/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="contemp_id"/>
    </bm:primary-key>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
       select * from (select ct.contemp_id,
       ct.bp_id,
       ct.batch_id,
       ct.source_trans_type,
       ct.source_contract_id,
       ct.contract_id,
       (select t.contract_number from con_contract t
       where t.contract_id = ct.contract_id
       and t.data_class = 'NORMAL'
       and rownum = 1) contract_number,
       ct.deposit_trans_type,
       (SELECT sc.code_value_name
          FROM sys_code_values_v sc
         WHERE sc.code = 'DEPOSIT_TRANS_TYPE'
           AND sc.code_value = ct.deposit_trans_type) deposit_trans_type_desc,
       ct.je_date,
       ct.deposit_amount,
       ct.deposit_info,
       cc.bp_id_agent_level1,
       (SELECT t.bp_name
          FROM hls_bp_master t
         WHERE t.bp_id = cc.bp_id_agent_level1) bp_id_agent_level1_n,
       cc.bp_id_tenant,
       (SELECT bpv.bp_name
          FROM hls_bp_master bpv
         WHERE bpv.bp_id = cc.bp_id_tenant) bp_name,
       (select count(1)
        from fnd_atm_attachment_multi fm
         where fm.table_name = 'CSH_TRANSACTION_CONTEMP'
           and fm.table_pk_value = ct.contemp_id) file_num
  from csh_transaction_contemp ct, con_contract cc
 where ct.contract_id = cc.contract_id
   and ct.trans_review_status = 'NEW'
   and cc.data_class = 'NORMAL') t1
        #WHERE_CLAUSE#
    order by t1.contemp_id
    		]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.source_contract_id=${@source_contract_id} "/>
        <bm:data-filter enforceOperations="query" expression="t1.bp_id=${@bp_id} "/>
    </bm:data-filters>
</bm:model>
