<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hc  
    $Date: 2015-10-9 下午03:35:35  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.document_category=&apos;CONTRACT&apos;" fetchAll="true" model="basic.hls_document_type_for_lov" rootPath="document_type_path"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_balance_details_link" url="${/request/@context_path}/modules/cont/CON305N/con_contract_balance_details.lview"/>
        <a:link id="con_contract_payment_detail_link" url="${/request/@context_path}/modules/cont/CON305N/con_contract_payment_detail.lview"/>
        <style><![CDATA[
        	a:link {color: #0000EE}  
        	a:hover {color: #ff8400} 
			a:active {color:#ff8400}
			a:visited {color:#338FCC} 
        ]]></style>
        <script type="text/javascript"><![CDATA[
            function query() {
                $('con_contract_outstanding_result_ds').query();
            }
            
            
            function reset() {
                $('con_contract_outstanding_query_ds').reset();
            }
            
            function con_contract_balance_export() {
                $('con_contract_outstanding_result_grid')._export();
            }
            //返回回访报告
            
            
            function con_contract_balance_back() {
                var winid = '${/parameter/@winid}';
                if (winid) {
                    $('${/parameter/@winid}').close();
                } else {
                    history.go(-1);
                }
            }
            
            function con_contract_balance_details_win(value, record, name) {
                var contract_id = record.get('contract_id');
                var url = $('con_contract_balance_details_link').getUrl();
                var total_rental = record.get('total_rental');
                var contract_number = record.get('contract_number');
                if (name == 'total_rental') {
                    return '<a  href="#' + Math.random() + '" onclick="openWindow(\'' + url + '\',' + contract_id + ')">' + Leaf.formatMoney(value) + '</a>';
                }else if (name == 'contract_number') {
                    return '<a  href="#' + Math.random() + '" onclick="openWindow(\'' + url + '\',' + contract_id + ')">' + value + '</a>';
            
                }
            }
            
            function openWindow(url, contract_id) {
                new Leaf.Window({
                    title: 'book',
                    id: 'con_contract_balance_details_win',
                    url: url,
                    params: {
                        'contract_id': contract_id
                    },
                    fullScreen: true
                });
            }
            
            function contract_payment_detail(value, record, name) {
                if (value != 0) {
                    var contract_id = record.get('contract_id');
                    var url = $('con_contract_payment_detail_link').getUrl();
                    return '<a  href="#' + Math.random() + '" onclick="openPaymentWindow(\'' + url + '\',' + contract_id + ')">' + Leaf.formatMoney(value) + '</a>';
                } else {
                    return Leaf.formatMoney(value);
                }
            }
            
            function openPaymentWindow(url, contract_id) {
                new Leaf.Window({
                    title: '合同收款明细',
                    id: 'con_contract_payment_detail_win',
                    url: url,
                    params: {
                        'contract_id': contract_id
                    },
                    fullScreen: true
                });
            }
            
            function contract_number_renderer(value, record, name) {
                if (record.get('overdue_amount') != 0) {
                    return '<span style="color:red">' + value + '</span>';
                } else {
                    return value;
                }
            }
            
            function on_con_contract_outstanding_result_load(ds) {
                var grid_id = $('con_contract_outstanding_result_grid');
                grid_id.hideColumn('project_number');
                grid_id.hideColumn('lease_times');
                grid_id.hideColumn('contract_name');
                grid_id.hideColumn('bp_code');
                grid_id.hideColumn('lease_organization_desc');
                grid_id.hideColumn('employee_name');
                grid_id.hideColumn('division_desc');
                grid_id.hideColumn('lease_channel_desc');
                grid_id.hideColumn('con_search_term_1');
                grid_id.hideColumn('con_search_term_2');
            
                var records = ds.getAll();
                for (var i = 0;i < records.length;i++) {
                    var record = records[i];
                    if (record.get('overdue_amount') > 0) {
                        record.getField('contract_number').setPropertity('tooltip', '<span style="color:#FF0000">已逾期!</span>');
                    }
                }
            }
            
            // function sumFunction_foot(data, name) {
                // if (name == 'row_num') {
                    // return '<font color=red>' + '合计' + '</font>';
                   // } else if(name == 'finance_amount'){
                // var sum = 0;
                // for (var i = 0;i < datas.length;i++) {
                    // var r = data[i];
                    // var d = r.get(name);
                    // var n = parseFloat(d);
                    // if (!isNaN(n)) {
                        // sum = plus(sum, n);
                    // }
                // }
                // var total = (typeof(sum) == 'undefined' ? '' : parseFloat(sum));
                // return '<font color=red>' + Leaf.formatNumber(total) + '</font>';
                // }
            // }
            function sumFunction_foot(data, name) {
                 if (name == 'row_num') {
                     return '<font color=red>' + '合计' + '</font>';
                   } else if(name == 'finance_amount'){
                       return colum_caculateTotal(data,name);
                   } else if(name == 'deposit'){
                       return colum_caculateTotal(data,name);
                   } else if(name == 'lease_charge'){
                      return colum_caculateTotal(data,name); 
                   }else if(name == 'other_fee2'){
                      return colum_caculateTotal(data,name); 
                   }else if(name == 'total_rental'){
                         return colum_caculateTotal(data,name); 
                   }else if( name == 'total_received'){
                        return colum_caculateTotal(data,name);
                   }else if(name == 'unreceived_totle_rental'){
                       return colum_caculateTotal(data,name); 
                   }
            }
            
            function colum_caculateTotal(data,name){
                var total=0;
                var length=data.length;
                var value=0;
                for(var i=0;i<length;i++){
                    if(Ext.isEmpty(data[i].get(name))){
                        value=0;
                    }else{
                        value=data[i].get(name);
                    }
                    total=plus(total,value);
                }
                 return '<font color=red>' +Leaf.formatMoney(total)+ '</font>';
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CON305&amp;custom_code=BALANCE_QUERY"/>
        <a:dataSets>
            <a:dataSet id="bp_scale_combox_ds" lookupCode="BP_SCALE"/>
            <a:dataSet id="con501_document_type_name_ds">
                <a:datas dataSource="/model/document_type_path"/>
            </a:dataSet>
            <a:dataSet id="lease_organization_name_ds" loadData="true" model="basic.hls_lease_organization_for_lov"/>
            <a:dataSet id="division_name_ds" loadData="true" model="basic.hls_division_for_lov"/>
            <a:dataSet id="contract_status_ds" lookupCode="CON500_CONTRACT_STATUS"/>
            <a:dataSet id="lease_channel_name_ds" loadData="true" model="basic.hls_lease_channel_for_lov"/>
            <a:dataSet id="con_contract_outstanding_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="bp_id" defaultValue="${/parameter/@bp_id}"/>
                    <a:field name="finance_amount_from"/>
                    <a:field name="finance_amount_to"/>
                    <a:field name="lease_start_date_from"/>
                    <a:field name="lease_start_date_to"/>
                    <a:field name="project_name"/>
                    <a:field name="bp_name" 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_name" to="bp_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_name"/>
                    <a:field name="lease_organization_name" displayField="description" options="lease_organization_name_ds" returnField="lease_organization" valueField="lease_organization"/>
                    <a:field name="manager_employee_name" lovGridHeight="350" lovHeight="500" lovService="basic.hls_salesman_v_for_lov" lovWidth="500">
                        <a:mapping>
                            <a:map from="employee_id" to="employee_id"/>
                            <a:map from="name" to="manager_employee_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="division_desc" displayField="description" options="division_name_ds" returnField="division" valueField="division"/>
                    <a:field name="lease_channel_desc" displayField="description" options="lease_channel_name_ds" returnField="lease_channel" valueField="lease_channel"/>
                    <a:field name="document_type_desc" displayField="description" options="con501_document_type_name_ds" returnField="document_type" valueField="document_type"/>
                    <a:field name="industry_big_n" lovGridHeight="350" lovHeight="500" lovService="cont.CON305N.con_industry_big_query_lov" lovWidth="500" title="行业查询">
                        <a:mapping>
                            <a:map from="description" to="industry_big_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="province_id_n" lovGridHeight="350" lovHeight="500" lovService="fnd.FND012.fnd_province" lovWidth="500" title="注册地查询">
                        <a:mapping>
                            <a:map from="description" to="province_id_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_scale_n" displayField="code_value_name" options="bp_scale_combox_ds" returnField="bp_scale_n" valueField="code_value_name"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_contract_outstanding_result_ds" autoPageSize="true" autoQuery="true" model="cont.CON305N.con_contract_outstanding_query" queryDataSet="con_contract_outstanding_query_ds">
                <a:events>
                    <a:event name="query" handler="aut_authority_list_validate_query"/>
                    <a:event name="load" handler="on_con_contract_outstanding_result_load"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <!-- <a:gridButton click="con_contract_balance_back" text="HLS.BACK"/> -->
                <a:gridButton click="query" text="HLS.QUERY"/>
                <a:gridButton click="reset" text="HLS.RESET"/>
                <a:gridButton click="con_contract_balance_export" text="HLS.EXPORT"/>
            </a:screenTopToolbar>
            <a:form bindTarget="con_contract_outstanding_query_ds" column="5" marginWidth="20" title="HLS.QUERY_TITLE">
                <!--  <a:textField name="project_name" bindTarget="con_contract_outstanding_query_ds" prompt="HLS.PROJECT_NAME"/> -->
                <a:textField name="contract_number" bindTarget="con_contract_outstanding_query_ds" prompt="合同号"/>
                <a:lov name="bp_name" bindTarget="con_contract_outstanding_query_ds" prompt="HLS.TENANT_NAME"/>
                <a:lov name="industry_big_n" bindTarget="con_contract_outstanding_query_ds" prompt="行业"/>
                <a:lov name="province_id_n" bindTarget="con_contract_outstanding_query_ds" prompt="注册地"/>
                <a:comboBox name="bp_scale_n" bindTarget="con_contract_outstanding_query_ds" prompt="客户规模"/>
                <a:datePicker name="lease_start_date_from" bindTarget="con_contract_outstanding_query_ds" prompt="起租日从"/>
                <a:datePicker name="lease_start_date_to" bindTarget="con_contract_outstanding_query_ds" prompt="起租日到"/>
                <a:numberField name="finance_amount_from" bindTarget="con_contract_outstanding_query_ds" prompt="租赁本金从"/>
                <a:numberField name="finance_amount_to" bindTarget="con_contract_outstanding_query_ds" prompt="租赁本金到"/>
                <a:comboBox name="lease_organization_name" bindTarget="con_contract_outstanding_query_ds" prompt="HLS.LEASE_ORGANIZATION"/>
                <a:lov name="manager_employee_name" bindTarget="con_contract_outstanding_query_ds" prompt="HLS.SALES_EMPLOYEE"/>
                <a:comboBox name="division_desc" bindTarget="con_contract_outstanding_query_ds" prompt="HLS.DIVISION_NAME"/>
                <a:comboBox name="lease_channel_desc" bindTarget="con_contract_outstanding_query_ds" prompt="HLS.LEASE_CHANNEL_NAME"/>
                <a:comboBox name="document_type_desc" bindTarget="con_contract_outstanding_query_ds" prompt="HLS.CONTRACT_TYPE"/>
                <!-- <a:textField name="con_search_term_1" bindTarget="con_contract_outstanding_query_ds" prompt="CON301.CON_CONTRACT_V.CON_SEARCH_TERM_1"/> -->
                <!-- <a:textField name="con_search_term_2" bindTarget="con_contract_outstanding_query_ds" prompt="CON301.CON_CONTRACT_V.CON_SEARCH_TERM_2"/> -->
                <a:textField name="contract_name" bindTarget="con_contract_outstanding_query_ds" prompt="HLS.CONTRACT_NAME"/>
            </a:form>
            <a:grid id="con_contract_outstanding_result_grid" bindTarget="con_contract_outstanding_result_ds" marginHeight="220" marginWidth="20" navBar="true">
                <a:columns>
                    <a:column name="row_num" align="center" footerRenderer="sumFunction_foot" lock="true" prompt="HLS.CONTRACT_SEQ" width="40"/>
                    <a:column name="contract_number" prompt="合同序号" renderer="con_contract_balance_details_win" width="180"/>
                    <a:column name="project_number" prompt="HLS.PROJECT_NUMBER" width="180"/>
                    <a:column name="bp_name" prompt="HLS.TENANT_NAME" width="195"/>
                    <a:column name="industry_big_n" prompt="行业" width="195"/>
                    <a:column name="province_id_n" prompt="注册地" width="70"/>
                    <a:column name="bp_scale_n" prompt="客户规模" width="70"/>
                    <a:column name="contract_name" prompt="HLS.CONTRACT_NAME" width="200"/>
                    <a:column name="lease_times" align="center" prompt="CON305.TIMES" width="60"/>
                    <a:column name="bp_code" prompt="CON305.BP_ID_TENANT" width="100"/>
                    <a:column name="finance_amount" align="right" footerRenderer="sumFunction_foot" prompt="租赁本金" renderer="Leaf.formatMoney" width="130"/>
                    <a:column name="deposit" align="right" footerRenderer="sumFunction_foot" prompt="保证金金额" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="hd_user_col_n03" align="right" prompt="留购价（不含税）" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="residual_value" align="right" prompt="留购价（含税）" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="lease_charge" align="right" footerRenderer="sumFunction_foot" prompt="手续费" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="other_fee2" align="right" footerRenderer="sumFunction_foot" prompt="咨询费" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="int_rate_n" align="right" prompt="租息率" width="90"/>
                    <a:column name="irr_n" align="right" prompt="IRR" width="90"/>
                    <a:column name="lease_start_date" prompt="首期租金日" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="lease_due_end_date" prompt="计划结束日" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="deposit_deduction_n" prompt="保证金处理方式" width="140"/>
                    <a:column name="price_list_n" prompt="租金计算方式" width="100"/>
                    <a:column name="address" prompt="邮寄地址" width="180"/>
                    <a:column name="zipcode" prompt="邮编" width="130"/>
                    <a:column name="contact_person" prompt="联系人" width="100"/>
                    <a:column name="email" prompt="电子邮箱" width="180"/>
                    <a:column name="phone" prompt="联系电话" width="100"/>
                    <a:column name="cell_phone" prompt="手机号码" width="100"/>
                    <a:column name="legal_person" prompt="法定代表人" width="100"/>
                    <a:column name="legal_phone" prompt="联系电话" width="100"/>
                    <a:column name="total_rental" align="right" footerRenderer="sumFunction_foot" prompt="租金总额（含税）" renderer="con_contract_balance_details_win" width="120"/>
                    <a:column name="total_received" align="right" footerRenderer="sumFunction_foot" prompt="已收租金（含税）" renderer="contract_payment_detail" width="120"/>
                    <a:column name="unreceived_totle_rental" align="right" footerRenderer="sumFunction_foot" prompt="未收租金（含税）" renderer="Leaf.formatMoney" width="120"/>
                    <!--<a:column name="lease_charge_mgt_fee" align="right" prompt="CON305.RECEIVED_LEASE_CHARGE" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="received_lease_charge_mgt_fee" align="right" prompt="CON305.RECEIVED_AMOUNT" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="unreceived_total_amount" align="right" prompt="CON305.UNRECEIVED_TOTAL_AMOUNT" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="overdue_amount" align="right" prompt="CON305.OVERDUE_AMOUNT" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="unreceived_fine_amount" align="right" prompt="未支付罚金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="document_type_desc" prompt="HLS.CONTRACT_TYPE" width="70"/>
                    <a:column name="contract_status_desc" align="center" prompt="HLS.CONTRACT_STATUS" width="70"/>
                    <a:column name="project_name" prompt="HLS.PROJECT_NAME" width="250"/>
                    <a:column name="lease_organization_desc" prompt="HLS.LEASE_ORGANIZATION"/>
                    <a:column name="employee_name" prompt="HLS.SALES_EMPLOYEE"/>
                    <a:column name="division_desc" prompt="HLS.DIVISION"/>
                    <a:column name="lease_channel_desc" prompt="HLS.LEASE_CHANNEL"/> -->
                    <!-- <a:column name="con_search_term_1" prompt="合同字符检索码"   /> -->
                    <!-- <a:column name="con_search_term_2" prompt="合同数字检索码"   /> -->
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
