<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: yuminhui 
    $Date: 2015-10-26 上午10:30:25  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure><![CDATA[
    ]]></a:init-procedure>
    <a:view>
        <a:link id="con_contract_update_link_id" url="${/request/@context_path}/modules/cont/CON501N/con_contract_modify.lview"/>
        <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"/>
        <a:link id="hls_contract_statistic_link" url="${/request/@context_path}/modules/rpt/RPT1040/bgfl_hls_1040_contract_static_details.lview"/>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
            function con303b_con_contract_return() {
                history.go(-1);
            }
            
            function con303b_con_contract_query() {
                $('con303b_contract_result_ds').query();
            }
            function con303b_con_contract_reset() {
                $('con303_contract_query_ds').reset();
            }
            
             function sumFunction_foot(data, name) {
                 if (name == 'row_num') {
                     return '<font color=red>' + '合计' + '</font>';
                   } else if(name == 'deposit'){
                       return colum_caculateTotal(data,name);
                   }else if(name == 'finance_amount'){
                       return colum_caculateTotal(data,name); 
                   }else if(name == 'total_received_principal'){
                       return colum_caculateTotal(data,name); 
                   }else if(name == 'unreceived_totle_principal'){
                       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>';
            } 
            
            function con303b_render_contractMaintainDs_grid(value, record, name) {
                if (name == 'contract_number') {
                    return '<a href="javascript:con303b_contractMaintainDs_grid_update(' + record.id + ');">' + value + '</a>';
                }
            }
            
            function con303b_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_update_link_id');
            }
            
            function con303b_contractMaintainDs_grid_update(id) {
                var current_record = $('con303b_contract_result_ds').findById(id);
                var param = current_record.data;
                param['document_id'] = current_record.get('contract_id');
                param['cond_para2'] = current_record.get('hn_industry_classification');
                con303b_param_set_value(param);
            }
			
			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 int_rate_render(value, record, name){
                 var contract_id = record.get('contract_id');
                 return '<a href="javascript:contract_statics_details_info(' + contract_id + ');">' + value +'</a>'; 
             }
             function contract_statics_details_info(contract_id){
             	new Leaf.Window({
                    id: 'hls_contract_statistic_ds',
                    url: $('hls_contract_statistic_link').getUrl(),
                    params: {
                        contract_id: contract_id  
                    },
                    title: '调息明细',
                    fullScreen: true
                });
             }
        ]]></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=CON301"/>
        <a:dataSets>
            <a:dataSet id="con303b_contract_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="project_name" lovGridHeight="300" lovHeight="450" lovService="cont.CON303B.con_project_number_for_query" lovWidth="500" title="项目查询">
                        <a:mapping>
                            <a:map from="project_name" to="project_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_number"/>
                    <!--  <a:field name="contract_number" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON303B.con_contract_for_query_lov" lovWidth="500" title="合同编号查询">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number"/>
                        </a:mapping>
                    </a:field> -->
                    <a:field name="bp_name"/>
                    <!--   <a:field name="bp_name" autoComplete="true" lovGridHeight="350" lovHeight="500" lovService="cont.CON303B.con_bp_name_for_query_lov" lovWidth="500" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_name" to="bp_name"/>
                        </a:mapping>
                    </a:field> -->
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con303b_contract_result_ds" autoQuery="true" fetchAll="true" model="cont.CON303B.con_had_implemented_contract_query" queryDataSet="con303b_contract_query_ds">
                <a:fields>
                    <a:field name="lease_due_end_date" datatype="date"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <!-- <a:gridButton click="con303b_con_contract_return" text="HLS.RETURN"/> -->
                <a:gridButton click="con303b_con_contract_query" text="HLS.QUERY"/>
                <a:gridButton click="con303b_con_contract_reset" text="HLS.RESET"/>
                <a:gridButton bind="con303b_con_contract_grid_ds" type="excel"/>
            </a:screenTopToolbar>
            <a:form column="4" labelSeparator=" " labelWidth="100" marginWidth="30" title="CON301.CONTRACT_QUERY">
                <a:lov name="project_name" bindTarget="con303b_contract_query_ds" prompt="项目名称"/>
                <!-- <a:lov name="contract_number" bindTarget="con303b_contract_query_ds" prompt="放款序号"/>
                <a:lov name="bp_name" bindTarget="con303b_contract_query_ds" prompt="承租人名称"/> -->
                <a:textField name="contract_number" bindTarget="con303b_contract_query_ds" prompt="合同号"/>
                <a:textField name="bp_name" bindTarget="con303b_contract_query_ds" prompt="承租人名称"/>
            </a:form>
            <a:grid id="con303b_con_contract_grid_ds" bindTarget="con303b_contract_result_ds" marginHeight="150" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="row_num" align="center" footerRenderer="sumFunction_foot" lock="true" prompt="序号" width="40"/>
                    <a:column name="project_name" lock="true" prompt="项目名称" width="180"/>
                    <a:column name="bp_name" prompt="承租人名称" width="200"/>
                    <a:column name="contract_number" prompt="放款序号" renderer="con303b_render_contractMaintainDs_grid" width="180"/>
                    <!-- <a:column name="bp_business" prompt="承租人简介" width="120"/>
                    <a:column name="bp_industry_big" prompt="行业" width="150"/> -->
                    <!--  <a:column name="con_bp_adress" align="center" prompt="注册地" width="100"/>
                    <a:column name="con_bp_scale" align="center" prompt="客户规模" width="100"/> -->
                    <a:column name="business_desc" align="center" prompt="租赁方式" width="100"/>
                    <!-- <a:column name="lease_item_short_name" prompt="租赁物" width="120"/> -->
                    <a:column name="inception_of_lease" align="center" prompt="投放时间" renderer="Leaf.formatDate" width="90"/>
                    <a:column name="finance_amount" align="right" footerRenderer="sumFunction_foot" prompt="放款本金" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="total_received_principal" align="right" footerRenderer="sumFunction_foot" prompt="已还本金" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="unreceived_totle_principal" align="right" footerRenderer="sumFunction_foot" prompt="未还本金" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="lease_times" prompt="租赁期数" width="80"/>
                    <a:column name="lease_term" align="center" prompt="期限（月）" width="80"/>
                    <a:column name="int_rate_n" align="right" prompt="租赁利率" renderer="int_rate_render" width="90"/>
                    <a:column name="irr_n" align="right" prompt="IRR" width="90"/>
                    <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="residual_value" align="right" prompt="留购价（含税）" renderer="Leaf.formatMoney" width="120"/>
                    <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="140"/>
                    <!-- <a:column name="irr_n" align="right" prompt="内部收益率"/> -->
                    <!-- <a:column name="guarantor_bp" prompt="保证人" width="200"/> -->
                    <a:column name="commission_charge" align="right" footerRenderer="colum_caculateTotal" prompt="手续费（含税）" renderer="Leaf.formatMoney"/>
                    <!--<a:column name="commission_charge_n" align="center" prompt="手续费/年（含税）" width="100"/>-->
                    <a:column name="deposit" align="right" footerRenderer="sumFunction_foot" prompt="保证金" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="deposit_ratio_n" align="right" prompt="保证金比例" width="100"/>
                    <a:column name="notes" prompt="备注" width="200"/>
                    <!-- <a:column name="org_name" prompt="责任部门" width="100"/> -->
                    <!-- <a:column name="sponsor" prompt="主办人" width="100"/> -->
                    <!--  <a:column name="assist" prompt="协办人" width="100"/> -->
                    <!-- <a:column name="int_rate_n" align="right" prompt="租赁利率" width="100"/> -->
                    <!--   <a:column prompt="关联借款合同信息">
                        <a:column name="loan_contract_number" prompt="筹资合同编号" width="180"/> -->
                    <!-- <a:column name="bank_branch_name" prompt="借款机构（分行）" width="180"/> -->
                    <!--   <a:column name="loan_date_from" align="center" prompt="借款期限从" renderer="Leaf.formatDate" width="100"/>
                        <a:column name="loan_date_to" align="center" prompt="借款期限到" renderer="Leaf.formatDate" width="100"/>
                        <a:column name="max_times" align="center" prompt="期数" width="100"/>
                        <a:column name="sum_principal" align="right" footerRenderer="colum_caculateTotal" prompt="本金" renderer="Leaf.formatMoney" width="150"/>
                        <a:column name="sum_interest" align="right" footerRenderer="colum_caculateTotal" prompt="利息" renderer="Leaf.formatMoney" width="150"/>
                        <a:column name="loan_charge" align="right" footerRenderer="colum_caculateTotal" prompt="手续费" renderer="Leaf.formatMoney" width="150"/>
                    </a:column> -->
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
