<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:view>
        <script type="text/javascript"><![CDATA[
             
             function con110_con_contract_return() {
                $('con_contract_interest_history_winid').close();
            }        
                
            function con110_con_contract_query() {
                var record= $('con110_contract_query_ds').getCurrentRecord();               
                $('con_contract_ds').setQueryParameter('interest_start_date_from', record.get('interest_start_date_from'));
                $('con_contract_ds').setQueryParameter('interest_start_date_to', record.get('interest_start_date_to'));
                $('con_contract_ds').query();
            }            
            
            function onSelect_contract(ds, record) {
                $('con_contract_workflow_ds').setQueryParameter('contract_id', record.get('contract_id'));
                $('con_contract_workflow_ds').query();
            } 
            
            //renderer函数，根据代码转化成图片
            function get_grid_pic(value, record, name) {               
              
                if (value == 'OUTFLOW') {
                    return '<img src="${/request/@context_path}/images/outflow.png" style="margin-top:4px"/>';
                } else if (value == 'INFLOW') {
                    return '<img src="${/request/@context_path}/images/inflow.png" style="margin-top:4px"/>';
                } else if (value == 'NONCASH') {
                    return '<img src="${/request/@context_path}/images/noncash.png" style="margin-top:4px"/>';
                } else if (value == 'CASH') {
                    return '<img src="${/request/@context_path}/images/cash.png" style="margin-top:4px"/>';
                }
                
            }
            
            //renderer函数，根据代码查找变更原因
            function get_Reason(value, record, name) {               
              
                if (value == 'CONTRACT_CREATION') {
                    return '合同创建';
                } else if (value == 'CHANGE_REQ') {
                    return '合同变更';
                }else if (value == 'ADJUST_INTEREST') {
                    return '调息';
                }            
            }           
                
            
            //renderer函数，百分比格式化
            function formatIntRate(value, record, name) { 
                
                if (!Ext.isEmpty(value))
                {
                    return value.toFixed(8);
                }                
            }
            
             
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con110_contract_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="interest_start_date_from"/>
                    <a:field name="interest_start_date_to"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_contract_ds" autoPageSize="true" autoQuery="true" model="cont.CON110.con_contract_interest_history" queryDataSet="con110_contract_query_ds" queryUrl="${/request/@context_path}/autocrud/cont.CON110.con_contract_interest_history/query?contract_number=${/parameter/@contract_number}" selectable="true" selectionModel="single">
                <a:events>
                    <a:event name="select" handler="onSelect_contract"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="con_contract_workflow_ds" autoPageSize="true" bindName="lines" bindTarget="con_contract_ds" model="cont.CON110.con_contract_cashflow_interset_history"><![CDATA[       
            ]]></a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="con110_con_contract_return" text="HLS.RETURN"/>
                <a:gridButton click="con110_con_contract_query" text="HLS.QUERY"/>
            </a:screenTopToolbar>
            <a:form column="2" labelSeparator=" " labelWidth="100" marginWidth="50" title="CON301.CONTRACT_QUERY">
                <a:datePicker name="interest_start_date_from" bindTarget="con110_contract_query_ds" prompt="调息日期从"/>
                <a:datePicker name="interest_start_date_to" bindTarget="con110_contract_query_ds" prompt="调息日期到"/>
            </a:form>
            <a:grid bindTarget="con_contract_ds" height="180" marginWidth="50" navBar="true">
                <a:columns>
                    <a:column name="contract_number" prompt="HLS.CONTRACT_NUMBER"/>
                    <a:column name="contract_name" prompt="HLS.CONTRACT_NAME"/>
                    <a:column name="version_date" prompt="变更日期" renderer="Leaf.formatDate"/>
                    <a:column name="version_display" prompt="版本号"/>
                    <a:column name="data_class" prompt="HLS.VERSION_TYPE"/>
                    <a:column name="version_reason" prompt="变更原因" renderer="get_Reason"/>
                    <a:column name="adjust_rate_type" prompt="调息节点"/>
                    <a:column name="int_rate_fixing_way" prompt="调息方式"/>
                    <a:column name="base_rate" prompt="基准利率(%)"/>
                    <a:column name="int_rate" prompt="合同利率(%)" renderer="formatIntRate"/>
                    <a:column name="total_rental" prompt="CON305.TOTAL_RENTAL" renderer="Leaf.formatMoney"/>
                    <a:column name="total_interest" prompt="利息总额" renderer="Leaf.formatMoney"/>
                    <a:column name="finance_income" prompt="融资收益" renderer="Leaf.formatMoney"/>
                </a:columns>
            </a:grid>
            <a:grid bindTarget="con_contract_workflow_ds" height="350" marginWidth="50" navBar="true">
                <a:columns>
                    <a:column name="cf_direction" prompt="收/付" renderer="get_grid_pic"/>
                    <a:column name="cf_status" prompt="状态"/>
                    <a:column name="times" prompt="期数"/>
                    <a:column name="cf_item" prompt="现金流项目"/>
                    <a:column name="calc_date" prompt="计算日" renderer="Leaf.formatDate"/>
                    <a:column name="due_date" prompt="CON901.DUE_DATE" renderer="Leaf.formatDate"/>
                    <a:column name="due_amount" prompt="CON305.ACC_AMOUNT" renderer="Leaf.formatMoney"/>
                    <a:column name="principal" prompt="CON305.ACC_PRINCIPAL" renderer="Leaf.formatMoney"/>
                    <a:column name="interest" prompt="CON305.ACC_INTEREST" renderer="Leaf.formatMoney"/>
                    <a:column name="outstanding_prin_tax_incld" prompt="当期剩余本金" renderer="Leaf.formatMoney"/>
                    <a:column name="generated_source" prompt="现金流来源"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
