<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: duzhihong  
    $Date: 2015-1-14 下午3:03:47  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="(exists(select 1 from hls_lease_org_assign ha where ha.unit_id=t1.unit_id))" fetchAll="true" model="basic.exp_org_unit_manager_lov" rootPath="con501_exp_org_unit_manager_path"/>
        <a:model-query defaultWhereClause="t1.batch_hd_id=${/parameter/@batch_hd_id}" model="cont.CON115.con_batch_adjust_ln_count" rootPath="batch_ln_count"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_update_link_id" url="${/request/@context_path}/modules/cont/CON500/con_contract_update.lview"/>
        <!-- <a:link id="pageLink_nanshan_all_layout" url="${/request/@context_path}/modules/nanshan_all_layout.lview"/> -->
        <a:link id="pageLink_nanshan_all_layout" url="${/request/@context_path}/modules/cont/CON115/con_contract_change_info.lview"/>
        <a:link id="con_contract_interest_float_link" url="${/request/@context_path}/modules/cont/CON110/con_contract_change_info.lview"/>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con_batch_adjust_interest_ln_link_id" model="cont.CON115.con_batch_adjust_interest_ln" modelaction="execute"/>
        <a:link id="batch_adjust_interest_link" model="cont.CON115.con_batch_adjust_interest_hd" modelaction="execute"/>
        <a:link id="con_batch_adjust_ln_count_link" model="cont.CON115.con_batch_adjust_ln_count" modelaction="execute"/>
        <a:link id="con_batch_adjust_ln_delete_link" url="${/request/@context_path}/modules/cont/CON115/bgfl_cancel_adjust_batch_ln.lsc"/>
        <a:link id="con115_calc_adjust_con_income_link" model="cont.CON115.calc_adjust_con_income" modelaction="update"/>
        <a:link id="rpt4070_hn_report_4070_query_link" url="${/request/@context_path}/modules/rpt/RPT4070/hn_report_4070_query.lview"/>
        <script type="text/javascript"><![CDATA[
            function lock_list_detail_window() {
                Leaf.Masker.mask($('${/parameter/@win_id}').wrap, '${l:HLS.EXECUTING}');
            }
            
            function unlock_list_detail_window() {
                Leaf.Masker.unmask($('${/parameter/@win_id}').wrap);
            }
            
            function con501_con_contract_return() {
                $('batch_adjust_detail_winid').close();
            }
            
            function con501_con_contract_query() {
                $('CON115_contract_result_ds').query();
            }
            
            function con501_con_contract_reset() {
                $('CON115_contract_query_ds').reset();
            }
            
            function open_rpt4070_hn_report_4070_query(contract_id,test_flag){

                var url = $('rpt4070_hn_report_4070_query_link').getUrl();
                  var win = new Leaf.Window({
                    id: 'rpt4070_hn_report_4070_query_winid',
                    url: url,
                    params: {
                        contract_id: contract_id,
                        test_flag: test_flag,
                        win_id: 'rpt4070_hn_report_4070_query_winid'
                    },
                    title: '收入明细界面',
                    fullScreen: true
                });
              
            }
            
            function CON115_contractRenderer(value, record, name) {
                var rec = $('bacth_adjust_hd_query').getAt(0);
                if (name == 'change_req_id') {
                    //if (rec.get('approval_status') == 'APPROVED') {
                    //return '';
                    //} else {
                    if (record.get('adjust_flag') == 'Y') {
                        return '<a href="javascript:con501_con_contract_cal(' + record.id + ');">' + '调息明细' + '</a>';
                    }
                    if (record.get('adjust_flag') == 'E') {
                        return '<font color="orange">' + record.get('batch_adjust_note') + '</font>';
                    } else {
                        return '';
                    }
                    //}
                }
                if(name=='before_income'){
                     return '<a href="javascript:open_rpt4070_hn_report_4070_query(' + record.get('contract_id') + ',\'Y\');">' + '调息前收入' + '</a>';
                }
                 if(name=='after_income'){
                     return '<a href="javascript:open_rpt4070_hn_report_4070_query(' +  record.get('change_req_id') + ',\'Y\');">' + '调息后收入' + '</a>';
                }
                return '';
            }
            
            function con501_con_contract_cal(id) {
            
            
                var record = $('CON115_contract_result_ds').findById(id);
                var param = record.data;
                param['contract_id'] = record.get('contract_id');
                param['document_id'] = record.get('contract_id');
                param['change_req_id'] = record.get('change_req_id');
                param['function_code'] = 'CON115_QUERY';
            
            
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'UPDATE';
                param['url_title'] = '调息现金流对比';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'pageLink_nanshan_all_layout');
            }
            
            function con505_render_contractMaintainDs_grid(value, record, name) {
                if (name == 'contract_number') {
                    return '<a href="javascript:con505_contractMaintainDs_grid_update(' + record.id + ');">' + value + '</a>';
                }
            }
            
            function con505_contractMaintainDs_grid_update(id) {
                var current_record = $('CON115_contract_result_ds').findById(id);
                var param = current_record.data;
                param['document_id'] = current_record.get('contract_id');
                con505_param_set_value(param);
            }
            
            function con505_param_set_value(param) {
                param['function_code'] = 'CON301';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'READONLY';
                param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_interest_float_link');
            }
            
            
            
            function adjust_flagRenderer(value, record, name) {
                var adjust_flag = record.get('adjust_flag');
                var batch_adjust_flag = record.get('batch_adjust_flag');
                if (name == 'inception_of_lease') {
                    if (adjust_flag == 'N') {
                        return '<font color="red">' + Leaf.formatDate(value) + '</font>';
                    }
                    if (adjust_flag == 'E') {
                        return '<font color="orange">' + Leaf.formatDate(value) + '</font>';
                    }
                    return Leaf.formatDate(value);
                }
                if (adjust_flag == 'E') {
                    return '<font color="orange">' + value + '</font>';
                }
                if (adjust_flag == 'N') {
                    return '<font color="red">' + value + '</font>';
                }
            
                return value;
            
            }
            
            function con115_calc_adjust_con_income() {
                lock_list_detail_window();
                setTimeout(function() {
                    Leaf.request({
                        url: $('con115_calc_adjust_con_income_link').getUrl(),
                        para: {
                            batch_hd_id: '${/parameter/@batch_hd_id}'
                        },
                        success: function(res) {
                            unlock_list_detail_window();
                            Leaf.SideBar.show({
                                msg: '${l:HLS.SUBMIT_SUCCESS}',
                                duration: 2000
                            });
            
                        },
                        failure: function() {
                            unlock_list_detail_window();
                        },
                        error: function() {
                            unlock_list_detail_window();
                        },
                        scope: this
                       
                    });
                }, 1000);
            }
            
            function con501_con_contract_export() {
                $('con501_con_contract_grid_ds')._export();
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:dataSets>
            <a:dataSet id="con501_employee_name_of_manager_ds">
                <a:datas dataSource="/model/con501_exp_org_unit_manager_path"/>
            </a:dataSet>
            <a:dataSet id="con501_lease_organization_name_ds" loadData="true" model="basic.hls_lease_organization_for_lov"/>
            <a:dataSet id="con501_lease_channel_name_ds" loadData="true" model="basic.hls_lease_channel_for_lov"/>
            <a:dataSet id="con501_status_name_ds" lookupCode="CON500_CONTRACT_STATUS"/>
            <a:dataSet id="bacth_adjust_hd_query" autoQuery="true" model="cont.CON115.con_batch_adjust_interest_hd" queryUrl="${/request/@context_path}/autocrud/cont.CON115.con_batch_adjust_interest_hd/query?batch_hd_id=${/parameter/@batch_hd_id}">
                <a:fields>
                    <a:field name="batch_num" readOnly="true"/>
                    <a:field name="approval_status_n" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="CON115_contract_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="bp_code" autoComplete="true" lovGridHeight="350" lovHeight="500" lovService="basic.hls_bp_master_v_for_lov?bp_category=TENANT" lovWidth="500" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code"/>
                            <a:map from="bp_id" to="bp_id_tenant"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_tenant"/>
                    <a:field name="project_number" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="prj.PRJ501.prj_project_for_lov" lovWidth="500" title="HLS.PROJECT_NUMBER">
                        <a:mapping>
                            <a:map from="project_number" to="project_number"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="project_employee_name" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="basic.hls_exp_employees_for_lov?sales_flag=Y" lovWidth="500" title="HLS.SALES_EMPLOYEE">
                        <a:mapping>
                            <a:map from="name" to="project_employee_name"/>
                            <a:map from="employee_id" to="employee_id"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_number" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON500.con_contract_number_lov" lovWidth="500" title="HLS.CONTRACT_NUMBER">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="employee_id"/>
                    <a:field name="employee_name_of_manager" displayField="mgr_employee_name" options="con501_employee_name_of_manager_ds" returnField="employee_id_of_manager" valueField="mgr_employee_id"/>
                    <a:field name="lease_organization_name" displayField="description" options="con501_lease_organization_name_ds" returnField="lease_organization" valueField="lease_organization"/>
                    <a:field name="lease_channel_desc" displayField="description" options="con501_lease_channel_name_ds" returnField="lease_channel" valueField="lease_channel"/>
                    <a:field name="contract_status_desc" displayField="code_value_name" options="con501_status_name_ds" readOnly="true" returnField="contract_status" valueField="code_value"/>
                    <a:field name="contract_status"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="CON115_contract_result_ds" autoQuery="true" model="cont.CON115.con_batch_adjust_interest_ln" queryDataSet="CON115_contract_query_ds" queryUrl="${/request/@context_path}/autocrud/cont.CON115.con_batch_adjust_interest_ln/query?batch_hd_id=${/parameter/@batch_hd_id}" selectable="true">
                <a:fields>
                    <a:field name="base_rate" readOnly="true"/>
                    <a:field name="int_rate_fixing_range" readOnly="true"/>
                    <a:field name="int_rate" readOnly="true"/>
                </a:fields>
                <!-- <a:events>
                    <a:event name="load" handler="CON115_load_limit"/>
                </a:events> -->
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <!-- <a:screenTitle/> -->
                <!-- <a:gridButton click="submit_workflow" text="提交"/> -->
                <!-- <a:gridButton id="batch_adjust" click="batch_adjust_interest" text="调息"/> -->
                <!--  <a:gridButton id="un_batch_adjust" click="un_batch_adjust_interest" text="取消调息"/> -->
                <!-- <a:gridButton id="adjust_print" click="adjust_interest_print" text="租金调整通知书"/> -->
                <!--  <a:gridButton click="delete_batch_ln" text="删除"/> -->
                <a:gridButton click="con501_con_contract_return" text="HLS.RETURN"/>
                <a:gridButton click="con501_con_contract_query" text="HLS.QUERY"/>
                <a:gridButton click="con501_con_contract_reset" text="HLS.RESET"/>
                <a:gridButton click="con115_calc_adjust_con_income" text="收入测算"/>
                <a:gridButton click="con501_con_contract_export" text="HLS.EXPORT"/>
            </a:screenTopToolbar>
            <a:form column="4" labelSeparator=" " labelWidth="100" marginWidth="30" title="CON301.CONTRACT_QUERY">
                <a:textField name="batch_num" bindTarget="bacth_adjust_hd_query" prompt="批量调息编号"/>
                <a:comboBox name="approval_status_n" bindTarget="bacth_adjust_hd_query" prompt="审批状态"/>
                <a:lov name="bp_code" bindTarget="CON115_contract_query_ds" prompt="HLS.TENANT_CODE"/>
                <a:textField name="bp_name" bindTarget="CON115_contract_query_ds" prompt="HLS.TENANT_NAME"/>
                <!-- <a:datePicker name="lease_start_date_from" bindTarget="CON115_contract_query_ds" prompt="HLS.LEASE_START_DATE_FROM"/> -->
                <!-- <a:datePicker name="lease_start_date_to" bindTarget="CON115_contract_query_ds" prompt="HLS.LEASE_START_DATE_TO"/> -->
                <a:datePicker name="inception_of_lease_from" bindTarget="CON115_contract_query_ds" prompt="放款日从"/>
                <a:datePicker name="inception_of_lease_to" bindTarget="CON115_contract_query_ds" prompt="放款日到"/>
                <!-- <a:lov name="project_number" bindTarget="CON115_contract_query_ds" prompt="HLS.PROJECT_NUMBER"/> -->
                <!-- <a:textField name="project_name" bindTarget="CON115_contract_query_ds" prompt="HLS.PROJECT_NAME"/> -->
                <a:textField name="virtual_con_number" bindTarget="CON115_contract_query_ds" prompt="合同号"/>
                <a:textField name="virtual_con_name" bindTarget="CON115_contract_query_ds" prompt="合同名称"/>
                <a:lov name="project_employee_name" bindTarget="CON115_contract_query_ds" prompt="HLS.SALES_EMPLOYEE"/>
                <a:comboBox name="lease_organization_name" bindTarget="CON115_contract_query_ds" prompt="HLS.LEASE_ORGANIZATION"/>
                <a:lov name="contract_number" bindTarget="CON115_contract_query_ds" prompt="HLS.CONTRACT_NUMBER"/>
                <!-- <a:textField name="contract_name" bindTarget="CON115_contract_query_ds" prompt="HLS.CONTRACT_NAME"/> -->
                <a:comboBox name="employee_name_of_manager" bindTarget="CON115_contract_query_ds" prompt="HLS.EMPLOYEE_OF_MANAGER"/>
                <!-- <a:comboBox name="lease_channel_desc" bindTarget="CON115_contract_query_ds" prompt="HLS.LEASE_CHANNEL_NAME"/> -->
                <!-- <a:comboBox name="con_mdy_status_desc" bindTarget="CON115_contract_query_ds" prompt="调息状态"/> -->
                <!-- <a:textField name="prj_search_term_1" bindTarget="CON115_contract_query_ds" prompt="CON301.CON_CONTRACT_V.PRJ_SEARCH_TERM_1"/>
                <a:textField name="prj_search_term_2" bindTarget="CON115_contract_query_ds" prompt="CON301.CON_CONTRACT_V.PRJ_SEARCH_TERM_2"/>
                <a:textField name="con_search_term_1" bindTarget="CON115_contract_query_ds" prompt="CON301.CON_CONTRACT_V.CON_SEARCH_TERM_1"/>
                <a:textField name="con_search_term_2" bindTarget="CON115_contract_query_ds" prompt="CON301.CON_CONTRACT_V.CON_SEARCH_TERM_2"/> -->
            </a:form>
            <a:grid id="con501_con_contract_grid_ds" bindTarget="CON115_contract_result_ds" marginHeight="265" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="contract_number" lock="true" prompt="合同编号" width="120"/>
                    <a:column name="virtual_con_number" lock="true" prompt="合同号" width="120"/>
                    <a:column name="virtual_con_name" lock="true" prompt="合同名称" width="220"/>
                    <a:column name="change_req_id" align="center" prompt="调息明细" renderer="CON115_contractRenderer"/>
                    <a:column name="before_income" align="center" prompt="调息前收入" renderer="CON115_contractRenderer"/>
                    <a:column name="after_income" align="center" prompt="调息后收入" renderer="CON115_contractRenderer"/>
                    <!-- <a:column name="contract_name" prompt="HLS.CONTRACT_NAME" renderer="adjust_flagRenderer" width="200"/> -->
                    <a:column name="inception_of_lease" prompt="放款日" renderer="adjust_flagRenderer" width="80"/>
                    <a:column name="bp_name" prompt="HLS.TENANT_NAME" renderer="adjust_flagRenderer" width="160"/>
                    <!-- <a:column name="project_number" prompt="HLS.PROJECT_NUMBER" renderer="adjust_flagRenderer"/> -->
                    <!-- <a:column name="project_name" prompt="HLS.PROJECT_NAME" renderer="adjust_flagRenderer" width="200"/> -->
                    <a:column name="employee_name" prompt="HLS.SALES_EMPLOYEE" renderer="adjust_flagRenderer" width="70"/>
                    <a:column name="employee_name_of_manager" prompt="HLS.EMPLOYEE_OF_MANAGER" renderer="adjust_flagRenderer" width="70"/>
                    <a:column name="lease_organization_desc" prompt="HLS.LEASE_ORGANIZATION" renderer="adjust_flagRenderer" width="70"/>
                    <!-- <a:column name="lease_channel_desc" prompt="HLS.LEASE_CHANNEL_NAME" width="70"/> -->
                    <!-- <a:column name="document_type_desc" prompt="HLS.CONTRACT_TYPE" renderer="adjust_flagRenderer" width="100"/> -->
                    <a:column name="int_rate_fixing_way_des" align="center" prompt="利率调整规则" renderer="adjust_flagRenderer"/>
                    <a:column name="int_rate_fixing_range_n" align="right" prompt="幅度(%)" renderer="adjust_flagRenderer"/>
                    <!-- <a:column name="flt_execute_times_rule_n" prompt="浮动周期规则" renderer="adjust_flagRenderer"/> -->
                    <a:column name="flt_annual_adj_times_des" align="center" prompt="调整频率" renderer="adjust_flagRenderer"/>
                    <a:column name="adjust_rate_type_n" prompt="调息类型"/>
                    <!-- <a:column name="contract_status_desc" prompt="合同状态" renderer="adjust_flagRenderer" width="60"/> -->
                    <a:column prompt="计算前">
                        <a:column name="base_rate_n" align="right" prompt="基准利率(%)" renderer="adjust_flagRenderer"/>
                        <a:column name="int_rate_n" align="right" prompt="租赁利率(%)" renderer="adjust_flagRenderer"/>
                        <a:column name="sum_due_amount" align="right" prompt="租金总额" renderer="Leaf.formatMoney" width="120"/>
                        <a:column name="sum_interest" align="right" prompt="利息总额" renderer="Leaf.formatMoney" width="120"/>
                    </a:column>
                    <a:column prompt="计算后">
                        <a:column name="base_rate_new_n" align="right" prompt="基准利率(%)" renderer="adjust_flagRenderer"/>
                        <a:column name="int_rate_new_n" align="right" prompt="租赁利率(%)" renderer="adjust_flagRenderer"/>
                        <a:column name="change_sum_due_amount" align="right" prompt="租金总额" renderer="Leaf.formatMoney" width="120"/>
                        <a:column name="change_sum_interest" align="right" prompt="利息总额" renderer="Leaf.formatMoney" width="120"/>
                    </a:column>
                    <a:column name="adjust_flag_desc" prompt="调息状态" renderer="adjust_flagRenderer" width="60"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
