<?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">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.document_category=&apos;CONTRACT&apos;" fetchAll="true" model="basic.hls_document_type_for_lov" rootPath="CON542_document_type_path"/>
        <a:model-query fetchAll="true" model="cont.CON301.con_contract_business_type_list" rootPath="CON542_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="CON542_exp_org_unit_manager_path"/>
    </a:init-procedure>
    <a:view>
        <!-- <a:link id="con_contract_closed_submit_link_id" model="cont.CON542.con_contract_cancel" modelaction="batch_update"/> -->
        <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_closed_link" model="cont.CON542.con_contract_closed" modelaction="batch_update"/>
        <a:link id="${/parameter/@layout_code}con_contract_query_link"
                url="${/request/@context_path}/modules/cont/CON505/con_contract_modify.lview"/>
        <a:link id="car_modify_special_link" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_maintain.lview"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:link id="car_modify_link_readonly_c" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_maintain_constru.lview"/>
        <script type="text/javascript"><![CDATA[
            function CON542_con_contract_query() {
                $('CON542_contract_result_ds').query();
            }
            
            function CON542_con_contract_reset() {
                $('CON542_contract_query_ds').reset();
            }

        function seeDetail_num(value, record, name) {
                if(value){
            if (name=='contract_number') {
               return '<a href="javascript:open_contract_win(\'' + record.id + '\',\''  + record.ds.id + '\');">' + value + '</a>';
            }else if(name=='project_number'){
                return '<a href="javascript:open_project_Window(\'' + record.id + '\',\''  + record.ds.id + '\');">' + value + '</a>';
            }}else{
                    return '';
                }
        }

        function open_contract_win(record_id,ds_id) {
                debugger;
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['function_code'] = 'CON301';
            param['function_usage'] = 'QUERY';
            param['winid'] = 'con_contract_modify_win_id';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}con_contract_query_link', ds_id);
        }

        function open_project_Window(record_id, ds_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            var url;
            param['company_id'] = record.get('company_id');
            param['project_id'] = record.get('project_id');
            param['function_usage'] = 'QUERY';
            param['bp_class'] = record.get('bp_class');
            param['maintain_type'] = 'QUERY';
            /*  param['window_open_flag'] = 'Y';
             param['show_history_flag'] = 'Y'; */
            param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
            if(record.get('is_constru_unit') == 'N'){
                //不是虚拟店
                param['function_code'] = 'PRJ501_WFL';
                url = 'car_modify_special_link';
            }else{
                //虚拟店
                param['function_code'] = 'PRJ501Q_CONSTRU';
                url = 'car_modify_link_readonly_c';
            }
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, url, ds_id, '${/parameter/@layout_code}');
        }

            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 == "bp_vender") {
                    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 CON542_con_contract_closed() {
                var records = $('CON542_contract_result_ds').getSelected();
                var cancelData = [];
                records[0].set('_status', 'update');
                var records_reason = $('contract_cancel_ds').getAt(0);


                cancelData.push(records[0].data);
                Leaf.showConfirm('${l:PROMPT}', '您确认要提交合同取消申请?', function() {
                    Leaf.request({
                        url: $('con_contract_closed_link').getUrl(),
                        para: cancelData,
                        success: function() {
                            Leaf.SideBar.show({
                                msg: '提交成功',
                                duration: 2000
                            });
                            $('CON542_contract_result_ds').query();
                        },
                        scope: this
                    });
                }, function() {
                }, null, null);
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CON542"/>
        <a:dataSets>
            <a:dataSet id="contract_cancel_ds" autoCreate="true">
                <a:fields>
                    <a:field name="cancel_reason" required="false"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="contract_document_ds" loadData="true" model="prj.PRJ415.hls_document_type_for_lov"/>
            <a:dataSet id="CON542_employee_name_of_manager_ds">
                <a:datas dataSource="/model/CON542_exp_org_unit_manager_path"/>
            </a:dataSet>
            <a:dataSet id="CON542_unit_name_ds" loadData="true" model="basic.exp_org_unit_name_lov"/>
            <a:dataSet id="CON542_lease_organization_name_ds" loadData="true" model="basic.hls_lease_organization_for_lov"/>
            <a:dataSet id="CON542_division_name_ds" loadData="true" model="basic.hls_division_for_lov"/>
            <a:dataSet id="CON542_lease_channel_name_ds" loadData="true" model="basic.hls_lease_channel_for_lov"/>
            <a:dataSet id="CON542_wfl_status_name_ds" lookupCode="CON500_WFL_STATUS"/>
            <a:dataSet id="CON542_companies_ds" loadData="true" model="fnd.fnd_companies"/>
            <a:dataSet id="CONTRACT_STATUS_DS">
                <a:datas>
                    <a:record code_value="NEW" code_value_name="新建"/>
                    <a:record code_value="INCEPT" code_value_name="起租"/>
                    <a:record code_value="INCEPTING" code_value_name="起租中"/>
                    <a:record code_value="INCEPT_RETURN" code_value_name="起租退回"/>
                    <a:record code_value="CANCEL" code_value_name="取消"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="SIGN_CONTRACT_STATUS_DS">
                <a:datas>
                    <a:record code_value="NEW" code_value_name="新建"/>
                    <a:record code_value="SIGN" code_value_name="签约"/>
                    <a:record code_value="SIGNING" code_value_name="签约中"/>
                    <a:record code_value="SIGN_RETURN" code_value_name="签约退回"/>
                    <a:record code_value="CANCEL" code_value_name="取消"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="CON542_document_type_name_ds">
                <a:datas dataSource="/model/CON542_document_type_path"/>
            </a:dataSet>
            <a:dataSet id="CON542_business_type_ds">
                <a:datas dataSource="/model/CON542_business_type_list"/>
            </a:dataSet>
            <a:dataSet id="CON542_contract_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="bp_id_tenant_n" autoComplete="true" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON541.hls_bp_master_v_for_lov?bp_category=TENANT" lovWidth="520" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_name" to="bp_id_tenant_n"/>
                            <a:map from="bp_id" to="bp_id_tenant"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_tenant"/>
                    <a:field name="bp_agent_name" autoComplete="true" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON541.hls_bp_master_v_for_lov?bp_category=AGENT" lovWidth="520" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_name" to="bp_agent_name"/>
                            <a:map from="bp_id" to="bp_id_agent_level1"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_status_n" options="CONTRACT_STATUS_DS"
                             returnField="contract_status" displayField="code_value_name" valueField="code_value"/>
                    <a:field name="sign_contract_status_n" options="SIGN_CONTRACT_STATUS_DS"
                             returnField="sign_contract_status" displayField="code_value_name" valueField="code_value"/>
                    <a:field name="bp_id_tenant"/>
                    <a:field name="contract_number" typeCase="Upper"/>
                    <a:field name="project_number" typeCase="Upper"/>
                    <a:field name="document_type_desc" displayField="description" options="contract_document_ds" returnField="document_type" valueField="document_type"/>
                    <a:field name="lease_organization_name" displayField="description" options="CON542_lease_organization_name_ds" returnField="lease_organization" valueField="lease_organization"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="CON542_contract_result_ds" autoPageSize="true" autoQuery="true" model="cont.CON542.con_contract_for_query" queryDataSet="CON542_contract_query_ds" queryUrl="${/request/@context_path}/autocrud/cont.CON542.con_contract_for_query/query" selectable="true" selectionModel="single">
                <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="CON542_con_contract_query" text="HLS.QUERY"/>
                <a:gridButton click="CON542_con_contract_reset" text="HLS.RESET"/>
                <a:gridButton click="CON542_con_contract_closed" text="合同取消"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="100" marginWidth="30" title="CON301.CONTRACT_QUERY">
                <a:textField name="contract_number" bindTarget="CON542_contract_query_ds" prompt="HLS.CONTRACT_NUMBER"/>
                <a:lov name="bp_id_tenant_n" bindTarget="CON542_contract_query_ds" prompt="HLS.TENANT_CODE"/>
                <a:lov name="bp_agent_name" bindTarget="CON542_contract_query_ds" prompt="代理店"/>
                <a:numberField name="lease_item_amount_from" bindTarget="CON542_contract_query_ds" prompt="租赁物总价从"/>
                <a:numberField name="lease_item_amount_to" bindTarget="CON542_contract_query_ds" prompt="租赁物总价到"/>
                <a:textField name="project_number" bindTarget="CON542_contract_query_ds" prompt="报单编号"/>
                <a:comboBox name="contract_status_n" bindTarget="CON542_contract_query_ds" prompt="合同状态"/>
                <a:comboBox name="sign_contract_status_n" bindTarget="CON542_contract_query_ds" prompt="签约状态"/>
            </a:form>
          <!--  <a:form labelWidth="100" marginWidth="30" title="取消原因">
                <a:textArea name="cancel_reason" bindTarget="contract_cancel_ds" height="60" prompt="取消原因" width="800"/>
            </a:form>-->
            <a:grid id="CON542_con_contract_grid_ds" bindTarget="CON542_contract_result_ds" marginHeight="150" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="contract_number" prompt="HLS.CONTRACT_NUMBER" width="150" renderer="seeDetail_num"/>
                    <a:column name="project_number" prompt="报单编号" width="120" renderer="seeDetail_num"/>
                    <a:column name="bp_id_agent_level1_n" prompt="代理店" width="200"/>
                    <a:column name="bp_name" prompt="HLS.TENANT_NAME" width="200"/>
                    <!--<a:column name="bp_vender" align="center" footerRenderer="summaryRenderer" prompt="主供应商名称" width="200"/>-->
                    <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="contract_status_n" prompt="合同状态" align="center"/>
                    <a:column name="sign_contract_status_n" prompt="签约状态" align="center"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
