<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LR  
    $Date: 2013-8-13 上午10:30:25  
    $Revision: 1.0  
    $Purpose: 
-->
<!--<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true" > -->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.document_category=&apos;CONTRACT&apos;" fetchAll="true" model="basic.hls_document_type_for_lov" rootPath="con501_document_type_path"/>
        <a:model-query fetchAll="true" model="cont.CON301.con_contract_business_type_list" rootPath="con501_business_type_list"/>
        <a:model-query defaultWhereClause="(exists(select 1 from hls_lease_org_assign ha where ha.unit_id=t1.unit_id))" fetchAll="true" model="basic.exp_org_unit_manager_lov" rootPath="con501_exp_org_unit_manager_path"/>
        <a:model-query fetchAll="true" model="cont.CON500.fnd_companies" rootPath="con501_spvs"/>
        <a:model-query defaultWhereClause="v.code = &apos;CON500_CONTRACT_STATUS&apos;" fetchAll="true" model="sys_code_value" rootPath="sys_code_value_path"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_update_link_id" url="${/request/@context_path}/modules/cont/CON500/con_contract_update.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_cancel_link_id" model="db.con_contract_pkg.con_contract_cancel" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
            function con501_con_contract_detail() {
                var records = $('con501_contract_result_ds').getSelected();
                if (records.length != 1) {
                    return;
                }
                var param = records[0].data;
                param['document_id'] = records[0].get('contract_id');
                con501_param_set_value(param);
            }
            
            function con501_render_contractMaintainDs_grid(value, record, name) {
                if (name == 'contract_number') {
                    return '<a href="javascript:con501_contractMaintainDs_grid_update(' + record.id + ');">' + value + '</a>';
                }
            }
            
            function con501_param_set_value(param) {
                param['function_code'] = 'ZXCON920';
                param['function_usage'] = 'QUERY';
                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', 'con501_contract_result_ds');
            }
            
            function con501_contractMaintainDs_grid_update(id) {
                var current_record = $('con501_contract_result_ds').findById(id);
                var param = current_record.data;
                param['document_id'] = current_record.get('contract_id');
                con501_param_set_value(param);
            }
            
            function con501_con_contract_return() {
                history.go(-1);
            }
            
            function con501_con_contract_query() {
                $('con501_contract_result_ds').query();
            }
            
            function con501_con_contract_reset() {
                $('con501_contract_query_ds').reset();
            }
            
            function con501_contract_query_ds_onUpdate(ds, record, name, value, oldvalue) {
                if (name == 'lease_start_date_from') {
                    if (!Leaf.isEmpty(value) && Leaf.isEmpty(record.get('lease_start_date_to'))) {
                        record.set('lease_start_date_to', value);
                    }
                }else if(name == 'lease_start_date_to'){
                    if(!Leaf.isEmpty(value) && Leaf.isEmpty(record.get('lease_start_date_from'))){
                        record.set('lease_start_date_from', value);
                    }
                }else if(name == 'contract_number_from'){
                    if (!Leaf.isEmpty(value) && Leaf.isEmpty(record.get('contract_number_to'))) {
                        record.set('contract_number_to', value);
                    }
                }else if(name == 'contract_number_to'){
                    if(!Leaf.isEmpty(value) && Leaf.isEmpty(record.get('contract_number_from'))){
                        record.set('contract_number_from', value);
                    }
                }
            }
            
            function lock_list_window() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            }
            
            function unlock_list_window() {
                Leaf.Masker.unmask(Ext.getBody());
            }
       		function summaryRenderer(datas, name) {
           		
                var sum = 0;
              	var sum2 = 0;
                for (var i = 0;i < datas.length;i++) {
                    record = datas[i];
                    if (name == "lease_item_amount" ) {
                        var t_1 = record.get("lease_item_amount" );
                        var  t_2 = parseFloat(t_1);
                        if (!isNaN(t_2)) {
                            sum += t_2;
                        }
                    }
                    if (name == "down_payment" ) {
                        var d_1 = record.get("down_payment" );
                        var  d_2 = parseFloat(d_1);
                        if (!isNaN(d_2)) {
                            sum2 += d_2;
                        }
                    }
                }
                if (name == "contract_status_desc") {
                    return '<div align="right">合计:</div>';
                }
                if (name == "lease_item_amount" ) {           
                    return '<font color="red">' + Leaf.formatNumber(sum, 2) + '</font>';
                }
                if (name == "down_payment" ) {           
                    return '<font color="red">' + Leaf.formatNumber(sum2, 2) + '</font>';
                } 
            }
            

            
            function con501_zx_con_contract() {
                var records = $('con501_contract_result_ds').getSelected();
                if (records.length != 1) {
                    return;
                }
                var param = records[0].data;
                param['document_id'] = records[0].get('contract_id');
                con920_param_set_value(param);
            }
            
            function con920_param_set_value(param) {
                param['function_code'] = 'ZXCON920';
                param['function_usage'] = 'MODIFY';
                param['maintain_type'] = 'UPDATE';
                param['url_title'] = '征信信息维护';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_update_link_id', 'con501_contract_result_ds');
            }
            function con501_con_contract_report_yes(){
                var ds=$('con501_contract_result_ds');
    		    var records = ds.getSelected();
    		    if(records.length==0)
                {
                    return;
                }
                var datas=[];
                for(var i=0;i<records.length;i++)
                {
                    var obj={};
                    obj['contract_id']=records[i].get('contract_id');
                    //obj['if_to_zx_flag']=records[i].get('if_to_zx_flag'); 
                    //obj['zx_last_updated_by']=records[i].get('zx_last_updated_by');
                    //obj['zx_last_update_date']=records[i].get('zx_last_update_date');
                    obj['_status']='update';
                    datas[i]=obj;
                }
                Leaf.request({
	                url: '${/request/@context_path}/autocrud/cont.ZXCON920.con_contract_report_yes/batch_update',
	                para: datas,
	                success: function(res) {
	                    Leaf.SideBar.show({
                            msg: '${l:HLS.SUBMIT_SUCCESS}',
                            duration: 1000
                        });
                        $('con501_contract_result_ds').query();
                        //alert(167);
	                },
	                failure: function() {
	                    //f_hls.winNoMask();
	                },
	                error: function() {
	                    //f_hls.winNoMask();
	                },
	                scope: this
	            });
            }
            function con501_con_contract_report_no(){
                var ds=$('con501_contract_result_ds');
    		    var records = ds.getSelected();
    		    if(records.length==0)
                {
                    return;
                }
                var datas=[];
                for(var i=0;i<records.length;i++)
                {
                    var obj={};
                    obj['contract_id']=records[i].get('contract_id');
                    //obj['if_to_zx_flag']=records[i].get('if_to_zx_flag'); 
                    //obj['zx_last_updated_by']=records[i].get('zx_last_updated_by');
                    //obj['zx_last_update_date']=records[i].get('zx_last_update_date');
                    obj['_status']='update';
                    datas[i]=obj;
                }
                Leaf.request({
	                url: '${/request/@context_path}/autocrud/cont.ZXCON920.con_contract_report_no/batch_update',
	                para: datas,
	                success: function(res) {
	                    Leaf.SideBar.show({
                            msg: '${l:HLS.SUBMIT_SUCCESS}',
                            duration: 1000
                        });
                        $('con501_contract_result_ds').query();
                        //alert(167);
	                },
	                failure: function() {
	                    //f_hls.winNoMask();
	                },
	                error: function() {
	                    //f_hls.winNoMask();
	                },
	                scope: this
	            });
            }
        ]]></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"/>
        <a:dataSets>
            <a:dataSet id="con501_yes_no" lookupCode="YES_NO"/>
            <a:dataSet id="con501_spv_company_ds">
                <a:datas dataSource="/model/con501_spvs"/>
            </a:dataSet>
            <a:dataSet id="con501_yes_no_ds" lookupCode="YES_NO"/>
            <a:dataSet id="con501_employee_name_of_manager_ds">
                <a:datas dataSource="/model/con501_exp_org_unit_manager_path"/>
            </a:dataSet>
            <a:dataSet id="con501_unit_name_ds" loadData="true" model="cont.CON500.marketing_unit_vl"/>
            <a:dataSet id="con501_lease_organization_name_ds" loadData="true" model="basic.hls_lease_organization_for_lov"/>
            <a:dataSet id="con501_division_name_ds" loadData="true" model="basic.hls_division_for_lov"/>
            <a:dataSet id="con501_lease_channel_name_ds" loadData="true" model="basic.hls_lease_channel_for_lov"/>
            <!-- <a:dataSet id="con501_status_name_ds" lookupCode="CON500_CONTRACT_STATUS"/> -->
            <a:dataSet id="con501_status_name_ds" loadData="true">
                <a:datas dataSource="/model/sys_code_value_path"/>
            </a:dataSet>
            <a:dataSet id="con501_document_type_name_ds">
                <a:datas dataSource="/model/con501_document_type_path"/>
            </a:dataSet>
            <a:dataSet id="con501_business_type_ds">
                <a:datas dataSource="/model/con501_business_type_list"/>
            </a:dataSet>
            <a:dataSet id="con501_contract_query_ds" autoCreate="true">
                <a:fields>
                    <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_code" to="bp_code"/>
                            <a:map from="bp_id" to="bp_id_tenant"/>
                            <a:map from="bp_name" to="bp_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_tenant"/>
                    <a:field name="project_employee_name" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="basic.hls_exp_employees_for_lov?sales_flag=Y" lovWidth="500" title="HLS.SALES_EMPLOYEE">
                        <a:mapping>
                            <a:map from="name" to="project_employee_name"/>
                            <a:map from="employee_id" to="employee_id"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_number" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON500.con_contract_number_lov" lovWidth="500" title="HLS.CONTRACT_NUMBER">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="employee_id"/>
                    <a:field name="employee_name_of_manager" displayField="mgr_employee_name" options="con501_employee_name_of_manager_ds" returnField="employee_id_of_manager" valueField="mgr_employee_id"/>
                    <a:field name="unit_name" displayField="description" options="con501_unit_name_ds" returnField="unit_id" valueField="unit_id"/>
                    <a:field name="lease_organization_name" displayField="description" options="con501_lease_organization_name_ds" returnField="lease_organization" valueField="lease_organization"/>
                    <a:field name="division_desc" displayField="description" options="con501_division_name_ds" returnField="division" valueField="division"/>
                    <a:field name="lease_channel_desc" displayField="description" options="con501_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="business_type_desc" displayField="business_type_desc" options="con501_business_type_ds" returnField="business_type" valueField="business_type"/>
                    <a:field name="contract_status_desc" displayField="code_value_name" options="con501_status_name_ds" returnField="contract_status" valueField="code_value"/>
                    <a:field name="contract_number_from" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON500.con_contract_number_lov" lovWidth="500" title="HLS.CONTRACT_NUMBER">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number_from"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_number_to" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON500.con_contract_number_lov" lovWidth="500" title="HLS.CONTRACT_NUMBER">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number_to"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="overdue_status_desc" displayField="code_value_name" options="con501_yes_no_ds" returnField="overdue_status" valueField="code_value"/>
                    <a:field name="spv_company" displayField="company_short_name" options="con501_spv_company_ds" returnField="spv_company_id" valueField="company_id"/>
                    <a:field name="sale_conselor_name" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON500.cwl_saleman_define_vl" lovWidth="500" title="销售顾问">
                        <a:mapping>
                            <a:map from="saleman_name" to="sale_conselor_name"/>
                            <a:map from="sale_conselor_id" to="sale_conselor_id"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="if_to_zx_flag_desc" displayField="code_value_name" options="con501_yes_no" returnField="if_to_zx_flag" valueField="code_value"/>
                    <!-- <a:field name="zx_last_update_date_from" />
                	<a:field name="zx_last_update_date_to" /> -->
                    <a:field name="zx_last_updated_by_desc" lovGridHeight="350" lovHeight="500" lovService="exp.exp_employees" lovWidth="500" title="HLS.SALESMAN">
                        <a:mapping>
                            <a:map from="employee_id" to="employee_id"/>
                            <a:map from="name" to="zx_last_updated_by_desc"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="con501_contract_query_ds_onUpdate"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="con501_contract_result_ds" autoQuery="true" model="cont.ZXCON920.con_contract_v" pageSize="10" queryDataSet="con501_contract_query_ds" queryUrl="${/request/@context_path}/autocrud/cont.ZXCON920.con_contract_v/query?contract_status!=CANCEL" selectable="true">
                <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="con501_con_contract_return" text="HLS.RETURN"/>
                <a:gridButton click="con501_con_contract_query" text="HLS.QUERY"/>
                <a:gridButton click="con501_con_contract_reset" text="HLS.RESET"/>
                <a:gridButton click="con501_con_contract_report_yes" text="上报征信系统"/>
                <a:gridButton click="con501_con_contract_report_no" text="不上报征信系统"/>
                <!-- <a:gridButton click="con501_zx_con_contract" text="征信信息维护"/> -->
            </a:screenTopToolbar>
            <a:form column="4" labelSeparator=" " labelWidth="100" marginWidth="30" title="CON301.CONTRACT_QUERY">
                <!-- <a:lov name="contract_number" bindTarget="con501_contract_query_ds" prompt="HLS.CONTRACT_NUMBER">
                    <a:events>
                        <a:event name="focus" handler="function(object){on_std_focus(object,&apos;CONTRACT&apos;)}"/>
                    </a:events>
                </a:lov> -->
                <a:lov name="contract_number_from" bindTarget="con501_contract_query_ds" prompt="合同编号从"/>
                <a:lov name="contract_number_to" bindTarget="con501_contract_query_ds" prompt="合同编号到"/>
                <a:lov name="bp_name" bindTarget="con501_contract_query_ds" prompt="承租人">
                    <a:events>
                        <a:event name="focus" handler="function(object){on_std_focus(object,&apos;BP&apos;)}"/>
                    </a:events>
                </a:lov>
                <a:comboBox name="division_desc" bindTarget="con501_contract_query_ds" prompt="HLS.DIVISION_NAME"/>
                <!-- <a:textField name="bp_name" bindTarget="con501_contract_query_ds" prompt="HLS.TENANT_NAME"/> -->
                <a:datePicker name="lease_start_date_from" bindTarget="con501_contract_query_ds" prompt="HLS.LEASE_START_DATE_FROM"/>
                <a:datePicker name="lease_start_date_to" bindTarget="con501_contract_query_ds" prompt="HLS.LEASE_START_DATE_TO"/>
                <a:textField name="project_number" bindTarget="con501_contract_query_ds" prompt="申请编号"/>
                <!-- <a:textField name="project_name" bindTarget="con501_contract_query_ds" prompt="HLS.PROJECT_NAME"/> -->
                <!-- <a:lov name="project_employee_name" bindTarget="con501_contract_query_ds" prompt="HLS.SALES_EMPLOYEE"/> -->
                <!-- <a:comboBox name="lease_organization_name" bindTarget="con501_contract_query_ds" prompt="HLS.LEASE_ORGANIZATION"/> -->
                <!-- <a:textField name="contract_name" bindTarget="con501_contract_query_ds" prompt="HLS.CONTRACT_NAME"/> -->
                <!-- <a:comboBox name="employee_name_of_manager" bindTarget="con501_contract_query_ds" prompt="HLS.EMPLOYEE_OF_MANAGER"/> -->
                <a:comboBox name="lease_channel_desc" bindTarget="con501_contract_query_ds" prompt="HLS.LEASE_CHANNEL_NAME"/>
                <!-- <a:textField name="prj_search_term_1" bindTarget="con501_contract_query_ds" prompt="CON301.CON_CONTRACT_V.PRJ_SEARCH_TERM_1"/> -->
                <!-- <a:textField name="prj_search_term_2" bindTarget="con501_contract_query_ds" prompt="CON301.CON_CONTRACT_V.PRJ_SEARCH_TERM_2"/> -->
                <!-- <a:textField name="con_search_term_1" bindTarget="con501_contract_query_ds" prompt="CON301.CON_CONTRACT_V.CON_SEARCH_TERM_1"/> -->
                <!-- <a:textField name="con_search_term_2" bindTarget="con501_contract_query_ds" prompt="CON301.CON_CONTRACT_V.CON_SEARCH_TERM_2"/> -->
                <!-- <a:comboBox name="document_type_desc" bindTarget="con501_contract_query_ds" prompt="HLS.CONTRACT_TYPE"/> -->
                <a:numberField name="lease_item_amount_from" bindTarget="con501_contract_query_ds" prompt="租赁物总价从"/>
                <a:numberField name="lease_item_amount_to" bindTarget="con501_contract_query_ds" prompt="租赁物总价到"/>
                <!-- <a:comboBox name="business_type_desc" bindTarget="con501_contract_query_ds" prompt="HLS.BUSINESS_TYPE_DESC"/> -->
                <a:lov name="sale_conselor_name" bindTarget="con501_contract_query_ds" prompt="销售顾问"/>
                <a:comboBox name="contract_status_desc" bindTarget="con501_contract_query_ds" prompt="HLS.CONTRACT_STATUS"/>
                <a:textField name="licenses" bindTarget="con501_contract_query_ds" prompt="牌照号"/>
                <a:comboBox name="unit_name" bindTarget="con501_contract_query_ds" prompt="4S店"/>
                <a:comboBox name="spv_company" bindTarget="con501_contract_query_ds" prompt="公司"/>
                <a:comboBox name="overdue_status_desc" bindTarget="con501_contract_query_ds" prompt="逾期状态"/>
                <a:comboBox name="if_to_zx_flag_desc" bindTarget="con501_contract_query_ds" prompt="是否上传征信"/>
                <a:lov name="zx_last_updated_by_desc" bindTarget="con501_contract_query_ds" prompt="最后更新上传状态人"/>
                <a:datePicker name="zx_last_update_date_from" bindTarget="con501_contract_query_ds" prompt="最后更新上传状态时间从"/>
                <a:datePicker name="zx_last_update_date_to" bindTarget="con501_contract_query_ds" prompt="最后更新上传状态时间到"/>
            </a:form>
            <a:grid id="con501_con_contract_grid_ds" bindTarget="con501_contract_result_ds" marginHeight="235" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="contract_number" align="left" lock="true" prompt="HLS.CONTRACT_NUMBER" renderer="con501_render_contractMaintainDs_grid" width="150"/>
                    <a:column name="contract_name" align="center" prompt="HLS.CONTRACT_NAME" width="150"/>
                    <a:column name="lease_start_date" align="center" prompt="HLS.LEASE_START_DATE" renderer="Leaf.formatDate" width="80"/>
                    <a:column name="project_number" align="center" prompt="申请编号"/>
                    <a:column name="bp_name" align="center" prompt="HLS.TENANT_NAME" width="150"/>
                    <a:column name="bp_tenant_class_n" align="center" prompt="承租人类型" width="100"/>
                    <!-- <a:column name="bp_id_agent_level1_n" align="center" prompt="经销商" width="150"/> -->
                    <!-- <a:column name="project_name" prompt="HLS.PROJECT_NAME" width="200"/> -->
                    <!-- <a:column name="employee_name" prompt="HLS.SALES_EMPLOYEE" width="70"/> -->
                    <!-- <a:column name="unit_name" prompt="HLS.UNIT_NAME"/> -->
                    <!-- <a:column name="employee_name_of_manager" prompt="HLS.EMPLOYEE_OF_MANAGER" width="70"/> -->
                    <!-- <a:column name="lease_organization_desc" align="center" prompt="HLS.LEASE_ORGANIZATION"/> -->
                    <a:column name="division_desc" align="center" prompt="HLS.DIVISION_NAME" width="70"/>
                    <a:column name="licenses" prompt="牌照号" showTitle="true" width="100"/>
                    <a:column name="lease_channel_desc" align="center" prompt="HLS.LEASE_CHANNEL_NAME" width="70"/>
                    <a:column name="document_type_desc" align="center" prompt="HLS.CONTRACT_TYPE" width="90"/>
                    <a:column name="contract_status_desc" footerRenderer="summaryRenderer" prompt="HLS.CONTRACT_STATUS" width="60"/>
                    <a:column name="if_to_zx_flag_desc" align="center" prompt="是否上传征信" width="120"/>
                    <a:column name="zx_last_updated_by_desc" align="center" prompt="最后更新上传状态人" width="120"/>
                    <a:column name="zx_last_update_date" align="center" prompt="最后更新上传状态时间" width="150"/>
                    <a:column name="lease_item_amount" align="right" footerRenderer="summaryRenderer" prompt="租赁物总价" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="down_payment" align="right" footerRenderer="summaryRenderer" prompt="首付款" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="spv_company_name" prompt="公司"/>
                    <a:column name="unit_name" prompt="4S店"/>
                    <a:column name="saleman_name" prompt="销售顾问"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
