<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm  
    $Date: 2013-5-30 下午08:08:02  
    $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,
       t1.transaction_num,
       t1.transaction_type,
       to_char(t1.transaction_date, 'yyyy-mm-dd') transaction_date,
       (select gc.currency_name
          from gld_currency_vl gc
         where gc.currency_code = t1.currency_code) as currency_name,
       t1.transaction_amount,
       t1.return_from_csh_trx_id,
       t1.bp_id,
       (select d.bp_name from hls_bp_master_v d where d.bp_id = t1.bp_id) as bp_name, 
        t1.period_name, 
        t1.bank_slip_num, 
        (select cp.description
          from csh_payment_method cp
         where cp.payment_method_id = t1.payment_method_id) as payment_method_display,
         t1.exchange_rate,
         t1.exchange_rate_type,
         t1.bank_account_id,
         (select a.bank_account_code
          from csh_bank_account a
         where a.bank_account_id = t1.bank_account_id
           and a.company_id = t1.company_id) as bank_account_code,
       (select a.bank_account_name
          from csh_bank_account a
         where a.bank_account_id = t1.bank_account_id
           and a.company_id = t1.company_id) as bank_account_name,
       (select a.bank_account_num
          from csh_bank_account a
         where a.bank_account_id = t1.bank_account_id
           and a.company_id = t1.company_id) as bank_account_num,
       (select a.bank_account_code
          from hls_bp_master_bank_account a
         where a.bank_account_id = t1.bp_bank_account_id) as bp_bank_account_code,
       (select a.bank_account_name
          from hls_bp_master_bank_account a
         where a.bank_account_id = t1.bp_bank_account_id) as bp_bank_account_name,
       t1.bp_bank_account_id,
       t1.bp_bank_account_num, 
       t1.bp_bank_branch_name,
       (t1.transaction_amount - nvl(t1.returned_amount, 0) - nvl(t1.write_off_amount, 0)) remain_total_amount,
       (select b.bank_full_name
          from hls_bp_master_bank_account b
         where b.bank_account_id = t1.bp_bank_account_id) bank_key,
       (select c.bank_account_num
          from csh_bank_account c
       where c.bank_account_id = t1.bank_account_id) bank_account_number,
       t1.ref_contract_id,
       (select h.bp_name
          from hls_bp_master h
         where h.bp_id = (select c.bp_id_agent_level1
                            from con_contract c
                           where contract_id = t1.ref_contract_id)) agent_name,
       
       t2.transaction_num rcpt_transaction_num,
       t2.transaction_date rcpt_transaction_date,
       t2.transaction_id rcpt_transaction_id,
       t2.transaction_amount rcpt_transaction_amount,
       t2.transaction_amount rcpt_trs_functional_amount,
       
       to_char(t2.transaction_date, 'yyyy-mm-dd') rcpt_transaction_date,
       (select gc.currency_name
          from gld_currency_vl gc
         where gc.currency_code = t2.currency_code) as rcpt_currency_name,
       

       (select d.bp_name from hls_bp_master_v d where d.bp_id = t2.bp_id) as rcpt_bp_name, 
       (select b.description
          from hls_bp_category b
         where b.bp_category = t2.bp_category) as rcpt_bp_category_display,
        t2.period_name rcpt_period_name, 
        t2.bank_slip_num rcpt_bank_slip_num, 
        (select cp.description
          from csh_payment_method cp
         where cp.payment_method_id = t2.payment_method_id) as rcpt_payment_method_display,
         t2.exchange_rate rcpt_exchange_rate,
         t2.exchange_rate_type rcpt_exchange_rate_type,
         t2.bank_account_id rcpt_bank_account_id,
         (select a.bank_account_code
          from csh_bank_account a
         where a.bank_account_id = t2.bank_account_id
           and a.company_id = t2.company_id) as rcpt_bank_account_code,
       (select a.bank_account_name
          from csh_bank_account a
         where a.bank_account_id = t2.bank_account_id
           and a.company_id = t2.company_id) as rcpt_bank_account_name,
       (select a.bank_account_num
          from csh_bank_account a
         where a.bank_account_id = t2.bank_account_id
           and a.company_id = t2.company_id) as rcpt_bank_account_num,
       (select a.bank_account_code
          from hls_bp_master_bank_account a
         where a.bank_account_id = t2.bp_bank_account_id) as rcpt_bp_bank_account_code,
       (select a.bank_account_name
          from hls_bp_master_bank_account a
         where a.bank_account_id = t2.bp_bank_account_id) as rcpt_bp_bank_account_name,
       t2.bp_bank_account_id rcpt_bp_bank_account_id,
       t2.bp_bank_account_num rcpt_bp_bank_account_num,
       (select tv.type_name
          from gld_exchangerate_types_vl tv
         where tv.type_code = t2.exchange_rate_type) as rcpt_exchange_rate_type_dis,
         t2.returned_amount,
         t2.write_off_amount,
         t1.description return_description,
         t2.description rcpt_description,
         t1.created_by,
       (select u.user_name from sys_user_v u where u.user_id=t1.created_by )user_desc,
       (select return_id from csh_transaction_return t where t.return_transaction_id = t1.transaction_id) return_id
  from csh_transaction t1,csh_transaction t2
  #WHERE_CLAUSE#
  order by t1.transaction_date desc,t1.transaction_num desc
]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:data-filters>
        <bm:data-filter name="query" expression="(t1.company_id=${/session/@company_id} and t1.posted_flag=&apos;Y&apos; and t1.reversed_flag=&apos;N&apos; and t1.write_off_flag = &apos;FULL&apos; and t1.returned_flag = &apos;RETURN&apos; and t1.return_from_csh_trx_id = t2.transaction_id) "/>
    </bm:data-filters>
    <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="bank_slip_num_from" queryExpression="t1.bank_slip_num &gt;= ${@bank_slip_num_from}"/>
        <bm:query-field name="bank_slip_num_to" queryExpression="t1.bank_slip_num &lt;= ${@bank_slip_num_to}"/>
        <bm:query-field name="transaction_amount_from" queryExpression="t1.transaction_amount &gt;= ${@transaction_amount_from}"/>
        <bm:query-field name="transaction_amount_to" queryExpression="t1.transaction_amount &lt;= ${@transaction_amount_to}"/>
        <bm:query-field name="rcpt_transaction_num_from" queryExpression="t2.transaction_num &gt;= ${@rcpt_transaction_num_from}"/>
        <bm:query-field name="rcpt_transaction_num_to" queryExpression="t2.transaction_num &lt;= ${@rcpt_transaction_num_to}"/>
        <bm:query-field name="transaction_date_from" queryExpression="trunc(t1.transaction_date) &gt;= to_date(${@transaction_date_from},&apos;YYYY-MM-DD&apos;)"/>
        <bm:query-field name="transaction_date_to" queryExpression="trunc(t1.transaction_date) &lt;= to_date(${@transaction_date_to},&apos;YYYY-MM-DD&apos;)"/>
        <bm:query-field name="currency_code_from" queryExpression="t1.currency_code &gt;= ${@currency_code_from}"/>
        <bm:query-field name="currency_code_to" queryExpression="t1.currency_code &lt;= ${@currency_code_to}"/>
        <bm:query-field name="user_id" queryExpression="t1.created_by=${@user_id}"/>
        <bm:query-field name="bp_name" queryExpression="t1.bp_id=${@bp_id}"/>
        <bm:query-field name="period_name" queryExpression="t1.period_name=${@period_name}"/>
        <bm:query-field name="transaction_type" queryExpression="t1.transaction_type=${@transaction_type}"/>
    </bm:query-fields>
</bm:model>
