<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ZLF  
    $Date: 2014-11-17 下午6:07:00  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_dun_record_id" url="${/request/@context_path}/modules/cont/CON747/con_dun_record.lview"/>
        <a:link id="hls_bp_master_id" url="${/request/@context_path}/modules/hls/HLS306/hls_bp_master_details_check.lview"/>
        <a:link id="con_contract_update_link_id" url="${/request/@context_path}/modules/cont/CON505/con_contract_modify.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_contract_lawyer_letter_print_link_id" url="${/request/@context_path}/modules/cont/CON620/con_contract_lawyer_letter_print.lview"/>
        <a:link id="penalty_change_id" url="${/request/@context_path}/modules/cont/CON747/con_contract_penatly_change_req_detail.lview"/>
        <script type="text/javascript"><![CDATA[
            function CON601_con_contract_query() {
                $('CON620_contract_result_ds').query();
            }
            
            function CON601_con_contract_reset() {
                $('CON620_contract_query_ds').reset();
            }
            
            function penalty_change_btn() {
                // Leaf.go(url);
                // var contract_id=$('CON620_contract_result_ds').getSelected().get('contract_id');
                var url = $('penalty_change_id').getUrl();
                var contract_id = $('CON620_contract_result_ds').getSelected()[0].get('contract_id');
                // var url=$('penalty_change_id').getUrl()+'?contract_id='+contract_id;
                new Leaf.Window({
                    id: 'penalty_change_window',
                    params: {
                        contract_id: contract_id
                    },
                    fullScreen: true,
                    url: url
                });
            }
            
            function CON620_render_contract_dun_grid(value, record, name) {
                if (name == 'contract_number') {
                    if (record.get('overdue_times') > 1) {
                        return '<u><a style="color:red" href="javascript:contract_link(' + record.id + ');">' + value + '</a></u>';
                    } else {
                        return '<a href="javascript:contract_link(' + record.id + ');">' + value + '</a>';
                    }
                } else if (name == 'bp_id_tenant_desc') {
                    //商业伙伴查询页面要做好，然后在此处关联。
                    if (record.get('overdue_times') > 1) {
                        return '<u><a style="color:red" href="javascript:bp_id_tenant_desc_link(' + record.get('contract_id') + ');">' + value + '</a></u>';
                    } else {
                        return '<a href="javascript:bp_id_tenant_desc_link(' + record.get('contract_id') + ');">' + value + '</a>';
                    }
                } else if (name == 'bp_id_agent_desc') {
                    if (record.get('bp_id_agent_desc') == null) {
                        return;
                    } else {
                        if (record.get('overdue_times') > 1) {
                            return '<u><a style="color:red" href="javascript:bp_id_agent_desc_link(' + record.get('bp_id_agent_level1') + ',\'' + record.get('bp_id_agent_class') + '\')">' + value + '</a></u>';
                        } else {
                            return '<a href="javascript:bp_id_agent_desc_link(' + record.get('bp_id_agent_level1') + ',\'' + record.get('bp_id_agent_class') + '\')">' + value + '</a>';
                        }
                    }
                }
            }
            
            function bp_id_tenant_desc_link(contract_id) {
                var url = $('con_dun_record_id').getUrl() + '?contract_id=' + contract_id;
            
                var win = new Leaf.Window({
                    id: 'con_dun_record_window',
                    url: url,
                    title: '催收记录',
                    fullScreen: true
                });
                win.on('close', function() {
                    $('CON620_contract_result_ds').query();
                });
            }
            
            function bp_id_agent_desc_link(bp_id, bp_class) {
                var url = $('hls_bp_master_id').getUrl();
                new Leaf.Window({
                    id: 'hls_bp_detail_winId',
                    url: url,
                    params: {
                        bp_id: bp_id,
                        bp_class: bp_class,
                        winId: 'hls_bp_detail_winId'
                    },
                    title: '${l:HLS212.BP_MASTER_MAINTAIN}',
                    fullScreen: true
                });
            
            }
            
            function con601_param_set_value(param) {
                param['document_category'] = 'CONTRACT';
                param['function_code'] = 'CON301';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'READONLY';
                param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
                param['company_id'] = '${/session/@company_id}';
                //
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_update_link_id', 'CON620_contract_result_ds');
            }
            
            function contract_link(id) {
                //
                var current_record = $('CON620_contract_result_ds').findById(id);
                var record = current_record;
                var saveData = [];
                for (var k in record.data) {
                    var item = record.data[k];
                    if (item && item.xtype == 'dataset') {
                        delete record.data[k];
                    }
                }
                var param = record.data;
                param['document_id'] = current_record.get('contract_id');
                con601_param_set_value(param);
            }
            
            function summaryRenderer(datas, name) {
                var sum = 0;
                for (var i = 0;i < datas.length;i++) {
                    var record = datas[i];
                    var d = record.get(name);
                    var n = parseFloat(d);
                    if (!isNaN(n)) {
                        sum += n;
                    }
                }
                if (name == "overdue_days") {
                    return '<div align="right">合计:</div>';
                }
                if (name == "overdue_amount") {
                    return '<font color="red">' + Leaf.formatNumber(sum, 2) + '</font>';
                }
                if (name == "remain_principal") {
                    return '<font color="red">' + Leaf.formatNumber(sum, 2) + '</font>';
                }
                if (name == "penalty") {
                    return '<font color="red">' + Leaf.formatNumber(sum, 2) + '</font>';
                }
                if (name == "promised_return_amount") {
                    return '<font color="red">' + Leaf.formatNumber(sum, 2) + '</font>';
                }
                if (name == "deposit") {
                    return '<font color="red">' + Leaf.formatNumber(sum, 2) + '</font>';
                }
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CON501&amp;"/>
        <a:dataSets>
            <a:dataSet id="CON601_lease_organization_name_ds" loadData="true" model="basic.hls_lease_organization_for_lov"/>
            <a:dataSet id="CON620_contract_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="bp_id_tenant_n" autoComplete="true" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON541.hls_bp_master_v_for_lov?bp_category=TENANT" lovWidth="520" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_name" to="bp_id_tenant_n"/>
                            <a:map from="bp_id" to="bp_id_tenant"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_tenant"/>
                    <!--                     <a:field name="contract_number" autoCompleteField="true" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON620.con_contract_number_query" lovWidth="520" title="HLS.CONTRACT_NUMBER">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number"/>
                        </a:mapping>
                    </a:field> -->
                    <a:field name="contract_number"/>
                    <!-- <a:field name="contract_name" autoCompleteField="true" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON620.con_contract_name_query" lovWidth="520" title="HLS.CONTRACT_NAME">
                        <a:mapping>
                            <a:map from="contract_name" to="contract_name"/>
                        </a:mapping>
                    </a:field> -->
                    <a:field name="project_number" autoCompleteField="true" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON620.prj_project_number_query" lovWidth="520" title="HLS.PROJECT_NUMBER">
                        <a:mapping>
                            <a:map from="project_number" to="project_number"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_tenant_desc" autoCompleteField="true" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON620.hls_bp_name_query" lovWidth="520" title="承租人名称">
                        <a:mapping>
                            <a:map from="bp_name" to="bp_id_tenant_desc"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="agent_id_n" autoCompleteField="true" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON620.hls_agent_id_n_query" lovWidth="520" title="经销商名称">
                        <a:mapping>
                            <a:map from="bp_name" to="agent_id_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="overdue_times"/>
                    <a:field name="lease_start_date_from"/>
                    <a:field name="lease_start_date_to"/>
                    <a:field name="received_times_from"/>
                    <a:field name="received_times_to"/>
                    <a:field name="inception_of_lease"/>
                    <a:field name="owner_user_id_desc" lovGridHeight="350" lovHeight="475" lovService="cont.CON620.sys_user_for_lov" lovWidth="520" title="出单人">
                        <a:mapping>
                            <a:map from="user_id" to="owner_user_id"/>
                            <a:map from="description" to="owner_user_id_desc"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="lease_organization_name" displayField="description" options="CON601_lease_organization_name_ds" returnField="lease_organization" valueField="lease_organization"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="CON620_contract_result_ds" autoPageSize="true" autoQuery="true" fetchAll="false" model="cont.CON620.con_contract_dun_for_query" pageSize="10" queryDataSet="CON620_contract_query_ds" queryUrl="${/request/@context_path}/autocrud/cont.CON620.con_contract_dun_for_query/query" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="promised_return_date" datatype="date"/>
                </a:fields>
                <a:events>
                    <a:event name="query" handler="aut_authority_list_validate_query"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="CON601_con_contract_query" text="HLS.QUERY"/>
                <a:gridButton click="CON601_con_contract_reset" text="HLS.RESET"/>
                <a:gridButton click="penalty_change_btn" text="滞纳金免除申请"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="100" marginWidth="30" title="CON301.CONTRACT_QUERY">
                <a:textField name="contract_number" bindTarget="CON620_contract_query_ds" prompt="HLS.CONTRACT_NUMBER"/>
                <a:textField name="contract_name" bindTarget="CON620_contract_query_ds" prompt="HLS.CONTRACT_NAME"/>
                <a:lov name="project_number" bindTarget="CON620_contract_query_ds" prompt="HLS.PROJECT_NUMBER"/>
                <a:lov name="bp_id_tenant_desc" bindTarget="CON620_contract_query_ds" prompt="承租人名称"/>
                <a:datePicker name="lease_start_date_from" bindTarget="CON620_contract_query_ds" prompt="起租日从"/>
                <a:datePicker name="lease_start_date_to" bindTarget="CON620_contract_query_ds" prompt="起租日到"/>
                <a:numberField name="lease_times_from" bindTarget="CON620_contract_query_ds" decimalPrecision="0" prompt="租赁期数从"/>
                <a:numberField name="lease_times_to" bindTarget="CON620_contract_query_ds" decimalPrecision="0" prompt="租赁期数到"/>
                <a:numberField name="received_times_from" bindTarget="CON620_contract_query_ds" decimalPrecision="0" prompt="已还款期数从"/>
                <a:numberField name="received_times_to" bindTarget="CON620_contract_query_ds" decimalPrecision="0" prompt="已还款期数到"/>
                <a:numberField name="overdue_days_from" allowDecimals="false" bindTarget="CON620_contract_query_ds" decimalPrecision="0" prompt="逾期天数从"/>
                <a:numberField name="overdue_days_to" allowDecimals="false" bindTarget="CON620_contract_query_ds" decimalPrecision="0" prompt="逾期天数到"/>
                <a:lov name="agent_id_n" bindTarget="CON620_contract_query_ds" prompt="经销商名称"/>
            </a:form>
            <a:grid id="CON601_con_contract_grid_ds" bindTarget="CON620_contract_result_ds" marginHeight="230" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="inception_of_lease" align="center" lock="true" prompt="起租日" renderer="Leaf.formatDate" width="80"/>
                    <a:column name="contract_number" align="left" lock="true" prompt="HLS.CONTRACT_NUMBER" renderer="CON620_render_contract_dun_grid" width="150"/>
                    <a:column name="contract_name" align="left" lock="true" prompt="HLS.CONTRACT_NAME" width="150"/>
                    <a:column name="project_number" align="left" prompt="申请编号" width="80"/>
                    <a:column name="agent_id_n" align="left" prompt="经销商名称" width="80"/>
                    <a:column name="bp_id_tenant_desc" align="left" prompt="承租人名称" width="150"/>
                    <a:column name="lease_times" align="center" prompt="租赁期数" width="80"/>
                    <!-- <a:column name="lease_organization_desc" align="center" prompt="业务部" width="120"/> -->
                    <a:column name="recieved_times" align="center" prompt="已还款期数" width="80"/>
                    <a:column name="overdue_times" align="center" prompt="逾期期数" width="80"/>
                    <a:column name="overdue_days" align="center" footerRenderer="summaryRenderer" prompt="逾期天数" width="80"/>
                    <a:column name="overdue_amount" align="right" footerRenderer="summaryRenderer" prompt="逾期金额" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="penalty" align="right" footerRenderer="summaryRenderer" prompt="罚息金额" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="remain_principal" align="right" footerRenderer="summaryRenderer" prompt="剩余本金" renderer="Leaf.formatMoney" width="120"/>
                    <!-- <a:column name="deposit" align="right" footerRenderer="summaryRenderer" prompt="保证金" renderer="Leaf.formatMoney" width="120"/> -->
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
