<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ericyin  
    $Date: 2013-3-26 上午11:06:41  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="sys_service_welcome_link" url="${/request/@context_path}/welcome.lview"/>
        <script type="text/javascript"><![CDATA[
            function hls_test_back() {
                history.go(-1);
            }
            
            function hls_test_next() {
                history.go(1);
            }
            
            function hls_test_quit() {
                location.href = $('sys_service_welcome_link').getUrl();
                parent.shMenu('show');
            }
            
            function hls_test_grid_clear() {
                $('hls_test_result_ds_grid').clear();
            }
            
            function cal_pv() {
                if (!$('hls_test_head_ds').validate()) {
                    return;
                }
                var head_rec = $('hls_test_head_ds').getAt(0);
                head_rec.set('function_type','PV');
                head_rec.set('_status','update');
                var param = [];
                param.push(head_rec.data); 
                
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/hls.HLS_TST.hls_financial_test_tmp/batch_update',
                    para: param,
                    success: function(response) {
                        //
                        var result_value = response.result.record.return_value;
                        if (result_value == -1) {
                            Leaf.showMessage('提示', 'rate、nper、pmt不能为空!');
                        } else{
                            var result1_rec = $('hls_test_result1_ds').getAt(0);
                            result1_rec.set('pv',result_value);
                        }
                    },
                    scope: this
                });
            }
            
            function cal_fv() {
                if (!$('hls_test_head_ds').validate()) {
                    return;
                }
                var head_rec = $('hls_test_head_ds').getAt(0);
                head_rec.set('function_type','FV');
                head_rec.set('_status','update');
                var param = [];
                param.push(head_rec.data); 
                
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/hls.HLS_TST.hls_financial_test_tmp/batch_update',
                    para: param,
                    success: function(response) {
                        //
                        var result_value = response.result.record.return_value;
                        if (result_value == -1) {
                            Leaf.showMessage('提示', 'rate、nper、pmt不能为空!');
                        } else{
                            var result1_rec = $('hls_test_result1_ds').getAt(0);
                            result1_rec.set('fv',result_value);
                        }
                    },
                    scope: this
                });
            }
            /*
            function cal_rate() {
                if (!$('hls_test_head_ds').validate()) {
                    return;
                }
                var head_rec = $('hls_test_head_ds').getAt(0);
                head_rec.set('function_type','RATE');
                head_rec.set('_status','update');
                var param = [];
                param.push(head_rec.data); 
                
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/hls.HLS_TST.hls_financial_test_tmp/batch_update',
                    para: param,
                    success: function(response) {
                        //
                        var result_value = response.result.record.return_value;
                        if (result_value == -1) {
                            Leaf.showMessage('提示', 'rate、nper、pmt不能为空!');
                        } else{
                            var result1_rec = $('hls_test_result1_ds').getAt(0);
                            result1_rec.set('pv',result_value);
                        }
                    },
                    scope: this
                });
            }
            */
            function cal_pmt() {
                if (!$('hls_test_head_ds').validate()) {
                    return;
                }
                var head_rec = $('hls_test_head_ds').getAt(0);
                head_rec.set('function_type','PMT');
                head_rec.set('_status','update');
                var param = [];
                param.push(head_rec.data); 
                
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/hls.HLS_TST.hls_financial_test_tmp/batch_update',
                    para: param,
                    success: function(response) {
                        //
                        var result_value = response.result.record.return_value;
                        if (result_value == -1) {
                            Leaf.showMessage('提示', 'rate、nper、pv不能为空!');
                        } else{
                            $('hls_test_result2_ds').query();
                        }
                    },
                    scope: this
                });
            }
            
            function cal_ipmt() {
                if (!$('hls_test_head_ds').validate()) {
                    return;
                }
                var head_rec = $('hls_test_head_ds').getAt(0);
                head_rec.set('function_type','IPMT');
                head_rec.set('_status','update');
                var param = [];
                param.push(head_rec.data); 
                
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/hls.HLS_TST.hls_financial_test_tmp/batch_update',
                    para: param,
                    success: function(response) {
                        //
                        var result_value = response.result.record.return_value;
                        if (result_value == -1) {
                            Leaf.showMessage('提示', 'rate、nper、pv不能为空!');
                        } else{
                            $('hls_test_result2_ds').query();
                        }
                    },
                    scope: this
                });
            }
            
            function hls_test_excel(){
                $('hls_test_result_ds_grid')._export();
            }
            
            function formatMoney(v){
                return Leaf.formatNumber(v,8);
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="type_ds">
                <a:datas>
                    <a:record name="0" value="0"/>
                    <a:record name="1" value="1"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="hls_test_head_ds" autoCreate="true">
                <a:fields>
                    <a:field name="pv" datatype="java.lang.Long"/>
                    <a:field name="fv" datatype="java.lang.Long"/>
                    <a:field name="rate" datatype="java.lang.Long"/>
                    <a:field name="pmt" datatype="java.lang.Long"/>
                    <a:field name="nper" datatype="java.lang.Long"/>
                    <a:field name="type_desc" datatype="java.lang.Long" displayField="name" options="type_ds" returnField="type" valueField="value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="hls_test_result1_ds" autoCreate="true">
                <a:fields>
                    <a:field name="pv" readOnly="true"/>
                    <a:field name="fv" readOnly="true"/>
                    <a:field name="rate" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="hls_test_result2_ds" autoQuery="true" model="hls.HLS_TST.hls_financial_test_tmp" pageSize="50" selectable="true">
                <a:fields>
                    <a:field name="per" readOnly="true"/>
                    <a:field name="pmt" readOnly="true"/>
                    <a:field name="ipmt" readOnly="true"/>
                    <a:field name="outstanding" readOnly="true"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar height="29">
                <a:button click="hls_test_back" height="20" icon="${/request/@context_path}/images/back.png" iconAlign="left" text="HLS.BACK" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="hls_test_next" height="20" icon="${/request/@context_path}/images/forward.png" iconAlign="left" text="HLS.FORWARD" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="hls_test_quit" height="20" icon="${/request/@context_path}/images/quit.png" iconAlign="left" text="HLS.EXIT" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="hls_test_grid_clear" height="20" icon="${/request/@context_path}/images/clear.png" iconAlign="left" text="HLS.CLEAR" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="hls_test_excel" height="20" icon="${/request/@context_path}/images/excel_16.png" iconAlign="left" text="导出" width="50"/>
                <a:separator style="margin-left:3px;"/>
            </a:screenTopToolbar>
            <a:hBox>
                <a:form column="2" title="租赁测算表" width="500">
                    <a:numberField name="pv" allowFormat="true" bindTarget="hls_test_head_ds" decimalPrecision="2" prompt="PV"/>
                    <a:numberField name="nper" bindTarget="hls_test_head_ds" decimalPrecision="0" prompt="NPER"/>
                    <a:numberField name="fv" allowFormat="true" bindTarget="hls_test_head_ds" decimalPrecision="2" prompt="FV"/>
                    <a:comboBox name="type_desc" bindTarget="hls_test_head_ds" prompt="TYPE"/>
                    <a:numberField name="rate" allowDecimals="true" allowFormat="true" bindTarget="hls_test_head_ds" decimalPrecision="10" prompt="RATE"/>
                    <a:numberField name="pmt" allowFormat="true" bindTarget="hls_test_head_ds" decimalPrecision="2" prompt="PMT"/>
                </a:form>
                <a:vBox>
                    <a:form column="3" title="显示结果" width="500">
                        <a:numberField name="pv" allowFormat="true" bindTarget="hls_test_result1_ds" decimalPrecision="8" prompt="PV"/>
                        <a:numberField name="fv" allowFormat="true" bindTarget="hls_test_result1_ds" decimalPrecision="8" prompt="FV"/>
                        <a:numberField name="rate" allowFormat="true" bindTarget="hls_test_result1_ds" decimalPrecision="8" prompt="RATE"/>
                    </a:form>
                    <a:hBox>
                        <a:button id="b_pv" click="cal_pv" text="PV"/>
                        <a:button id="b_fv" click="cal_fv" text="FV"/>
                        <a:button id="b_irr" text="IRR"/>
                        <a:button id="b_pmt" click="cal_pmt" text="PMT"/>
                        <a:button id="b_ipmt" click="cal_ipmt" text="IPMT"/>
                    </a:hBox>
                </a:vBox>
            </a:hBox>
            <a:grid id="hls_test_result_ds_grid" Height="450" bindTarget="hls_test_result2_ds" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="per" prompt="PER" width="100"/>
                    <a:column name="pmt" prompt="PMT" renderer="formatMoney" width="140"/>
                    <a:column name="ipmt" prompt="IPMT" renderer="formatMoney" width="140"/>
                    <a:column name="outstanding" prompt="本金余额" renderer="formatMoney" width="140"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>