<?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.CON630N.cus_rpt_con630n_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.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                Leaf.request({
                    url: $('con643_refresh_link').getUrl(),
                    para: {'control_id':control_id},
                    success: function(res) {
                        // Leaf.Masker.unmask(Ext.getBody());
                        // if (res.result.job_stauts == 'FINISH'){
                            // var param = {'control_id':control_id};
                            // $('con630_result_ds').query();
                        // }
                        // eg_rpt100_head_query();
                    // },
                    if (res.result.job_stauts == 'FINISH') {
                            var result_ds = $('con630_result_ds');
                            var record = $('con630_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() {
                        con630_unlock_current_window();
                        // Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function() {
                        con630_unlock_current_window();
                        // Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });
			}
			
			function con630_lock_current_window() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            }
			
			function con630_unlock_current_window() {
                Leaf.Masker.unmask(Ext.getBody());
            }
			
			function con630_load(ds) {
                result_load_flag = 'Y';
                unlock_window_after_load();
            }
			
			// function con630_query(){
			    // eg_rpt100_head_query();
			    // var control_id = $('con630_head_ds').getAt(0).get('control_id');
			    // var status  = $('con630_head_ds').getAt(0).get('status');
			    // if (status == 'FINISH'){
			         // var param = {'control_id':control_id};
			         // $('con630_result_ds').query();
			    // }else{
			        // eg_rpt100_status_find(control_id);
			    // }
			    
			// }
			
			function con630_query() {
                var record = $('con630_status_ds').getCurrentRecord();
                if (record && record.get('calc_date')) {
                    eg_rpt100_head_query();
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请输入计算日期！');
                    return;
                }
            }
			
			
			function on_con630_head_ds_load(ds) {
                head_load_flag = 'Y';
                if (from_update_flag == 'N') {
                    var record = $('con630_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 = $('con630_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 con630_submit(){
			    // var control_id = $('con630_head_ds').getAt(0).get('control_id');
			    // var calc_date = $('con630_status_ds').getAt(0).get('calc_date');
			    // if (!calc_date) {
                    // Leaf.showMessage('${l:HLS.PROMPT}', '请输入计算日期！');
                    // return;
                // }
			    var record = $('con630_head_ds').getCurrentRecord(),
                    status_record = $('con630_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() {
			        $('con630_result_ds').removeAll();
			       // Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
	                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) {
	                        // con630_unlock_current_window();
	                        // Leaf.Masker.unmask(Ext.getBody());
	                        eg_rpt100_head_query();
	                    },
	                    failure: function() {
	                        con630_unlock_current_window();
	                        // Leaf.Masker.unmask(Ext.getBody());
	                    },
	                    error: function() {
	                        con630_unlock_current_window();
	                        // Leaf.Masker.unmask(Ext.getBody());
	                    },
	                    scope: this
	                });  
			    });
			    
			} else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请输入计算日期！');
                    return;
                }
            }
			
			function eg_rpt100_head_query(){
                $('con630_head_ds').query();
			}
			function con630_red_fun(value,record,name){
			    return '<font style="color:red;bold:true">'+value+'</font>';
			}
				
			function con630_excel(){
			    $('con630_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';
                    con630_unlock_current_window();
                }
            }
            
            var head_load_flag = 'N';
            var result_load_flag = 'N';
            var from_update_flag = 'N';
			
			function con630_update(ds,record,name,value,oldvalue){
			    //
			    if (value){
			        con630_lock_current_window();
			        Leaf.request({
	                    url: $('con643_get_control_id_link').getUrl(),
	                    para: {'report_name':'CON630N',
	                        	'check_company_id' : ${/session/@company_id},
	                           'check_date':value},
	                    success: function(res) {
	                        // Leaf.Masker.unmask(Ext.getBody());
	                        // $('con630_head_ds').setQueryParameter('control_id',res.result.control_id);
	                        // $('con630_result_ds').setQueryParameter('control_id',res.result.control_id);
	                        // $('con630_head_ds').query();
	                        // $('con630_result_ds').query();
	                        from_update_flag = 'Y';
                            var head_ds = $('con630_head_ds');
                            var result_ds = $('con630_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 {
                                con630_unlock_current_window();
                            }
	                    },
	                    failure: function() {
	                        con630_unlock_current_window();
	                        // Leaf.Masker.unmask(Ext.getBody());
	                    },
	                    error: function() {
	                        con630_unlock_current_window();
	                        // Leaf.Masker.unmask(Ext.getBody());
	                    },
	                    scope: this
	                	});
				    }
			}
			
			function con630_reset() {
                $('cus312_query_ds').reset();
            }
		]]></script>
        <a:dataSets>
            <a:dataSet id="con630_head_ds" model="cus.CUS312.cus_rpt_report_control">
                <a:events>
                    <a:event name="load" handler="on_con630_head_ds_load"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="con630_status_ds" autoCreate="true">
                <a:events>
                    <a:event name="update" handler="con630_update"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="con630_query_ds">
                <a:fields>
                    <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="npl_flag" checkedValue="Y" defaultValue="" uncheckedValue=""/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con630_result_ds" autoPageSize="true" autoQuery="true" model="cont.CON630N.cus_rpt_con630_o" queryDataSet="con630_query_ds">
                <a:events>
                    <a:event name="load" handler="con630_load"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:toolbarButton click="con630_query" text="查询"/>
                <a:toolbarButton click="con630_submit" text="计算"/>
                <a:toolbarButton click="con630_reset" text="重置"/>
                <a:toolbarButton click="con630_excel" text="导出"/>
            </a:screenTopToolbar>
            <a:form column="4" marginWidth="100" title="数据刷新状态">
                <a:datePicker name="calc_date" bindTarget="con630_status_ds" prompt="计算时间"/>
                <a:label name="last_submit_date" bindTarget="con630_head_ds" prompt="最后刷新时间" renderer="con630_red_fun"/>
                <a:label name="last_submitted_by" bindTarget="con630_head_ds" prompt="最后刷新人" renderer="con630_red_fun"/>
                <a:label name="status" bindTarget="con630_head_ds" prompt="状态" renderer="con630_red_fun"/>
            </a:form>
            <a:form column="4" marginWidth="100" title="查询条件">
                <a:textField name="search_term_1" bindTarget="con630_query_ds" prompt="合同号"/>
                <a:textField name="contract_number" bindTarget="con630_query_ds" prompt="合同序号"/>
                <a:lov name="collector_user_id_n" bindTarget="con630_query_ds" prompt="客户服务专员"/>
                <!-- <a:textField name="collector_user_id_n" bindTarget="con630_query_ds" prompt="客户服务专员"/> -->
                <a:textField name="serial_number" bindTarget="con630_query_ds" prompt="机编号"/>
                <a:datePicker name="lease_start_date_from" bindTarget="con630_query_ds" prompt="起租日从"/>
                <a:datePicker name="lease_start_date_to" bindTarget="con630_query_ds" prompt="起租日到"/>
                <a:checkBox name="npl_flag" bindTarget="con630_query_ds" prompt="NPL标志"/>
            </a:form>
            <a:grid id="con630_result_grid_ds" bindTarget="con630_result_ds" marginHeight="260" marginWidth="80" navBar="true">
                <a:columns>
                    <a:column name="risk_flag_n" align="center" prompt="危险标志" renderer="con630_red_fun" width="60"/>
                    <a:column name="contract_number" align="left" prompt="合同序号" width="100"/>
                    <a:column name="search_term_1" align="left" prompt="合同号" width="100"/>
                    <a:column name="bp_id_tenant_n" align="center" prompt="承租人" width="100"/>
                    <a:column name="times_01" align="center" prompt="次数" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="overdue_times" align="right" prompt="逾期期数" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="overdue_month_times" align="right" prompt="逾期月数" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="lease_channel" align="center" prompt="商业模式" width="100"/>
                    <a:column name="serial_number" align="center" prompt="机编号" width="100"/>
                    <a:column name="specification" align="left" prompt="机型" width="100"/>
                    <a:column name="branch_company" align="left" prompt="分公司" width="100"/>
                    <!-- <a:column name="status" align="left" prompt="状态" width="100"/> -->
                    <a:column name="province_id_n" align="left" prompt="省份" width="100"/>
                    <a:column name="legal_times" align="right" prompt="律师函发函次数" width="100"/>
                    <a:column name="lawsuit_status_n" align="center" prompt="诉讼状态" width="100"/>
                    <!-- <a:column name="lawsuit_flag" align="right" prompt="是否诉讼" width="100"/> -->
                    <a:column name="accounting_period" 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="lease_end_date" align="right" prompt="租赁到期日" renderer="Leaf.formatDate" width="100"/>
                    <!-- <a:column name="due_date" align="right" prompt="本月支付日" renderer="Leaf.formatDate" width="100"/> -->
                    <a:column name="pay_rate" align="right" prompt="首付比例" width="100"/>
                    <a:column name="lease_item_amount" align="right" prompt="融资额" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="times" align="right" prompt="总期数" width="100"/>
                    <a:column name="overdue_amount" align="right" prompt="逾期租金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="received_amount" align="right" prompt="已收租金合计" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="month_disposed_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="outstanding_principal" align="right" prompt="未到期本金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="outstanding_interest" align="right" prompt="未到期利息" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="employee_id_n" align="right" prompt="业务员" width="100"/>
                    <a:column name="collector_user_id_n" align="right" prompt="客户服务专员" 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="lease_item_amount" 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="unreceived_rental" align="right" prompt="未收本金" renderer="Leaf.formatMoney" 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="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="contract_status" align="right" prompt="合同状态" width="100"/>
                    <a:column name="legal_status" align="right" prompt="法务状态" width="100"/>
                    <a:column name="description" align="right" prompt="法务备注" width="100"/>
                    <a:column name="legal_way" align="right" prompt="法务途径" width="100"/>
                    <!-- <a:column name="followed_method" align="right" prompt="法务后续方式" width="100"/> -->
                    <a:column name="penalty_all" 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="et_external" align="right" prompt="提前结清" width="100"/>
                    <a:column name="penalty" align="right" prompt="本月实收滞纳金" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="lb_pattern" align="right" prompt="CAT回租方式" width="100"/>
                    <a:column name="company_id_n" align="right" prompt="融资公司" width="100"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
