<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Clocc  
    $Date: 2015-9-11 下午2:16:27  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:view>
        <a:link id="hls531_journal_merge_link" model="hls.HLS531.hls_journal_merge" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
            function hls531_merge_journal() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                var ds = $('hls531_result_ds');
                var status_record = $('hls531_query_ds').getCurrentRecord();
                var calc_date = status_record.get('calc_date');
                var records = ds.getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请选择数据！');
                    return;
                }
                var datas = [];
                for (var i = 0;i < records.length;i++) {
                    var obj = {};
                    obj['journal_date'] = calc_date;
                    obj['je_transaction_code'] = records[i].get('je_transaction_code');
                    obj['_status'] = 'execute';
                    datas[i] = obj;
                }
                Leaf.showConfirm('${l:PROMPT}', '确认合并？', function() {
                    journal_submit_merge(datas);
                });
            }
            
            function journal_submit_merge(datas) {
                Leaf.request({
                    url: $('hls531_journal_merge_link').getUrl(),
                    para: datas,
                    success: function(res) {
                        Leaf.Masker.unmask(Ext.getBody());
                        Leaf.SideBar.show({
                            msg: '${l:HLS.SUBMIT_SUCCESS}',
                            duration: 2000
                        });
                        $('hls531_result_ds').query();
                    },
                    failure: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function() {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });
            }
            
            function queryFunction() {
                var record = $('hls531_query_ds').getCurrentRecord();
                if (record && record.get('calc_date')) {
                    eg_rpt100_head_query();
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请输入凭证日期！');
                    return;
                }
            }
            
            function eg_rpt100_head_query() {
                $('hls531_result_ds').query();
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="hls531_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="calc_date"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="hls531_result_ds" autoPageSize="true" autoQuery="true" model="hls.HLS531.hls_journal_merge_detail" queryDataSet="hls531_query_ds" selectable="true"><![CDATA[
            ]]></a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="queryFunction" text="刷新"/>
                <a:gridButton click="hls531_merge_journal" text="合并"/>
            </a:screenTopToolbar>
            <a:form bindTarget="hls531_query_ds" column="4" labelWidth="130">
                <a:datePicker name="calc_date" bindTarget="hls531_query_ds" prompt="凭证日期"/>
            </a:form>
            <a:grid id="hls531_result_ds_id" bindTarget="hls531_result_ds" height="430" navBar="true" width="850">
                <a:columns>
                    <a:column name="je_transaction_code" prompt="凭证事务代码" width="230"/>
                    <a:column name="je_transaction_desc" prompt="凭证事务描述" width="160"/>
                    <a:column name="seq" prompt="数量"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
