<?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" xmlns:s="leaf.plugin.script" customizationEnabled="true" trace="true">
    <a:init-procedure>
        <s:server-script import="con_print_path.js"><![CDATA[
            set_parameter_file_path();
        ]]></s:server-script>
        <a:model-query model="csh.CSH502.csh_bpm_branch_init" rootPath="branch_init_ds"/>
        <!-- <a:model-query autoCount="false" defaultWhereClause=" contract_id=${/parameter/@contract_id}" fetchAll="true" model="csh.CSH501.csh_payment_req_selected" rootPath="payment_req_selected"/> -->
        <a:model-query autoCount="false" defaultWhereClause=" document_category=&apos;PAYMENT_REQ&apos; and  enabled_flag=&apos;Y&apos;" fetchAll="true" model="hls.HLS003.hls_document_type" rootPath="payment_document_type"/>
        <a:model-query autoCount="false" defaultWhereClause=" enabled_flag=&apos;Y&apos;" fetchAll="true" model="gld.gld_exchangerate_types" rootPath="exchangerate_types"/>
        <a:model-query autoCount="false" defaultWhereClause=" payment_req_id=${/parameter/@payment_req_id}" fetchAll="true" model="csh.CSH502.csh_payment_req_pay_query" rootPath="csh_payment_req_pay_query"/>
        <a:model-query fetchAll="true" model="csh.CSH511.csh_transaction_default_exchange_rate_type" rootPath="default_exchange_rate_type_path"/>
        <a:model-query defaultWhereClause="t1.enabled_flag=&apos;Y&apos;" fetchAll="true" model="basic.csh_payment_method_for_lov" rootPath="payment_method_path"/>
        <a:model-query fetchAll="true" model="gld.gld_exchangerate_type_lov" rootPath="exchangerate_type_path"/>
    </a:init-procedure>
    <a:view>
        <div/>
        <a:link id="csh_payment_content_link_id" model="csh.CSH502.csh_payment_create_content" modelaction="update"/>
        <a:link id="csh_payment_req_pay_query" url="${/request/@context_path}/modules/csh/CSH502/csh_payment_req_query.lview"/>
        <a:link id="csh_payment_req_pay_link_id" url="${/request/@context_path}/modules/csh/CSH502/csh_payment_req_pay.lsc"/>
        <a:link id="csh_payment_req_pay_bpm_link_id" url="${/request/@context_path}/modules/csh/CSH502/csh_payment_req_pay_bpm.lsc"/>
        <a:link id="get_period_name_id" model="csh.CSH511.csh_transaction_get_period_name" modelaction="query"/>
        <a:link id="get_exchange_rate_link_id" model="csh.CSH511.csh_transaction_get_exchange_rate" modelaction="query"/>
        <a:link id="con_doc_batch_create_link_id" url="${/request/@context_path}/modules/cont/CON500/con_doc_batch_create.lsc"/>
        <a:link id="con_doc_batch_create_job_link_id" url="${/request/@context_path}/modules/csh/CSH502/csh_atm_batch_download_pdf_job.lsc"/>
        <a:link id="csh_atm_batch_download_pdf_link_id" url="${/request/@context_path}/modules/csh/CSH502/csh_atm_batch_download_pdf.lsc"/>
        <script src="${/request/@context_path}/javascripts/calculate.js" type="text/javascript"/>
        <script type="text/javascript"><![CDATA[

            function csh502_pay_lock_window() {
                Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
            }
            
            function csh502_pay_unlock_window() {
                Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
            }
            
            function csh502_payment_pay_submit() {
                var record = $('csh_payment_req_pay_ds').getCurrentRecord();
                var check_flag=true;
                var this_pay_agent_amount=record.get('this_pay_agent_amount');
                var this_pay_vender_amount=record.get('this_pay_vender_amount');
                var residual_agent_amount=record.get('residual_agent_amount');
                var residual_vender_amount=record.get('residual_vender_amount');
                var bank_account_num=record.get('bank_account_num');
                var pay_amount=plus(this_pay_agent_amount,this_pay_vender_amount);
                var identify_category='';
                if(!bank_account_num){
                    $L.showErrorMessage("提示",'请维护银行信息!');
                    return;
                }
                if(this_pay_agent_amount!=0&&this_pay_vender_amount!=0){
                    $L.showErrorMessage("提示",'每个只能选择代理店,厂商中的其中一个进行支付');
                    return;
                }
                if(this_pay_agent_amount==0&&this_pay_vender_amount==0){
                    $L.showErrorMessage("提示",'付款金额不能为0!');
                    return;
                }

                record.set('transaction_amount', pay_amount);
                //检验手动输入的金额必须小于应付金额
                if((this_pay_agent_amount>residual_agent_amount)||(this_pay_vender_amount>residual_vender_amount)){
                    $L.showErrorMessage("提示",'本次付代理店金额,厂商金额不能超过未付金额!');
                    check_flag=false;
                }

                if (record.validateRecord(true)&&check_flag){

                    ajax_flag = 'Y';
                    //锁屏
                    csh502_pay_lock_window();
                    var param = record.data;
                    var saveData = [];
                    var pre_line_records = $('${/parameter/@lnds_id}').getSelected();

                    for (var i = 0;i < pre_line_records.length;i++) {
                        var pre_line_record = pre_line_records[i];
                        //由于每次只有代理店或者厂商进行付款,进行判断,银行账号取金额不为0的付款对象,默认为代理店

                        if(this_pay_vender_amount>0) {
                            var agent_bank_account=pre_line_record.get('vender_bank_account_id');
                            pre_line_record.set('bp_bank_account_id',agent_bank_account);
                            identify_category='VENDER';
                        }else{
                            pre_line_record.set('bp_category','AGENT');
                            identify_category='AGENT';
                        }
                        pre_line_record.set('_status', 'insert');
                        pre_line_record.set('type', 'PAYMENT_REQ_PAYMENT');
                        pre_line_record.set('id', pre_line_record.get('payment_req_ln_id'));
                        pre_line_record.set('amt', pay_amount);
                        pre_line_record.set('transaction_date', record.get('transaction_date'));
                        pre_line_record.set('internal_period_num', record.get('internal_period_num'));
                        pre_line_record.set('period_name', record.get('period_name'));
                        pre_line_record.set('exchange_rate', record.get('exchange_rate'));
                        pre_line_record.set('payment_description', record.get('payment_description'));
                        pre_line_record.set('cashflow_id', record.get('cashflow_id'));
                        pre_line_record.set('bank_slip_num', record.get('bank_slip_num'));
                        pre_line_record.set('payment_method_id', record.get('payment_method_id'));
                        pre_line_record.set('merge_flag', record.get('merge_flag'));
                        pre_line_record.set('this_pay_agent_amount',this_pay_agent_amount );
                        pre_line_record.set('this_pay_vender_amount',this_pay_vender_amount );
                        pre_line_record.set('bank_flag','Y' );
                        //付款行临时表
                        saveData.push(pre_line_record.data);
                    }
                    param['payment_req_id'] = pre_line_records[0].get('payment_req_id');
                    param['payment_req_ln_id'] = pre_line_records[0].get('payment_req_ln_id');
                    param['merge_flag'] = 'N';
                    param['bp_category'] =identify_category;
                    param['details'] = saveData;
                    Leaf.showConfirm('${l:PROMPT_MESSAGE}', '确定提交?', function okFun() {
                        Leaf.request({
                            url: $('csh_payment_req_pay_link_id').getUrl(),
                            para: param,
                            success: function(res) {
                                Leaf.SideBar.show({
                                    msg: '${l:HLS.SUBMIT_SUCCESS}',
                                    duration: 2000
                                });
                                csh502_pay_unlock_window();
                                csh502_payment_pay_back();
                            },
                            failure: function() {
                                csh502_pay_unlock_window();
                            },
                            error: function() {
                                csh502_pay_unlock_window();
                            },
                            scope: this
                        });
                    }, function cacelFun() {
                        csh502_pay_unlock_window();
                    });
            
                }
            }
            
            function csh502_create_pdf1() {
                lock_current_window();
                Leaf.request({
                    url: $('csh_payment_content_link_id').getUrl(),
                    para: {
                        contract_id: '${/parameter/@contract_id}'
                    },
                    success: function(res) {
                        unlock_current_window();
                    },
                    error: function() {
                        unlock_current_window();
                    },
                    failure: function() {
                        unlock_current_window();
                    },
                    scope: this
                });
            }
            
            function csh502_create_pdf2() {
                lock_current_window();
                Leaf.request({
                    url: $('con_doc_batch_create_job_link_id').getUrl(),
                    para: {
                        contract_id: '${/parameter/@contract_id}',
                        file_path: '${/parameter/@file_path}',
                        batch_flag: 'Y'
                    },
                    success: function(res) {
                        Leaf.SideBar.enable = true;
                        Leaf.SideBar.show({
                            msg: '生成完毕',
                            duration: 2000
                        });
                        unlock_current_window();
                    },
                    error: function() {
                        unlock_current_window();
                    },
                    failure: function() {
                        unlock_current_window();
                    },
                    scope: this
                });
            }
            
            function csh502_create_pdf3() {
                lock_current_window();
                Leaf.request({
                    url: $('csh_payment_content_link_id').getUrl(),
                    para: {
                        contract_id: '${/parameter/@contract_id}'
                    },
                    success: function(res) {
                        // Leaf.request({
                        // url: $('con_doc_batch_create_link_id').getUrl(),
                        // para: {
                        // contract_id: '${/parameter/@contract_id}',
                        // file_path: '${/parameter/@file_path}',
                        // batch_flag: 'Y'
                        // },
                        // success: function(res) {
                        // Leaf.request({
                        // url: $('csh_atm_batch_download_pdf_link_id').getUrl(),
                        // para: {
                        // contract_id: '${/parameter/@contract_id}'
                        // },
                        // success: function(res) {
                        // Leaf.SideBar.enable = true;
                        // Leaf.SideBar.show({
                        // msg: '生成完毕',
                        // duration: 2000
                        // });
                        // unlock_current_window();
                        // },
                        // error: function() {
                        // unlock_current_window();
                        // },
                        // failure: function() {
                        // unlock_current_window();
                        // },
                        // scope: this
                        // });
                        // },
                        // error: function() {
                        // unlock_current_window();
                        // },
                        // failure: function() {
                        // unlock_current_window();
                        // },
                        // scope: this
                        // });
                        Leaf.request({
                            url: $('con_doc_batch_create_job_link_id').getUrl(),
                            para: {
                                contract_id: '${/parameter/@contract_id}',
                                file_path: '${/parameter/@file_path}',
                                batch_flag: 'Y'
                            },
                            success: function(res) {
                                Leaf.SideBar.enable = true;
                                Leaf.SideBar.show({
                                    msg: '生成完毕',
                                    duration: 2000
                                });
                                unlock_current_window();
                            },
                            error: function() {
                                unlock_current_window();
                            },
                            failure: function() {
                                unlock_current_window();
                            },
                            scope: this
                        });
                    },
                    error: function() {
                        unlock_current_window();
                    },
                    failure: function() {
                        unlock_current_window();
                    },
                    scope: this
                });
            }
            
            function csh502_payment_pay_bpm_submit() {
                var record = $('csh_payment_req_pay_ds').getCurrentRecord();
                if (record.validateRecord(true)) {
                    ajax_flag = 'Y';
                    csh502_pay_lock_window();
                    var param = record.data;
                    var saveData = [];
                    var pre_line_records = $('${/parameter/@lnds_id}').getSelected();
                    for (var i = 0;i < pre_line_records.length;i++) {
                        var pre_line_record = pre_line_records[i];
                        pre_line_record.set('_status', 'insert');
                        pre_line_record.set('type', 'PAYMENT_REQ_PAYMENT');
                        pre_line_record.set('id', pre_line_record.get('payment_req_ln_id'));
                        pre_line_record.set('amt', pre_line_record.get('pay_amount') || 0);
                        saveData.push(pre_line_record.data);
                    }
                    param['payment_req_id'] = pre_line_records[0].get('payment_req_id');
                    param['payment_req_ln_id'] = pre_line_records[0].get('payment_req_ln_id');
                    param['merge_flag'] = 'N';
                    param['details'] = saveData;
                    Leaf.showConfirm('${l:PROMPT_MESSAGE}', '确定提交?', function okFun() {
                        Leaf.request({
                            url: $('csh_payment_req_pay_bpm_link_id').getUrl(),
                            para: param,
                            success: function(res) {
                                Leaf.SideBar.show({
                                    msg: '${l:HLS.SUBMIT_SUCCESS}',
                                    duration: 2000
                                });
                                csh502_pay_unlock_window();
                                csh502_payment_pay_back();
                            },
                            failure: function() {
                                csh502_pay_unlock_window();
                            },
                            error: function() {
                                csh502_pay_unlock_window();
                            },
                            scope: this
                        });
                    }, function cacelFun() {
                        csh502_pay_unlock_window();
                    });
            
                }
            }
            
            function csh502_payment_pay_back() {
                $('${/parameter/@winid}').close();
            }
            
            function csh502_payment_pay_reset() {
                $('csh_payment_req_pay_ln_ds').setQueryParameter('payment_req_id', '${/parameter/@payment_req_id}');
                $('csh_payment_req_pay_ln_ds').query();
                //load_complete();
            }
            
            function execute_exchange_rate_type(ds) {
                var record = ds.getCurrentRecord();
                record.getField('bp_bank_account_code').setLovPara('bp_id', record.get('bp_id'));
                var value = record.get('currency_code');
                var functional_currency_code = '${/model/default_exchange_rate_type_path/record/@functional_currency_code}';
                record.getField('bank_account_code').setLovPara('currency_code', value);
                record.set('functional_currency_code', functional_currency_code);
                record.set('exchange_rate', '');
                record.set('exchange_rate_type', '');
                record.set('rate_method_code', '');
                record.set('exchange_rate_type_display', '');
                record.set('exchange_rate_quotation', '');
                if (value == functional_currency_code) {
                    record.getField('exchange_rate_type_display').setRequired(false);
                    record.getField('exchange_rate_type').setReadOnly(true);
                    record.getField('exchange_rate_type_display').setReadOnly(true);
                    record.getField('exchange_rate').setReadOnly(true);
                    record.set('exchange_rate', 1);
                } else {
                    record.set('exchange_rate_type', '${/model/fnd_financial_option_path/record/@default_exchange_rate_type}');
                    record.set('rate_method_code', '${/model/fnd_financial_option_path/record/@rate_method_code}');
                    record.set('exchange_rate_type_display', '${/model/fnd_financial_option_path/record/@exchange_rate_type_display}');
                    record.getField('exchange_rate_type_display').setRequired(true);
                    record.getField('exchange_rate_type_display').setReadOnly(false);
                }
            }
            
            function on_csh_payment_req_pay_ds_add(ds) {
                var pre_ln_ds = $('${/parameter/@lnds_id}'),
                    pre_hd_ds = $('${/parameter/@hdds_id}');
                var current_bp_bank_account_id = '';
                var pre_ln_records = pre_ln_ds.getSelected();
                var pre_hd_record = pre_hd_ds.getCurrentRecord();
                var current_record = ds.getCurrentRecord();
                var sum_pay_amount = 0;
                var sum_residual_amount = 0;
                for (var i = 0;i < pre_ln_records.length;i++) {
                    var pre_ln_record = pre_ln_records[i];
                    sum_pay_amount = plus(sum_pay_amount, pre_ln_record.get('pay_amount') || 0);
                    sum_residual_amount = plus(sum_residual_amount, pre_ln_record.get('residual_amount') || 0);
                    if (!current_bp_bank_account_id && pre_ln_record.get('bp_bank_account_id')) {
                        current_bp_bank_account_id = pre_ln_record.get('bp_bank_account_id');
                    }
                    if (current_bp_bank_account_id && pre_ln_record.get('bp_bank_account_id') && current_bp_bank_account_id != pre_ln_record.get('bp_bank_account_id')) {
                        current_record.getField('bp_bank_account_code').setReadOnly(true);
                    }
                }
                current_record.set('transaction_amount', sum_pay_amount);
                current_record.set('residual_amount', sum_residual_amount);
                current_record.set('bp_id', pre_ln_records[0].get('bp_id'));
                current_record.set('bp_name', pre_ln_records[0].get('bp_name'));
                current_record.set('functional_currency_code', '${/model/default_exchange_rate_type_path/record/@functional_currency_code}');
                current_record.set('currency_code', pre_ln_records[0].get('currency_code'));
                current_record.set('currency_name', pre_ln_records[0].get('currency_name')); /* current_record.set('transaction_date', pre_hd_record.get('req_date'));  modified by Harry 9952 2017/1/23 */
                if (!'${/parameter/@loan_date}') {
                    var date = new Date();
                    current_record.set('transaction_date', Leaf.formatDate(date));
                }
                execute_exchange_rate_type(ds);
            }
            
            
            function on_csh_payment_req_pay_ds_update(ds, record, name, value, oldvalue) {
                var handling_charge = record.get('handling_charge');
             /*   console.log(record);*/
                if (Ext.isEmpty(handling_charge)) {
                    handling_charge = 0;
                }
                if (name == 'currency_code') {
                    if (value != oldvalue) {
                        record.set('exchange_rate', '');
                        record.set('exchange_rate_type', '');
                        record.set('rate_method_code', '');
                        record.set('exchange_rate_type_display', '');
                        record.set('exchange_rate_quotation', '');
                        if (oldvalue != null && oldvalue != '') {
                            record.set('transaction_amount', '');
                            record.set('transaction_functional_amount', '');
                            record.set('handling_charge', '');
                        }
                    }
                    if (value == record.get('functional_currency_code')) {
                        record.getField('exchange_rate_type_display').setRequired(false);
                        record.getField('exchange_rate_type').setReadOnly(true);
                        record.getField('exchange_rate_type_display').setReadOnly(true);
                        record.getField('exchange_rate').setReadOnly(true);
                        record.set('exchange_rate', 1);
                    } else {
                        record.set('exchange_rate_type', '${/model/fnd_financial_option_path/record/@default_exchange_rate_type}');
                        record.set('rate_method_code', '${/model/fnd_financial_option_path/record/@rate_method_code}');
                        record.set('exchange_rate_type_display', '${/model/fnd_financial_option_path/record/@exchange_rate_type_display}');
                        record.getField('exchange_rate_type_display').setRequired(true);
                        record.getField('exchange_rate_type_display').setReadOnly(false);
                    }
                } else if (name == 'rate_method_code') {
                    record.set('exchange_rate_quotation', '');
                    record.set('exchange_rate', '1');
            
                    if (value == 'PERIOD' || value == 'DAILY' || value == 'FIXED') {
                        record.getField('exchange_rate').setReadOnly(true);
                        record.set('exchange_rate', '');
                        getExchangeRate({
                            fromCur: record.get('functional_currency_code'),
                            toCur: record.get('currency_code'),
                            exchangeRateType: record.get('exchange_rate_type'),
                            exchangeDate: record.get('transaction_date'),
                            periodName: record.get('period_name')
                        });
                    } else {
                        record.getField('exchange_rate').setReadOnly(false);
                        record.set('exchange_rate', '');
                    }
                } else if (name == 'exchange_rate') {
                    if (record.get('exchange_rate') != null && record.get('exchange_rate') != '') {
                        setfunctionamount(record);
                    } else {
                        record.set('transaction_functional_amount', '');
                    }
                }else if(name=='this_pay_agent_amount'||name=='this_pay_vender_amount'){

                   var agent_amount= record.get('this_pay_agent_amount');
                   var  vender_amount= record.get('this_pay_vender_amount');
                   if(agent_amount&&vender_amount){
                       $('csh_payment_req_pay_ds').getAt(0).set('transaction_amount',agent_amount+vender_amount)
                   }else if(agent_amount){
                       $('csh_payment_req_pay_ds').getAt(0).set('transaction_amount',agent_amount)
                   }else if(vender_amount){
                       $('csh_payment_req_pay_ds').getAt(0).set('transaction_amount',vender_amount)
                   }else{
                       $('csh_payment_req_pay_ds').getAt(0).set('transaction_amount',0)
                   }



                } else if (name == 'handling_charge') {
                    if (value === 0 && record.get('zero_amounts_allowed') == 'N') {
                        Leaf.showMessage('${l:PROMPT}', '${l:CSH510.ZERO_AMOUNTS_ALLOWED}');
                    }
                    if (record.get('currency_code') == record.get('functional_currency_code')) {
                        record.set('transaction_functional_amount', value + record.get('transaction_amount'));
                    } else {
                        setfunctionamount(record);
                    }
                } /*else if (name == 'transaction_amount') {
                    if (value === 0 && record.get('zero_amounts_allowed') == 'N') {
                        Leaf.showMessage('${l:PROMPT}', '${l:CSH510.ZERO_AMOUNTS_ALLOWED}');
                    }
                    if (record.get('currency_code') == record.get('functional_currency_code')) {
                        record.set('transaction_functional_amount', value + handling_charge);
                    } else {
                        setfunctionamount(record);
                    }
                } */else if (name == 'transaction_date') {
                    showPeriod(record);
                }/*else if(name='this_pay_agent_amount'&&value){
                    if(record.get('this_pay_vender_amount')){

                    }

                }*//*else if(name='this_pay_vender_amount'){
                    var agent_amount=record.get('this_pay_agent_amount');
                    alert(agent_amount);
                    if(agent_amount){
                        alert(value+agent_amount)
                        record.set('transaction_amount',value+agent_amount);
                    }

                }*/ else if (name == 'precision') {
                    record.getField('transaction_amount').setPropertity('decimalprecision', value);
                    record.getField('transaction_functional_amount').setPropertity('decimalprecision', value);
                    record.getField('handling_charge').setPropertity('decimalprecision', value);
                    if (record.get('transaction_amount') || record.get('transaction_amount') == 0 || record.get('handling_charge')) {
                        setfunctionamount(record);
                    }
                } /*else if (name == 'bank_account_id') {

                    if (record.get('zero_amounts_allowed') == 'N' && record.get('transaction_amount') === 0) {
                        Leaf.showMessage('${l:PROMPT}', '${l:CSH510.ZERO_AMOUNTS_ALLOWED}');
                    }
                }*/
            }
            
            function showPeriod(record) {
                var r_date = record.get('transaction_date');
                r_date = Leaf.formatDate(r_date);
                Leaf.request({
                    url: $('get_period_name_id').getUrl(),
                    para: {
                        p_date: r_date
                    },
                    success: function(res) {
                        if (res) {
                            var period_name = res.result.record.period_name,
                                internal_period_num = res.result.record.internal_period_num;
                            if (period_name) {
                                record.set('period_name', period_name);
                                record.set('internal_period_num', internal_period_num);
                            } else {
                                record.set('period_name', '');
                                record.set('internal_period_num', '');
                            }
                        }
                    },
                    scope: this
                });
            }
            
            function getExchangeRate(param) {
            
                Leaf.request({
                    url: $('get_exchange_rate_link_id').getUrl(),
                    para: {
                        from_currency: param.fromCur,
                        to_currency: param.toCur,
                        exchange_date: param.exchangeDate,
                        exchange_period_name: param.periodName,
                        exchange_rate_type: param.exchangeRateType
                    },
                    success: setRateAndQuotation,
                    scope: this
                });
            }
            
            function setRateAndQuotation(res) {
                var record = $('csh_payment_req_pay_ds').getCurrentRecord();
                if (Ext.isDefined(res.result.record.exchange_rate)) {
                    record.set('exchange_rate', res.result.record.exchange_rate);
                }
                if (Ext.isDefined(res.result.record.exchange_rate_quotation)) {
                    record.set('exchange_rate_quotation', res.result.record.exchange_rate_quotation);
                } else {
                    record.set('exchange_rate_quotation', 'DIRECT QUOTATION');
                }
            }
            
            function setfunctionamount(record) {
                var quotation = record.get('exchange_rate_quotation');
                var a = record.get('transaction_amount');
                var b = record.get('exchange_rate');
                var c = record.get('handling_charge');
                if (Ext.isEmpty(c)) {
                    c = 0;
                }
                a = a + c;
                if (Ext.isDefined(a) && Ext.isDefined(b)) {
                    if (quotation == 'DIRECT QUOTATION') {
                        record.set('transaction_functional_amount', parseFloat((a / b).toFixed(record.get('precision') || 2)));
                    } else {
                        record.set('transaction_functional_amount', parseFloat((a * b).toFixed(record.get('precision') || 2)));
                    }
                }
            }
            
            function lock_current_window() {
                Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
            }
            
            function unlock_current_window() {
                Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
            }
            
            Leaf.onReady(function() {
                //
                // if ('${/parameter/@first_repayment_flag}' == 'Y') {
                // ds.getField('first_payment_date').setRequired(true);
                // } else {
                // ds.getField('first_payment_date').setRequired(false);
                // }
               /*console.log('${/parameter}');*/
               // var lnds='${/parameter/@lnds_id}';
                //根据前面的是代理店还是厂商,来判断此次可以手动输入的是代理店还是厂商
                var pre_line_records = $('${/parameter/@lnds_id}').getSelected();
                var pre_line_record=pre_line_records[0];
                //代理店不为空
                if(pre_line_record.get('bp_bank_account_id')==undefined){
                     $('agent_num').hide();
                     $('agent_id').hide();
                     $('bank_account_ds').hideColumn('this_pay_agent_amount');
                }
                if(pre_line_record.get('vender_bank_account_id')==undefined){
                    $('vender_id').hide();
                    $('vender_num').hide();
                    $('bank_account_ds').hideColumn('this_pay_vender_amount');
                }

                var date = new Date();
                if ('${/parameter/@loan_date}') {
                    r_date = (('${/parameter/@loan_date}').match(/\d{4}.\d{1,2}.\d{1,2}/mg).toString()).replace(/[^0-9]/mg, '-');
                } else {
                    r_date = ((Leaf.formatDate(date)).match(/\d{4}.\d{1,2}.\d{1,2}/mg).toString()).replace(/[^0-9]/mg, '-');
                }
                Leaf.request({
                    url: $('get_period_name_id').getUrl(),
                    para: {
                        p_date: r_date
                    },
                    success: function(res) {
                        if (res) {

                            var ds = $('csh_payment_req_pay_ds');
                            var record = ds.getAll();
                            var period_name = res.result.record.period_name,
                                internal_period_num = res.result.record.internal_period_num;
                            if (period_name) {
                                record[0].set('period_name', period_name);
                                record[0].set('internal_period_num', internal_period_num);
                            } else {
                                record[0].set('period_name', '');
                                record[0].set('internal_period_num', '');
                            }
                        }
                    },
                    scope: this
                });
            
            });
            
            function rendererDay(cell, date, text, currentMonth) {
                //
                var today = new Date();
                if (date.getDate() != '5' && date.getDate() != '10' && date.getDate() != '15' && date.getDate() != '20' && date.getDate() != '25' && date.getDate() != '30') {
                    cell.disabled = 'true';
                }
                return text;
            }
            
            // function rendererDay(cell, date, text, currentMonth) {
            // var today = new Date();
            // if (date < new Date(today.getFullYear(), today.getMonth(), today.getDate())) {
            // cell.disabled = true;
            // }
            // return text;
            // }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="payment_method_ds">
                <a:datas dataSource="/model/payment_method_path"/>
            </a:dataSet>
            <a:dataSet id="exchangerate_type_ds">
                <a:datas dataSource="/model/exchangerate_type_path"/>
            </a:dataSet>
            <a:dataSet id="csh_payment_req_pay_ds" autoCreate="true">
                <a:fields>
                    <!-- <a:field name="branch_code" defaultValue="${/parameter/@branch_code}" required="true"/> -->
                    <a:field name="city_code" defaultValue="${/model/branch_init_ds/record/@city_code}"/>
                    <a:field name="branch_code" defaultValue="${/model/branch_init_ds/record/@branch_code}"/>
                    <a:field name="bank_name" defaultValue="${/model/branch_init_ds/record/@bank_name}"/>
                    <a:field name="bank_full_name" defaultValue="${/model/branch_init_ds/record/@branch_name}" lovGridHeight="300" lovHeight="500" lovService="csh.CSH502.hls_sap_branch_lov" lovWidth="530" title="支行">
                        <a:mapping>
                            <a:map from="city_code" to="city_code"/>
                            <a:map from="branch_code" to="branch_code"/>
                            <a:map from="bank_name" to="bank_name"/>
                            <a:map from="branch_name" to="bank_full_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_code" lovGridHeight="300" lovHeight="500" lovService="csh.CSH501.csh_payment_bp_for_lov?bp_id=${/model/payment_req_selected/record/@tenant_bp_id}" lovWidth="530" required="false" title="CSH502.CSH_PAYMENT_OBJ">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code"/>
                            <a:map from="bp_name" to="bp_name"/>
                            <a:map from="bp_id" to="bp_id"/>
                            <a:map from="bp_category" to="bp_category"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="exchange_rate_type_display" displayField="type_name" options="exchangerate_type_ds" readOnly="false" returnField="exchange_rate_type" valueField="type_code">
                        <a:mapping>
                            <a:map from="type_code" to="exchange_rate_type"/>
                            <a:map from="rate_method_code" to="rate_method_code"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="this_pay_agent_amount">

                    </a:field>
                    <a:field name="transaction_date" defaultValue="${/parameter/@loan_date}" required="true"/>
                    <a:field name="exchange_rate_type"/>
                    <a:field name="exchange_rate" readOnly="true" required="false"/>
                    <a:field name="rate_method_code"/>
                    <a:field name="transaction_amount" readOnly="true"/>
                    <a:field name="transaction_functional_amount" readOnly="true" required="true"/>
                    <a:field name="precision" defaultValue="2"/>
                    <a:field name="zero_amounts_allowed" defaultValue="N"/>
                    <a:field name="currency_code" defaultValue="CNY"/>
                    <a:field name="currency_name" defaultValue="人民币"/>
                    <a:field name="bank_account_id"/>
                    <a:field name="bank_account_name"/>
                    <a:field name="bank_account_num" autoComplete="true" autoCompleteField="bank_account_num" lovGridHeight="350" lovHeight="550" lovLabelWidth="90" lovService="csh.CSH101.csh_bank_account_lov" lovWidth="850" required="true" title="CSH511.BANK_ACCOUNT_CODE">
                        <a:mapping>
                            <a:map from="precision" to="precision"/>
                            <a:map from="zero_amounts_allowed" to="zero_amounts_allowed"/>
                            <a:map from="bank_account_id" to="bank_account_id"/>
                            <a:map from="bank_account_num" to="bank_account_num"/>
                            <a:map from="bank_account_id" to="bank_account_id"/>
                            <a:map from="bank_account_name" to="bank_account_name"/>
                            <a:map from="bank_account_code" to="bank_account_code"/>
                            <a:map from="currency_code" to="currency_code"/>
                            <a:map from="currency_name" to="currency_name"/>
                            <a:map from="bank_branch_name" to="bank_branch_name"/>
                        </a:mapping>
                    </a:field>
                   <!-- <a:field name="bp_bank_account_code" autoComplete="true" autoCompleteField="bank_account_num" lovGridHeight="350" lovHeight="550" lovLabelWidth="90" lovService="basic.hls_bp_master_bank_account_v_for_lov?enabled_flag=Y&amp;bp_enabled_flag=Y" lovWidth="580" title="CSH511.BANK_ACCOUNT_CODE">
                        <a:mapping>
                            <a:map from="bank_account_id" to="bp_bank_account_id"/>
                            <a:map from="bank_account_num" to="bp_bank_account_num"/>
                            <a:map from="bank_account_name" to="bp_bank_account_name"/>
                            <a:map from="bank_account_code" to="bp_bank_account_code"/>
                        </a:mapping>
                    </a:field>-->
                    <a:field name="payment_method_display" defaultValue="银行转账" displayField="description" options="payment_method_ds" returnField="payment_method_id" valueField="payment_method_id"/>
                    <a:field name="payment_method_id" defaultValue="10"/>
                    <a:field name="payment_req_id" defaultValue="${/parameter/@payment_req_id}"/>
                    <!-- <a:field name="first_contract_day" readOnly="true" defaultValue="${/parameter/@first_contract_day}"/> -->
                    <a:field name="period_name"/>
                    <!-- <a:field name="first_payment_date" required="false"/> -->
                </a:fields>
                <a:events>
                    <a:event name="add" handler="on_csh_payment_req_pay_ds_add"/>
                    <a:event name="update" handler="on_csh_payment_req_pay_ds_update"/>
                    <!-- <a:event name="load" handler="on_csh_payment_req_pay_ds_load" /> -->
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <!-- <a:gridButton click="csh502_payment_pay_bpm_submit" text="BPM付款"/> -->
                <a:gridButton click="csh502_payment_pay_back" text="HLS.BACK"/>
                <a:gridButton click="csh502_payment_pay_submit" text="CSH502.CSH_PAY"/>
                <!--                 <a:gridButton click="csh502_create_pdf1" text="pdf测试1"/>
                <a:gridButton click="csh502_create_pdf2" text="pdf测试2"/>
                <a:gridButton click="csh502_create_pdf3" text="pdf测试3"/> -->
                <!-- <a:gridButton click="csh502_payment_pay_reset" text="HLS.RESET"/> -->
            </a:screenTopToolbar>
            <a:form labelWidth="180" title="CSH502.CSH_PAYMENT_REQ_PAY">
                <a:box column="4">
                  <!--  <a:textField name="bp_name" bindTarget="csh_payment_req_pay_ds" prompt="CSH501.CSH_PAYMENT_OBJ_NAME" readOnly="true" width="150"/>-->
                    <a:textField id="agent_num" name="bp_bank_account_name" bindTarget="csh_payment_req_pay_ds" prompt="付款代理商对象" readOnly="true" width="150"/>
                    <a:textField  id="agent_id" name="bp_bank_account_num" bindTarget="csh_payment_req_pay_ds" prompt="付款代理商账号" readOnly="true" width="150"/>
                    <a:textField id="vender_id" name="vender_bank_account_id" bindTarget="csh_payment_req_pay_ds" prompt="付款厂商对象" readOnly="true" width="150"/>
                    <a:textField id="vender_num" name="vender_bank_account_num" bindTarget="csh_payment_req_pay_ds" prompt="付款厂商账号" readOnly="true" width="150"/>
                </a:box>
                <a:box column="4">
                    <a:textField name="contract_number" bindTarget="csh_payment_req_pay_ds" prompt="合同编号" readOnly="true" width="150"/>
                    <a:textField name="cf_description" bindTarget="csh_payment_req_pay_ds" prompt="应付项目" readOnly="true" width="150"/>
                    <a:numberField name="residual_agent_amount" bindTarget="csh_payment_req_pay_ds" prompt="未付代理店金额" readOnly="true" width="150" renderer="Leaf.formatMoney"/>
                    <a:numberField name="residual_vender_amount" bindTarget="csh_payment_req_pay_ds" prompt="未付厂商金额" readOnly="true" width="150" renderer="Leaf.formatMoney"/>
<!--                    <a:numberField name="amount_paid" bindTarget="csh_payment_req_pay_ds" prompt="本次付款金额" readOnly="true" width="150" renderer="Leaf.formatMoney"/>-->
               </a:box>
                <a:box column="2">
                    <a:numberField name="transaction_amount" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_pay_ds" prompt="本次付款金额" width="150"/>
                    <a:textField name="period_name" bindTarget="csh_payment_req_pay_ds" prompt="HLS.ACCOUNT_PERIOD_NAME" readOnly="true"/>
                    <a:datePicker name="transaction_date" bindTarget="csh_payment_req_pay_ds" prompt="CSH502.CSH_PAY_DATE" width="150"/>
                </a:box>
                   <!-- <a:box column="4">
                        <a:lov name="bp_bank_account_code" bindTarget="csh_payment_req_pay_ds" prompt="对方账户"/>
                        <a:textField name="bp_bank_account_num" bindTarget="csh_payment_req_pay_ds" prompt="对方账号" readOnly="true"/>
                       &lt;!&ndash; <a:lov name="bank_account_code" bindTarget="csh_payment_req_pay_ds" prompt="付款账户" width="150"/>
                        <a:textField name="bank_account_num" bindTarget="csh_payment_req_pay_ds" prompt="HLS.BANK_ACCOUNT_NUM" readOnly="true" width="150"/>&ndash;&gt;
                        &lt;!&ndash; <a:textField name="bank_account_name" bindTarget="csh_payment_req_pay_ds" prompt="HLS.BANK_ACCOUNT_NAME" readOnly="true" width="428"/> &ndash;&gt;
                    </a:box>-->

                    <a:box column="1">
                        <a:textField name="payment_description" bindTarget="csh_payment_req_pay_ds" prompt="HLS.COMMENT" width="849"/>
                    </a:box>
                    <!-- <a:textField name="cf_description" bindTarget="csh_payment_req_pay_ds" prompt="CSH501.CSH_PAYMENT_PRJ" readOnly="true" width="150"/> -->
                    <!-- <a:numberField name="residual_amount" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_pay_ds" prompt="CSH501.CSH_RESIDUAL_AMOUNT" readOnly="true" width="150"/>-->
                    <!-- <a:textField name="currency_name" bindTarget="csh_payment_req_pay_ds" prompt="HLS.CURRENCY" readOnly="true" width="150"/> -->
                    <!-- <a:textField name="branch_code" bindTarget="csh_payment_req_pay_ds" prompt="SAP支行编号" readOnly="true" width="150"/> -->
                    <!-- <a:comboBox name="exchange_rate_type_display" bindTarget="csh_payment_req_pay_ds" prompt="HLS.EXCHANGE_RATE_TYPE_DESC" width="150"/> -->
                    <!-- <a:numberField name="due_amount" bindTarget="csh_payment_req_pay_ds" prompt="CSH502.CSH_PAYMENT_AMOUNT" readOnly="true" width="150"/>
                    <a:datePicker name="due_date" bindTarget="csh_payment_req_pay_ds" prompt="CSH501.CSH_DUE_DATE" readOnly="true" width="150"/> -->

                <!-- <a:numberField name="handling_charge" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_pay_ds" prompt="HLS.HANDLING_CHARGE" width="150"/> -->
                 <!--   <a:numberField name="transaction_functional_amount" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_pay_ds" prompt="HLS.FUNCTIONAL_AMOUNT" readOnly="true" width="150"/>
                    &lt;!&ndash; <a:comboBox name="exchange_rate_type_display" bindTarget="csh_payment_req_pay_ds" prompt="HLS.EXCHANGE_RATE_TYPE_DESC" width="150"/> &ndash;&gt;
                    <a:textField name="bank_slip_num" bindTarget="csh_payment_req_pay_ds" prompt="CSH511.CSH_TRANSACTION.BANK_SLIP_NUM"/>


                <a:box column="4">
                    <a:textField name="bp_bank_account_name" bindTarget="csh_payment_req_pay_ds" prompt="对方账户名" readOnly="true" width="382"/>
                    <a:textField name="bank_account_name" bindTarget="csh_payment_req_pay_ds" prompt="HLS.BANK_ACCOUNT_NAME" readOnly="true" width="382"/>
                </a:box>
                <a:box column="4">
                    <a:textField name="bank_branch_name" bindTarget="csh_payment_req_pay_ds" prompt="银行分行名称" readOnly="true" width="382"/>
                    <a:comboBox name="payment_method_display" bindTarget="csh_payment_req_pay_ds" prompt="HLS.PAYMENT_METHOD"/>
                    <a:numberField name="exchange_rate" allowNegative="false" bindTarget="csh_payment_req_pay_ds" decimalPrecision="-1" prompt="HLS.EXCHANGE_RATE" readOnly="true" width="150"/>
                </a:box>
                <a:box column="4">
                    &lt;!&ndash; <a:textField name="first_contract_day" bindTarget="csh_payment_req_pay_ds" prompt="首次支付表日期末位" readOnly="true"/> &ndash;&gt;
                    &lt;!&ndash; <a:datePicker name="first_payment_date" bindTarget="csh_payment_req_pay_ds" dayRenderer="rendererDay" prompt="首期还款日" width="150"/> &ndash;&gt;
                </a:box>-->
                <!-- <a:box column="4">
                    <a:numberField name="transaction_amount" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_pay_ds" prompt="CSH502.CSH_PAYMENT_AMOUNT" width="150"/>
                    <a:numberField name="handling_charge" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_pay_ds" prompt="HLS.HANDLING_CHARGE" width="150"/>
                    <a:numberField name="transaction_functional_amount" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_pay_ds" prompt="HLS.FUNCTIONAL_AMOUNT" readOnly="true" width="150"/>
                    <a:comboBox name="exchange_rate_type_display" bindTarget="csh_payment_req_pay_ds" prompt="HLS.EXCHANGE_RATE_TYPE_DESC" width="150"/>
                    <a:textField name="bank_slip_num" bindTarget="csh_payment_req_pay_ds" prompt="CSH511.CSH_TRANSACTION.BANK_SLIP_NUM"/>
                    <div/>
                </a:box> -->

            </a:form>
            <a:grid id="bank_account_ds" bindTarget="csh_payment_req_pay_ds" height="200">

                <a:columns>
                    <a:column name="bank_account_num" prompt="银行账号" editor="lov_editor" width="150"/>
                    <a:column name="bank_branch_name" prompt="银行名称" width="150"/>
                    <a:column name="bank_account_name" prompt="账户名" width="150"/>
                    <a:column name="this_pay_agent_amount" prompt="本次付代理店金额" editor="number_editor" width="150" renderer="Leaf.formatMoney" align="right"/>
                    <a:column name="this_pay_vender_amount" prompt="本次付厂商金额" editor="number_editor" width="150" renderer="Leaf.formatMoney" align="right"/>
                </a:columns>
                <a:editors>
                    <a:lov id="lov_editor"/>
                    <a:numberField id="number_editor"/>
                </a:editors>
            </a:grid>
            <script type="text/javascript"><![CDATA[
            	    $('csh_payment_req_pay_ds').getAt(0).set('bp_bank_account_num','${/parameter/@bp_bank_account_num}');
            	    $('csh_payment_req_pay_ds').getAt(0).set('bp_bank_account_code','${/parameter/@bp_bank_account_code}');
            	    $('csh_payment_req_pay_ds').getAt(0).set('bp_bank_account_name','${/parameter/@bp_bank_account_name}');
                    $('csh_payment_req_pay_ds').getAt(0).set('bp_bank_account_id','${/parameter/@bp_bank_account_id}');
                    $('csh_payment_req_pay_ds').getAt(0).set('vender_bank_account_id','${/parameter/@vender_bank_account_id}');
                    $('csh_payment_req_pay_ds').getAt(0).set('vender_bank_account_num','${/parameter/@vender_bank_account_num}');
            	    $('csh_payment_req_pay_ds').getAt(0).set('contract_number','${/parameter/@contract_number}');
            	    $('csh_payment_req_pay_ds').getAt(0).set('cf_description','${/parameter/@cf_description}');
            	    $('csh_payment_req_pay_ds').getAt(0).set('residual_agent_amount','${/parameter/@residual_agent_amount}');
            	    $('csh_payment_req_pay_ds').getAt(0).set('residual_vender_amount','${/parameter/@residual_vender_amount}');
            	    $('csh_payment_req_pay_ds').getAt(0).set('this_pay_agent_amount',0);
            	    $('csh_payment_req_pay_ds').getAt(0).set('this_pay_vender_amount',0);

            ]]></script>
        </a:screenBody>
    </a:view>
</a:screen>