<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Eugene Song $
    $Date: 2018年11月2日10:19:17 $
    $Revision: 1.1 $
    $Purpose: 网银代扣管理
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:view>
        <a:link id="hls_ebank_create_link" model="ccb.CCB600.hls_ebank_batch" modelaction="execute"/>
        <a:link id="query_ebank_detail_link"
                url="${/request/@context_path}/modules/ccb/CCB600/ccb_ebank_detail_query.lview"/>
        <a:link id="modify_ebank_detail_link"
                url="${/request/@context_path}/modules/ccb/CCB600/ccb_ebank_detail.lview"/>
        <script type="text/javascript"><![CDATA[

        function return_batch() {
            $('${/parameter/@winid}').close();
        }

        function batch_detail_renderer(value, record, name) {
            if ('${/parameter/@status}' == 'NEW') {
                return '<a href="javascript:open_batch_detail_modify_window(' + record.get('hd_id') + ')">' + '${l:PROMPT.DETAIL}' + '</a>';
            } else {
                return '<a href="javascript:open_batch_detail_query_window(' + record.get('hd_id') + ')">' + '${l:PROMPT.DETAIL}' + '</a>';
            }
        }

        function hls_ccb_merge_result() {
            var hd_id = $('hls_ccb_grid_ln_ds').getAt(0).get('hd_id') || -1;
            if ('${/parameter/@status}' == 'NEW') {
                open_batch_detail_modify_window(hd_id);
            } else {
                open_batch_detail_query_window(hd_id);
            }
        }

        function open_batch_detail_query_window(hd_id) {
            var win = new Leaf.Window({
                id: 'batch_link_query_winId',
                url: $('query_ebank_detail_link').getUrl(),
                params: {
                    hd_id: hd_id,
                    winid: 'batch_link_query_winId'
                },
                title: '代扣指令明细',
                draggable: true,
                width: 1100,
                height: 680
            });
        }


        function open_batch_detail_modify_window(hd_id) {
            var win = new Leaf.Window({
                id: 'batch_modify_link_winId',
                url: $('modify_ebank_detail_link').getUrl(),
                params: {
                    hd_id: hd_id,
                    winid: 'batch_modify_link_winId'
                },
                title: '代扣指令明细',
                draggable: true,
                width: 900,
                height: 680
            });
        }

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

        function sumAmount(record, name) {
            if (name == 'cf_item_desc') {
                return '<font color=red>合计:</font>';
            }
            if (name == 'due_amount' || name == 'manual_amount') {
                return '<font color=red>' + colum_caculateTotal(record, name) + '</font>';
            }
        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="rates_type_combobox_ds">
                <a:datas dataSource="/model/ratesType"/>
            </a:dataSet>
            <a:dataSet id="pay_methods_ds">
                <a:datas>
                    <a:record code_value="AGRI_THREE" code_value_name="农行扣款(三方)"/>
                    <a:record code_value="CCB_THREE" code_value_name="建行扣款(三方)"/>
                    <a:record code_value="AGRI_TWO" code_value_name="农行扣款(两方)"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="hls_ccb_form_create_ds" autoQuery="true" model="ccb.CCB600.hls_ebank_batch"
                       queryUrl="${/request/@context_path}/autocrud/ccb.CCB600.hls_ebank_batch/query?batch_id=${/parameter/@batch_id}">
                <a:fields>
                    <a:field name="bank_account_num" autoComplete="true" lovGridHeight="350" lovHeight="550"
                             lovService="ccb.CCB600.hls_ebank_bank" lovWidth="1000" readOnly="true"
                             title="银行账户" prompt="银行账户">
                        <a:mapping>
                            <a:map from="bank_account_name" to="bank_account_name"/>
                            <a:map from="bank_account_num" to="bank_account_num"/>
                            <a:map from="bank_short_name" to="bank_name"/>
                            <a:map from="bank_account_id" to="bank_account_id"/>
                            <a:map from="currency_code" to="currency"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="currency_name" readOnly="true"/>
                    <a:field name="bank_account_name" readOnly="true"/>
                    <a:field name="bank_name" readOnly="true"/>
                    <a:field name="pay_method_desc" readOnly="true" prompt="支付方式" displayField="code_value_name" options="pay_methods_ds" returnField="pay_method" valueField="code_value"/>
                    <a:field name="pay_method"/>
                    <a:field name="currency" readOnly="true"/>
                    <a:field name="due_date" required="true" prompt="应收日期" readOnly="true"/>
                    <a:field name="merger_rules" defaultValue="NONE" prompt="" readOnly="true"/>
                    <a:field name="payment_amount_from" readOnly="true"/>
                    <a:field name="payment_amount_to" readOnly="true"/>
                </a:fields>
            </a:dataSet>

            <a:dataSet id="hls_ccb_grid_create_ds" autoCount="true" autoQuery="true" fetchAll="false"
                       model="ccb.CCB600.hls_ebank_batch_hd" pageSize="15"
                       queryUrl="${/request/@context_path}/autocrud/ccb.CCB600.hls_ebank_batch_hd/query?batch_id=${/parameter/@batch_id}"
                       selectable="true">
                <a:fields>
                    <a:field name="num" readOnly="true"/>
                </a:fields>
            </a:dataSet>

        </a:dataSets>

        <a:dataSet id="hls_ccb_grid_ln_ds" fetchAll="true" autoQuery="true" model="ccb.CCB600.hls_ebank_batch_ln"
                   queryUrl="${/request/@context_path}/autocrud/ccb.CCB600.hls_ebank_batch_ln/query?batch_id=${/parameter/@batch_id}">
            <a:fields>
                <a:field name="cashflow_id"/>
                <a:field name="bp_tenant_name" readOnly="true"/>
                <a:field name="contract_id"/>
                <a:field name="contract_number" readOnly="true"/>
                <a:field name="times" readOnly="true"/>
                <a:field name="cf_item" readOnly="true"/>
                <a:field name="due_amount" readOnly="true"/>
                <a:field name="manual_amount" required="true" prompt="扣款金额"/>
                <a:field name="description"/>
            </a:fields>
        </a:dataSet>

        <a:screenBody>
            <a:screenTopToolbar height="29">
                <a:gridButton click="return_batch" text="返回"/>
            </a:screenTopToolbar>

            <a:fieldSet title="本方账户" column="3">
                <a:lov name="bank_account_num" bindTarget="hls_ccb_form_create_ds" prompt="银行账户"/>
                <a:textField name="bank_account_name" bindTarget="hls_ccb_form_create_ds" prompt="账户名"/>
                <a:textField name="bank_name" bindTarget="hls_ccb_form_create_ds" prompt="银行"/>
                <a:textField name="currency_name" bindTarget="hls_ccb_form_create_ds" prompt="币种"/>
                <a:comboBox name="pay_method_desc" bindTarget="hls_ccb_form_create_ds" prompt="支付方式"/>
            </a:fieldSet>
            <a:fieldSet title="合并规则" column="2">
                <a:radio name="merger_rules" bindTarget="hls_ccb_form_create_ds" layout="horizontal" width="600">
                    <a:items>
                        <a:item label="按合同" value="CONTRACT"/>
                        <a:item label="按期数" value="TIMES"/>
                        <a:item label="不合并" value="NONE"/>
                    </a:items>
                </a:radio>
            </a:fieldSet>
            <!--            <a:fieldSet title="筛选条件" column="2">-->
            <!--                <a:numberField name="payment_amount_from" bindTarget="hls_ccb_form_create_ds" prompt="付款金额从"/>-->
            <!--                <a:numberField name="payment_amount_to" bindTarget="hls_ccb_form_create_ds" prompt="付款金额到"/>-->
            <!--            </a:fieldSet>-->

            <!--            <a:grid id="hls_ccb_create_grid" bindTarget="hls_ccb_grid_create_ds" height="200" width="800" navBar="true">-->
            <!--                <a:columns>-->
            <!--                    <a:column name="num" align="left" prompt="序号" width="80"/>-->
            <!--                    <a:column name="detail" align="center" prompt="明细" renderer="batch_detail_renderer" width="100"/>-->
            <!--                </a:columns>-->
            <!--            </a:grid>-->
            <a:grid id="hls_ccb_ln_grid" bindTarget="hls_ccb_grid_ln_ds" height="300" width="800" navBar="true">
                <a:toolBar>
                    <a:button click="hls_ccb_merge_result" text="合并结果"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="bp_tenant_name" prompt="客户名称" align="center"/>
                    <a:column name="contract_number" prompt="合同号" align="center"/>
                    <a:column name="times" prompt="期数" align="center"/>
                    <a:column name="due_date" prompt="应付日期" align="center" renderer="Leaf.formatDate"/>
                    <a:column name="cf_item_desc" prompt="现金流类型" align="center" footerRenderer="sumAmount"/>
                    <a:column name="due_amount" prompt="应收金额" align="right" renderer="Leaf.formatMoney"
                              footerRenderer="sumAmount"/>
                    <a:column name="manual_amount" prompt="扣款金额" align="right" renderer="Leaf.formatMoney"
                              footerRenderer="sumAmount"/>
                    <a:column name="description" prompt="备注" width="200"/>
                </a:columns>
            </a:grid>

            <a:fieldSet title="应收日期" column="2">
                <a:datePicker name="due_date" bindTarget="hls_ccb_form_create_ds" prompt="应收日期"/>
            </a:fieldSet>
        </a:screenBody>
    </a:view>
</a:screen>