<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: lpc 9874
    $Date: 2017/11/20 14:35:56 $
    $Revision: 1.0 $
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure><![CDATA[     
    ]]></a:init-procedure>
    <a:view>
        <a:link id="insert_cashflow_req_link" model="cont.CON355.cashflow_req" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
            function cashflow_req_add() {
                $('cashflow_req_grid').showEditorByRecord($('cashflow_req_ds').create());
            }
            
            function cashflow_req_close() {
                $('cashflow_req_id').close();
            }
            
            function cashflow_req_submit() {
                $('cashflow_req_ds').submit();
            }
            
            function cashflow_req_delete() {
               var ds = $('cashflow_req_ds');
                var records = ds.getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                    return;
                }
                Leaf.showConfirm('${l:HLS.PROMPT}', '是否删除现金流？', function() {
                    var datas = [];
                    for (var i = 0;i < records.length;i++) {
                        var obj = {};
                        obj['contract_id'] = records[i].get('contract_id');
                        obj['cashflow_id'] = records[i].get('cashflow_id');
                        obj['_status'] = 'delete';
                        datas[i] = obj;
                    }
                    Leaf.request({
                        url: $('insert_cashflow_req_link').getUrl(),
                        para: datas,
                        success: function() {
                            Leaf.SideBar.show({
                                msg: '操作成功',
                                duration: 2000
                            });
                            $('cashflow_req_ds').query();
                        },
                        scope: this
                    });
                });
            }
            
            function cashflow_req_cashflow() {
                var ds = $('cashflow_req_ds');
                var records = ds.getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                    return;
                }
                Leaf.showConfirm('${l:HLS.PROMPT}', '是否确定同步至现金流表？', function() {
                    var datas = [];
                    for (var i = 0;i < records.length;i++) {
                        var obj = {};
                        obj['contract_id'] = records[i].get('contract_id');
                        obj['cashflow_id'] = records[i].get('cashflow_id');
                        obj['_status'] = 'update';
                        datas[i] = obj;
                    }
                    Leaf.request({
                        url: $('insert_cashflow_req_link').getUrl(),
                        para: datas,
                        success: function() {
                            Leaf.SideBar.show({
                                msg: '操作成功',
                                duration: 2000
                            });
                            $('cashflow_req_ds').query();
                        },
                        scope: this
                    });
                });
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="cf_direction_ds" lookupCode="CF_DIRECTION"/>
            <a:dataSet id="cf_status_ds" lookupCode="HLS005_CF_STATUS"/>
            <a:dataSet id="cashflow_req_ds" autoQuery="true" fetchAll="false" model="cont.CON355.con_contract_cashflow_req" pageSize="15" queryUrl="${/request/@context_path}/autocrud/cont.CON355.con_contract_cashflow_req/query?contract_id=${/parameter/@contract_id}" selectable="true" selectionModel="multiple">
                <a:fields>
                    <a:field name="contract_id" defaultValue="${/parameter/@contract_id}"/>
                    <a:field name="cf_direction" defaultValue="INFLOW"/>
                    <a:field name="cf_direction_n" defaultValue="收" displayField="code_value_name" options="cf_direction_ds" required="true" returnField="cf_direction" valueField="code_value"/>
                    <a:field name="cf_status" defaultValue="RELEASE"/>
                    <a:field name="cf_status_n" defaultValue="下达" displayField="code_value_name" options="cf_status_ds" returnField="cf_status" valueField="code_value"/>
                    <a:field name="cf_item_n" lovHeight="500" lovService="cont.CON355.hls_billing_method_cf_for_lov" lovWidth="550" prompt="现金流项目" required="true" title="现金流项目">
                        <a:mapping>
                            <a:map from="cf_item" to="cf_item"/>
                            <a:map from="description" to="cf_item_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="due_date"/>
                    <a:field name="due_amount"/>
                    <a:field name="write_off_flag" defaultValue="NOT"/>
                    <a:field name="write_off_flag_n" defaultValue="未核销"/>
                    <a:field name="insert_flag" defaultValue="N"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="cashflow_req_close" text="HLS.EXIT"/>
                <a:gridButton click="cashflow_req_add" text="HLS.NEW"/>
                <a:gridButton click="cashflow_req_delete" text="HLS.DELETE"/>
                <a:gridButton click="cashflow_req_submit" text="HLS.SAVE"/>
                <a:gridButton click="cashflow_req_cashflow" text="费用确认"/>
            </a:screenTopToolbar>
            <a:grid id="cashflow_req_grid" bindTarget="cashflow_req_ds" height="450" marginWidth="100" navBar="true">
                <!-- <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="delete"/>
                    <a:button type="save"/>
                </a:toolBar> -->
                <a:columns>
                    <a:column name="cf_direction_n" align="center" prompt="收/付" width="150"/>
                    <a:column name="cf_status_n" align="center" prompt="现金流状态" width="150"/>
                    <a:column name="cf_item_n" align="center" editor="cashflow_req_lov" prompt="现金流项目" width="200"/>
                    <a:column name="due_date" align="center" editor="cashflow_req_dp" prompt="支付日" renderer="Leaf.formatDate" width="150"/>
                    <a:column name="due_amount" align="center" editor="cashflow_req_nf" prompt="应收金额" renderer="Leaf.formatMoney" width="200"/>
                    <a:column name="write_off_flag_n" align="center" prompt="核销标志" width="200"/>
                </a:columns>
                <a:editors>
                    <a:lov id="cashflow_req_lov"/>
                    <a:datePicker id="cashflow_req_dp"/>
                    <a:numberField id="cashflow_req_nf"/>
                    <a:textField id="cashflow_req_tf"/>
                    <a:checkBox id="cashflow_req_cb"/>
                    <a:comboBox id="cashflow_req_combox"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
