<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ZLF  
    $Date: 2015-4-17 上午11:47:38  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query model="cont.CON327.get_current_period_by date" rootPath="get_current_period"/>
        <a:model-query model="gld.gld_period_status" queryOrderBy="period_name asc" rootPath="gld_periods_combo"/>
    </a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
			function query()
			{
			    $('con_added_tax_income_ratio_result_ds').query();			    
			}
			function reset()
			{
			    $('con_added_tax_query_ds').reset();			    
			}
			
			function moneyRenderer(value,record,name) {
			    //增值税收入比例
			    if(name=="added_tax_ratio") {
			        var added_tax_ratio;
			        if(Leaf.isEmpty(record.get('sum_income')) || Leaf.isEmpty(record.get('sum_added_tax'))) {
			            added_tax_ratio = 0;
			            record.set('added_tax_ratio',added_tax_ratio,false);
			            return '';
			        }else {
				        added_tax_ratio=record.get('sum_added_tax')/record.get('sum_income');
				        record.set('added_tax_ratio',added_tax_ratio,false);
				        return Leaf.formatNumber(added_tax_ratio*100,2)+'%';
			        }
			    }
			    //待抵扣进项税（按收入比例）
			    if(name=='sum_input_tax') {
			        var sum_input_tax=record.get('sum_vat_accrued_interest')*record.get('added_tax_ratio');
			        record.set('sum_input_tax',sum_input_tax);
			        return Leaf.formatNumber(sum_input_tax,2);
			    }
			    //利息支出
			    if(name=='finance_cost_exclusive_tax') {
			        var finance_cost_exclusive_tax=record.get('sum_accrued_finance_cost')-record.get('sum_input_tax');
			        record.set('finance_cost_exclusive_tax',finance_cost_exclusive_tax,false);
			        return Leaf.formatMoney(finance_cost_exclusive_tax,2);
			    }
			    
			    //待抵扣进项税差额
			    if(name=='c') {
			        var c=record.get('a')-record.get('sum_input_tax');
			        return Leaf.formatNumber(c,2);
			    }
			    
			    //利息支出差额
			    if(name=='d') {
			        var d=record.get('finance_cost_exclusive_tax')-record.get('sum_vat_accrued_interest');
			        return Leaf.formatNumber(d,2);
			    }
			    
			}
			
			function updateHandler(ds,rocord,name,value,oldValue) {
			    if(name=='added_tax_ratio') {
			        record.set(name,value);
			    }
			    if(name=='sum_input_tax') {
			        record.set(name,value);
			    }
			}
			
			function summaryRenderer(datas, name) {          		
                var sum = 0;        
                for (var i = 0;i < datas.length;i++) {
                    record = datas[i];
                    if (name == "unearned_finance_income" ) {
                        var t_1 = record.get("unearned_finance_income" );
                        var  t_2 = parseFloat(t_1);
                        if (!isNaN(t_2)) {
                            sum += t_2;
                        }
                    }             
                }
                if (name == "calc_end_date") {
                    return '<div align="right">合计:</div>';
                }
                if (name == "unearned_finance_income" ) {           
                    return '<font color="red">' + Leaf.formatNumber(sum, 2) + '</font>';
                }       
            }
		]]></script>
        <a:dataSets>
            <a:dataSet id="CON327_period_name_ds">
                <a:datas dataSource="/model/gld_periods_combo"/>
            </a:dataSet>
            <a:dataSet id="finance_income_recognized_ds">
                <a:datas>
                    <a:record code_value="Y" code_value_name="是"/>
                    <a:record code_value="N" code_value_name="否"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="con_added_tax_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="period_name_from" displayField="period_name" options="CON327_period_name_ds" returnField="period_name_from" valueField="period_name"/>
                    <a:field name="period_name_to" displayField="period_name" options="CON327_period_name_ds" returnField="period_name_to" valueField="period_name"/>
                    <!-- <a:field name="contract_id"/>
                    <a:field name="contract_number" lovGridHeight="300" lovHeight="430" lovService="cont.CON327.con_contract_lov" lovWidth="400">
                        <a:mapping>
                            <a:map from="contract_id" to="contract_id"/>
                            <a:map from="contract_number" to="contract_number"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_vender"/>
                    <a:field name="bp_vender_n" lovGridHeight="300" lovHeight="430" lovService="basic.hls_bp_master_v_all_lov?bp_category=VENDER" lovWidth="550">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id_vender"/>
                            <a:map from="bp_name" to="bp_vender_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_tenant"/>
                    <a:field name="bp_tenant_n" lovGridHeight="300" lovHeight="430" lovService="basic.hls_bp_master_v_all_lov?bp_category=TENANT" lovWidth="550">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id_tenant"/>
                            <a:map from="bp_name" to="bp_tenant_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_agent_level1"/>
                    <a:field name="bp_agent_n" lovGridHeight="300" lovHeight="430" lovService="basic.hls_bp_master_v_all_lov?bp_category=AGENT" lovWidth="550">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id_agent_level1"/>
                            <a:map from="bp_name" to="bp_agent_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="finance_income_recognized" displayField="code_value" options="finance_income_recognized_ds" returnField="finance_income_recognized" valueField="code_value"><![CDATA[                   	
                    ]]></a:field> -->
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_added_tax_income_ratio_result_ds" autoQuery="true" model="cont.CON327.con_added_tax_income_ratio" pageSize="15" queryDataSet="con_added_tax_query_ds">
                <a:fields>
                    <a:field name="period_name" defaultValue="&apos;${/model/get_current_period/record/@period_name}&apos;"/>
                    <a:field name="sum_added_tax"/>
                    <a:field name="sum_income"/>
                    <a:field name="sum_accrued_finance_cost"/>
                    <a:field name="sum_input_tax"/>
                    <a:field name="finance_cost_exclusive_tax"/>
                </a:fields>
                <!-- <a:events >
                	<a:event name="update" handler="updateHandler"   />
                </a:events> -->
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="reset" text="HLS.RESET"/>
                <a:gridButton click="query" text="HLS.QUERY"/>
            </a:screenTopToolbar>
            <a:form column="3" marginWidth="30" title="查询条件">
                <a:comboBox name="period_name_from" bindTarget="con_added_tax_query_ds" prompt="期间从"/>
                <a:comboBox name="period_name_to" bindTarget="con_added_tax_query_ds" prompt="期间到"/>
            </a:form>
            <a:grid bindTarget="con_added_tax_income_ratio_result_ds" marginHeight="180" marginWidth="30" navBar="true">
                <a:toolBar>
                    <a:button type="excel"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="period_name" align="center" prompt="期间" sortable="true" width="120"/>
                    <a:column name="sum_added_tax" align="right" prompt="增值税收入之和" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="sum_income" align="right" prompt="收入总和" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="added_tax_ratio" align="center" prompt="增值税收入比例" renderer="moneyRenderer" sortable="true" width="140"/>
                    <a:column name="sum_accrued_finance_cost" align="right" prompt="应付利息" renderer="Leaf.formatMoney" width="120"/>
                    <a:column name="sum_input_tax" align="right" prompt="待抵扣进项税（按收入比例）" renderer="moneyRenderer" width="160"/>
                    <a:column name="finance_cost_exclusive_tax" align="right" prompt="利息支出（按收入比例）" renderer="moneyRenderer" width="160"/>
                    <a:column name="a" align="right" prompt="待抵扣进项税（按17%）" renderer="Leaf.formatMoney" width="160"/>
                    <a:column name="b" align="right" prompt="利息支出（按17%）" renderer="Leaf.formatMoney" width="140"/>
                    <a:column name="c" align="right" prompt="待抵扣进项税差额" renderer="moneyRenderer" width="140"/>
                    <a:column name="d" align="right" prompt="利息支出差额" renderer="moneyRenderer" width="120"/>
                </a:columns>
            </a:grid>
            <script type="text/javascript"><![CDATA[
            Leaf.onReady(function() {
                var record = $('con_added_tax_query_ds').getCurrentRecord();
                record.set('period_name_from','${/model/get_current_period/record/@period_name}');
                record.set('period_name_to','${/model/get_current_period/record/@period_name}');
            });
        ]]></script>
        </a:screenBody>
    </a:view>
</a:screen>
