<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hc  
    $Date: 2015-8-13 上午10:30:25  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true">
    <a:init-procedure>
        <a:model-query model="cont.CON114.get_batch_id" rootPath="batch_id"/>
        <a:model-query defaultWhereClause="t1.contract_id =${/parameter/@contract_id}" fetchAll="true" model="cont.CON114.con_contract_cashflow" rootPath="con_times_path"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_adj_submit_link" url="${/request/@context_path}/modules/cont/CON114/con_adj_submit.lsc"/>
        <a:link id="con_contract_cashflow_excel_link" url="${/request/@context_path}/modules/cont/CON114/con_contract_cashflow_excel.lsc"/>
        <a:link id="con_contract_interest_main_link" url="${/request/@context_path}/modules/cont/CON114/con_contract_adj_main.lview"/>
        <a:link id="import_upload_link" url="${/request/@context_path}/modules/cont/CON114/import_upload.lview"/>
        <script type="text/javascript"><![CDATA[
            function con114_contract_cf_return() {
                window.location.href = $('con_contract_interest_main_link').getUrl();
            }
            
            function con114_contract_cf_excel() {
                var url;
                url = $('con_contract_cashflow_excel_link').getUrl() + '?contract_id=${/parameter/@contract_id}';
                window.open(url);
            }
            
            function con114_contract_cf_input() {
                var ds = $('con_contract_ds');
                var record = ds.getCurrentRecord();
                if (ds.validate()) {
                    new Leaf.Window({
                        id: 'upload_window',
                        url: $('import_upload_link').getUrl() + '?batch_id=${/model/batch_id/record/@batch_id}' + '&contract_id=${/parameter/@contract_id}' + '&adj_start_times=' + record.get('adj_start_times'),
                        title: '导入实例',
                        width: 420,
                        height: 275
                    });
                }
            }
            
            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"/>';
                }
            
            }
            
            function update_con_contract_event(dataset, record, name, value, oldvalue) {
                if (name == 'adj_start_times' && !Ext.isEmpty(value)) {
                    record.set('leave_times', record.get('pay_times') - value + 1);
                }
            }
            
            function lock_current_window() {
                Leaf.Masker.mask(document.documentElement, '${l:HLS.EXECUTING}');
            }
            
            function unlock_current_window() {
                Leaf.Masker.unmask(document.documentElement);
            }
            
            function con114_contract_cf_sumbit() {
                var ds = $('con_contract_ds');
                var record = ds.getCurrentRecord();
                lock_current_window();
                Leaf.request({
                    url: $('con_adj_submit_link').getUrl(),
                    para: {
                        contract_id: '${/parameter/@contract_id}'
                    },
                    success: function(res) {
                        unlock_current_window();
                    },
                    error: function() {
                        unlock_current_window();
                    },
                    failure: function() {
                        unlock_current_window();
                    },
                    scope: this
                });
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con_times_path_ds">
                <a:datas dataSource="/model/con_times_path"/>
            </a:dataSet>
            <a:dataSet id="con_contract_ds" autoCreate="true" autoQuery="true" model="cont.CON114.con_contract" queryUrl="${/request/@context_path}/autocrud/cont.CON114.con_contract/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="adj_start_times" displayField="times" options="con_times_path_ds" required="true" returnField="adj_start_times" valueField="times"/>
                    <a:field name="leave_times" readOnly="true"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="update_con_contract_event"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="con114_contract_cf_result_ds" autoPageSize="true" autoQuery="true" model="cont.CON114.con_contract_cashflow" queryUrl="${/request/@context_path}/autocrud/cont.CON114.con_contract_cashflow/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="bp_name"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con114_contract_cf_change_ds" autoPageSize="true" autoQuery="true" model="cont.CON114.con_contract_change_cf" queryUrl="${/request/@context_path}/autocrud/cont.CON114.con_contract_change_cf/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="bp_name"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="con114_contract_cf_return" text="HLS.RETURN"/>
                <a:gridButton click="con114_contract_cf_excel" text="导出"/>
                <!-- <a:gridButton type="excel" bind="con114_contract_cf_grid_ds"/> -->
                <a:gridButton click="con114_contract_cf_input" text="导入"/>
                <a:gridButton click="con114_contract_cf_sumbit" text="HLS.SUBMIT"/>
            </a:screenTopToolbar>
            <a:form>
                <a:hBox>
                    <a:comboBox name="adj_start_times" bindTarget="con_contract_ds" prompt="开始期数"/>
                    <a:comboBox name="leave_times" bindTarget="con_contract_ds" prompt="剩余期数"/>
                </a:hBox>
            </a:form>
            <a:tabPanel marginHeight="150" marginWidth="20">
                <a:tabs>
                    <a:tab prompt="当前现金流" width="100">
                        <a:grid id="con114_contract_cf_grid_ds" bindTarget="con114_contract_cf_result_ds" marginHeight="200" marginWidth="30" 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_n" 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:columns>
                        </a:grid>
                    </a:tab>
                    <a:tab prompt="新的现金流" width="100">
                        <a:grid id="con114_contract_cf_change_grid_ds" bindTarget="con114_contract_cf_change_ds" marginHeight="200" marginWidth="30" 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_n" 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:columns>
                        </a:grid>
                    </a:tab>
                </a:tabs>
            </a:tabPanel>
        </a:screenBody>
    </a:view>
</a:screen>
