<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Clocc  
    $Date: 2015-7-31 上午10:24:35  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query model="cus.CUS100.cus_default_values" rootPath="cus_default_value"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con643_submit_link" model="cont.CON631N.cus_rpt_con631n_submit_rpt" modelaction="execute"/>
        <a:link id="con643_get_control_id_link" model="db.rpt_report_control_pkg.checkin_rpt" modelaction="execute"/>
        <a:link id="con643_refresh_link" model="db.rpt_report_control_pkg.refresh_rpt" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
			function eg_rpt100_status_find(control_id){			    
                Leaf.request({
                    url: $('con643_refresh_link').getUrl(),
                    para: {'control_id':control_id},
                    success: function(res) {
                        if (res.result.job_stauts == 'FINISH') {
                            var result_ds = $('con631_result_ds');
                            var record = $('con631_head_ds').getCurrentRecord();
                            record.set('status', res.result.job_stauts);
                            result_ds.setQueryParameter('control_id', control_id);
                            result_ds.query();
                        } else {
                            eg_rpt100_head_query();
                        }
                    },
                    failure: function() {
                        con631_unlock_current_window();
                    },
                    error: function() {
                        con631_unlock_current_window();
                    },
                    scope: this
                });
			}
			
			function con631_lock_current_window() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            }
			
			function con631_unlock_current_window() {
                Leaf.Masker.unmask(Ext.getBody());
            }
			
			function con631_load(ds) {
                result_load_flag = 'Y';
                unlock_window_after_load();
            }
			
			function con631_query() {
                var record = $('con631_status_ds').getCurrentRecord();
                if (record && record.get('calc_date')) {
                    eg_rpt100_head_query();
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请输入计算日期！');
                    return;
                }
            }
			
			function on_con631_head_ds_load(ds) {
                head_load_flag = 'Y';
                if (from_update_flag == 'N') {
                    var record = $('con631_head_ds').getCurrentRecord();
                    var control_id = null,
                        status = null;
                    if (record) {
                        control_id = record.get('control_id');
                        status = record.get('status');
                    }
            
                    if (status == 'FINISH') {
                        var result_ds = $('con631_result_ds');
                        record.set('status', status);
                        result_ds.setQueryParameter('control_id', control_id);
                        result_ds.query();
                    } else {
                        eg_rpt100_status_find(control_id);
                    }
                } else {
                    from_update_flag = 'N';
                    unlock_window_after_load();
                }
            }
			
			function con631_submit(){
			    var record = $('con631_head_ds').getCurrentRecord(),
                    status_record = $('con631_status_ds').getCurrentRecord();
                var control_id = record.get('control_id');
                var calc_date = status_record.get('calc_date');
			    if (status_record && calc_date) {
			    Leaf.showConfirm('${l:PROMPT}', '计算将清除上次运行结果，并且执行时间较长，是否确认提交？', function() {
			        $('con631_result_ds').removeAll();			       
	                Leaf.request({
	                    url: $('con643_submit_link').getUrl(),
	                    para: {'control_id':control_id,
	                        	'check_company_id' : ${/session/@company_id},
	                          'calc_date':calc_date},
	                    success: function(res) {
	                        eg_rpt100_head_query();
	                    },
	                    failure: function() {
	                        con631_unlock_current_window();
	                    },
	                    error: function() {
	                        con631_unlock_current_window();
	                    },
	                    scope: this
	                });  
			    });			    
			} else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请输入计算日期！');
                    return;
                }
            }
			
			function eg_rpt100_head_query(){
                $('con631_head_ds').query();
			}
			function con630_red_fun(value,record,name){
			    return '<font style="color:red;bold:true">'+value+'</font>';
			}
				
			function con631_excel(){
			    $('con631_result_grid_ds')._export('xls','excel_report');
			}
			
			function unlock_window_after_load() {
                if (head_load_flag == 'Y' && result_load_flag == 'Y') {
                    head_load_flag = 'N';
                    result_load_flag = 'N';
                    con631_unlock_current_window();
                }
            }
            
            var head_load_flag = 'N';
            var result_load_flag = 'N';
            var from_update_flag = 'N';
			
			function con631_update(ds,record,name,value,oldvalue){
			    //
			    if (value){
			        con631_lock_current_window();
			        Leaf.request({
	                    url: $('con643_get_control_id_link').getUrl(),
	                    para: {'report_name':'CON631N',
	                        	'check_company_id' : ${/session/@company_id},
	                           'check_date':value},
	                    success: function(res) {
	                        from_update_flag = 'Y';
                            var head_ds = $('con631_head_ds');
                            var result_ds = $('con631_result_ds');
                            if (res.result.control_id) {
                                head_ds.setQueryParameter('control_id', res.result.control_id);
                                result_ds.setQueryParameter('control_id', res.result.control_id);
                                head_ds.query();
                                result_ds.query();
                                } else {
                                con631_unlock_current_window();
                            }
	                    },
	                    failure: function() {
	                        con631_unlock_current_window();
	                    },
	                    error: function() {
	                        con631_unlock_current_window();
	                    },
	                    scope: this
	                	});
				    }
			}
			
			function con631_reset() {
                $('cus312_query_ds').reset();
            }
		]]></script>
        <a:dataSets>
            <a:dataSet id="con631_head_ds" model="cus.CUS312.cus_rpt_report_control">
                <a:events>
                    <a:event name="load" handler="on_con631_head_ds_load"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="division_name_ds" loadData="true" model="basic.hls_division_for_lov"/>
            <a:dataSet id="legal_status_ds" lookupCode="LEG501_LEGAL_STATUS"/>
            <a:dataSet id="contract_status_ds" lookupCode="CON500_CONTRACT_STATUS"/>
            <a:dataSet id="con631_status_ds" autoCreate="true">
                <a:events>
                    <a:event name="update" handler="con631_update"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="con631_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="province_id_n" lovGridHeight="350" lovHeight="500" lovService="cont.CON631N.cus_rpt_con631_province_n_lov" lovWidth="500">
                        <a:mapping>
                            <a:map from="province_code" to="province_code"/>
                            <a:map from="description" to="province_id_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="collector_user_id_n" lovGridHeight="350" lovHeight="500" lovService="cont.CON305.hls_collector_user" lovWidth="500">
                        <a:mapping>
                            <a:map from="collector_user_id" to="collector_user_id"/>
                            <a:map from="employee_name" to="collector_user_id_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="employee_id_n" lovGridHeight="350" lovHeight="500" lovService="cont.CON631N.cus_rpt_con631_employee_n_lov" lovWidth="500">
                        <a:mapping>
                            <a:map from="employee_code" to="employee_code"/>
                            <a:map from="name" to="employee_id_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_control" lovGridHeight="350" lovHeight="500" lovService="cont.CON631N.cus_rpt_con631_bp_id_control_n_lov" lovWidth="500">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code"/>
                            <a:map from="bp_name" to="bp_id_control"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_status_n" displayField="code_value_name" options="contract_status_ds" returnField="contract_status" valueField="code_value"/>
                    <a:field name="division_n" displayField="description" options="division_name_ds" returnField="division" valueField="division"/>
                    <a:field name="legal_status" displayField="code_value_name" options="legal_status_ds" returnField="legal_status" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con631_result_ds" autoPageSize="true" autoQuery="true" model="cont.CON631N.cus_rpt_con631_o" queryDataSet="con631_query_ds">
                <a:events>
                    <a:event name="load" handler="con631_load"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:toolbarButton click="con631_query" text="查询"/>
                <a:toolbarButton click="con631_submit" text="计算"/>
                <a:toolbarButton click="con631_reset" text="重置"/>
                <a:toolbarButton click="con631_excel" text="导出"/>
            </a:screenTopToolbar>
            <a:form column="4" marginWidth="100" title="数据刷新状态">
                <a:datePicker name="calc_date" bindTarget="con631_status_ds" prompt="计算时间"/>
                <a:label name="last_submit_date" bindTarget="con631_head_ds" prompt="最后刷新时间" renderer="con630_red_fun"/>
                <a:label name="last_submitted_by" bindTarget="con631_head_ds" prompt="最后刷新人" renderer="con630_red_fun"/>
                <a:label name="status" bindTarget="con631_head_ds" prompt="状态" renderer="con630_red_fun"/>
            </a:form>
            <a:form column="4" marginWidth="100" title="查询条件">
                <a:comboBox name="division_n" bindTarget="con631_query_ds" prompt="产品线"/>
                <a:lov name="province_id_n" bindTarget="con631_query_ds" prompt="省份"/>
                <a:datePicker name="lease_start_date_from" bindTarget="con631_query_ds" prompt="起租日从"/>
                <a:datePicker name="lease_start_date_to" bindTarget="con631_query_ds" prompt="起租日到"/>
                <a:comboBox name="contract_status_n" bindTarget="con631_query_ds" prompt="合同状态"/>
                <a:comboBox name="legal_status" bindTarget="con631_query_ds" prompt="法务状态"/>
                <a:textField name="times_from" bindTarget="con631_query_ds" prompt="逾期期数从"/>
                <a:textField name="times_to" bindTarget="con631_query_ds" prompt="逾期期数到"/>
                <a:lov name="employee_id_n" bindTarget="con631_query_ds" prompt="业务员"/>
                <a:lov name="collector_user_id_n" bindTarget="con631_query_ds" prompt="客户服务专员"/>
                <a:lov name="bp_id_control" bindTarget="con631_query_ds" prompt="实际控制人"/>
                <a:textField name="contract_number" bindTarget="con631_query_ds" prompt="合同编号"/>
            </a:form>
            <a:grid id="con631_result_grid_ds" bindTarget="con631_result_ds" marginHeight="280" marginWidth="80" navBar="true">
                <a:columns>
                    <a:column name="contract_number" align="left" lock="true" prompt="合同编号" width="100"/>
                    <!-- <a:column name="search_term_1" align="left" lock="true" prompt="合同号" width="100"/> -->
                    <a:column name="bp_id_tenant_n" align="left" lock="true" prompt="承租人" width="100"/>
                    <a:column name="division_n" align="center" prompt="产品线" width="60"/>
                    <a:column name="brand_id_n" align="center" prompt="车辆品牌" width="100"/>
                    <a:column name="license_plate_number" align="right" prompt="车牌号" width="100"/>
                    <a:column name="aircraft_category_n" align="center" prompt="车辆/设备类型" width="100"/>
                    <a:column name="serial_number" align="center" prompt="机编号/车架号" width="100"/>
                    <a:column name="valid_to" align="left" prompt="保险到期日" renderer="Leaf.formatDate" width="100"/>
                    <!-- <a:column name="status" align="left" prompt="状态" width="100"/> -->
                    <a:column name="quantity" align="left" prompt="台数" width="100"/>
                    <a:column name="employee_id_n" align="left" prompt="业务员" width="100"/>
                    <a:column name="collector_user_id_n" align="right" prompt="客户服务专员" width="100"/>
                    <a:column name="lease_start_date" align="right" prompt="起租日" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="month_due_date" align="right" prompt="本月计划还款日" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="max_due_date" align="right" prompt="到期日" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="times" align="right" prompt="总期数" width="100"/>
                    <a:column name="overdue_times" align="right" prompt="逾期期数" width="100"/>
                    <a:column name="overdue_amount" align="right" prompt="逾期租金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="overdue_amount_1_30" align="right" prompt="1-30" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="overdue_amount_31_60" align="right" prompt="31-60" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="overdue_amount_61_90" align="right" prompt="61-90" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="overdue_amount_91_120" align="right" prompt="91-120" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="overdue_amount_121_360" align="right" prompt="121-360" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="overdue_amount_360" align="right" prompt="大于360" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="last_received_date" align="right" prompt="最近一次还款日" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="promised_repay_amount" align="right" prompt="上一次承诺还款金额" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="due_amount_current_month" align="right" prompt="本月计划租金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="month_received_amount" align="right" prompt="本月实收租金" renderer="Leaf.formatMoney" width="100"/>
                    <!-- <a:column name="month_received_amount" align="right" prompt="本月实收租金" renderer="Leaf.formatMoney" width="100"/> -->
                    <a:column name="lease_item_amount" align="right" prompt="设备原值" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="total_rental" align="right" prompt="租金总额" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="received_rental" align="right" prompt="已收租金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="unreceived_rental" align="right" prompt="未收租金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="npa" align="right" prompt="不良资产金额" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="unreceived_principal" align="right" prompt="未收本金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="overdue_interest_4" align="right" prompt="小于4期的逾期利息" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="deposit" align="right" prompt="客户保证金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="thrid_party_deposit" align="right" prompt="供应商保证金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="gps_flag" align="right" prompt="GPS控制" width="100"/>
                    <a:column name="lock_flag" align="right" prompt="密码控制" width="100"/>
                    <a:column name="bp_id_vender_n" align="right" prompt="供应商" width="100"/>
                    <a:column name="tenant_contract_person_1" align="right" prompt="承租人联系人1" width="100"/>
                    <a:column name="tenant_cell_phone_1" align="right" prompt="承租人联系人1电话" width="100"/>
                    <a:column name="tenant_contract_person_2" align="right" prompt="承租人联系人2" width="100"/>
                    <a:column name="tenant_cell_phone_2" align="right" prompt="承租人联系人2电话" width="100"/>
                    <a:column name="province_id_tenant_n" align="right" prompt="承租人省份" width="100"/>
                    <a:column name="city_id_tenant_n" align="right" prompt="承租人市" width="100"/>
                    <a:column name="tenant_address" align="right" prompt="承租人联系地址" width="100"/>
                    <a:column name="guarantee_1" align="right" prompt="担保人1" width="100"/>
                    <a:column name="guarantee_cell_phone_1" align="right" prompt="担保人1电话" width="100"/>
                    <a:column name="guarantee_address_1" align="right" prompt="担保人1地址" width="100"/>
                    <a:column name="guarantee_2" align="right" prompt="担保人2" width="100"/>
                    <a:column name="guarantee_cell_phone_2" align="right" prompt="担保人2电话" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="guarantee_address_2" align="right" prompt="担保人2地址" width="100"/>
                    <a:column name="guarantee_3" align="right" prompt="担保人3" width="100"/>
                    <a:column name="guarantee_cell_phone_3" align="left" prompt="担保人3电话" width="100"/>
                    <a:column name="guarantee_address_3" align="left" prompt="担保人3地址" width="100"/>
                    <a:column name="guarantee_4" align="left" prompt="担保人4" width="100"/>
                    <a:column name="guarantee_cell_phone_4" align="center" prompt="担保人4电话" width="100"/>
                    <a:column name="guarantee_address_4" align="center" prompt="担保人4地址" width="100"/>
                    <a:column name="vender_contract_person" align="right" prompt="供应商联系人" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="vender_ceel_phone" align="center" prompt="供应商联系电话" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="vender_email" align="center" prompt="供应商联系邮箱" width="100"/>
                    <a:column name="bp_id_control" align="left" prompt="实际控制人" width="100"/>
                    <a:column name="city_id_n" align="left" prompt="市" width="100"/>
                    <a:column name="province_id_n" align="left" prompt="省份" width="100"/>
                    <a:column name="contract_status_n" align="center" prompt="合同状态" width="50"/>
                    <a:column name="legal_status_n" align="center" prompt="法务状态" width="50"/>
                    <a:column name="lawsuit_status" align="center" prompt="诉讼状态" width="50"/>
                    <a:column name="penalty" align="right" prompt="滞纳金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="legal_fee" align="right" prompt="法律费用" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="external_fee" align="right" prompt="其他费用" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="company_id_n" align="right" prompt="出租人" width="100"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
