<?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_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 == "write_off_classification_n") {
                return '<font color="red">合计:</font>';
            }
            if (name == "write_off_due_amount") {
                for (var i = 0; i < datas.length; i++) {
                    var record = datas[i];
                    var payment_amount_vl = record.get("write_off_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 == "write_off_principal") {
                for (var i = 0; i < datas.length; i++) {
                    var record = datas[i];
                    var payment_amount_vl = record.get("write_off_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 == "write_off_interest") {
                for (var j = 0; j < datas.length; j++) {
                    var record1 = datas[j];
                    var payment_amount_vl1 = record1.get("write_off_interest");
                    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="receipts_details_form_ds">
                <a:fields>
                    <a:field name="bp_name" autoComplete="true" lovGridHeight="350" lovHeight="500" lovService="cont.CON1250.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.CON1250.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.CON1250.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="journal_date_from" defaultValue="${/model/sys_default_time/record/@month_first_day}"/>
                    <a:field name="journal_date_to" defaultValue="${/model/sys_default_time/record/@now_date}"/>
                    <a:field name="__async__"  defaultValue="Y" prompt="异步导出"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="receipts_details_grid_ds" autoQuery="false"
                       model="cont.CON1250.receipts_detail_write"
                       queryDataSet="receipts_details_form_ds" selectable="true" selectionModel="single" autoPageSize="false" 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_name" bindTarget="receipts_details_form_ds" prompt="客户名称" />
                <a:lov name="bp_agent_name" bindTarget="receipts_details_form_ds" prompt="代理商名称" />
                <a:textField name="transaction_num" bindTarget="receipts_details_form_ds" prompt="现金事务编号" />
                <a:datePicker name="transaction_date_from" bindTarget="receipts_details_form_ds" prompt="收款日期从" />
                <a:datePicker name="transaction_date_to" bindTarget="receipts_details_form_ds" prompt="收款日期到" />
                <a:datePicker name="due_date_from" bindTarget="receipts_details_form_ds" prompt="应收日期从" />
                <a:datePicker name="due_date_to" bindTarget="receipts_details_form_ds" prompt="应收日期到" />
                <a:datePicker name="journal_date_from" bindTarget="receipts_details_form_ds" prompt="核销日期从" />
                <a:datePicker name="journal_date_to" bindTarget="receipts_details_form_ds" prompt="核销日期到" />
                <a:numberField name="csh_write_off_amount_sum_from" bindTarget="receipts_details_form_ds" prompt="总核销金额从"/>
                <a:numberField name="csh_write_off_amount_sum_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="transaction_date"  prompt="收款日期" width="100" renderer="Leaf.formatDate"/>
                    <a:column name="cf_item_n" prompt="核销现金流" />
                    <a:column name="times" prompt="核销期数" width="80"/>
<!--                    <a:column name="write_off_classification_n"  prompt="核销分类" width="100" footerRenderer="summaryRenderer"/>-->
                    <a:column name="write_off_due_amount"  prompt="核销金额" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="write_off_principal"  prompt="核销本金" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="write_off_interest"  prompt="核销利息" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                    <a:column name="due_date"  prompt="应收日期" width="100" renderer="Leaf.formatDate"/>
                    <a:column name="journal_date"  prompt="核销基准日期" width="100" renderer="Leaf.formatDate"/>
                    <a:column name="write_off_date"  prompt="核销日期" width="100" renderer="Leaf.formatDate"/>
                    <a:column name="transaction_num"  prompt="现金事务编号" width="100"/>
                    <a:column name="csh_write_off_amount_sum"  prompt="总核销金额" width="100" renderer="Leaf.formatMoney" footerRenderer="summaryRenderer"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
