<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: yuminhui  
    $Date: 2015-10-28 下午03:35:35  
    $Revision: 1.0  
    $Purpose: 租赁合同账龄分析表
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query model="cont.CON307B.con_aging_schedule_today_query" rootPath="current_date"/>
    </a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
        	function con_contract_return() {
                history.go(-1);
            }
            function con_contract_query() {
                var record = $('con_lease_aging_schedule_query_ds').getCurrentRecord();
                if(record.get('analysis_date') == '' || record.get('analysis_date') == null){
                    Leaf.showMessage('${l:PROMPT}','请输入分析日期，<font color="red">分析日期不能为空！</font>');
                }else{
                $('con_lease_aging_schedule_result_ds').query();
            		}
            }
            function con_contract_reset() {
                $('con_lease_aging_schedule_query_ds').reset();
            }
            
            function con_contract_balance_export() {
                $('con_lease_aging_schedule_result_grid')._export();
            }
            function con_contract_number_query(){
                $('con_lease_aging_schedule_result_ds').query();
            }
            
            function sum_foot(data, name) {
                if (name == 'row_num') {
                    return '<font color=red>' + '合计' + '</font>';
                } else if (name == 'lease_principal') {
                    return colum_caculateTotal(data, name);
                } else if (name == 'lease_due_amount') {
                    return colum_caculateTotal(data, name);
                } else if (name == 'rental_one') {
                    return colum_caculateTotal(data, name);
                } else if (name == 'rental_one_to_two') {
                    return colum_caculateTotal(data, name);
                } else if (name == 'rental_two_to_three') {
                    return colum_caculateTotal(data, name);
                } else if (name == 'rental_upper_three') {
                    return colum_caculateTotal(data, name);
                }
            
            }
            
            function colum_caculateTotal(data, name) {
                var total = 0;
                var length = data.length;
                var value = 0;
                for (var i = 0;i < length;i++) {
                    if (Ext.isEmpty(data[i].get(name))) {
                        value = 0;
                    } else {
                        value = data[i].get(name);
                    }
                    total = plus(total, value);
                }
                return '<font color=red>' + Leaf.formatMoney(total) + '</font>';
            }
            
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con_lease_aging_schedule_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="contract_number" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON303B.con_contract_for_query_lov" lovWidth="500" title="合同编号查询">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number"/>
                            <a:map from="contract_name" to="contract_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="five_class_code_n" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON307B.con_lease_five_class_query" lovWidth="500" title="五级分类查询">
                        <a:mapping>
                            <a:map from="description" to="five_class_code_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_id_tenant_n" autoComplete="true" lovGridHeight="350" lovHeight="500" lovService="cont.CON303B.con_bp_name_for_query_lov" lovWidth="500" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id_tenant"/>
                            <a:map from="bp_name" to="bp_id_tenant_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="analysis_date" defaultValue="${/model/current_date/record/@today}" required="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_lease_aging_schedule_result_ds" autoPageSize="true" autoQuery="true" model="cont.CON307B.con_lease_aging_schedule_query" queryDataSet="con_lease_aging_schedule_query_ds" queryUrl="${/request/@context_path}/autocrud/cont.CON307B.con_lease_aging_schedule_query/query"/>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <!-- <a:gridButton click="con_contract_return" text="HLS.RETURN"/> -->
                <a:gridButton click="con_contract_query" text="HLS.QUERY"/>
                <a:gridButton click="con_contract_reset" text="HLS.RESET"/>
                <a:gridButton click="con_contract_balance_export" text="HLS.EXPORT"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="100" marginWidth="30" title="查询条件">
                <a:datePicker name="analysis_date" bindTarget="con_lease_aging_schedule_query_ds" emptyText="比如：2015-1-1" prompt="分析日期" viewSize="2">
                    <a:events>
                        <a:event name="enterdown" handler="con_contract_number_query"/>
                    </a:events>
                </a:datePicker>
                <a:lov name="bp_id_tenant_n" bindTarget="con_lease_aging_schedule_query_ds" prompt="承租人名称">
                    <a:events>
                        <a:event name="enterdown" handler="con_contract_number_query"/>
                    </a:events>
                </a:lov>
                <a:lov name="contract_number" bindTarget="con_lease_aging_schedule_query_ds" prompt="合同编号">
                    <a:events>
                        <a:event name="enterdown" handler="con_contract_number_query"/>
                    </a:events>
                </a:lov>
                <a:lov name="five_class_code_n" bindTarget="con_lease_aging_schedule_query_ds" prompt="五级分类">
                    <a:events>
                        <a:event name="enterdown" handler="con_contract_number_query"/>
                    </a:events>
                </a:lov>
            </a:form>
            <a:grid id="con_lease_aging_schedule_result_grid" bindTarget="con_lease_aging_schedule_result_ds" marginHeight="185" marginWidth="20" navBar="true">
                <a:columns>
                    <a:column name="row_num" align="center" footerRenderer="sum_foot" lock="true" prompt="HLS.CONTRACT_SEQ" width="40"/>
                    <a:column name="contract_number" lock="true" prompt="提款编号" width="180"/>
                    <a:column name="five_class_code_n" prompt="五级分类" width="90"/>
                    <a:column name="lease_principal" align="right" footerRenderer="sum_foot" prompt="到期剩余本金" renderer="Leaf.formatMoney" width="150"/>
                    <a:column name="lease_due_amount" align="right" footerRenderer="sum_foot" prompt="到期剩余租金" renderer="Leaf.formatMoney" width="150"/>
                    <a:column name="project_id_n" prompt="项目名称" width="180"/>
                    <a:column prompt="长期应收款">
                        <a:column name="rental_one" align="right" footerRenderer="sum_foot" prompt="1年内" renderer="Leaf.formatMoney" width="120"/>
                        <a:column name="rental_one_to_two" align="right" footerRenderer="sum_foot" prompt="1-2年" renderer="Leaf.formatMoney" width="120"/>
                        <a:column name="rental_two_to_three" align="right" footerRenderer="sum_foot" prompt="2-3年" renderer="Leaf.formatMoney" width="120"/>
                        <a:column name="rental_upper_three" align="right" footerRenderer="sum_foot" prompt="3年以上" renderer="Leaf.formatMoney" width="120"/>
                    </a:column>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
