<?xml version="1.0" encoding="UTF-8"?>

<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:view>
        <script type="text/javascript"><![CDATA[
        function csh_deposit_query() {
            $('execute_calendar_grid_ds').query();
        }

        function csh_deposit_reset(){
            $('execute_calendar_form_ds').reset();
        }

        function csh_deposit_export() {
            $('source_to_grid')._export();
        }

        function summaryRenderer(datas, name) {
            var sum = 0;
            var sum1 = 0;
            var sum2 = 0;
            var sum3 = 0;
            if (name == "calc_date") {
                return '<font color="red">合计:</font>';
            }
            if (name == "due_amount") {
                for (var i = 0; i < datas.length; i++) {
                    var record = datas[i];
                    var payment_amount_vl = record.get("due_amount");
                    var payment_amount = parseFloat(payment_amount_vl);
                    if (!isNaN(payment_amount)) {
                        sum += payment_amount;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum, 2) + '</font>';
            }
            if (name == "principal") {
                for (var i = 0; i < datas.length; i++) {
                    var record = datas[i];
                    var payment_amount_vl = record.get("principal");
                    var payment_amount = parseFloat(payment_amount_vl);
                    if (!isNaN(payment_amount)) {
                        sum += payment_amount;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum, 2) + '</font>';
            }
            if (name == "interest") {
                for (var j = 0; j < datas.length; j++) {
                    var record1 = datas[j];
                    var payment_amount_vl1 = record1.get("interest");
                    var payment_amount1 = parseFloat(payment_amount_vl1);
                    if (!isNaN(payment_amount1)) {
                        sum1 += payment_amount1;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum1, 2) + '</font>';
            }
        }



        function aut_authority_list_validate_query(ds, qpara) {
            qpara['authority_flag'] = 'Y';
            qpara['contract_ref_content_flag'] = 'Y';
            qpara['trx_category'] = 'CONTRACT';
            qpara['trx_id'] = 't1.contract_id';

        }

        ]]></script>

        <a:dataSets>
            <a:dataSet id="execute_calendar_form_ds"  >
                <a:fields>
                    <a:field name="contract_number" required="true" lovGridHeight="400" lovHeight="500" lovService="cont.CON1210.execute_calendar_form_query" lovWidth="500" title="合同编号" prompt="合同编号">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number"/>
                            <a:map from="bp_name" to="bp_name"/>
                            <a:map from="finance_amount" to="finance_amount"/>
                            <a:map from="lease_execution_date" to="lease_execution_date"/>
                            <a:map from="business_type" to="business_type"/>
                            <a:map from="deposit" to="deposit"/>
                            <a:map from="contract_id" to="contract_id"/>
                            <a:map from="amount_rent" to="amount_rent"/>
                            <a:map from="lease_channel_desc" to="lease_channel_desc"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_name"/>
                    <a:field name="finance_amount"/>
                    <a:field name="lease_execution_date"/>
                    <a:field name="business_type"/>
                    <a:field name="deposit"/>
                    <a:field name="contract_id"/>
                    <a:field name="amount_rent"/>
                    <a:field name="lease_channel_desc"/>
                </a:fields>
            </a:dataSet>

            <a:dataSet id="execute_calendar_grid_ds" fetchAll="true" autoQuery="false" model="cont.CON1210.execute_calendar_query" queryDataSet="execute_calendar_form_ds" selectionModel="single">
           <a:events>
               <a:event  name="query" handler="aut_authority_list_validate_query"/>
           </a:events>
            </a:dataSet>
        </a:dataSets>

        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="csh_deposit_query" text="查询"/>
                <a:gridButton click="csh_deposit_reset" text="重置"/>
                <a:gridButton click="csh_deposit_export" text="导出"/>
            </a:screenTopToolbar>
            <a:form column="4" marginWidth="100" title="查询条件">
                <a:lov name="contract_number" bindTarget="execute_calendar_form_ds" prompt="合同编号" />
                <a:textField name="bp_name" bindTarget="execute_calendar_form_ds" prompt="主承租人" readOnly="true"/>
                <a:numberField name="finance_amount" bindTarget="execute_calendar_form_ds" prompt="融资额" readOnly="true" renderer="Leaf.formatMoney"/>
                <a:datePicker name="lease_execution_date" bindTarget="execute_calendar_form_ds" prompt="执行日期" readOnly="true"/>
                <a:textField name="business_type" bindTarget="execute_calendar_form_ds" prompt="业务类型" readOnly="true"/>
                <a:numberField name="deposit" bindTarget="execute_calendar_form_ds" prompt="保证金" readOnly="true" renderer="Leaf.formatMoney"/>
                <a:numberField name="amount_rent" bindTarget="execute_calendar_form_ds" prompt="租金总额" readOnly="true" renderer="Leaf.formatMoney"/>
                <a:textField name="lease_channel_desc" bindTarget="execute_calendar_form_ds" prompt="商业模式" readOnly="true"/>
            </a:form>
            <a:grid id="source_to_grid" bindTarget="execute_calendar_grid_ds" navBar="true" height="400" marginWidth="100">
                <a:columns>
                    <a:column name="times" align="center" prompt="期数" width="150" />
                    <a:column name="contract_number" prompt="合同编号" width="120"/>
                    <a:column name="bp_name"  prompt="主承租人" align="center" width="120"/>
                    <!--<a:column name="lease_channel" prompt="商业模式" group="true" />
                    <a:column name="total_rental" prompt="租金总额" group="true" renderer="Leaf.formatMoney"/>
                    <a:column name="cf_direction"  prompt="收/付" width="100" />-->
                    <a:column name="cf_item_n" align="center" prompt="现金流项目" width="180" />
                    <a:column name="calc_date" align="center" prompt="应收日" width="180" renderer="Leaf.formatDate" footerRenderer="summaryRenderer"/>
                    <a:column name="due_amount" align="center" prompt="应收/付金" width="180" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="principal" align="center" prompt="应收本金" width="180" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="interest" align="center" prompt="应收利息" width="180" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="outstanding_prin_tax_incld" align="center" prompt="当期剩余本金" width="180" renderer="Leaf.formatMoney"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>

</a:screen>