<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: jinphen  
    $Date: 2013-6-5 下午3:03:33  
    $Revision: 1.0  
    $Purpose: 
-->
<ns1:model xmlns:ns1="http://www.leaf-framework.org/schema/bm" alias="t1" extendMode="reference" needAccessControl="false">
    <ns1:fields>
        <ns1:field name="withdraw_id"/>
        <ns1:field name="loan_contract_id"/>
        <ns1:field name="withdraw_number" forDisplay="true" forQuery="true" prompt="TRE_LOAN_CONTRACT_WITHDRAW.WITHDRAW_NUMBER"/>
        <ns1:field name="withdraw_date" forDisplay="true" prompt="TRE_LOAN_CONTRACT_WITHDRAW.WITHDRAW_DATE"/>
        <ns1:field name="withdraw_amount" forDisplay="true" prompt="TRE_LOAN_CONTRACT_WITHDRAW.WITHDRAW_AMOUNT"/>
        <ns1:field name="remaining_amount"/>
        <ns1:field name="vat_rate_of_interest"/>
        <ns1:field name="loan_accrued_interest"/>
    </ns1:fields>
    <ns1:operations>
        <ns1:operation name="query">
            <ns1:query-sql><![CDATA[
    		select lcw.withdraw_id,
				       lcw.loan_contract_id,
				       lcw.withdraw_number,
				       to_char(lcw.withdraw_date,'yyyy-mm-dd') withdraw_date,
				       lcw.vat_rate_of_interest,
				       lcw.withdraw_amount,
				       lcw.remaining_amount,
				       ( SELECT 
                       t.accrued_interest
                  FROM tre_loan_contract_v c, tre_interest_payable t
                 WHERE c.loan_contract_id = t.loan_contract_id 
                 AND c.loan_contract_id=lcw.loan_contract_id and t.interest_payment_date= to_date(${/parameter/@repayment_date},'yyyy-mm-dd')) loan_accrued_interest
				  from tre_loan_contract_withdraw_v lcw 
				  #WHERE_CLAUSE#
    		]]></ns1:query-sql>
        </ns1:operation>
    </ns1:operations>
    <ns1:query-fields>
        <ns1:query-field field="withdraw_id" queryOperator="="/>
        <ns1:query-field field="loan_contract_id" queryOperator="=" required="true"/>
        <ns1:query-field field="withdraw_number" queryOperator="like"/>
    </ns1:query-fields>
    <ns1:data-filters>
        <ns1:data-filter enforceOperations="query" expression="lcw.status=&apos;REVIEWED&apos; and nvl(lcw.reversed_flag,&apos;N&apos;)=&apos;N&apos; and (lcw.remaining_amount&gt;0 or ${@repayment_type}=&apos;INTEREST&apos;)"/>
    </ns1:data-filters>
</ns1:model>
