<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang 
    $Date: 2015-8-17 下午02:10:01  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="gld.gld_currency_vl" rootPath="acr512_currency_list"/>
        <a:model-query fetchAll="true" model="basic.hls_sys_time_default_value" rootPath="sys_time_default_value_list"/>
    </a:init-procedure>
    <a:view>
        <a:link id="csh_payment_req_cat_cashflow_id_link" url="${/request/@context_path}/modules/csh/CSH506/csh_payment_req_cat_cashflow_id.lsc"/>
        <a:link id="csh506_csh_payment_req_link_id" url="${/request/@context_path}/modules/csh/CSH501/csh_payment_req.lview"/>
        <a:link id="csh506_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <style><![CDATA[
        	#sum_pay_amount_numberfield_id input{
        	    background:#FF9965
        	}
        ]]></style>
        <script type="text/javascript"><![CDATA[
            function csh506_lock_current_window() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            }
            
            function csh506_unlock_current_window() {
                Leaf.Masker.unmask(Ext.getBody());
            }
            
            function confirmFun() {
                csh506_lock_current_window();
                var records = $('csh_payment_req_selectedDs').getSelected();
                var param = {};
                param['csh_req_type'] = 'CON_CONTRACT_CASHFLOW';
                var cashflow_id_list = [];
                if (!records.length) {
                    Leaf.showMessage('${l:PROMPT_MESSAGE}', '未选中行', null, 250, 100);
                    csh506_unlock_current_window();
                } else {
                    for (i = 0;i < records.length;i++) {
                        var record = records[i];
                        var arr = {};
                        arr['_status'] = 'insert';
                        arr['cashflow_id'] = record.get('cashflow_id');
                        arr['contract_id'] = record.get('contract_id');
                        arr['csh_req_type'] = 'CON_CONTRACT_CASHFLOW';
                        arr['amt'] = record.get('real_pay_amount');
                        cashflow_id_list.push(arr);
                    }
                    param['details'] = cashflow_id_list;
                    Leaf.request({
                        url: $('csh_payment_req_cat_cashflow_id_link').getUrl(),
                        para: param,
                        success: function(res) {
                            if (res.result.payment_req_id) {
                                var param = {};
                                param['function_usage'] = 'UPDATE';
                                param['document_category'] = 'PAYMENT_REQ';
                                param['payment_req_id'] = res.result.payment_req_id;
                                param['business_type'] = 'PAYMENT';
                                param['function_code'] = 'CSH501D';
                                param['winid'] = 'csh_payment_update_window';
                                param['url_title'] = '付款申请';
                                hls_doc_get_layout_code('csh506_get_layout_code_link_id', param, 'csh506_csh_payment_req_link_id', 'csh_payment_req_selectedDs');
                                var sum_record = $('csh_payment_req_cat_sum_pay_amount').getCurrentRecord();
                                sum_record.set('sum_pay_amount', null);
                            } else {
                                $('csh_payment_req_selectedDs').query();
                                Leaf.showMessage('${l:PROMPT}', '数据存在异常请联系管理员!');
                            }
                            csh506_unlock_current_window();
                        },
                        failure: function() {
                            csh506_unlock_current_window();
                        },
                        error: function() {
                            csh506_unlock_current_window();
                        },
                        scope: this
                    });
                }
            }
            
            
            function payment_req_query() {
                $('csh_payment_req_selectedDs').query();
            }
            
            function csh506_payment_maintain_update(ds, record, name, value, oldvalue) {
                if (name == 'pay_contract_from') {
                    if (record.get('pay_contract_to') == 'undefined' || record.get('pay_contract_to') == null || record.get('pay_contract_to') == '') {
                        record.set('pay_contract_to', value);
                    }
                } else if (name == 'pay_contract_to') {
                    if (record.get('pay_contract_from') == 'undefined' || record.get('pay_contract_from') == null || record.get('pay_contract_from') == '') {
                        record.set('pay_contract_from', value);
                    }
                } else if (name == 'due_date_from') {
                    if (record.get('due_date_to') == 'undefined' || record.get('due_date_to') == null || record.get('due_date_to') == '') {
                        record.set('due_date_to', value);
                    }
                } else if (name == 'due_date_to') {
                    if (record.get('due_date_from') == 'undefined' || record.get('due_date_from') == null || record.get('due_date_from') == '') {
                        record.set('due_date_from', value);
                    }
                }
            
            }
            
            function csh506_payment_reset() {
                $('csh_payment_req_query_ds').reset();
            }
            
            function csh_payment_req_selectedDs_select(ds, record) {
                var sum_record = $('csh_payment_req_cat_sum_pay_amount').getCurrentRecord();
                var sum_pay_amount = sum_record.get('sum_pay_amount') || 0;
                sum_record.set('sum_pay_amount', plus(sum_pay_amount, record.get('real_pay_amount') || 0));
            }
            
            function csh_payment_req_selectedDs_unselect(ds, record) {
                var sum_record = $('csh_payment_req_cat_sum_pay_amount').getCurrentRecord();
                var sum_pay_amount = sum_record.get('sum_pay_amount') || 0;
                sum_record.set('sum_pay_amount', minus(sum_pay_amount, record.get('real_pay_amount') || 0));
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CSH501"/>
        <a:dataSets>
            <a:dataSet id="csh_payment_req_cat_sum_pay_amount" autoCreate="true">
                <a:fields>
                    <a:field name="sum_pay_amount" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="acr512_currency_ds">
                <a:datas dataSource="/model/acr512_currency_list"/>
            </a:dataSet>
            <a:dataSet id="csh_payment_req_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="due_date_to" defaultValue="${/model/sys_time_default_value_list/record/@now_time}"/>
                    <a:field name="project_number_from" lovGridHeight="300" lovHeight="450" lovService="prj.PRJ501.prj_project_for_lov" lovWidth="500" title="ACR510.FIELD.PROJECT_NUMBER_FROM">
                        <a:mapping>
                            <a:map from="project_number" to="project_number_from"/>
                            <a:map from="project_name" to="project_name_from"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="project_number_to" lovGridHeight="300" lovHeight="450" lovService="prj.PRJ501.prj_project_for_lov" lovWidth="500" title="ACR510.FIELD.PROJECT_NUMBER_TO">
                        <a:mapping>
                            <a:map from="project_number" to="project_number_to"/>
                            <a:map from="project_name" to="project_name_to"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="cf_item_desc" lovGridHeight="300" lovHeight="500" lovService="hls.HLS005.hls_cashflow_item_v_lov?cf_direction=OUTFLOW" lovWidth="850" title="ACR510.ACR_INVOICE_CONTRACT_CF_V.CF_ITEM_DESC">
                        <a:mapping>
                            <a:map from="cf_item" to="cf_item"/>
                            <a:map from="cf_item_desc" to="cf_item_desc"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_code" lovGridHeight="300" lovHeight="450" lovLabelWidth="120" lovService="basic.hls_bp_master_v_for_lov" lovWidth="600" title="承租人">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id"/>
                            <a:map from="bp_code" to="bp_code"/>
                            <a:map from="bp_name" to="bp_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_name" readOnly="true"/>
                    <a:field name="bp_name_tenant" readOnly="true"/>
                    <a:field name="bp_code_tenant" lovGridHeight="300" lovHeight="450" lovLabelWidth="120" lovService="basic.hls_bp_master_v_for_lov" lovWidth="600" title="HLS.TENANT_NUMBER_FROM">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code_tenant"/>
                            <a:map from="bp_name" to="bp_name_tenant"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_code_tenant_from" lovGridHeight="300" lovHeight="450" lovLabelWidth="120" lovService="basic.hls_bp_master_v_for_lov" lovWidth="600" title="HLS.TENANT_NUMBER_FROM">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code_tenant_from"/>
                            <a:map from="bp_name" to="bp_name_tenant_from"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_code_tenant_to" lovGridHeight="300" lovHeight="450" lovLabelWidth="120" lovService="basic.hls_bp_master_v_for_lov" lovWidth="600" title="HLS.TENANT_NUMBER_TO">
                        <a:mapping>
                            <a:map from="bp_code" to="bp_code_tenant_to"/>
                            <a:map from="bp_name" to="bp_name_tenant_to"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="currency_name" displayField="currency_name" options="acr512_currency_ds" returnField="currency" valueField="currency_code"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="csh506_payment_maintain_update"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="csh_payment_req_selectedDs" autoPageSize="true" autoQuery="true" model="csh.CSH506.csh_payment_req_cat_cashflow_source" queryDataSet="csh_payment_req_query_ds" selectable="true">
                <a:events>
                    <a:event name="query" handler="aut_authority_list_validate_query"/>
                    <a:event name="select" handler="csh_payment_req_selectedDs_select"/>
                    <a:event name="unselect" handler="csh_payment_req_selectedDs_unselect"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton id="csh511_receipt_back_id" click="payment_req_query" text="HAP_QUERY"/>
                <a:gridButton click="csh506_payment_reset" text="HLS.RESET"/>
                <a:gridButton id="csh511_receipt_posted_id" click="confirmFun" text="HAP_CONFIRM"/>
            </a:screenTopToolbar>
            <a:hBox>
                <a:form column="4" labelWidth="100" title="CSH501.CSH_REQ_CREATE">
                    <a:textField name="pay_contract_from" bindTarget="csh_payment_req_query_ds" prompt="合同编号从" width="150"/>
                    <a:textField name="pay_contract_to" bindTarget="csh_payment_req_query_ds" prompt="合同编号至" width="150"/>
                    <a:datePicker name="due_date_from" bindTarget="csh_payment_req_query_ds" prompt="CSH501.CSH_DUE_DATE_FROM" width="150"/>
                    <a:datePicker name="due_date_to" bindTarget="csh_payment_req_query_ds" prompt="CSH501.CSH_DUE_DATE_TO" width="150"/>
                    <a:lov name="bp_code_tenant" bindTarget="csh_payment_req_query_ds" prompt="承租人">
                        <a:events>
                            <a:event name="focus" handler="function(object){on_std_focus(object,&apos;BP&apos;)}"/>
                        </a:events>
                    </a:lov>
                    <a:textField name="serial_number" bindTarget="csh_payment_req_query_ds" prompt="机编号">
                        <a:events>
                            <a:event name="focus" handler="function(object){on_std_focus(object,&apos;BP&apos;)}"/>
                        </a:events>
                    </a:textField>
                    <a:numberField name="due_amount_from" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_query_ds" prompt="CSH501.CSH_DUE_AMOUNT_FROM" width="150"/>
                    <a:numberField name="due_amount_to" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_query_ds" prompt="CSH501.CSH_DUE_AMOUNT_TO" width="150"/>
                    <a:lov name="bp_code" bindTarget="csh_payment_req_query_ds" prompt="付款对象">
                        <a:events>
                            <a:event name="focus" handler="function(object){on_std_focus(object,&apos;BP&apos;)}"/>
                        </a:events>
                    </a:lov>
                    <a:textField name="bp_name" bindTarget="csh_payment_req_query_ds" prompt="付款对象"/>
                    <a:lov name="cf_item_desc" bindTarget="csh_payment_req_query_ds" prompt="HLS.PAYMENT_PROJECT"/>
                    <a:comboBox name="currency_name" bindTarget="csh_payment_req_query_ds" prompt="HLS.CURRENCY" width="150"/>
                </a:form>
                <a:vBox>
                    <div style="height:46px;"/>
                    <a:form column="1" labelWidth="100" title="实际支付金额合计">
                        <a:numberField name="sum_pay_amount" id="sum_pay_amount_numberfield_id" allowDecimals="true" allowFormat="true" bindTarget="csh_payment_req_cat_sum_pay_amount" prompt="金额合计"/>
                    </a:form>
                </a:vBox>
            </a:hBox>
            <a:grid id="csh_payment_req_maintain_grid_ds" bindTarget="csh_payment_req_selectedDs" marginHeight="230" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="contract_number" prompt="合同编号" width="100"/>
                    <a:column name="bp_id_tenant_n" prompt="承租人" width="120"/>
                    <a:column name="serial_number" prompt="机编号" width="90"/>
                    <a:column name="contract_name" width="150"/>
                    <!-- <a:column name="times" align="cneter" width="40"/> -->
                    <!-- <a:column name="project_name" width="170"/> -->
                    <a:column name="bp_name" width="170"/>
                    <a:column name="cf_item_desc" width="80"/>
                    <a:column name="due_amount" align="right" renderer="Leaf.formatMoney" width="110"/>
                    <!-- <a:column name="currency" width="60"/> -->
                    <a:column name="residual_amount" align="right" renderer="Leaf.formatMoney" width="110"/>
                    <a:column name="dd_amount" align="right" prompt="抵扣金额" renderer="Leaf.formatMoney"/>
                    <a:column name="real_pay_amount" align="right" prompt="实际支付金额" renderer="Leaf.formatMoney"/>
                    <a:column name="applied_pay_amount" align="right" prompt="CSH501.CSH_APPLIED_PAYMENT_AMOUNT" renderer="Leaf.formatMoney" width="110"/>
                    <a:column name="due_date"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>