<?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:init-procedure>
        <a:model-query model="cont.CON620.get_sys_role" rootPath="role_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="acr_invoice_apply_detail_link"
                url="${/request/@context_path}/modules/acr/ACR514/acr_invoice_reverse_apply_temp_detail.lview"/>
        <a:link id="acr514_invoice_apply_status_change" model="acr.acr514.acr_invoice_apply_query"
                modelaction="delete"/>

        <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 acr514_invoice_query() {
            $('acr514_invoice_result_ds').query();
        }

        function acr514_invoice_reset() {
            $('acr514_invoice_apply_query_ds').reset();
        }

        function acr514_grid_update(record_id, ds_id) {
            debugger;
            var readOnly_flag = 'N';
            var url = $('acr_invoice_apply_detail_link').getUrl();
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['winId'] = 'acr_invoice_apply_detail_link_winid';
            if (("${/model/role_info/record/@role_code}" != "0014" && record.get('vat_interface_status') == 'TRANSFERED')
                || (record.get('reversing_flag') == 'Y')) {
                readOnly_flag = 'Y';
            }
            param['readOnly_flag'] = readOnly_flag;
            var win = new Leaf.Window({
                id: 'acr_invoice_apply_detail_link_winid',
                params: param,
                url: url,
                title: '申请明细',
                fullScreen: true
            });
            win.on('close', function () {
                $('acr514_invoice_result_ds').query();
            });
        }

        function acr514_apply_num_render(value, record, name) {
            if (name == 'invoice_apply_num') {
                return '<a href="javascript:acr514_grid_update(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
            }
        }

        function acr514_formatMoney(value, record, name) {
            return Leaf.formatNumber(value);
        }

        // function acr514_invoice_cancel() {
        //     var records = $('acr514_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: $('acr514_invoice_apply_status_change').getUrl(),
        //             para: record.data,
        //             success: function () {
        //                 unlock_current_window();
        //                 Leaf.SideBar.show({
        //                     msg: '操作成功',
        //                     duration: 2000
        //                 });
        //                 $('acr514_invoice_result_ds').query();
        //             },
        //             error: function () {
        //                 unlock_current_window();
        //             },
        //             scope: this
        //         });
        //     }, function () {
        //         unlock_current_window();
        //
        //     });
        // }

        function acr514_invoice_result_select(ds, record, bp_seq) {
            // if(record.get('wfl_apply_status') != 'NEW'){
            //     document.getElementById("acr514_invoice_cancel_id").style.display = "none";
            // }else{
            //     document.getElementById("acr514_invoice_cancel_id").style.display = "";
            // }
            // if(record.get('wfl_apply_status') == 'CANCEL'){
            //     document.getElementById("acr514_invoice_print_id").style.display = "none";
            // }else{
            //     document.getElementById("acr514_invoice_print_id").style.display = "";
            // }

        }

        // function acr514_invoice_print(){
        //     var record = $('acr514_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="acr514_invoice_apply_status_ds" lookupCode="WFL_STATUS"/>
            <a:dataSet id="acr514_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="acr514_invoice_apply_status_ds"
                             returnField="wfl_apply_status" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="acr514_invoice_result_ds" autoPageSize="true" autoQuery="true"
                       model="acr.ACR514.acr_invoice_reverse"
                       queryUrl="${/request/@context_path}/autocrud/acr.ACR514.acr_invoice_reverse/query?apply_mode=APPLY"
                       queryDataSet="acr514_invoice_apply_query_ds"
                       selectable="true" selectionModel="single">
                <!--                <a:events>-->
                <!--                    <a:event name="select" handler="acr514_invoice_result_select"/>-->
                <!--                </a:events>-->
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:toolbarButton click="acr514_invoice_reset" text="HLS.RESET"/>
                <a:toolbarButton click="acr514_invoice_query" text="HLS.QUERY"/>
                <!--                <a:toolbarButton id="acr514_invoice_print_id" click="acr514_invoice_print" text="HLS.PRINT"/>-->
                <!--                <a:toolbarButton id="acr514_invoice_cancel_id" click="acr514_invoice_cancel" text="取消申请"/>-->
            </a:screenTopToolbar>
            <a:form marginWidth="200" padding="0" title="销项发票申请">
                <a:hBox labelSeparator=" ">
                    <a:textField name="invoice_apply_num" bindTarget="acr514_invoice_apply_query_ds" prompt="申请编号"
                                 width="135"/>
                    <a:datePicker name="invoice_apply_date" bindTarget="acr514_invoice_apply_query_ds" prompt="申请时间"
                                  width="135"/>
                    <a:lov name="invoice_apply_user_n" bindTarget="acr514_invoice_apply_query_ds" prompt="申请人"
                           width="135"/>
                    <a:comboBox name="wfl_apply_status_n" bindTarget="acr514_invoice_apply_query_ds" prompt="申请状态"
                                width="135"/>
                </a:hBox>
            </a:form>
            <a:grid id="acr514_invoice_update_grid_ds" bindTarget="acr514_invoice_result_ds" marginHeight="120"
                    marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="invoice_apply_num" lock="true" prompt="申请编号" renderer="acr514_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="acr514_formatMoney"
                              width="100"/>
                    <a:column name="net_amount" prompt="不含税总金额" align="right" renderer="acr514_formatMoney"
                              width="100"/>
                    <a:column name="tax_amount" prompt="税额总金额" align="right" renderer="acr514_formatMoney" width="150"/>
                    <a:column name="vat_interface_status_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>