<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hyb  
    $Date: 2012-10-10 下午3:12:32  
    $Revision: 1.0  
    $Purpose: 科目余额查询
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="company_id=${/session/@company_id}" model="fnd.fnd_companies_vl" rootPath="gld_company"/>
        <a:model-query defaultWhereClause="enabled_flag=&apos;Y&apos;" fetchAll="true" model="gld.GLD5010.gld_currency" queryOrderBy="functional_flag desc,currency_code" rootPath="gld3020_gld_currency_list"/>
        <a:model-query defaultWhereClause="company_id=${/session/@company_id} and period_status_code in (&apos;O&apos;,&apos;C&apos;) and substr(period_name,0,4)=${@balances_year}" model="gld.gld_period_status_v" rootPath="gld3020_period"/>
        <a:model-query fetchAll="true" model="gld.GLD3020.gld_balances_get_year" rootPath="gld3020_gld_balances_year"/>
        <a:model-query fetchAll="true" model="gld.GLD130.get_functional_balances" rootPath="gld130_set_of_books_list"/>
        <a:model-query defaultWhereClause="company_id=${/session/@company_id}" fetchAll="true" model="public.get_cur_period_code_v" rootPath="get_cur_period"/>
    </a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
        	  function gld3020_balances_result_query() {
                if (!$('gld3020_balances_query_ds').validate()) {
                    return;
                }
                $('gld3020_balances_result_ds').query();
            }
       		function on_year_changed(cmp, newValue, oldValue)
            {
                //alert('aaa');
            	 $('gld3020_period_name_ds').setQueryUrl('${/request/@context_path}/autocrud/gld.GLD533.gld_periods_combo/query');
               $('gld3020_period_name_ds').setQueryParameter('period_year',newValue);
               $('gld3020_period_name_ds').setQueryParameter('period_set_code','${/model/get_cur_period/record/@period_set_code}');
               $('gld3020_period_name_ds').query();
            }
            function onUpdate(ds, record, name, value)
            {
                
                if(name=='check_flag')
                {
	                if (record.get('check_flag') == 'N') {
	                    record.set('currency_desc', null);
	                    record.set('currency_code', null);
	                    record.getMeta().getField('currency_desc').setReadOnly(false);
	                } else {
	                    record.set('currency_desc', '${/model/gld130_set_of_books_list/record/@functional_currency_name}');
	                    record.set('currency_code', '${/model/gld130_set_of_books_list/record/@functional_currency_code}');
	                    record.getMeta().getField('currency_desc').setReadOnly(true);
	                }
            	}
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="gld3020_currency_list_ds">
                <a:datas dataSource="/model/gld3020_gld_currency_list"/>
            </a:dataSet>
            <!--          <a:dataSet id="gld3020_periods_ds">
                
            </a:dataSet> -->
            <a:dataSet id="gld3020_period_name_ds" fetchAll="true" loadData="true"/>
            <a:dataSet id="gld3020_balances_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="balances_year" defaultValue="${/model/gld3020_gld_balances_year/record/@year}"/>
                    <a:field name="company_desc" defaultValue="${/model/gld_company/record/@company_short_name}" readOnly="true"/>
                    <a:field name="period_name_from" displayField="period_name" options="gld3020_period_name_ds" required="true" returnField="period_name_from" valueField="period_name"/>
                    <a:field name="period_name_to" displayField="period_name" options="gld3020_period_name_ds" required="true" returnField="period_name_to" valueField="period_name"/>
                    <a:field name="account_id_from"/>
                    <a:field name="account_desc_from"/>
                    <a:field name="account_code_from" autoComplete="true" lovGridHeight="325" lovHeight="450" lovService="gld.FND2140.gld_accounts_vl?account_set_id=${/model/get_cur_period/record/@account_set_id}" lovWidth="500" title="科目">
                        <a:mapping>
                            <a:map from="account_id" to="account_id_from"/>
                            <a:map from="account_code" to="account_code_from"/>
                            <a:map from="description" to="account_desc_from"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="account_id_to"/>
                    <a:field name="account_desc_to"/>
                    <a:field name="account_code_to" autoComplete="true" lovGridHeight="325" lovHeight="450" lovService="gld.FND2140.gld_accounts_vl?account_set_id=${/model/get_cur_period/record/@account_set_id}" lovWidth="500" title="科目">
                        <a:mapping>
                            <a:map from="account_id" to="account_id_to"/>
                            <a:map from="account_code" to="account_code_to"/>
                            <a:map from="description" to="account_desc_to"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="currency_code"/>
                    <a:field name="currency_desc" displayField="currency_name" options="gld3020_currency_list_ds" required="true" returnField="currency_code" valueField="currency_code"/>
                    <a:field name="check_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="onUpdate"><![CDATA[                		
                	]]></a:event>
                </a:events>
            </a:dataSet>
            <a:dataSet id="gld3020_balances_result_ds" model="gld.GLD3020.gld_balances_query" queryDataSet="gld3020_balances_query_ds"><![CDATA[
        		
        	]]></a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="gld3020_balances_result_query" text="HLS.QUERY"/>
            </a:screenTopToolbar>
            <a:form title="科目余额查询">
                <a:hBox>
                    <a:textField name="company_desc" bindTarget="gld3020_balances_query_ds" prompt="公司" width="200"/>
                    <a:textField name="balances_year" bindTarget="gld3020_balances_query_ds" prompt="会计年度" width="200">
                        <a:events>
                            <a:event name="change" handler="on_year_changed"/>
                        </a:events>
                    </a:textField>
                    <a:comboBox name="period_name_from" bindTarget="gld3020_balances_query_ds" prompt="期间" width="200">
                        <a:events>
                            <a:event name="enterdown" handler="gld3020_balances_result_query"/>
                        </a:events>
                    </a:comboBox>
                    <a:comboBox name="period_name_to" bindTarget="gld3020_balances_query_ds" prompt="至" width="200">
                        <a:events>
                            <a:event name="enterdown" handler="gld3020_balances_result_query"/>
                        </a:events>
                    </a:comboBox>
                </a:hBox>
                <a:hBox>
                    <a:lov name="account_code_from" id="gld3020_account_desc_from_lov" bindTarget="gld3020_balances_query_ds" prompt="科目" width="200">
                        <a:events>
                            <a:event name="enterdown" handler="gld3020_balances_result_query"/>
                        </a:events>
                    </a:lov>
                    <a:lov name="account_code_to" id="gld3020_account_desc_to_lov" bindTarget="gld3020_balances_query_ds" prompt="至" width="200">
                        <a:events>
                            <a:event name="enterdown" handler="gld3020_balances_result_query"/>
                        </a:events>
                    </a:lov>
                    <a:comboBox name="currency_desc" bindTarget="gld3020_balances_query_ds" prompt="币种" width="200"/>
                    <a:checkBox name="check_flag" bindTarget="gld3020_balances_query_ds" prompt="本位币汇总" width="100"/>
                </a:hBox>
            </a:form>
            <a:tabPanel height="380" width="1030">
                <a:tabs>
                    <a:tab prompt="本位币">
                        <a:grid id="gld3020_gld_balances_functional_ds" bindTarget="gld3020_balances_result_ds" height="350" navBar="true" width="1000">
                            <a:columns>
                                <a:column name="account_code" lock="true" prompt="科目代码" sortable="true" width="100"/>
                                <a:column name="account_desc" lock="true" prompt="科目名称" sortable="true" width="180"/>
                                <a:column name="period_name" align="true" lock="true" prompt="期间" sortable="true" width="80"/>
                                <a:column name="entered_period_to_date_amt" align="right" prompt="期初余额" renderer="Leaf.formatMoney" sortable="true" width="150"/>
                                <a:column name="functional_period_net_dr_amt" align="right" prompt="本期借方发生额" renderer="Leaf.formatMoney" sortable="true" width="150"/>
                                <a:column name="functional_period_net_cr_amt" align="right" prompt="本期贷方发生额" renderer="Leaf.formatMoney" sortable="true" width="150"/>
                                <!-- <a:column name="entered_project_to_date_amt" align="right" prompt="原币" renderer="Leaf.formatMoney" width="80"/> -->
                                <a:column name="functional_project_to_date" align="right" prompt="期末余额" renderer="Leaf.formatMoney" sortable="true" width="150"/>
                            </a:columns>
                            <a:toolBar>
                                <a:button click="excel" type="excel"/>
                                <!--   <a:button id="delete_id" click="delete" type="delete"/> -->
                            </a:toolBar>
                        </a:grid>
                    </a:tab>
                    <a:tab prompt="原币">
                        <a:grid id="gld3020_gld_balances_entered_ds" bindTarget="gld3020_balances_result_ds" height="350" navBar="true" width="1000">
                            <a:columns>
                                <a:column name="account_code" lock="true" prompt="科目代码" sortable="true" width="100"/>
                                <a:column name="account_desc" lock="true" prompt="科目名称" sortable="true" width="180"/>
                                <a:column name="period_name" align="true" lock="true" prompt="期间" sortable="true" width="80"/>
                                <a:column name="entered_period_to_date_amt" align="right" prompt="期初余额" renderer="Leaf.formatMoney" sortable="true" width="150"/>
                                <a:column name="entered_period_net_dr_amt" align="right" prompt="本期借方发生额" renderer="Leaf.formatMoney" sortable="true" width="150"/>
                                <a:column name="entered_period_net_cr_amt" align="right" prompt="本期贷方发生额" renderer="Leaf.formatMoney" sortable="true" width="150"/>
                                <a:column name="entered_project_to_date_amt" align="right" prompt="期末余额" renderer="Leaf.formatMoney" sortable="true" width="150"/>
                            </a:columns>
                        </a:grid>
                    </a:tab>
                </a:tabs>
            </a:tabPanel>
        </a:screenBody>
        <script type="text/javascript"><![CDATA[
            Leaf.onReady(function() {
            		 var period_year = $('gld3020_balances_query_ds').getCurrentRecord().get('balances_year');
            		
            		 $('gld3020_period_name_ds').setQueryUrl('${/request/@context_path}/autocrud/gld.GLD533.gld_periods_combo/query');
                $('gld3020_period_name_ds').setQueryParameter('period_year',period_year);
                $('gld3020_period_name_ds').setQueryParameter('period_set_code','${/model/get_cur_period/record/@period_set_code}');
                $('gld3020_period_name_ds').query();
                //$('gld533_get_period_name_by_date_ds').setQueryParameter('reverse_date', '${/model/gld533_get_sysdate/record/@currentdate}');
                //$('gld533_get_period_name_by_date_ds').query();
            });
        ]]></script>
    </a:view>
</a:screen>