<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LR
    $Date: 2013-7-18 上午09:34:43
    $Revision: 1.0
    $Purpose:
-->
<a:screen xmlns:s="leaf.plugin.script" 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="acr515_currency_list"/>
        <a:model-query fetchAll="true" model="acr.ACR512.acr_invoice_business_type_list" rootPath="acr515_business_type_list"/>
    </a:init-procedure>
    <a:view>
        <a:link id="bmLink_vat_pause_or_submit" model="acr.ACR515.acr_invoice_vat" modelaction="batch_update"/>
        <a:link id="bmLink_vat_receive" model="acr.ACR515.acr_invoice_vat" modelaction="execute"/>
        <a:link id="acr515_update_post_link" url="${/request/@context_path}/modules/acr/ACR515/acr_invoice_insert_tmp.lsc"/>
        <a:link id="acr515_interface_excel_link" url="${/request/@context_path}/modules/acr/ACR515/acr_invoice_interface_excel_sheets.lsc"/>
        <a:link id="acr515_interface_network_link" url="${/request/@context_path}/modules/acr/ACR515/acr_invoice_interface_network_sheets.lsc"/>
        <a:link id="acr515_interface_import_link" url="${/request/@context_path}/modules/acr/ACR515/hls_acr_vat_import_data.lview"/>
        <a:screen-include screen="modules/hls/hls_common_javascript.lview"/>
        <script><![CDATA[
        function acr515_invoice_query() {
            $('acr515_invoiceVatDs').query();
        }

        function acr515_invoice_refresh() {
            var ds = $('acr515_invoiceVatDs');
            ds.query(ds.currentPage);
        }

        function acr515_invoice_reset() {
            $('acr515_invoiceVatParaDs').reset();
        }

        function onUpdate_acr515_invoiceVatParaDs(ds, record, name, value, oldVlaue) {
            if (name == 'document_number_f') {
                if (Leaf.isEmpty(record.get('document_number_t'))) {
                    record.set('document_number_t', value);
                }
            } else if (name == 'project_number_f') {
                if (Leaf.isEmpty(record.get('project_number_t'))) {
                    record.set('project_number_t', value);
                }
            } else if (name == 'invoice_number_f') {
                if (Leaf.isEmpty(record.get('invoice_number_t'))) {
                    record.set('invoice_number_t', value);
                }
            } else if (name == 'contract_number_f') {
                if (Leaf.isEmpty(record.get('contract_number_t'))) {
                    record.set('contract_number_t', value);
                }
            } else if (name == 'invoice_bp_code_f') {
                if (Leaf.isEmpty(record.get('invoice_bp_code_t'))) {
                    record.set('invoice_bp_code_t', value);
                }
            } else if (name == 'total_amount_f') {
                if (Leaf.isEmpty(record.get('total_amount_t'))) {
                    record.set('total_amount_t', value);
                }
            }

            // if(Ext.isEmpty(record.get('project_number_f'))&&Ext.isEmpty(record.get('project_number_t')))
            // {
            // record.set('query_project_number','');
            // }
            // else
            // {
            // record.set('query_project_number','Y');
            // }
            // if(Ext.isEmpty(record.get('contract_number_f'))&&Ext.isEmpty(record.get('contract_number_t')))
            // {
            // record.set('query_contract_number','');
            // }
            // else
            // {
            // record.set('query_contract_number','Y');
            // }
        }

        function onSubmitSuccess_acr515_invoiceVatDs(ds) {
            acr515_invoice_refresh();
        }

        function invoiceVat_submitHandle(datas) {
            Leaf.request({
                url: $('bmLink_vat_pause_or_submit').getUrl(),
                para: datas,
                success: function(res) {
                    f_hls.winNoMask();
                    Leaf.SideBar.show({
                        msg: '${l:HLS.SUBMIT_SUCCESS}',
                        duration: 2000
                    });
                    acr515_invoice_refresh();
                },
                failure: function() {
                    f_hls.winNoMask();
                },
                error: function() {
                    f_hls.winNoMask();
                },
                scope: this
            });
        }

        function acr515_vat_receive() {
            Leaf.request({
                url: $('bmLink_vat_receive').getUrl(),
                para: {},
                success: function(res) {
                    f_hls.winNoMask();
                    Leaf.SideBar.show({
                        msg: '${l:HLS.SUBMIT_SUCCESS}',
                        duration: 2000
                    });
                    acr515_invoice_refresh();
                },
                failure: function() {
                    f_hls.winNoMask();
                },
                error: function() {
                    f_hls.winNoMask();
                },
                scope: this
            });
        }



        function acr515_vat_create() {
            f_hls.winMask();

            var ds = $('acr515_invoiceVatDs');
            var records = ds.getSelected();
            if (records.length == 0) {
                f_hls.winNoMask();
                return;
            }
            var datas = [];
            for (var i = 0;i < records.length;i++) {
                var obj = {};
                obj['invoice_hd_id'] = records[i].get('invoice_hd_id');
                obj['_status'] = 'insert';
                datas[i] = obj;
            }
            invoiceVat_submitHandle(datas);
        }


        function acr515_vat_handle_pause(type) {
            f_hls.winMask();

            var ds = $('acr515_invoiceVatDs');
            var records = ds.getSelected();
            if (records.length == 0) {
                f_hls.winNoMask();
                return;
            }
            var datas = [];
            for (var i = 0;i < records.length;i++) {
                var obj = {};
                obj['invoice_hd_id'] = records[i].get('invoice_hd_id');
                obj['type'] = type;
                obj['_status'] = 'update';
                datas[i] = obj;
            }
            invoiceVat_submitHandle(datas);
        }

        function acr515_vat_pause() {
            acr515_vat_handle_pause('PAUSE');
        }

        function acr515_vat_cancel_pause() {
            acr515_vat_handle_pause('CANCEL');
        }

        function acr515_vat_delete() {
            var ds = $('acr515_invoiceVatDs');
            var records = ds.getSelected();
            if (records.length == 0) {
                return;
            }
            var datas = [];
            for (var i = 0;i < records.length;i++) {
                var obj = {};
                obj['invoice_hd_id'] = records[i].get('invoice_hd_id');

                obj['_status'] = 'delete';
                datas[i] = obj;
            }
            invoiceVat_submitHandle(datas);

        }

        function acr515_invoice_post() {


            var ds = $('acr515_invoiceVatDs');
            var records = ds.getSelected();
            if (records.length == 0) {
                Leaf.showMessage('提示', '请选择要开票的数据');
                return;
            }
            var param = {};
            var saveData = [];
            //var kind = $('acr515_invoiceVatParaDs').getAt(0).get('invoice_kind');

            // if (kind=='0') {  //如果是转票弹出 正常金税发票
            // url = $('acr515_interface_excel_link').getUrl();
            // } else {//否则弹出电子发票
            // url = $('acr515_interface_network_link').getUrl();
            // }
            var detail_mask = Ext.getBody();
            Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
            for (var i = 0;i < records.length;i++) {
                saveData.push({
                    'invoice_hd_id': records[i].get('invoice_hd_id'),
                    '_status': 'insert'
                });
            }
            param['details'] = saveData;
            Leaf.request({
                url: $('acr515_update_post_link').getUrl(),
                para: param,
                success: function() {
                    Leaf.Masker.unmask(detail_mask);
                    var _url=$('acr515_interface_excel_link').getUrl();
                    window.open(_url);
                    ds.query();
                },
                failure: function() {
                    Leaf.Masker.unmask(detail_mask);
                },
                error: function() {
                    Leaf.Masker.unmask(detail_mask);
                },
                scope: this
            });
        }
        function acr515_invoice_import(){

            var kind = $('acr515_invoiceVatParaDs').getAt(0).get('invoice_kind');
            //默认为2
            kind=2;
            new Leaf.Window({
                id: 'gld_interface_window',
                url: $('acr515_interface_import_link').getUrl()+'?kind='+kind,
                title: '导入开票结果',
                fullScreen :true
            });
           // window.location.href =
        }
        function summaryRenderer(datas, name) {
            var sum=0;
            var sum1=0;
            var sum2=0;
            if(name=="invoice_title"){
                return '合计:<font color="red"></font>';
            }
            if(name=="total_amount"){
                for(var i=0;i<datas.length;i++){
                    var record=datas[i];
                    var payment_amount_vl=record.get("total_amount");
                    var payment_amount=parseFloat(payment_amount_vl);
                    if(!isNaN(payment_amount)){
                        sum+=payment_amount;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum ,2)+ '</font>';
            }
            if(name=="tax_amount"){
                for(var j=0;j<datas.length;j++){
                    var record1=datas[j];
                    var payment_amount_vl1=record1.get("tax_amount");
                    var payment_amount1=parseFloat(payment_amount_vl1);
                    if(!isNaN(payment_amount1)){
                        sum1+=payment_amount1;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum1 ,2)+ '</font>';
            }
            if(name=="net_amount"){
                for(var k=0;k<datas.length;k++){
                    var record2=datas[k];
                    var payment_amount_vl2=record2.get("net_amount");
                    var payment_amount2=parseFloat(payment_amount_vl2);
                    if(!isNaN(payment_amount2)){
                        sum2+=payment_amount2;
                    }
                }
                return '<font color="red">' + Leaf.formatNumber(sum2 ,2)+ '</font>';
            }
        }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="acr515_invoiceKindDs" lookupCode="ACR510_INVOICE_KIND"/>
            <a:dataSet id="acr515_invoiceStatusDs" lookupCode="ACR510_AR_INVOICE_STATUS"/>
            <a:dataSet id="acr515_express_status_ds" lookupCode="ACR518_EXPRESS_STATUS"/>
            <a:dataSet id="acr515_vat_interface_status_ds" lookupCode="ACR515_VAT_INTERFACE_STATUS"/>
            <a:dataSet id="acr515_businessTypeDs">
                <a:datas dataSource="/model/acr515_business_type_list"/>
            </a:dataSet>
            <a:dataSet id="acr515_currencyDs">
                <a:datas dataSource="/model/acr515_currency_list"/>
            </a:dataSet>

            <a:dataSet id="acr515_invoiceVatParaDs" autoCreate="true" model="acr.acr_invoice_hd_v">
                <a:fields>
                    <a:field name="currency_desc" displayField="currency_name" options="acr515_currencyDs" returnField="currency" valueField="currency_code"/>
                    <a:field name="invoice_kind"/>
                    <a:field name="invoice_kind_desc" displayField="code_value_name" options="acr515_invoiceKindDs"  returnField="invoice_kind" valueField="code_value"/>
                    <a:field name="invoice_status_desc" displayField="code_value_name" options="acr515_invoiceStatusDs" returnField="invoice_status" valueField="code_value"/>
                    <a:field name="vat_interface_status" defaultValue="UNTRANSFERED"/>
                    <a:field name="vat_interface_status_desc" defaultValue="未传金税" displayField="code_value_name" options="acr515_vat_interface_status_ds" returnField="vat_interface_status" valueField="code_value"/>
                    <a:field name="business_type_desc" displayField="business_type_desc" options="acr515_businessTypeDs" returnField="business_type" valueField="business_type"/>
                    <a:field name="created_by_name" lovGridHeight="320" lovHeight="500" lovService="acr.ACR512.acr_invoice_sys_user_lov" lovWidth="500" title="ACR.CREATED_BY_NAME">
                        <a:mapping>
                            <a:map from="user_id" to="created_by"/>
                            <a:map from="description" to="created_by_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="confirmed_by_name" lovGridHeight="320" lovHeight="500" lovService="acr.ACR512.acr_invoice_sys_user_lov" lovWidth="500" title="ACR.CONFIRMED_BY_NAME">
                        <a:mapping>
                            <a:map from="user_id" to="confirmed_by"/>
                            <a:map from="description" to="confirmed_by_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="invoice_bp_code_f" lovGridHeight="320" lovHeight="480" lovService="acr.ACR512.acr_invoice_bp_master_list" lovWidth="500" title="ACR.INVOICE_BP_CODE">
                        <a:mapping>
                            <a:map from="bp_code" to="invoice_bp_code_f"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="invoice_bp_code_t" lovGridHeight="320" lovHeight="480" lovService="acr.ACR512.acr_invoice_bp_master_list" lovWidth="500" title="ACR.INVOICE_BP_CODE">
                        <a:mapping>
                            <a:map from="bp_code" to="invoice_bp_code_t"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="project_number_f" lovGridHeight="320" lovHeight="480" lovService="acr.ACR512.acr_invoice_project_list" lovWidth="500" title="HLS.PROJECT_NUMBER_FROM">
                        <a:mapping>
                            <a:map from="project_number" to="project_number_f"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="project_number_t" lovGridHeight="320" lovHeight="480" lovService="acr.ACR512.acr_invoice_project_list" lovWidth="500" title="HLS.PROJECT_NUMBER_FROM">
                        <a:mapping>
                            <a:map from="project_number" to="project_number_t"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_number_f" lovGridHeight="320" lovHeight="480" lovService="acr.ACR512.acr_invoice_contract_list" lovWidth="500" title="HLS.CONTRACT_NUMBER_FROM">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number_f"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="contract_number_t" lovGridHeight="320" lovHeight="480" lovService="acr.ACR512.acr_invoice_contract_list" lovWidth="500" title="HLS.CONTRACT_NUMBER_FROM">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number_t"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="received_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="express_status_name" displayField="code_value_name" options="acr515_express_status_ds" returnField="express_status" valueField="code_value"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="onUpdate_acr515_invoiceVatParaDs"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="acr515_invoiceVatDs" autoPageSize="true" maxPageSize="10000" model="acr.acr_invoice_hd_v" queryDataSet="acr515_invoiceVatParaDs" selectable="true">
                <a:fields><![CDATA[
                    ]]></a:fields>
                <a:events>
                    <a:event name="submitsuccess" handler="onSubmitSuccess_acr515_invoiceVatDs"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="acr515_invoice_query" text="HLS.QUERY"/>
                <a:gridButton click="acr515_invoice_reset" text="HLS.RESET"/>
                <a:gridButton click="acr515_invoice_post" text="开票"/>
                <a:gridButton click="acr515_invoice_import" text="导入开票结果"/>
                <!-- <a:gridButton click="acr515_vat_pause" text="暂挂"/>
                <a:gridButton click="acr515_vat_cancel_pause" text="取消暂挂"/>
                <a:gridButton click="acr515_vat_create" text="传入接口"/>
                <a:gridButton click="acr515_vat_delete" text="删除接口"/>
                <a:gridButton click="acr515_vat_receive" text="更新开票信息"/> -->
            </a:screenTopToolbar>
            <a:form column="1" marginWidth="30" padding="0">
                <a:hBox labelSeparator=" " labelWidth="100" column="4">
                    <a:textField name="document_number_f" bindTarget="acr515_invoiceVatParaDs" prompt="HLS.DOCUMENT_NUMBER_FROM" width="150"/>
                    <div><![CDATA[${l:HLS.DOCUMENT_NUMBER_TO}]]></div>
                    <a:textField name="document_number_t" bindTarget="acr515_invoiceVatParaDs" prompt="" width="150"/>

                    <a:lov name="contract_number_f" bindTarget="acr515_invoiceVatParaDs" prompt="HLS.CONTRACT_NUMBER_FROM" width="150"/>
                    <div>到</div>
                    <a:lov name="contract_number_t" bindTarget="acr515_invoiceVatParaDs" prompt="" width="150"/>
                    <a:textField name="invoice_title" bindTarget="acr515_invoiceVatParaDs" width="150"/>
                    <a:lov name="confirmed_by_name" bindTarget="acr515_invoiceVatParaDs" width="150"/>
                </a:hBox>
                <a:hBox labelSeparator=" " labelWidth="100">
                    <a:datePicker name="invoice_date_f" bindTarget="acr515_invoiceVatParaDs" prompt="ACR.INVOICE_DATE_FROM" width="150"/>
                    <div><![CDATA[${l:ACR.INVOICE_DATE_TO}]]></div>
                    <a:datePicker name="invoice_date_t" bindTarget="acr515_invoiceVatParaDs" prompt="" width="150"/>
                    <a:lov name="invoice_bp_code_f" bindTarget="acr515_invoiceVatParaDs" prompt="HLS.CUSTOMER_NUMBER_FROM" width="150"/>
                    <div><![CDATA[${l:HLS.CUSTOMER_NUMBER_TO}]]></div>
                    <a:lov name="invoice_bp_code_t" bindTarget="acr515_invoiceVatParaDs" prompt="" width="150"/>
                    <a:comboBox name="invoice_status_desc" bindTarget="acr515_invoiceVatParaDs" width="150"/>
                    <a:comboBox name="vat_interface_status_desc" bindTarget="acr515_invoiceVatParaDs" width="150"/>

                </a:hBox>
                <a:hBox labelSeparator=" " labelWidth="100">

                    <a:numberField name="total_amount_f" allowFormat="true" bindTarget="acr515_invoiceVatParaDs" prompt="ACR.TOTAL_AMOUNT_FROM" width="150"/>
                    <div><![CDATA[${l:ACR.TOTAL_AMOUNT_TO}]]></div>
                    <a:numberField name="total_amount_t" allowFormat="true" bindTarget="acr515_invoiceVatParaDs" prompt="" width="150"/>
                    <a:datePicker name="accounting_date_f" bindTarget="acr515_invoiceVatParaDs" prompt="HLS.ACCOUNT_DATE_FROM" width="150"/>
                    <div><![CDATA[${l:HLS.ACCOUNT_DATE_TO}]]></div>
                    <a:datePicker name="accounting_date_t" bindTarget="acr515_invoiceVatParaDs" prompt="" width="150"/>
                    <a:comboBox name="invoice_kind_desc" bindTarget="acr515_invoiceVatParaDs" width="150"/>
                    <a:lov name="created_by_name" bindTarget="acr515_invoiceVatParaDs" width="150"/>

                </a:hBox>
                <a:hBox labelSeparator=" " labelWidth="100">
                    <a:textField name="invoice_number_f" bindTarget="acr515_invoiceVatParaDs" prompt="ACR.INVOICE_NUMBER_FROM" width="150"/>
                    <div><![CDATA[${l:ACR.INVOICE_NUMBER_TO}]]></div>
                    <a:textField name="invoice_number_t" bindTarget="acr515_invoiceVatParaDs" prompt="" width="150"/>

                </a:hBox>
            </a:form>
            <a:grid id="acr515_invoiceVatDs_grid" bindTarget="acr515_invoiceVatDs"  marginWidth="80" navBar="true" height="300">
                <a:columns>
                    <a:column name="contract_number" width="120"/>
                    <a:column name="document_number" lock="true" width="120"/>
                    <a:column name="business_type_desc" width="80"/>
                    <a:column name="billing_way_desc" width="80" prompt="开票方式"/>
                    <a:column name="invoice_kind_desc" width="100"/>
                    <a:column name="invoice_number" width="120"/>
                    <a:column name="invoice_date" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="invoice_bp_code" width="100"/>
                    <a:column name="invoice_bp_name" autoAdjust="false" showTitle="true" width="150"/>
                    <a:column name="invoice_title" autoAdjust="false" footerRenderer="summaryRenderer" showTitle="true" width="150"/>
                    <a:column name="total_amount" align="right" footerRenderer="summaryRenderer" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="tax_amount" align="right" footerRenderer="summaryRenderer" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="net_amount" align="right" footerRenderer="summaryRenderer" renderer="Leaf.formatMoney" width="100"/>
                    <a:column name="currency" width="80"/>
                    <a:column name="created_by_name" autoAdjust="false" showTitle="true" width="150"/>
                    <a:column name="confirmed_by_name" autoAdjust="false" showTitle="true" width="150"/>
                    <a:column name="invoice_status_desc" width="100"/>
                    <a:column name="vat_interface_status_desc" width="100"/>
                    <a:column name="accounting_date" renderer="Leaf.formatDate" width="100"/>
                    <!-- <a:column name="create_je_flag" width="60"/> -->
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>