<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2013-4-17 下午03:22:27  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="gld.gld_currency_vl" rootPath="currency"/>
        <a:model-query defaultWhereClause="t1.price_list=${/session/@price_list}" fetchAll="true"
                       model="hls.HLS050.hls_price_list_for_lov" rootPath="default_price_list_path"/>
        <a:model-query defaultWhereClause="t1.currency_code=&apos;CNY&apos;" fetchAll="true" model="gld.gld_currency_vl"
                       rootPath="default_currency"/>
    </a:init-procedure>
    <a:view>
        <a:link id="hls_fin_calculator_id"
                url="${/request/@context_path}/modules/hls/HLS500N/hls_fin_calculator_n.lview"/>
        <a:link id="hls_fin_calculator_id_new"
                url="${/request/@context_path}/modules/hls/HLS500N/hls_fin_calculator_update_n.lview"/>
        <script type="text/javascript"><![CDATA[
        function hls_hls500_confirm() {
            debugger;
            $('hls_hls500_confirm_id').disable();
            if (!$('hls_fin_calc_list_head_ds').validate()) {
                $('hls_hls500_confirm_id').enable();
                return;
            }
            var record = $('hls_fin_calc_list_head_ds').getAt(0);
            var url = $('hls_fin_calculator_id').getUrl() + '?price_list=' + record.get('price_list') + '&currency=' + record.get('currency_code') + '&precision=' + record.get('precision') + '&calc_method=' + record.get('calc_method');
            window.location.href = url;
        }
        // function hls_hls500_confirm() {
        //
        //     var url;
        //     var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
        //     var quotation_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_quotation');
        //     var history_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CASHFLOW_NS', 'prj_quotation');
        //
        //     var record = $(quotation_ds_id).getCurrentRecord();
        //     var head_record = $(ds_id).getAt(0);
        //
        //     url = $('hls_fin_calculator_id_new').getUrl();
        //
        //     if (record.dirty == true) {
        //         Leaf.showMessage('${l:PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
        //         return;
        //     }
        //     if ($(quotation_ds_id).validate()) {
        //         /*if (!record.get('price_list') || !record.get('currency') || !record.get('lease_times')) {
        //             Leaf.showMessage('${l:PROMPT}', '${l:HLS.QUOTATION_EXECUTE_AFTER_SAVE}');
        //             return;
        //         }*/
        //
        //         var parent_pk_value = head_record.get('project_id');
        //         record.set('function_code', 'PRJ505_QUOTATION');
        //         record.set('function_usage', 'UPDATE');
        //         record.set('project_id', parent_pk_value);
        //         //拆分合同可维护
        //         window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
        //         //首次插入
        //         if (!record.get('calc_session_id')) {
        //             record.set('to_doc_table', 'HLS_FIN_CALCULATOR_HD');
        //             var calc_recreate_L_formula;
        //             calc_recreate_L_formula = 'Y';
        //
        //             record.set('_status', 'update');
        //             record.set('from_doc_table', 'PRJ_QUOTATION');
        //             record.set('from_doc_pk', record.get('quotation_id'));
        //             record.set('calculate_flag', 'N');
        //             if (!'${/parameter/@document_id}') {
        //                 record.set('document_id', parent_pk_value);
        //             }
        //             var saveData = [];
        //             saveData.push(record.data);
        //             Leaf.request({
        //                 url: $('${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_doc_quotation_link_id').getUrl(),
        //                 para: saveData,
        //                 success: function (res) {
        //
        //                     window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //                     $(quotation_ds_id).query();
        //                     $(history_ds_id).query();
        //                     var quotation_id = record.get('quotation_id') || res.result.record.quotation_id;
        //                     var win = new Leaf.Window({
        //                         id: 'hls_fin_calc_quotation_link_winid',
        //                         params: {
        //                             document_id: parent_pk_value,
        //                             document_category: 'PROJECT',
        //                             maintain_type: 'MODIFY',
        //                             calc_session_id: res.result.record.calc_session_id,
        //                             quotation_id: quotation_id,
        //                             dsId: quotation_ds_id,
        //                             winId: 'hls_fin_calc_quotation_link_winid',
        //                             global_flag: 'Y',
        //                             id_num: 0,
        //                             calc_type: '${/parameter/@calc_type}' || 'CLASSIC_CALCULATOR',
        //                             recreate_L_formula: calc_recreate_L_formula
        //                         },
        //                         url: url,
        //                         fullScreen: true,
        //                         draggable: true
        //                     });
        //                     win.on('close', function () {
        //                         $(quotation_ds_id).query();
        //                         $(history_ds_id).query();
        //
        //                     });
        //                 },
        //                 failure: function () {
        //                     window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //                 },
        //                 error: function () {
        //                     window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //                 },
        //                 scope: this
        //             });
        //         } else {
        //             window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //             var cal_hd_price_list = record.get('cal_hd_price_list');
        //             var price_list = record.get('price_list');
        //             if (cal_hd_price_list == price_list) {
        //
        //                 //直接进入报价页面
        //                 var win = new Leaf.Window({
        //                     id: 'hls_fin_calc_quotation_update_link_winid',
        //                     params: {
        //                         document_id: parent_pk_value,
        //                         document_category: 'PROJECT',
        //                         maintain_type: 'MODIFY',
        //                         calc_session_id: record.get('calc_session_id'),
        //                         quotation_id: record.get('quotation_id'),
        //                         dsId: quotation_ds_id,
        //                         winId: 'hls_fin_calc_quotation_update_link_winid',
        //                         global_flag: 'Y',
        //                         id_num: 0,
        //                         calc_type: '${/parameter/@calc_type}',
        //                         recreate_L_formula: 'N'
        //                     },
        //                     url: url,
        //                     fullScreen: true,
        //                     draggable: true
        //                 });
        //                 win.on('close', function () {
        //                     $(quotation_ds_id).query();
        //                     $(history_ds_id).query();
        //                 });
        //             } else {
        //                 record.set('to_doc_table', 'HLS_FIN_CALCULATOR_HD');
        //                 var calc_recreate_L_formula;
        //                 calc_recreate_L_formula = 'Y';
        //
        //                 record.set('_status', 'update');
        //                 record.set('from_doc_table', 'PRJ_QUOTATION');
        //                 record.set('from_doc_pk', record.get('quotation_id'));
        //                 record.set('calculate_flag', 'N');
        //                 if (!'${/parameter/@document_id}') {
        //                     record.set('document_id', parent_pk_value);
        //                 }
        //                 var saveData = [];
        //                 saveData.push(record.data);
        //                 Leaf.request({
        //                     url: $('${/parameter/@layout_code}${/parameter/@tree_code}_hls_fin_doc_quotation_link_id').getUrl(),
        //                     para: saveData,
        //                     success: function (res) {
        //
        //                         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //                         $(quotation_ds_id).query();
        //                         var quotation_id = record.get('quotation_id') || res.result.record.quotation_id;
        //                         var win = new Leaf.Window({
        //                             id: 'hls_fin_calc_quotation_link_winid',
        //                             params: {
        //                                 document_id: parent_pk_value,
        //                                 document_category: 'PROJECT',
        //                                 maintain_type: 'MODIFY',
        //                                 calc_session_id: res.result.record.calc_session_id,
        //                                 quotation_id: quotation_id,
        //                                 dsId: quotation_ds_id,
        //                                 winId: 'hls_fin_calc_quotation_link_winid',
        //                                 global_flag: 'Y',
        //                                 id_num: 0,
        //                                 calc_type: '${/parameter/@calc_type}' || 'CLASSIC_CALCULATOR',
        //                                 recreate_L_formula: calc_recreate_L_formula
        //                             },
        //                             url: url,
        //                             fullScreen: true,
        //                             draggable: true
        //                         });
        //                         win.on('close', function () {
        //                             $(quotation_ds_id).query();
        //                             $(history_ds_id).query();
        //
        //                         });
        //                     },
        //                     failure: function () {
        //                         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //                     },
        //                     error: function () {
        //                         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
        //                     },
        //                     scope: this
        //                 });
        //             }
        //         }
        //     }
        // }

        Leaf.onReady(function () {
            document.onkeydown = function (event) {
                var e = event || window.event || arguments.callee.caller.arguments[0];
                if (e && e.keyCode == 13) { // enter 键
                    hls_hls500_confirm();
                }
            };
        });
        ]]></script>
        <a:dataSets>
            <a:dataSet id="currency_ds">
                <a:datas dataSource="/model/currency"/>
            </a:dataSet>
            <a:dataSet id="hls_fin_calc_list_head_ds" autoCreate="true">
                <a:fields>
                    <a:field name="currency_code" defaultValue="${/model/default_currency/record/@currency_code}"/>
                    <a:field name="currency_name" defaultValue="${/model/default_currency/record/@currency_name}"
                             displayField="currency_name" options="currency_ds" required="true"
                             returnField="currency_code" valueField="currency_code">
                        <a:mapping>
                            <a:map from="precision" to="precision"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="precision" defaultValue="${/model/default_currency/record/@precision}"/>
                    <a:field name="price_list_name" autoComplete="true"
                             defaultValue="${/model/default_price_list_path/record/@description}" fetchSingle="true"
                             lovGridHeight="350" lovHeight="500" lovService="hls.HLS050.hls_price_list_for_lov"
                             lovWidth="500" required="true" title="HLS.PRICE_LIST">
                        <a:mapping>
                            <a:map from="price_list" to="price_list"/>
                            <a:map from="description" to="price_list_name"/>
                            <a:map from="calc_method" to="calc_method"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="calc_method" defaultValue="${/model/default_price_list_path/record/@calc_method}"/>
                    <a:field name="price_list" defaultValue="${/model/default_price_list_path/record/@price_list}"
                             fetchSingle="true" lovGridHeight="350" lovHeight="500"
                             lovService="hls.HLS500N.hls_price_list_lov" lovWidth="500" required="true"
                             title="HLS.PRICE_LIST">
                        <a:mapping>
                            <a:map from="price_list" to="price_list"/>
                            <a:map from="description" to="price_list_name"/>
                            <a:map from="calc_method" to="calc_method"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton id="hls_hls500_confirm_id" click="hls_hls500_confirm" text="HLS.CONFIRM"/>
            </a:screenTopToolbar>
            <a:form title="HLS.FIN_CALCULATOR" width="350">
                <a:lov name="price_list" bindTarget="hls_fin_calc_list_head_ds" prompt="HLS.PRICE_LIST_CODE"
                       width="220"/>
                <a:lov name="price_list_name" bindTarget="hls_fin_calc_list_head_ds" prompt="HLS.PRICE_LIST_NAME"
                       width="220"/>
                <a:comboBox name="currency_name" bindTarget="hls_fin_calc_list_head_ds" prompt="HLS.CURRENCY"
                            width="220"/>
            </a:form>
        </a:screenBody>
    </a:view>
</a:screen>
