<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: DJ
    $Date: 2013-2-26 下午2:37:49
    $Revision: 1.0
    $Purpose: 凭证模板行
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view>
        <a:link id="pageLink_tpltLine_copy" url="${/request/@context_path}/modules/gld/GLD107/gld_je_template_line_copy.lview"/>
        <script type="text/javascript"><![CDATA[

        function lineScreen_close() {
            $('gld_je_template_lines').close();
        }

        function lineDs_query() {
            $('lineDs').query();
        }

        function lineDs_add() {
            $('lineDs').create();
        }

        function lineDs_remove() {
            $('lineDs_basic_grid').remove();
        }

        function linePage_headDs_save() {
            var ds = $('linePage_headDs');
            if (ds.validate()) {
                ds.submit();
            }
        }

        function onUpdate_linePage_headDs(ds,record,name,value,oldvalue)
        {
            if(name=='je_desc')
            {
                record.getField('je_desc').setLovPara('je_desc',encodeURIComponent(value));
            }
            if(name=='je_company_id_config'||name=='journal_date_config')
            {
                set_advanceConfig(record,name,'${/parameter/@je_template_hd_id}','HEAD');
            }
        }

        function onSubmitSuccess_lineDs(ds,res)
        {
            ds.query();
        }

        function set_advanceConfig(record,name,source_id,source_type)
        {
            var field=record.getField(name);
            field.setLovUrl('${/request/@context_path}/modules/gld/GLD107/gld_je_template_config_advance.lview');
            field.setMapping([
                {from:'config_id', to: name+'_id'},
                {from:'config_desc', to: name}
            ]);
            field.setLovWidth(870);
            field.setLovHeight(550);
            field.setLovPara('source_column',name);
            field.setLovPara('config_id',record.get(name+'_id'));
            field.setLovPara('source_id',source_id);
            field.setLovPara('je_transaction_code','${/parameter/@je_transaction_code}');
            field.setLovPara('source_type',source_type);
            if(source_type=='LINE')
            {
                field.setLovPara('page_identifier','line');
                if(record.get('je_ln_type')=='LOOP')
                {
                    field.setLovPara('is_loop','Y');
                }
                if(name=='loop_config')
                {
                    field.setLovPara('column_mode','SIMPLE');
                }
            }
            else if(source_type=='HEAD')
            {
                field.setLovPara('page_identifier','head');
            }

        }

        function set_advanceAccountConfig(record,name,source_id,source_type)
        {
            var field=record.getField(name);
            field.setLovUrl('${/request/@context_path}/modules/gld/GLD107/gld_je_template_config_advance_account.lview');
            field.setMapping([
                {from:'config_id', to: name+'_id'},
                {from:'config_desc', to: name},
                {from:'account_config_type',to:'account_config_type'},
                {from:'usage_code',to:'usage_code'}
            ]);
            field.setLovWidth(870);
            field.setLovHeight(550);
            field.setLovPara('source_column',name);
            field.setLovPara('config_id',record.get(name+'_id'));
            field.setLovPara('source_id',source_id);
            field.setLovPara('je_transaction_code','${/parameter/@je_transaction_code}');
            field.setLovPara('source_type',source_type);
            field.setLovPara('column_mode','SIMPLE');

            var account_config_type=record.get('account_config_type');
            field.setLovPara('account_config_type',account_config_type);
            if (account_config_type=='USAGE_CODE')
            {
                field.setLovPara('usage_code',record.get('usage_code'));
            }
            field.setLovPara('page_identifier','acc');
            if(record.get('je_ln_type')=='LOOP')
            {
                field.setLovPara('is_loop','Y');
            }

        }


        function jeDesc_set(record,name,je_desc)
        {
            if(Ext.isEmpty(je_desc))
            {
                je_desc='';
            }
            var field=record.getField(name);
            field.setLovUrl('${/request/@context_path}/modules/gld/GLD107/gld_je_template_je_desc.lview');
            field.setMapping([{from:'je_desc', to: name}]);
            field.setLovWidth(650);
            field.setLovHeight(350);
            field.setLovPara('je_transaction_code','${/parameter/@je_transaction_code}');
            field.setLovPara('je_desc',encodeURIComponent(je_desc));

        }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="je_ln_type_ds">
                <a:datas>
                    <a:record name="固定" value="FIXED"/>
                    <a:record name="循环" value="LOOP"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="jeTemplateDrCrDs" lookupCode="GLD_JE_TEMPLATE_DR_CR"/>
            <a:dataSet id="linePage_headDs" loadData="true" model="gld.GLD107.gld_je_template_hds" submitUrl="gld_je_template_header.lsc">
                <a:fields>
                    <a:field name="je_company_id_config" title="GLD107.GLD_JE_TEMPLATE_HDS.JE_COMPANY_ID_CONFIG"/>
                    <a:field name="journal_date_config" title="GLD107.GLD_JE_TEMPLATE_HDS.JOURNAL_DATE_CONFIG"/>
                    <a:field name="je_desc" fetchRemote="false" title="GLD107.GLD_JE_TEMPLATE_HDS.JE_DESC"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="onUpdate_linePage_headDs"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="lineDs" autoQuery="true" bindName="line_info" bindTarget="linePage_headDs" fetchAll="true" model="gld.GLD107.gld_je_template_lns" queryUrl="${/request/@context_path}/autocrud/gld.GLD107.gld_je_template_lns/query?je_template_hd_id=${/parameter/@je_template_hd_id}" selectable="true">
                <a:fields>
                    <a:field name="je_ln_type_desc" displayField="name" options="je_ln_type_ds" required="true" returnField="je_ln_type" valueField="value"/>
                    <a:field name="je_template_hd_id" defaultValue="${/parameter/@je_template_hd_id}"/>
                    <a:field name="je_ln_number" required="true"/>
                    <a:field name="dr_cr"/>
                    <a:field name="dr_cr_desc" displayField="code_value_name" options="jeTemplateDrCrDs" required="true" returnField="dr_cr" valueField="code_value"/>
                    <a:field name="je_desc" fetchRemote="false" title="GLD107.GLD_JE_TEMPLATE_LNS.JE_DESC"/>
                    <a:field name="account_config" title="科目"/>
                    <a:field name="amount_config" title="GLD107.GLD_JE_TEMPLATE_LNS.AMOUNT_CONFIG"/>
                    <a:field name="cashflow_id_config" title="GLD107.GLD_JE_TEMPLATE_LNS.CASHFLOW_ID_CONFIG"/>
                    <a:field name="contract_id_config" title="GLD107.GLD_JE_TEMPLATE_LNS.CONTRACT_ID_CONFIG"/>
                    <a:field name="project_id_config" title="GLD107.GLD_JE_TEMPLATE_LNS.PROJECT_ID_CONFIG"/>
                    <a:field name="ref_1_config" title="GLD107.GLD_JE_TEMPLATE_LNS.REF_1_CONFIG"/>
                    <a:field name="ref_2_config" title="GLD107.GLD_JE_TEMPLATE_LNS.REF_2_CONFIG"/>
                    <a:field name="ref_3_config" title="GLD107.GLD_JE_TEMPLATE_LNS.REF_3_CONFIG"/>
                    <a:field name="ref_4_config" title="GLD107.GLD_JE_TEMPLATE_LNS.REF_4_CONFIG"/>
                    <a:field name="ref_5_config" title="GLD107.GLD_JE_TEMPLATE_LNS.REF_5_CONFIG"/>
                    <a:field name="ref_6_config" title="GLD107.GLD_JE_TEMPLATE_LNS.REF_6_CONFIG"/>
                    <a:field name="ref_7_config" title="GLD107.GLD_JE_TEMPLATE_LNS.REF_7_CONFIG"/>
                    <a:field name="ref_8_config" title="GLD107.GLD_JE_TEMPLATE_LNS.REF_8_CONFIG"/>
                    <a:field name="ref_9_config" title="GLD107.GLD_JE_TEMPLATE_LNS.REF_9_CONFIG"/>
                    <a:field name="ref_10_config" title="参考信息10"/>
                    <a:field name="ref_11_config" title="参考信息11"/>
                    <a:field name="ref_12_config" title="参考信息12"/>
                    <a:field name="ref_13_config" title="参考信息13"/>
                    <a:field name="ref_14_config" title="参考信息14"/>
                    <a:field name="ref_15_config" title="参考信息15"/>
                    <a:field name="ref_16_config" title="参考信息16"/>
                    <a:field name="ref_17_config" title="参考信息17"/>
                    <a:field name="ref_18_config" title="参考信息18"/>
                    <a:field name="ref_19_config" title="参考信息19"/>
                    <a:field name="ref_20_config" title="参考信息20"/>
                    <a:field name="resp_center_config" title="GLD107.GLD_JE_TEMPLATE_LNS.RESP_CENTER_CONFIG"/>
                    <a:field name="transaction_date_config" title="GLD107.GLD_JE_TEMPLATE_LNS.TRANSACTION_DATE_CONFIG"/>
                    <a:field name="loop_config" title="循环配置"/>
                </a:fields>
                <a:events>
                    <a:event name="submitsuccess" handler="onSubmitSuccess_lineDs"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <script type="text/javascript"><![CDATA[
        (
            function ()
            {
                record = $('linePage_headDs').getAt(0);
                var name_list=['je_company_id_config','journal_date_config'];

                for (var i=0;i<name_list.length;i++)
                {
                    set_advanceConfig(record,name_list[i],'${/parameter/@je_template_hd_id}','HEAD');

                }

                jeDesc_set(record,'je_desc',record.get('je_desc'));

            })();

        ]]></script>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="lineScreen_close" text="HLS.CLOSE"/>
                <a:gridButton click="lineDs_add" text="HLS.NEW"/>
                <a:gridButton click="lineDs_remove" text="HLS.REMOVE"/>
                <a:gridButton click="linePage_headDs_save" text="HLS.SAVE"/>
            </a:screenTopToolbar>
            <a:form title=" ">
                <a:lov name="je_company_id_config" bindTarget="linePage_headDs" editable="false" width="260"/>
                <a:lov name="journal_date_config" bindTarget="linePage_headDs" editable="false" width="260"/>
                <a:lov name="je_desc" bindTarget="linePage_headDs" width="650"/>
            </a:form>
            <script type="text/javascript"><![CDATA[

            function editorFunction_lineDs_basic_grid_advanceConfig(record,name)
            {
                if(name=='je_desc')
                {
                    jeDesc_set(record,name,record.get('je_desc'));
                    return 'lineDs_basic_grid_lov';
                }

                if(record.isNew)
                {
                    return '';
                }

                var je_ln_type = record.get('je_ln_type');

                if(name=='loop_config')
                {
                    var field = record.getField(name);
                    if(je_ln_type=='FIXED')
                    {
                        field.setRequired(false);
                        return '';
                    }
                    else
                    {
                        field.setRequired(true);
                        set_advanceConfig(record,name,record.get('je_template_ln_id'),'LINE');
                        return 'lineDs_basic_grid_lov_read';
                    }
                }
                else if(name=='account_config')
                {
                    if(je_ln_type!='LOOP' || (je_ln_type=='LOOP' && !Ext.isEmpty(record.get('loop_config'))))
                    {
                        set_advanceAccountConfig(record,name,record.get('je_template_ln_id'),'LINE');
                        return 'lineDs_basic_grid_lov_read';
                    }
                    return '';
                }
                else
                {
                    if(je_ln_type!='LOOP' || (je_ln_type=='LOOP' && !Ext.isEmpty(record.get('loop_config'))))
                    {
                        set_advanceConfig(record,name,record.get('je_template_ln_id'),'LINE');
                        return 'lineDs_basic_grid_lov_read';
                    }
                    return '';
                }
            }

            function editorFunction_lineDs_ref_grid_advanceConfig(record,name)
            {
                if(record.isNew)
                {
                    return '';
                }

                var je_ln_type = record.get('je_ln_type');
                if(je_ln_type!='LOOP' || (je_ln_type=='LOOP' && !Ext.isEmpty(record.get('loop_config'))))
                {
                    set_advanceConfig(record,name,record.get('je_template_ln_id'),'LINE');
                    return 'lineDs_ref_grid_lov_read';
                }
                return '';
            }

            function editorFunction_lineDs_additional_grid_advanceConfig(record,name)
            {
                if(record.isNew)
                {
                    return '';
                }

                var je_ln_type = record.get('je_ln_type');
                if(je_ln_type!='LOOP' || (je_ln_type=='LOOP' && !Ext.isEmpty(record.get('loop_config'))))
                {

                    set_advanceConfig(record,name,record.get('je_template_ln_id'),'LINE');
                    return 'lineDs_additional_grid_lov_read';
                }
                return '';
            }

            function winOpen_templateLineCopy(je_template_ln_id,je_ln_number)
            {
                var win = new Leaf.Window({
                    id: 'gld_je_template_line_copy',
                    url: $('pageLink_tpltLine_copy').getUrl(),
                    params:{
                        je_template_ln_id:je_template_ln_id,
                        je_ln_number:je_ln_number
                    },
                    title: '复制',
                    height: 200,
                    width: 600
                });

                win.on('close', function() {
                    lineDs_query();
                });
            }

            function render_lineDs_additional_grid(value,record,name)
            {
                return '<a href="javascript:winOpen_templateLineCopy('+ record.get('je_template_ln_id') + ',' + record.get('je_ln_number') + ');">' + '复制' + '</a>';
            }
            ]]></script>
            <a:tabPanel marginHeight="250" marginWidth="30">
                <a:tabs>
                    <a:tab prompt="GLD107.TAB.BASIC_INFO" width="100">
                        <a:grid id="lineDs_basic_grid" bindTarget="lineDs" marginHeight="300" marginWidth="60">
                            <a:columns>
                                <a:column name="je_ln_number" align="right" editor="lineDs_basic_grid_nf_integer" width="50"/>
                                <a:column name="je_ln_type_desc" editor="lineDs_basic_grid_comb" prompt="行类型" width="50"/>
                                <a:column name="je_desc" autoAdjust="false" editorFunction="editorFunction_lineDs_basic_grid_advanceConfig" showTitle="true" width="240"/>
                                <a:column name="dr_cr_desc" editor="lineDs_basic_grid_comb" prompt="GLD107.GLD_JE_TEMPLATE_LNS.DR_CR" width="50"/>
                                <a:column name="account_config" editorFunction="editorFunction_lineDs_basic_grid_advanceConfig" width="250"/>
                                <a:column name="amount_config" editorFunction="editorFunction_lineDs_basic_grid_advanceConfig" width="200"/>
                                <a:column name="resp_center_config" editorFunction="editorFunction_lineDs_basic_grid_advanceConfig" width="150"/>
                                <a:column name="loop_config" editorFunction="editorFunction_lineDs_basic_grid_advanceConfig" width="200"/>
                            </a:columns>
                            <a:editors>
                                <a:textField id="lineDs_basic_grid_tf"/>
                                <a:comboBox id="lineDs_basic_grid_comb"/>
                                <a:lov id="lineDs_basic_grid_lov_read" editable="false"/>
                                <a:lov id="lineDs_basic_grid_lov"/>
                                <a:numberField id="lineDs_basic_grid_nf_integer" allowDecimals="false" allowNegative="false"/>
                            </a:editors>
                        </a:grid>
                    </a:tab>
                    <a:tab prompt="GLD107.TAB.REF_INFO" width="100">
                        <a:grid id="lineDs_ref_grid" bindTarget="lineDs" marginHeight="300" marginWidth="60">
                            <a:columns>
                                <a:column name="je_ln_number" align="right" editor="lineDs_ref_grid_nf_integer" width="50"/>
                                <a:column name="ref_1_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" width="150"/>
                                <a:column name="ref_2_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" width="150"/>
                                <a:column name="ref_3_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" width="150"/>
                                <a:column name="ref_4_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" width="150"/>
                                <a:column name="ref_5_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" width="150"/>
                                <a:column name="ref_6_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" width="150"/>
                                <a:column name="ref_7_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" width="150"/>
                                <a:column name="ref_8_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" width="150"/>
                                <a:column name="ref_9_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" width="150"/>
                                <a:column name="ref_10_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息10" width="150"/>
                                <a:column name="ref_11_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息11" width="150"/>
                                <a:column name="ref_12_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息12" width="150"/>
                                <a:column name="ref_13_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息13" width="150"/>
                                <a:column name="ref_14_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息14" width="150"/>
                                <a:column name="ref_15_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息15" width="150"/>
                                <a:column name="ref_16_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息16" width="150"/>
                                <a:column name="ref_17_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息17" width="150"/>
                                <a:column name="ref_18_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息18" width="150"/>
                                <a:column name="ref_19_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息19" width="150"/>
                                <a:column name="ref_20_config" editorFunction="editorFunction_lineDs_ref_grid_advanceConfig" prompt="参考信息20" width="150"/>
                            </a:columns>
                            <a:editors>
                                <a:textField id="lineDs_ref_grid_tf"/>
                                <a:comboBox id="lineDs_ref_grid_comb"/>
                                <a:lov id="lineDs_ref_grid_lov_read" editable="false"/>
                                <a:lov id="lineDs_ref_grid_lov"/>
                                <a:numberField id="lineDs_ref_grid_nf_integer" allowDecimals="false" allowNegative="false"/>
                            </a:editors>
                        </a:grid>
                    </a:tab>
                    <a:tab prompt="GLD107.TAB.ADDITIONAL_INFO" width="100">
                        <a:grid id="lineDs_additional_grid" bindTarget="lineDs" marginHeight="300" marginWidth="60">
                            <a:columns>
                                <a:column name="je_ln_number" align="right" editor="lineDs_additional_grid_nf_integer" width="50"/>
                                <a:column name="amount_fuc_config" editorFunction="editorFunction_lineDs_additional_grid_advanceConfig" width="250"/>
                                <a:column name="project_id_config" editorFunction="editorFunction_lineDs_additional_grid_advanceConfig" width="200"/>
                                <a:column name="contract_id_config" editorFunction="editorFunction_lineDs_additional_grid_advanceConfig" width="200"/>
                                <a:column name="cashflow_id_config" editorFunction="editorFunction_lineDs_additional_grid_advanceConfig" width="200"/>
                                <a:column name="transaction_date_config" editorFunction="editorFunction_lineDs_additional_grid_advanceConfig" width="200"/>
                                <a:column name="line_copy" align="center" renderer="render_lineDs_additional_grid" width="50"/>
                            </a:columns>
                            <a:editors>
                                <a:textField id="lineDs_additional_grid_tf"/>
                                <a:comboBox id="lineDs_additional_grid_comb"/>
                                <a:lov id="lineDs_additional_grid_lov_read" editable="false"/>
                                <a:lov id="lineDs_additional_grid_lov"/>
                                <a:numberField id="lineDs_additional_grid_nf_integer" allowDecimals="false" allowNegative="false"/>
                            </a:editors>
                        </a:grid>
                    </a:tab>
                </a:tabs>
            </a:tabPanel>
        </a:screenBody>
    </a:view>
</a:screen>