<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-10-10 下午01:46:54  
    $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 t1.transaction_id exchange_out_transaction_id,
				       t1.transaction_num,
				       t1.transaction_date,
				       t1.posted_flag,
				       t1.currency_code exchange_out_currency_code,
				       (select gc.currency_name
				          from gld_currency_vl gc
				         where gc.currency_code = t1.currency_code) exchange_out_currency_name,
				       t1.transaction_amount exchange_out_trx_amount,
				       t1.bank_slip_num exchange_out_bank_slip_num,
				       t1.bank_account_id exchange_out_bank_account_id,
				       (select a.bank_account_name
				          from csh_bank_account a
				         where a.bank_account_id = t1.bank_account_id) exchange_out_bank_account_name,
				       (select a.bank_account_num
				          from csh_bank_account a
				         where a.bank_account_id = t1.bank_account_id) exchange_out_bank_account_num,
				       t2.transaction_id exchange_in_transaction_id,
				       t2.currency_code exchange_in_currency_code,
				       (select gc.currency_name
				          from gld_currency_vl gc
				         where gc.currency_code = t2.currency_code) exchange_in_currency_name,
				       t2.transaction_amount exchange_in_trx_amount,
				       t2.bank_slip_num exchange_in_bank_slip_num,
				       t2.bank_account_id exchange_in_bank_account_id,
				       (select a.bank_account_name
				          from csh_bank_account a
				         where a.bank_account_id = t2.bank_account_id) exchange_in_bank_account_name,
				       (select a.bank_account_num
				          from csh_bank_account a
				         where a.bank_account_id = t1.bank_account_id) exchange_in_bank_account_num,
				       t1.created_by,
				         (SELECT
                            e.name
                        FROM
                            sys_user u,
                            exp_employees e
                        WHERE
                            t1.created_by = u.user_id AND
                            u.employee_id   = e.employee_id
                        )user_name
				  from csh_transaction t1, csh_transaction t2
				  #WHERE_CLAUSE#
	     ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="exchange_out_transaction_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EXCHANGE_OUT_TRANSACTION_ID"/>
        <bm:field name="transaction_num" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TRANSACTION_NUM"/>
        <bm:field name="transaction_date" databaseType="DATE" datatype="java.util.Date" physicalName="TRANSACTION_DATE"/>
        <bm:field name="posted_flag" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="POSTED_FLAG"/>
        <bm:field name="exchange_out_currency_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EXCHANGE_OUT_CURRENCY_CODE"/>
        <bm:field name="exchange_out_currency_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EXCHANGE_OUT_CURRENCY_NAME"/>
        <bm:field name="exchange_out_trx_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="EXCHANGE_OUT_TRX_AMOUNT"/>
        <bm:field name="exchange_out_bank_slip_num" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EXCHANGE_OUT_BANK_SLIP_NUM"/>
        <bm:field name="exchange_out_bank_account_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EXCHANGE_OUT_BANK_ACCOUNT_ID"/>
        <bm:field name="exchange_out_bank_account_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EXCHANGE_OUT_BANK_ACCOUNT_NAME"/>
        <bm:field name="exchange_out_bank_account_num" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EXCHANGE_OUT_BANK_ACCOUNT_NUM"/>
        <bm:field name="exchange_in_transaction_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EXCHANGE_IN_TRANSACTION_ID"/>
        <bm:field name="exchange_in_currency_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EXCHANGE_IN_CURRENCY_NAME"/>
        <bm:field name="exchange_in_trx_amount" databaseType="NUMBER" datatype="java.lang.Double" physicalName="EXCHANGE_IN_TRX_AMOUNT"/>
        <bm:field name="exchange_in_bank_slip_num" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EXCHANGE_IN_BANK_SLIP_NUM"/>
        <bm:field name="exchange_in_bank_account_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="EXCHANGE_IN_BANK_ACCOUNT_ID"/>
        <bm:field name="exchange_in_bank_account_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EXCHANGE_IN_BANK_ACCOUNT_NAME"/>
        <bm:field name="exchange_in_bank_account_num" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="EXCHANGE_IN_BANK_ACCOUNT_NUM"/>
        <bm:field name="created_by" databaseType="NUMBER" datatype="java.lang.Long" physicalName="CREATED_BY"/>
        <bm:field name="user_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="USER_NAME"/>
    </bm:fields>
    <bm:query-fields>
        <bm:query-field name="transaction_num_from" queryExpression="t1.transaction_num &gt;= ${@transaction_num_from}"/>
        <bm:query-field name="transaction_num_to" queryExpression="t1.transaction_num &lt;= ${@transaction_num_to}"/>
        <bm:query-field name="currency_in" queryExpression="t2.currency_code = ${@currency_in}"/>
        <bm:query-field name="currency_out" queryExpression="t1.currency_code = ${@currency_out}"/>
        <bm:query-field name="transaction_date_from" queryExpression="t1.transaction_date &gt;= to_date(${@transaction_date_from},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="transaction_date_to" queryExpression="t1.transaction_date &lt;= to_date(${@transaction_date_to},&apos;yyyy-mm-dd&apos;)"/>
        <bm:query-field name="exchange_in_bank_account_id" queryExpression="t2.bank_account_id=${@exchange_in_bank_account_id}"/>
        <bm:query-field name="exchange_out_bank_account_id" queryExpression="t1.bank_account_id=${@exchange_out_bank_account_id}"/>
        <bm:query-field name="exchange_in_bank_slip_num_from" queryExpression="t2.bank_slip_num &gt;= ${@exchange_in_bank_slip_num_from}"/>
        <bm:query-field name="exchange_in_bank_slip_num_to" queryExpression="t2.bank_slip_num &lt;= ${@exchange_in_bank_slip_num_to}"/>
        <bm:query-field name="exchange_out_bank_slip_num_from" queryExpression="t1.bank_slip_num &gt;= ${@exchange_out_bank_slip_num_from}"/>
        <bm:query-field name="exchange_out_bank_slip_num_to" queryExpression="t1.bank_slip_num &lt;= ${@exchange_out_bank_slip_num_to}"/>
        <bm:query-field field="posted_flag" queryExpression="t1.posted_flag=${@posted_flag} or ${@posted_flag}=&apos;ALL&apos;"/>
        <bm:query-field name="user_id" queryExpression="t1.created_by=${@user_id}"/>
    </bm:query-fields>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="t1.twin_csh_trx_id = t2.transaction_id and t1.transaction_type = &apos;EXCHANGE_OUT&apos; and t1.company_id=${/session/@company_id}"/>
    </bm:data-filters>
</bm:model>
