<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm  
    $Date: 2013-5-22 上午11:10:19  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=PAYMENT_REQ&amp;function_code=CSH502"/>
        <a:link id="payment_req_post_link" url="${/request/@context_path}/modules/csh/CSH502/payment_seq_insert_tmp.lsc"/>
        <a:link id="payment_req_excel_link" url="${/request/@context_path}/modules/csh/CSH502/payment_seq_excel_sheets.lsc"/>
        <a:link id="payment_req_excel_cib_link" url="${/request/@context_path}/modules/csh/CSH502/payment_seq_excel_sheets_cib.lsc"/>
        <a:link id="csh_payment_req_pay_link" url="${/request/@context_path}/modules/csh/CSH502/csh_payment_req_maintain.lview"/>
        <a:link id="csh_payment_req_close_link" url="${/request/@context_path}/modules/csh/CSH502/csh_payment_req_close.lview"/>
        <a:link id="csh_payment_req_doc_print_link" url="${/request/@context_path}/modules/csh/CSH502/csh_payment_doc_print.lview"/>
        <a:link id="csh_payment_req_doc_print_d_link" url="${/request/@context_path}/modules/csh/CSH502/csh_payment_doc_print_d.lview"/>
        <a:link id="csh502_csh_payment_req_link_id" url="${/request/@context_path}/modules/csh/CSH501/csh_payment_req.lview"/>
        <a:link id="save_payment_flag_link" model="csh.CSH502.csh_payment_req_query" modelaction="batch_update"/>
        <a:link id="csh502_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <div/>
        <script type="text/javascript"><![CDATA[
            function csh502_payment_query() {
                $('csh_payment_req_queryDs').query();
            }
            
            function csh502_payment_reset() {
                $('csh_payment_req_query_ds').reset();
            }
            
            function render_objectDs_grid(value, record, name) {
                if (name === 'payment_req_number') {
                    if (!record.isNew) {
                        return '<a href="javascript:winOpen_req_pay(\'' + record.id + '\')">' + value + '</a>';
                    }
                } else if (name === 'print_flag') {
                    if (value === 'Y') {
                        return '已打印';
                    } else {
                        return '<font color="red">未打印</font>';
                    }
                }
                // if (record.get('payment_req_id')) {
                // var url;
                // url = $('csh_payment_req_pay_link').getUrl() + '?payment_req_id=' + record.get('payment_req_id');
                // return '<a href="javascript:openWindow(\'' + url + '\');">' + value + '</a>';
                // }
            }
        function construct_from_to() {
            var config = ['amount', 'bank_slip_num', 'transaction_amount', 'currency_code', 'bank_account_code'];
            var pattern = ['_from', '_to'];
            var obj = {};
            for (var i = 0,
                     j = config.length; i < j; i++) {
                for (var m = 0,
                         n = pattern.length; m < n; m++) {
                    obj[config[i] + pattern[m]] = config[i] + pattern[n - 1 - m];
                }
            }
            return obj;
        }
            
            // function openWindow(url) {
            // new Leaf.Window({
            // id: 'csh_payment_req_pay_window',
            // params:{
            // winId:'csh_payment_req_pay_link_winid'
            // },
            // url: url,
            // title: '付款申请支付',
            // fullScreen: true
            // });
            // }
            
            function winOpen_req_pay(record_id) {
                var record = $('csh_payment_req_queryDs').findById(record_id);
                var param = {};
                // param['function_usage'] = 'QUERY';
                // param['maintain_type'] = 'READONLY';
                param['function_usage'] = 'MODIFY';
                param['maintain_type'] = 'UPDATE';
                param['payment_req_id'] = record.get('payment_req_id');
                param['document_category'] = record.get('document_category');
                param['business_type'] = record.get('business_type');
                param['function_code'] = 'CSH502';
                param['winid'] = 'csh_payment_update_window';
                param['url_title'] = '付款申请';
                hls_doc_get_layout_code('csh502_get_layout_code_link_id', param, 'csh502_csh_payment_req_link_id', 'csh_payment_req_queryDs');
            }
            
            function onUpdate_payment_req(ds, record, name, value, oldvalue) {

/*
                var from_to = construct_from_to();
                var opposite_name = from_to[name];
                if (!Ext.isEmpty(opposite_name)) {
                    var opposite_value = record.get(opposite_name);
                    if (!Ext.isEmpty(value) && Ext.isEmpty(opposite_value)) {
                        record.set(opposite_name, value);
                    }
                }
*/

                if (name == 'payment_req_number_from') {
                    if (record.get('payment_req_number_to') == 'undefined' || record.get('payment_req_number_to') == null || record.get('payment_req_number_to') == '') {
                        record.set('payment_req_number_to', value);
                    }
                } else if (name == 'payment_req_number_to') {
                    if (record.get('payment_req_number_from') == 'undefined' || record.get('payment_req_number_from') == null || record.get('payment_req_number_from') == '') {
                        record.set('payment_req_number_from', value);
                    }
                } else if (name == 'approval_date_from') {
                    if (record.get('approval_date_to') == 'undefined' || record.get('approval_date_to') == null || record.get('approval_date_to') == '') {
                        record.set('approval_date_to', value);
                    }
                } else if (name == 'approval_date_to') {
                    if (record.get('approval_date_from') == 'undefined' || record.get('approval_date_from') == null || record.get('approval_date_from') == '') {
                        record.set('approval_date_from', value);
                    }
                } else if (name == 'amount_from') {
                    var formatMoney=value.replace(/\,/g, "");
                    if (record.get('amount_to') == 'undefined' || record.get('amount_to') == null || record.get('amount_to') == '') {

                        record.set('amount_to', formatMoney);
                    }
                    ds.getAt(0).set('amount_from', formatMoney)
                    record.set('amount_from', formatMoney);

                } else if (name == 'amount_to') {
                    var formatMoney=value.replace(/\,/g, "");
                    if (record.get('amount_from') == 'undefined' || record.get('amount_from') == null || record.get('amount_from') == '') {
                        record.set('amount_from', formatMoney);
                    }
                    record.set('amount_to', formatMoney);

                } else if (name == 'req_date_from') {
                    if (record.get('req_date_to') == 'undefined' || record.get('req_date_to') == null || record.get('req_date_to') == '') {
                        record.set('req_date_to', value);
                    }
                } else if (name == 'req_date_to') {
                    if (record.get('req_date_from') == 'undefined' || record.get('req_date_from') == null || record.get('req_date_from') == '') {
                        record.set('req_date_from', value);
                    }
                } else if (name == 'bp_code_from') {
                    if (record.get('bp_code_to') == 'undefined' || record.get('bp_code_to') == null || record.get('bp_code_to') == '') {
                        record.set('bp_code_to', value);
                    }
                } else if (name == 'bp_code_to') {
                    if (record.get('bp_code_from') == 'undefined' || record.get('bp_code_from') == null || record.get('bp_code_from') == '') {
                        record.set('bp_code_from', value);
                    }
                }
            }
            
            function csh502_payment_close() {
                var record = $('csh_payment_req_queryDs').getSelected();
                if (record == undefined) {
                    Leaf.showMessage('${l:PROMPT_MESSAGE}', '未选中行', null, 250, 100);
                } else {
                    new Leaf.Window({
                        id: 'csh_payment_req_close_window',
                        url: $('csh_payment_req_close_link').getUrl(),
                        params: {
                            winId: 'csh_payment_req_close_window'
                        },
                        title: '付款申请关闭',
                        height: 200,
                        width: 650
                    });
                }
            }
            
            function csh502_payment_post() {
                var records = $('csh_payment_req_queryDs').getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                    return;
                } else {
                    winOpen_req_pay(records[0].id);
                }
            }
            
            function csh502_payment_doc_print() {
                var records = $('csh_payment_req_queryDs').getSelected();
                if (records.length === 0) {
                    Leaf.showMessage('${l:PROMPT}', '请选择至少一条记录');
                    return;
                } else if (!check_data(records)) {
                    Leaf.showWarningMessage('提示', '仅能打印汇签单列显示为<font color="red">未打印</font>或已打印的数据!');
                    return;
                }
                var instr = '';
                for (var i = 0;i < records.length;i++) {
                    if (i == 0) {
                        instr = instr + records[i].get('payment_req_id');
                    } else {
                        instr = instr + ',' + records[i].get('payment_req_id');
                    }
                }
                var url = $('csh_payment_req_doc_print_link').getUrl() + '?payment_req_id=' + instr;
                window.open(url);
            }
            
            function csh502_payment_doc_print_d() {
                var records = $('csh_payment_req_queryDs').getSelected();
                if (records.length === 0) {
                    Leaf.showMessage('${l:PROMPT}', '请选择至少一条记录');
                    return;
                } else if (!check_data(records)) {
                    Leaf.showWarningMessage('提示', '仅能打印汇签单列显示为<font color="red">未打印</font>或已打印的数据!');
                    return;
                }
                var instr = '';
                for (var i = 0;i < records.length;i++) {
                    if (i == 0) {
                        instr = instr + records[i].get('payment_req_id');
                    } else {
                        instr = instr + ',' + records[i].get('payment_req_id');
                    }
                }
                var url = $('csh_payment_req_doc_print_d_link').getUrl() + '?payment_req_id=' + instr;
                window.open(url);
            }
            
            function check_data(records) {
                for (var i = 0;i < records.length;i++) {
                    if (records[i].get('approval_status') === 'APPROVED') {
                        continue;
                    } else {
                        return false;
                    }
                }
                return true;
            }
            
            function csh502_payment_save() {
                $('csh_payment_req_queryDs').submit();
            }
            
            function csh502_payment_excel() {
                var ds = $('csh_payment_req_queryDs');
                var records = ds.getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('提示', '请选择要导出的数据');
                    return;
                }
                var param = {};
                var saveData = [];
                var detail_mask = Ext.getBody();
                Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                for (var i = 0;i < records.length;i++) {
                    saveData.push({
                        'payment_req_id': records[i].get('payment_req_id'),
                        '_status': 'insert'
                    });
                }
                param['details'] = saveData;
                var payment_bank = $('csh_payment_req_query_ds').getAt(0).get('payment_bank');
                var url_link = $('payment_req_excel_link').getUrl();
                //alert(payment_bank);
                if (payment_bank == 'CCB') {
                    url_link = $('payment_req_excel_link').getUrl();
                } else if (payment_bank == 'CIB') {
                    url_link = $('payment_req_excel_cib_link').getUrl();           
                }
                Leaf.request({
                    url: $('payment_req_post_link').getUrl(),
                    para: param,
                    success: function() {
                        Leaf.Masker.unmask(detail_mask);
                        // window.open($('payment_req_excel_link').getUrl());
                        window.open(url_link);
                    },
                    failure: function() {
                        Leaf.Masker.unmask(detail_mask);
                    },
                    error: function() {
                        Leaf.Masker.unmask(detail_mask);
                    },
                    scope: this
                });
            }
            
            function on_grid_load(ds) {
                records = ds.getAll();
                if ('${/session/@company_id}' != '1') {
                    for (i = 0;i < records.length;i++) {
                        records[i].getField('payment_flag').setReadOnly(true);
                    }
                }
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:dataSets>
            <a:dataSet id="payment_bank_ds" lookupCode="CSH_PAYMENT_BANK"/>
            <a:dataSet id="approval_status_ds" lookupCode="CSH_PAYMENT_REQ_APPROVAL_STATUS"/>
            <a:dataSet id="bp_category_ds">
                <a:datas>
                    <a:record code_value="AGENT" code_value_name="经销商"/>
                    <a:record code_value="VENDER" code_value_name="供应商"/>
                    <a:record code_value="TENANT" code_value_name="主承租人"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="yes_no_ds">
                <a:datas>
                    <a:record name="是" value="Y"/>
                    <a:record name="否" value="N"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="print_ds">
                <a:datas>
                    <a:record name="已打印" value="Y"/>
                    <a:record name="未打印" value="N"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="csh_payment_req_query_ds">
                <a:fields>
                    <a:field name="approval_status_desc" displayfield="code_value_name" options="approval_status_ds" returnfield="approval_status" valuefield="code_value"/>
                    <a:field name="bp_category_n" displayField="code_value_name" options="bp_category_ds" returnField="bp_category" valueField="code_value"/>
                    <a:field name="closed_flag"/>
                    <a:field name="bp_code_from" lovGridHeight="350" lovHeight="500" lovService="basic.hls_bp_master_v_for_lov" lovWidth="500">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code_from"/>
                            <a:map from="bp_name" to="bp_code_desc_from"/>
                            <a:map from="bp_id" to="bp_id_from"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_code_to" lovGridHeight="350" lovHeight="500" lovService="basic.hls_bp_master_v_for_lov" lovWidth="500">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code_to"/>
                            <a:map from="bp_name" to="bp_code_desc_to"/>
                            <a:map from="bp_id" to="bp_id_to"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="payment_flag"/>
                    <a:field name="payment_flag_des" displayField="name" options="yes_no_ds" returnField="payment_flag" valueField="value"/>
                    <a:field name="print_flag"/>
                    <a:field name="print_flag_des" displayField="name" options="print_ds" returnField="print_flag" valueField="value"/>
                    <a:field name="user_id"/>
                    <a:field name="employee_name"/>
                    <a:field name="user_name" lovGridHeight="300" lovHeight="460" lovService="csh.CSH502.apply_query" lovWidth="600" title="提交人">
                        <a:mapping>
                            <a:map from="user_id" to="user_id"/>
                            <a:map from="user_name" to="user_name"/>
                            <a:map from="employee_name" to="employee_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="payment_bank_des" defaultValue="建设银行" displayField="code_value_name" options="payment_bank_ds" required="true" returnField="payment_bank" valueField="code_value"/>
                    <a:field name="payment_bank" defaultValue="CCB"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="onUpdate_payment_req"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="csh_payment_req_queryDs" autoPageSize="true" autoQuery="true" model="csh.CSH502.csh_payment_req_query" queryDataSet="csh_payment_req_query_ds" selectable="true">
                <a:fields>
                    <a:field name="bp_id_tenant_n"/>
                    <a:field name="closed_flag" checkedValue="Y" defaultValue="Y" readOnly="true" uncheckedValue="N"/>
                    <a:field name="submitted_flag" checkedValue="Y" defaultValue="Y" readOnly="true" uncheckedValue="N"/>
                    <a:field name="payment_flag_des" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <a:field name="closed_date"/>
                </a:fields>
                <a:events>
                    <a:event name="load" handler="on_grid_load"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="csh502_payment_query" text="HAP_QUERY"/>
                <!--  <a:gridButton click="csh502_payment_excel" text="导出"/> -->
                <a:gridButton click="csh502_payment_reset" text="HLS.RESET"/>
                <!-- <a:gridButton click="csh502_payment_post" text="HAP_CONFIRM"/> -->
                <!-- <a:gridButton click="csh502_payment_close" text="HLS.CLOSE"/> -->
                <!-- <a:gridButton click="csh502_payment_save" text="HLS.SAVE"/> -->
                <!-- <a:gridButton click="csh502_payment_doc_print" text="汇签单打印"/> -->
               <!-- <a:gridButton click="csh502_payment_doc_print_d" text="汇签单"/>-->
              <!--  <div style="margin-left:30px;margin-top:13px"><![CDATA[注:汇签单打印之后请重新点击查询按钮以获取最新数据后进行其它操作]]></div>-->
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="130" marginWidth="35" title="CSH502.CSH_PAYMENT_REQ_PAY">
                <a:textField name="payment_req_number" bindTarget="csh_payment_req_query_ds" prompt="申请单号"/>
               <!-- <a:textField name="bp_id_tenant_n" bindTarget="csh_payment_req_query_ds" prompt="商业伙伴名称"/>-->
<!--                <a:datePicker name="approval_date_from" bindTarget="csh_payment_req_query_ds" prompt="CSH502.CSH_APR_DATE_FROM" width="150"/>-->
<!--                <a:datePicker name="approval_date_to" bindTarget="csh_payment_req_query_ds" prompt="CSH502.CSH_APR_DATE_TO" width="150"/>-->
                <a:textField name="contract_number" bindTarget="csh_payment_req_query_ds" prompt="合同编号"/>
                <a:datePicker name="req_date_from" bindTarget="csh_payment_req_query_ds" prompt="CSH502.CSH_REQ_DATE_FROM" width="150"/>
                <a:datePicker name="req_date_to" bindTarget="csh_payment_req_query_ds" prompt="CSH502.CSH_REQ_DATE_TO" width="150"/>
                <a:textField name="amount_from" bindTarget="csh_payment_req_query_ds" prompt="应付金额从"/>
                <a:textField name="amount_to" bindTarget="csh_payment_req_query_ds" prompt="应付金额到"/>
                <!-- <a:lov name="user_name" bindTarget="csh_payment_req_query_ds" prompt="提交人帐号" width="150"/> -->
                <!-- <a:textField name="employee_name" bindTarget="csh_payment_req_query_ds" prompt="提交人姓名" readOnly="true" width="150"/> -->
<!--                <a:textField name="user_name" bindTarget="csh_payment_req_query_ds" prompt="申请人" width="150"/>-->
<!--                <a:comboBox name="print_flag_des" bindTarget="csh_payment_req_query_ds" prompt="汇签单" width="150"/>-->
                <!-- <a:comboBox name="approval_status_desc" bindTarget="csh_payment_req_query_ds" prompt="CSH502.CSH_APR_STATE" width="150"/> -->
                <!-- <a:textField name="submitted_flag" bindTarget="csh_payment_req_query_ds" prompt="CSH502.CSH_SUBMIT_STATE" width="150"/> -->
                <!-- <a:checkBox name="closed_flag" bindTarget="csh_payment_req_query_ds" prompt="CSH502.CSH_CLOSED_FLAG" width="70"/> -->
                <!-- <a:comboBox name="payment_bank_des" bindTarget="csh_payment_req_query_ds" prompt="付款银行" width="150"/> -->
<!--                <a:comboBox name="bp_category_n" bindTarget="csh_payment_req_query_ds" prompt="对象类型" width="150"/>-->
            </a:form>
            <a:grid id="csh_payment_req_grid_ds" bindTarget="csh_payment_req_queryDs" marginHeight="240" marginWidth="35" navBar="true">
                <a:toolBar>
                    <a:button type="excel"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="payment_req_number" lock="true" prompt="CSH502.CSH_REQ_NO" renderer="render_objectDs_grid" width="130"/>
                    <a:column name="contract_number" prompt="合同编号" showTitle="true" width="120"/>
<!--                    <a:column name="print_flag" align="center" prompt="汇签单" renderer="render_objectDs_grid" width="80"/>-->
                    <!-- <a:column name="status_n" align="center" prompt="BPM状态" width="80"/> -->
                  <!--  <a:column name="user_name" prompt="CSH502.CSH_PROPOSER" width="120"/>-->
                    <a:column name="req_date" align="center" prompt="CSH502.CSH_REQ_DATE" width="120"/>
                    <a:column name="amount" align="right" prompt="应付金额" width="120" renderer="Leaf.formatMoney"/>
                    <a:column name="bp_id_agent_n" align="center" prompt="代理店" width="120"/>
                    <a:column name="amount_agent_total" align="right" prompt="应付代理店金额" width="120" renderer="Leaf.formatMoney"/>
                    <a:column name="residual_agent_amount" align="right" prompt="未付代理店金额" width="120" renderer="Leaf.formatMoney"/>
                    <a:column name="vender_name" align="center" prompt="厂商" width="120"/>
                    <a:column name="amount_vender_total" align="right" prompt="应付厂商金额" width="120" renderer="Leaf.formatMoney"/>
                    <a:column name="residual_vender_amount" align="right" prompt="未付厂商金额" width="120" renderer="Leaf.formatMoney"/>

<!--                    <a:column name="bp_id_tenant_n" align="center" prompt="承租人"/>-->
<!--                    <a:column name="apply_amount" align="right" prompt="CSH501.CSH_APPLIED_TOTAL_AMOUNT" renderer="Leaf.formatMoney"/>-->
<!--                    <a:column name="sum_act_amount" align="right" prompt="实际申请金额" renderer="Leaf.formatMoney"/>-->
                    <!-- <a:column name="print_flag" align="center" prompt="汇签单" renderer="render_objectDs_grid" width="60"/> -->
                    <!-- <a:column name="document_type_dis" prompt="CSH502.CSH_REQ_TYPE"/> -->
                    <!-- <a:column name="price" align="right" prompt="指导价" renderer="Leaf.formatMoney"/> -->
<!--                    <a:column name="bp_category_desc" prompt="对象类别"/>-->
                    <!-- <a:column name="bp_code" prompt="CSH501.CSH_PAYMENT_OBJ"/> -->
<!--                    <a:column name="bp_name" prompt="CSH501.CSH_PAYMENT_OBJ_NAME" showTitle="true" width="180"/>-->
<!--                    <a:column name="bp_bank_account_name" prompt="对象账户"/>-->
<!--                    <a:column name="bp_bank_account_num" prompt="对象账号" width="150"/>-->
                    <!-- <a:column name="bank_account_num" prompt="出租方账户" showTitle="true" width="200"/>
                    <a:column name="bank_account_name" prompt="出租方账户名称" showTitle="true" width="200"/> -->
                    <!-- <a:column name="bp_category_dis" prompt="CSH502.CSH_OBJ_CATEGORY"/> -->
                    <!-- <a:column name="currency_name" align="center" prompt="HLS.CURRENCY" width="60"/> -->
                    <!-- <a:column name="submitted_flag" editor="grid_checkbox" prompt="CSH502.CSH_SUBMIT_STATE"/> -->
<!--                    <a:column name="approval_status_desc" align="center" prompt="CSH502.CSH_APR_STATE" width="80"/>-->
<!--                    <a:column name="approval_date" align="center" prompt="CSH502.CSH_APR_DATE" width="80"/>-->
                    <!-- <a:column name="closed_flag" editor="grid_checkbox" prompt="CSH502.CSH_CLOSED_FLAG"/> -->
                </a:columns>
                <a:editors>
                    <a:checkBox id="grid_checkbox"/>
                    <a:textArea id="grid_textArea" height="30"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>