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

<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="cont.CON1240.con_cf_direction" rootPath="cf_direction_ds"/>
        <a:model-query fetchAll="true" model="cont.CON1240.con_get_period" rootPath="sys_default_time"/>
    </a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
        function receipts_details_query() {
            $('receipts_details_grid_ds').query();
        }

        function receipts_details_reset(){
            $('receipts_details_form_ds').reset();
        }

        function receipts_details_export() {
            $('source_to_grid')._export(null,'收款明细查询（一）');
        }

        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';

        }

        function summaryRenderer(datas, name) {
            var sum = 0;
            var sum1 = 0;
            var sum2 = 0;
            var sum3 = 0;
            if (name == "due_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>';
            }
            if (name == "received_amount") {
                for (var j = 0; j < datas.length; j++) {
                    var record1 = datas[j];
                    var payment_amount_vl1 = record1.get("received_amount");
                    var payment_amount1 = parseFloat(payment_amount_vl1);
                    if (!isNaN(payment_amount1)) {
                        sum1 += payment_amount1;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum1, 2) + '</font>';
            }
            if (name == "received_principal") {
                for (var j = 0; j < datas.length; j++) {
                    var record1 = datas[j];
                    var payment_amount_vl1 = record1.get("received_principal");
                    var payment_amount1 = parseFloat(payment_amount_vl1);
                    if (!isNaN(payment_amount1)) {
                        sum1 += payment_amount1;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum1, 2) + '</font>';
            }
            if (name == "received_interest") {
                for (var j = 0; j < datas.length; j++) {
                    var record1 = datas[j];
                    var payment_amount_vl1 = record1.get("received_interest");
                    var payment_amount1 = parseFloat(payment_amount_vl1);
                    if (!isNaN(payment_amount1)) {
                        sum1 += payment_amount1;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum1, 2) + '</font>';
            }
            if (name == "due_amount_penalty") {
                for (var j = 0; j < datas.length; j++) {
                    var record1 = datas[j];
                    var payment_amount_vl1 = record1.get("due_amount_penalty");
                    var payment_amount1 = parseFloat(payment_amount_vl1);
                    if (!isNaN(payment_amount1)) {
                        sum1 += payment_amount1;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum1, 2) + '</font>';
            }
            if (name == "received_amount_penalty") {
                for (var j = 0; j < datas.length; j++) {
                    var record1 = datas[j];
                    var payment_amount_vl1 = record1.get("received_amount_penalty");
                    var payment_amount1 = parseFloat(payment_amount_vl1);
                    if (!isNaN(payment_amount1)) {
                        sum1 += payment_amount1;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum1, 2) + '</font>';
            }
        }

        ]]></script>

        <a:dataSets>
            <a:dataSet id="cf_direction_ds">
                <a:datas dataSource="/model/cf_direction_ds"/>
            </a:dataSet>
            <a:dataSet id="receipts_details_form_ds">
                <a:fields>
                    <a:field name="bp_name" autoComplete="true" lovGridHeight="350" lovHeight="500" lovService="cont.CON1240.con_bp_query" lovWidth="500" title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_name" to="bp_name"/>
                            <a:map from="bp_code" to="bp_code"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_number" lovGridHeight="400" lovHeight="500" lovLabelWidth="100" lovService="cont.CON1240.receipts_details_contract" lovWidth="500"  title="合同编号">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_agent_name" lovGridHeight="330" lovHeight="470" lovLabelWidth="120" lovService="cont.CON1240.con_bp_agent_query" lovWidth="700" title="代理商">
                        <a:mapping>
                            <a:map from="bp_agent_name" to="bp_agent_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_code"/>
                    <a:field name="cf_direction_n" displayField="code_value_name" options="cf_direction_ds"  returnField="cf_direction" valueField="code_value"/>
                    <a:field name="cf_direction"/>
                    <a:field name="lease_execution_date_from"/>
                    <a:field name="lease_execution_date_to"/>
                    <a:field name="__async__"  defaultValue="Y" prompt="异步导出"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="receipts_details_grid_ds" autoQuery="false"
                       model="cont.CON1240.receipts_details_query"
                       queryDataSet="receipts_details_form_ds" selectable="true" selectionModel="single" pageSize="100">
                <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="receipts_details_query" text="查询"/>
                <a:gridButton click="receipts_details_reset" text="重置"/>
                <a:gridButton click="receipts_details_export" text="导出"/>
            </a:screenTopToolbar>
            <a:form column="4" marginWidth="100" title="查询条件">
                <a:lov name="contract_number" bindTarget="receipts_details_form_ds" prompt="合同编号" />
                <a:lov name="bp_agent_name" bindTarget="receipts_details_form_ds" prompt="代理商名称" />
                <a:lov name="bp_name" bindTarget="receipts_details_form_ds" prompt="客户名称" />
                <a:datePicker name="lease_execution_date_from" bindTarget="receipts_details_form_ds" prompt="执行日期从"/>
                <a:datePicker name="lease_execution_date_to" bindTarget="receipts_details_form_ds" prompt="执行日期到"/>
            </a:form>
            <a:grid id="source_to_grid" bindTarget="receipts_details_grid_ds" navBar="true" height="400" marginWidth="100">
                <a:columns>
                    <a:column name="contract_number"  prompt="合同编号" width="120"/>
                    <a:column name="bp_name" prompt="客户名称" width="120"/>
                    <a:column name="bp_agent_name" prompt="代理商名称" width="120"/>
                    <!--<a:column name="cf_direction_n" prompt="方向" />-->
                    <a:column name="times" prompt="期数"/>
                    <a:column name="cf_item_n"  prompt="现金流项目" width="100" />
                    <a:column name="due_date"  prompt="应收日期" width="100" renderer="Leaf.formatDate" footerRenderer="summaryRenderer"/>
                    <a:column name="due_amount"  prompt="应收金额" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="principal"  prompt="应收本金" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="interest"  prompt="应收利息" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="received_amount"  prompt="实收金额" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="received_principal"  prompt="实收本金" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="received_interest"  prompt="实收利息" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <!--<a:column name="due_amount_penalty"  prompt="应收罚息" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>-->
                    <a:column name="received_amount_penalty"  prompt="实收罚息" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="delay_yn" prompt="是否逾期"/>
                    <a:column name="delay_dd" prompt="逾期天数"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
