<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LR  
    $Date: 2013-7-15 下午04:39:15  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true">
    <a:view>
        <a:link id="acr_invoice_apply_detail_link"
                url="${/request/@context_path}/modules/acr/ACR610/acr_invoice_apply_detail.lview"/>
        <a:link id="acr_invoice_apply_detail_readonly_link"
                url="${/request/@context_path}/modules/acr/ACR610/acr_invoice_apply_detail_wfl.lview"/>
        <a:link id="acr610_invoice_apply_status_change" model="acr.ACR610.acr_invoice_apply_query"
                modelaction="delete"/>
        <a:link id="acr_invoice_finish_print_link_id"
                url="${/request/@context_path}/modules/csh/CSH501/csh_payment_req_history_pdf_print.lsc"/>
        <script><![CDATA[

        function lock_current_window() {
            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
        }

        function unlock_current_window() {
            Leaf.Masker.unmask(Ext.getBody(), '${l:HLS.EXECUTING}');
        }

        function acr610_invoice_query() {
            $('acr610_invoice_result_ds').query();
        }

        function acr610_invoice_reset() {
            $('acr610_invoice_apply_query_ds').reset();
        }

        function acr610_grid_update(url) {
            var win = new Leaf.Window({
                id: 'acr_invoice_apply_detail_link_winid',
                params: {
                    winId: 'acr_invoice_apply_detail_link_winid'
                },
                url: url,
                title: '申请明细',
                fullScreen: true
            });
            win.on('close', function () {
                $('acr610_invoice_result_ds').query();
            });
        }

        function acr610_apply_num_render(value, record, name) {
            if (name == 'invoice_apply_num') {
                if (record.get('wfl_apply_status') == 'NEW') {
                    url = $('acr_invoice_apply_detail_link').getUrl() + '?invoice_apply_id=' + record.get('invoice_apply_id') + '&invoice_apply_num=' + record.get('invoice_apply_num') + '&invoice_apply_user_n=' + record.get('invoice_apply_user_n') + '&invoice_apply_date=' + record.get('invoice_apply_date');
                } else {
                    url = $('acr_invoice_apply_detail_readonly_link').getUrl() + '?invoice_apply_id=' + record.get('invoice_apply_id') + '&invoice_apply_num=' + record.get('invoice_apply_num') + '&invoice_apply_user_n=' + record.get('invoice_apply_user_n') + '&invoice_apply_date=' + record.get('invoice_apply_date') + '&button_flag=YES';
                }
                return '<a href="javascript:acr610_grid_update(\'' + url + '\');">' + value + '</a>';
            }
        }

        function acr610_formatMoney(value, record, name) {
            return Leaf.formatMoney(value);
        }

        function acr610_invoice_cancel() {
            var records = $('acr610_invoice_result_ds').getSelected();
            if (records.length == 0) {
                $L.showInfoMessage('提示', '请至少选择一条数据!');
                return;
            }
            var record = records[0];
            if (record.get('wfl_apply_status') != 'NEW') {
                $L.showInfoMessage('提示', '仅新建状态的申请单据可以取消!');
                return;
            }

            Leaf.showConfirm('提示', "确认执行该操作?", function () {
                lock_current_window();
                Leaf.request({
                    url: $('acr610_invoice_apply_status_change').getUrl(),
                    para: record.data,
                    success: function () {
                        unlock_current_window();
                        Leaf.SideBar.show({
                            msg: '操作成功',
                            duration: 2000
                        });
                        $('acr610_invoice_result_ds').query();
                    },
                    error: function () {
                        unlock_current_window();
                    },
                    scope: this
                });
            }, function () {
                unlock_current_window();

            });
        }

        function acr610_invoice_result_select(ds, record, bp_seq) {
            if (record.get('wfl_apply_status') != 'NEW') {
                document.getElementById("acr610_invoice_cancel_id").style.display = "none";
            } else {
                document.getElementById("acr610_invoice_cancel_id").style.display = "";
            }
            if (record.get('wfl_apply_status') == 'CANCEL') {
                document.getElementById("acr610_invoice_print_id").style.display = "none";
            } else {
                document.getElementById("acr610_invoice_print_id").style.display = "";
            }

        }

        function acr610_invoice_print() {
            var record = $('acr610_invoice_result_ds').getSelected()[0];
            var document_id = record.get('invoice_apply_id');
            var url_l = $('acr_invoice_finish_print_link_id').getUrl() + '?document_id=' + document_id + '&document_table=ACR_INVOICE_APPLY&batch_flag=Y&source_type=COMMON';
            var OpenWindow = window.open(href = url_l, target = "_blank");
        }

        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:dataSets>
            <a:dataSet id="acr610_invoice_apply_status_ds" lookupCode="WFL_STATUS"/>
            <a:dataSet id="acr610_invoice_apply_query_ds">
                <a:fields>
                    <a:field name="invoice_apply_num"/>
                    <a:field name="invoice_apply_date"/>
                    <a:field name="invoice_apply_user_n" lovGridHeight="320" lovHeight="500"
                             lovService="acr.ACR512.acr_invoice_sys_user_lov" lovWidth="500" title="开票人选择">
                        <a:mapping>
                            <a:map from="user_id" to="invoice_apply_user"/>
                            <a:map from="description" to="invoice_apply_user_n"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="invoice_apply_user"/>
                    <a:field name="wfl_apply_status_n" displayField="code_value_name"
                             options="acr610_invoice_apply_status_ds"
                             returnField="wfl_apply_status" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="acr610_invoice_result_ds" autoPageSize="true" autoQuery="true"
                       model="acr.ACR610.acr_invoice_apply_query"
                       queryUrl="${/request/@context_path}/autocrud/acr.ACR610.acr_invoice_apply_query/query?apply_mode=APPLY"
                       queryDataSet="acr610_invoice_apply_query_ds"
                       selectable="true" selectionModel="single">
                <a:events>
                    <a:event name="select" handler="acr610_invoice_result_select"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:toolbarButton click="acr610_invoice_reset" text="HLS.RESET"/>
                <a:toolbarButton click="acr610_invoice_query" text="HLS.QUERY"/>
                <a:toolbarButton id="acr610_invoice_print_id" click="acr610_invoice_print" text="HLS.PRINT"/>
                <a:toolbarButton id="acr610_invoice_cancel_id" click="acr610_invoice_cancel" text="取消申请"/>
            </a:screenTopToolbar>
            <a:form marginWidth="200" padding="0" title="销项发票申请">
                <a:hBox labelSeparator=" ">
                    <a:textField name="invoice_apply_num" bindTarget="acr610_invoice_apply_query_ds" prompt="申请编号"
                                 width="135"/>
                    <a:datePicker name="invoice_apply_date" bindTarget="acr610_invoice_apply_query_ds" prompt="申请时间"
                                  width="135"/>
                    <a:lov name="invoice_apply_user_n" bindTarget="acr610_invoice_apply_query_ds" prompt="申请人"
                           width="135"/>
                    <a:comboBox name="wfl_apply_status_n" bindTarget="acr610_invoice_apply_query_ds" prompt="申请状态"
                                width="135"/>
                </a:hBox>
            </a:form>
            <a:grid id="acr610_invoice_update_grid_ds" bindTarget="acr610_invoice_result_ds" marginHeight="135"
                    marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="invoice_apply_num" lock="true" prompt="申请编号" renderer="acr610_apply_num_render"
                              align="center" width="150"/>
                    <a:column name="invoice_apply_date" prompt="申请日期" align="center" width="100"/>
                    <a:column name="invoice_apply_user_n" prompt="申请人" align="center" width="100"/>
                    <a:column name="total_amount" prompt="开票总金额" align="right" renderer="acr610_formatMoney"
                              width="100"/>
                    <a:column name="net_amount" prompt="不含税总金额" align="right" renderer="acr610_formatMoney"
                              width="100"/>
                    <a:column name="tax_amount" prompt="税额总金额" align="right" renderer="acr610_formatMoney" width="150"/>
					<a:column name="invoice_kind_type_n" prompt="发票种类" align="center" width="150"/>
                    <a:column name="wfl_apply_status_n" prompt="申请状态" align="center" width="150"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>