<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang 
    $Date: 2015-1-27 上午09:27:36  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:s="leaf.plugin.script" xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <s:server-script import="birt_print_path.js"><![CDATA[
        	$ctx.parameter.birt_print_path = birt_print_path['birt_print_path'];
    	]]></s:server-script>
        <a:model-query autoCount="false" defaultWhereClause=" document_category=&apos;PAYMENT_REQ&apos; and  document_type=&apos;STD_PREPAYMENT_REQ&apos;" fetchAll="true" model="hls.HLS003.hls_document_type" rootPath="default_prepayment_document_type"/>
        <a:model-query autoCount="false" defaultWhereClause=" document_category=&apos;PAYMENT_REQ&apos; and  document_type=&apos;STD_PAYMENT_REQ&apos;" fetchAll="true" model="hls.HLS003.hls_document_type" rootPath="default_payment_document_type"/>
    </a:init-procedure>
    <a:view>
        <a:link id="csh_req_ddct_link" url="${/request/@context_path}/modules/csh/CSH504/csh_payment_req_ln_ddct.lview"/>
        <a:link id="csh_payment_prepayment_dk" url="${/request/@context_path}/modules/csh/CSH501/csh_payment_prepayment_dk.lview"/>
        <a:link id="csh_payment_req_prepayment_dk_detail_link_id" url="${/request/@context_path}/modules/csh/CSH501/csh_payment_req_prepayment_dk_detail.lview"/>
        <a:link id="csh_payment_req_ln_del_link" model="csh.CSH504.csh_payment_req_ln_del" modelaction="batch_update"/>
        <a:link id="csh501d_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="csh_payment_req_pay_win_link" url="${/request/@context_path}/modules/csh/CSH502/csh_payment_req_pay.lview"/>
        <a:link id="csh_payment_req_ln_temp_link" url="${/request/@context_path}/modules/csh/CSH502/csh_payment_req_ln_temp.lsc"/>
        <a:link id="prj_project_modify_link" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_create_tree_n.lview"/>
        <a:link id="con_contract_balance_details_link" url="${/request/@context_path}/modules/csh/CSH501/con_contract_balance_details.lview"/>
        <a:link id="csh501d_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="csh501d_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script type="text/javascript"><![CDATA[
            if ('${/parameter/@payment_req_id}') {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            }
            window['${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                var lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                var hd_ds, ln_ds, lineRecords, currency_code;
                if (hdds_id) {
                    hd_ds = $(hdds_id);
                    hdrecord = hd_ds.getCurrentRecord();
                }
                if (lnds_id && $L.CmpManager.get(lnds_id)) {
                    ln_ds = $(lnds_id);
                    lineRecords = ln_ds.getAll();
                }
                if (hdds_id && ds.id == hdds_id) {
                    if (name == 'req_date') {
                        for (var i = 0;i < lineRecords.length;i++) {
                            lineRecords[i].set('apply_pay_date', value);
                        }
                    } else if (name == 'bp_id') {
                        for (var j = 0;j < lineRecords.length;j++) {
                            lineRecords[j].set('bp_code', record.get('bp_code'));
                            lineRecords[j].set('bp_name', record.get('bp_name'));
                            lineRecords[j].set('bp_id', record.get('bp_id'));
                        }
            
                    }
                } else if (lnds_id && lnds_id == ds.id) {
                    if (name == 'amount') {
                        var amount = 0;
                        for (var m = 0;m < lineRecords.length;m++) {
                            var lineRecord = lineRecords[m];
                            currency_code = lineRecord.get('currency_code');
                            if (hdrecord.get('currency_code') != currency_code) {
                                hdrecord.set('amount', null);
                                hdrecord.set('currency_code', null);
                                return;
                            } else {
                                current_amount = lineRecord.get('amount') || 0;
                                amount = plus(amount, current_amount);
                            }
                        }
                        hdrecord.set('amount', amount);
                        hdrecord.set('currency_code', currency_code);
                    }
                }
                
                var real_pay_amount=hdrecord.get('amount');
                if (hdrecord.get('lease_charge_buckle')) {
                    real_pay_amount=real_pay_amount-hdrecord.get('lease_charge_buckle');
                }
                // if (hdrecord.get('lease_charge_cash')) {
                    // real_pay_amount=real_pay_amount-hdrecord.get('lease_charge_cash');
                // }
                if (hdrecord.get('zero_rent_buckle')) {
                    real_pay_amount=real_pay_amount-hdrecord.get('zero_rent_buckle');
                }
                // if (hdrecord.get('zero_rent_cash')) {
                    // real_pay_amount=real_pay_amount-hdrecord.get('zero_rent_cash');
                // }
                if (hdrecord.get('deposit_buckle')) {
                    real_pay_amount=real_pay_amount-hdrecord.get('deposit_buckle');
                }
                // if (hdrecord.get('deposit_cash')) {
                    // real_pay_amount=real_pay_amount-hdrecord.get('deposit_cash');
                // }
                if (hdrecord.get('insurance_fee_buckle')) {
                    real_pay_amount=real_pay_amount-hdrecord.get('insurance_fee_buckle');
                }
                // if (hdrecord.get('insurance_fee_cash')) {
                    // real_pay_amount=real_pay_amount-hdrecord.get('insurance_fee_cash');
                // }
                if (hdrecord.get('other_fee_buckle')) {
                    real_pay_amount=real_pay_amount-hdrecord.get('other_fee_buckle');
                }
                // if (hdrecord.get('other_fee_cash')) {
                    // real_pay_amount=real_pay_amount-hdrecord.get('other_fee_cash');
                // }
                hdrecord.set('real_pay_amount', real_pay_amount);
                //real_pay_amount = lease_charge_buckle + lease_charge_cash + zero_rent_buckle + zero_rent_cash + deposit_buckle + deposit_cash + insurance_fee_buckle + insurance_fee_cash + other_fee_buckle + other_fee_cash;
            };
            
            
            //保存submitsuccess调用
            window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function(ds, record, res, bp_seq) {
            
                //插入权限
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                var hd_record = $(ds_id).getCurrentRecord();
                var payment_req_id = hd_record.get('payment_req_id');
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/csh.CSH501.csh_payment_submit/execute',
                    para: {
                        payment_req_id: payment_req_id,
                        _status: 'execute'
                    },
                    success: function(res) {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
            
                });
            
            
            
            
            
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            };
            
            
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                var hd_ds, lineRecords, currency_code;
                if (hdds_id) {
                    hd_ds = $(hdds_id);
                    hdrecord = hd_ds.getCurrentRecord();
                }
                if ('${/parameter/@function_code}' == 'CSH502D') {
                    record.getField('pay_amount').setReadOnly(false);
                }
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            };
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_add'] = function(ds, record, config_records, bp_seq) {
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                if (!'${/parameter/@payment_req_id}' && hdds_id) {
                    var hd_ds = $(hdds_id);
                    var hd_record = hd_ds.getCurrentRecord();
                    var amount = hd_record.get('amount') || 0;
                    hd_record.set('currency_code', record.get('currency_code'));
                    hd_record.set('amount', plus(amount, record.get('amount')));
                }
            };
            
            function on_csh_payment_req_temp_ln_ds_load(ds) {
                var lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                var records = ds.getAll();
                if (!'${/parameter/@payment_req_id}' && lnds_id && '${/parameter/@business_type}' == 'PAYMENT') {
                    for (var i = 0;i < records.length;i++) {
                        var record = records[i];
                        if (!record.get('apply_pay_date')) {
                            record.set('apply_pay_date', Leaf.formatDate(new Date()));
                        }
                        $(lnds_id).create(Ext.apply({}, record.data));
                    }
                }
            }
            
            function csh_payment_req_submit_finally() {
                var win = Leaf.showConfirm('${l:HLS.PROMPT}', '${l:HLS.ARE_YOU_SURE_TO_SUBMIT}', function okFun() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                    var hd_record = $(ds_id).getCurrentRecord();
                    var payment_req_id = hd_record.get('payment_req_id');
                    Leaf.request({
                        url: '${/request/@context_path}/autocrud/csh.CSH501.upd_csh_payment_sub_flag/execute',
                        para: {
                            payment_req_id: payment_req_id,
                            _status: 'execute'
                        },
                        success: function(res) {
                            Leaf.SideBar.enable = true;
                            Leaf.SideBar.show({
                                msg: '${l:HLS.SUBMIT_SUCCESS}',
                                duration: 2000
                            });
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            $('${/parameter/@winid}').close();
                        },
                        failure: function() {
                            Leaf.SideBar.enable = true;
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        error: function() {
                            Leaf.SideBar.enable = true;
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                }, function cancelFun() {
                    Leaf.SideBar.enable = true;
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                });
                win.on('close', function() {
                    Leaf.SideBar.enable = true;
                });
            }
            //打印
            
            function csh501_print() {
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                var lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                var records_l = $(lnds_id).getAll();
            
                var hd_record = $(hdds_id).getCurrentRecord();
                if (records_l.length > 0) {
                    // var birt_print_path = '${/parameter/@birt_print_path}';
                    var birt_print_path = '${/request/@context_path}/reports';
                    // var url_1 = 'http://199.10.10.65:8180/reportapp/frameset?__report=reports/req/new/' + 'con_payment_req.rptdesign' + '&&__format=PDF';
                    var url_1 = birt_print_path + '?__report=reports/req/new/' + 'con_payment_req.rptdesign' + '&&__format=PDF';
                    var url_1_param = '&&batch_id=' + ${/session/@session_id} + '&&payment_req_id=' + hd_record.get('payment_req_id');
                    window.open(url_1 + url_1_param);
                }
            }
            window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
                Leaf.SideBar.enable = false;
                window['${/parameter/@layout_code}_SAVE_LAYOUT_DYNAMIC_CLICK'](csh_payment_req_submit_finally);
            };
            window['${/parameter/@layout_code}_print_layout_dynamic_click'] = function() {
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                var lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                var hd_ds = $(hdds_id),
                    ln_ds = $(lnds_id);
                var hd_record = hd_ds.getCurrentRecord(),
                    ln_records = ln_ds.getAll();
                if (ln_records.length > 0 && !ln_records[0].get('payment_req_ln_id')) {
                    Leaf.showMessage('${HLS.PROMPT}', '请先保存!');
                } else {
                    Leaf.request({
                        url: '${/request/@context_path}/autocrud/csh.CSH504.csh_payment_print/execute',
                        para: {
                            payment_req_id: hd_record.get('payment_req_id'),
                            _status: 'execute'
                        },
                        success: function(res) {
                            csh501_print();
                        },
                        sync: true,
                        failure: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    }, Leaf.Masker.unmask(Ext.getBody()));
                }
            };
            // window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                // var lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                // var ln_ds = $(lnds_id);
                // ln_ds.showEditorByRecord(ln_ds.create());
            // };
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {

                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                var record=$(hdds_id).getAt(0);
                var url;
                var query_flag='${/parameter/@function_usage}';
                if(query_flag=='QUERY'){
                    url = $('csh501d_cdd_downloadFile_id').getUrl() + '?table_name=CSH_PAYMENT_REQ_HD&header_id=' + record.get('payment_req_id');
                }else
                {
                    url = $('csh501d_cdd_uploadFile_id').getUrl() + '?table_name=CSH_PAYMENT_REQ_HD&header_id=' + record.get('payment_req_id');
                }
                if (record.get('payment_req_id')){
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: 'csh501d_cdd_uploadFile_screen_id',
                        width: 850,
                        height: 400
                    });
                }else{
                    Leaf.showMessage('${l:PROMPT}', '请先保存数据!');
                    return;
                }
                
            };
            window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                var lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                var hd_ds = $(hdds_id),
                    ln_ds = $(lnds_id);
                Leaf.showConfirm('${l:HLS.PROMPT}', '${l:HLS.DELETE_CONFIRM}', function okFun() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    var Array = ln_ds.getSelected();
                    if (Array.length < 1) {
                        Leaf.showMessage('${l:PROMPT}', '${l:CHOOSE_ONE_RECORD}');
                    }
                    for (var i = 0,
                        length = Array.length;i < length;i++) {
                        if (Array[i].isNew) {
                            ln_ds.removeLocal(Array[i]);
                        }
                    }
                    if (Array.length > 0) {
                        var param = ln_ds.getJsonData(true);
                        Leaf.request({
                            url: $('csh_payment_req_ln_del_link').getUrl(),
                            para: param,
                            success: function() {
                                if (hd_ds.getCurrentRecord().get('payment_req_id')) {
                                    ln_ds.query(ln_ds.currentPage);
                                }
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            error: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            failure: function() {
                                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            scope: this
                        });
                    } else {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    }
                });
            };
            window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                var ln_ds = $(lnds_id);
                var records = ln_ds.getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请先选择要抵扣预付款的行明细!');
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    return;
                }
                if (!records[0].get('payment_req_ln_id')) {
                    Leaf.showMessage('${l:PROMPT}', '请先保存数据!');
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    return;
                }
                var param = {};
                if ('${/parameter/@function_usage}' == 'QUERY') {
                    param['function_code'] = 'CSH501_PRE_DK_READONLY';
                    param['function_usage'] = 'QUERY';
                } else {
                    param['function_code'] = 'CSH501_PRE_DK';
                    param['function_usage'] = 'UPDATE';
                }
                param['payment_req_id'] = records[0].get('payment_req_id');
                param['winid'] = 'csh501_csh_payment_req_link_winid';
                param['url_title'] = '预付款抵扣';
                param['screen_width'] = '800';
                param['screen_height'] = '500';
                hls_doc_get_layout_code('csh501d_get_layout_code_link_id', param, 'csh_payment_prepayment_dk', lnds_id, '${/parameter/@layout_code}');
            };
            window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function() {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd'),
                    lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                var hd_ds = $(hdds_id),
                    ln_ds = $(lnds_id);
                var hd_record = hd_ds.getCurrentRecord(),
                    line_records = ln_ds.getSelected();
                var payment_req_id = hd_record.get('payment_req_id');
                if (line_records.length == 0) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showMessage('${l:PROMPT}', '请先选择要支付的行明细!');
                    return;
                }
                var current_bp_id;
                for (var i = 0;i < line_records.length;i++) {
                    var line_record = line_records[i];
                    if (!current_bp_id && line_record.get('bp_id')) {
                        current_bp_id = line_record.get('bp_id');
                    }
                    if (current_bp_id && line_record.get('bp_id') && current_bp_id != line_record.get('bp_id')) {
                        Leaf.showMessage('${l:PROMPT}', '付款对象必须相同!');
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        return;
                    }
                    if (Ext.isEmpty(line_record.get('pay_amount'))) {
                        Leaf.showMessage('${l:PROMPT}', '本次支付金额为空!');
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        return;
                    }
                    if (line_record.get('payment_status') == 'FULL') {
                        Leaf.showMessage('${l:PROMPT}', '存在已全部付款的付款行,请核查付款明细!');
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        return;
                    }
                }
                if (line_records.length > 1) {
                    Leaf.showMessage('${l:PROMPT}', '不能同时选择多条记录!');
                    return;
                }
                // modify by syj
                var param = {};
                var saveData = [];
                for (i = 0;i < line_records.length;i++) {
                    var pre_line_record = 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['details'] = saveData;
                Leaf.request({
                    url: $('csh_payment_req_ln_temp_link').getUrl(),
                    para: param,
                    success: function(args) {
                        var readonly_flag = args.result.readonly_flag;
                        var win = new Leaf.Window({
                            id: 'csh_payment_req_pay_win',
                            url: $('csh_payment_req_pay_win_link').getUrl(),
                            params: {
                                payment_req_id: payment_req_id,
                                winid: 'csh_payment_req_pay_win',
                                hdds_id: hdds_id,
                                lnds_id: lnds_id,
                                readonly_flag: readonly_flag,
                                contract_number:line_records[0].get('contract_number'),
                                contract_name:line_records[0].get('contract_name'),
                                pre_inception_of_lease:line_records[0].get('inception_of_lease').parseDate('yyyy-mm-dd').format('yyyy-mm-dd')
                            },
                            title: '款项支付',
                            fullScreen: true
                        });
                        win.on('close', function() {
                            var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                            $(hdds_id).query();
                        });
                    },
                    scope: this
                });
            
            };
            window['${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function(ds, record, config_records, bp_seq) {
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                if (hdds_id == ds.id && record.isNew) {
                    if ('${/parameter/@business_type}' == 'PAYMENT') {
                        record.set('business_type', '${/model/default_payment_document_type/record/@business_type}');
                        record.set('document_type', '${/model/default_payment_document_type/record/@document_type}');
                        record.set('document_type_n', '${/model/default_payment_document_type/record/@description}');
                    } else if ('${/parameter/@business_type}' == 'PREPAYMENT') {
                        record.set('business_type', '${/model/default_prepayment_document_type/record/@business_type}');
                        record.set('document_type', '${/model/default_prepayment_document_type/record/@document_type}');
                        record.set('document_type_n', '${/model/default_prepayment_document_type/record/@description}');
                    }
                }
                if('${/parameter/@cf_item}' != 0){
                   var head_record = $(hdds_id).getAt(0);
                        head_record.getField('con_pay_type').setRequired(false);
                        head_record.getField('con_pay_type').setReadOnly(true); 
                }
            };
            
            function csh504_ddct_link(record_id, name) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][record_id + '---' + name];
                var payment_req_ln_id = record.get('payment_req_ln_id'),
                    apply_amount = record.get('amount'),
                    contract_number = record.get('contract_number'),
                    ref_doc_id = record.get('ref_doc_id');
                var win = new Leaf.Window({
                    id: 'csh_req_ddct_link_winid',
                    url: $('csh_req_ddct_link').getUrl(),
                    params: {
                        apply_amount: apply_amount,
                        payment_req_ln_id: payment_req_ln_id,
                        contract_number: contract_number,
                        contract_id: ref_doc_id,
                        winid: 'csh_req_ddct_link_winid',
                        function_usage: '${/parameter/@function_usage}'
                    },
                    title: '抵扣',
                    width: 1000,
                    height: 500
                });
                win.on('close', function() {
                    var lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                    $(lnds_id).query($(lnds_id).currentPage);
                });
            }
            
            function csh504_prepayment_dk_link(record_id, name) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][record_id + '---' + name];
                var payment_req_ln_id = record.get('payment_req_ln_id');
                var win = new Leaf.Window({
                    id: 'csh_payment_req_prepayment_dk_detail_link_winid',
                    url: $('csh_payment_req_prepayment_dk_detail_link_id').getUrl(),
                    params: {
                        bp_id: record.get('bp_id'),
                        payment_req_ln_id: payment_req_ln_id,
                        payment_req_id: record.get('payment_req_id'),
                        winid: 'csh_payment_req_prepayment_dk_detail_link_winid',
                        function_usage: '${/parameter/@function_usage}'
                    },
                    title: '预付款抵扣明细',
                    width: 650,
                    height: 500
                });
                win.on('close', function() {
                    var lnds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_ln');
                    $(lnds_id).query($(lnds_id).currentPage);
                });
            }
            // 查看项目附件
            
            function prj_project_attachment_link(record_id, name) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][record_id + '---' + name];
                var ref_doc_id = record.get('ref_doc_id');
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/csh.CSH501.get_project_id_by_csh/query',
                    para: {
                        contract_id: record.get('ref_doc_id')
                    },
                    success: function(res) {
                        var param = res.result.record;
                        if ('${/parameter/@modify_att_flag}' === 'Y') {
                            param['function_code'] = 'PRJ501M';
                            param['function_usage'] = 'MODIFY';
                            param['maintain_type'] = 'UPDATE';
                        } else {
                            param['function_code'] = 'PRJ501Q';
                            param['function_usage'] = 'QUERY';
                            param['maintain_type'] = 'READONLY';
                        }
                        param['document_id'] = res.result.record.project_id;
                        param['company_id'] = ${/session/@company_id};
                        param['document_category'] = 'PROJECT';
                        param['cond_para2'] = res.result.record.project_type;
                        param['url_title'] = '资料清单';
                        hls_doc_get_layout_code('csh501d_get_layout_code_link_id', param, 'prj_project_modify_link', null, '${/parameter/@layout_code}', '${/parameter/@winid}');
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    failure: function() {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            
            }
            // 查看现金流信息
            
            function con_contract_cashflow_link(record_id, name) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][record_id + '---' + name];
                var ref_doc_id = record.get('ref_doc_id');
                new Leaf.Window({
                    title: '合同余额明细信息',
                    id: 'con_contract_balance_details_win',
                    url: $('con_contract_balance_details_link').getUrl(),
                    params: {
                        'contract_id': ref_doc_id
                    },
                    fullScreen: true
                });
            }
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record, bp_seq) {
                var link_function = '';
                window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
                if (name == 'ddct_link') {
                    link_function = 'csh504_ddct_link';
                    if (record.get('payment_req_ln_id')) {
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + config_record.get('prompt') + '</a>';
                    } else {
                        return '';
                    }
                } else if (name == 'act_amount') {
                    var act_amount = record.get('act_amount');
                    return Leaf.formatMoney(act_amount);
                } else if (name == 'prepayment_dk') {
                    link_function = 'csh504_prepayment_dk_link';
                    if (record.get('payment_req_ln_id')) {
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + config_record.get('prompt') + '</a>';
                    } else {
                        return '';
                    }
                } else if (name === 'project_attachment') {
                    link_function = 'prj_project_attachment_link';
                    if (record.get('ref_doc_category') === 'CONTRACT' && record.get('ref_doc_id')) {
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + '<font color="red">资料清单</font>' + '</a>';
                    }
                } else if (name === 'contract_number') {
                    link_function = 'con_contract_cashflow_link';
                    if (record.get('ref_doc_category') === 'CONTRACT' && record.get('ref_doc_id')) {
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + value + '</a>';
                    }
                }
                return value;
            };
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) {
                var hdds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'csh_payment_req_hd');
                var hd_record = $(hdds_id).getCurrentRecord();
                qpara['payment_req_id'] = hd_record.get('payment_req_id');
            };
            
            function on_csh_payment_req_temp_ln_ds_query(ds, qpara) {
                qpara['payment_bp_id'] = '${/parameter/@payment_bp_id}';
            }
            Leaf.onReady(function() {
                btnInterval = setInterval(function() {
                    for (var id in $L.CmpManager.cache) {
                        if ($L.CmpManager.cache[id] instanceof $L.Grid) {
                            if (id.match(/csh_payment_req_ln_layout_grid_id$/)) {
                                var grid = $(id);
                                if ('${/parameter/@function_usage}' != 'QUERY') {
                                    grid.hideColumn('pay_amount');
                                }
                            }
                        }
                        clearInterval(btnInterval);
                        btnInterval = null;
                    }
                }, 10);
            });
            
            function sumFunction(datas, name) {
                var sum = 0;
                for (var i = 0;i < datas.length;i++) {
                    var r = datas[i];
                    var d = r.get(name);
                    var n = parseFloat(d);
                    if (!isNaN(n)) {
                        sum = plus(sum, n);
                    }
                }
                var total = (typeof(sum) == 'undefined' ? '' : parseFloat(sum));
                return '<font>' + Leaf.formatMoney(total) + '</font>';
            }
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_select'] = function(ds, record, bp_seq) {
                if (record.get('payment_status') != 'FULL' && Ext.isEmpty(record.get('pay_amount'))) {
                    record.set('pay_amount', record.get('act_amount'));
                }
            };
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_unselect'] = function(ds, record, bp_seq) {
                record.set('pay_amount', '');
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:dataSets>
            <a:dataSet id="csh_payment_req_temp_ln_ds" autoQuery="true" fetchAll="true" model="csh.CSH501.csh_payment_req_ln_query">
                <a:events>
                    <a:event name="load" handler="on_csh_payment_req_temp_ln_ds_load"/>
                    <a:event name="query" handler="on_csh_payment_req_temp_ln_ds_query"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
    </a:view>
</a:screen>