<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true">
    <a:init-procedure>

    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_modify_link"
                url="${/request/@context_path}/modules/cont/CON505/con_contract_modify.lview"/>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>

        <script type="text/javascript"><![CDATA[

        function document_number_render(value, record, name) {
            if (name == 'document_number' && value) {
                return '<a href="javascript:open_document_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
            }
            return value;
        }

        function open_document_win(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['function_code'] = 'ACR513';
            param['function_usage'] = 'QUERY';
            param['maintain_type'] = 'UPDATE';
            param['url_title'] = '${l:ACR.INVOICE_DETAIL}';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_modify_link', ds_id);
        }

        //发票超练级
        function acr516_invoice_query() {
            $('acr516_invoice_result_ds').query();
        }

        function acr516_invoice_reset() {
            $('acr516_invoice_query_ds').reset();
        }

        function acr516_invoice_apply() {
            var records = $('acr516_invoice_result_ds').getSelected();
            var datas = [];
            for (var i = 0; i < records.length; i++) {
                datas.push({
                    'invoice_hd_id': records[i].get('invoice_hd_id'),
                    '_status': 'update'
                })

            }
            $L.showConfirm("提示", '确认执行该操作?', function () {
                Leaf.Masker.mask(Ext.getBody(),'正在操作...');
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/acr.ACR604.acr_invoice_claim_application_new/batch_update',
                    para: datas,
                    success: function () {
                        Leaf.Masker.unmask(Ext.getBody());
                        Leaf.SideBar.show({
                            msg: '操作成功',
                            duration: 2000
                        });
                        $('acr516_invoice_result_ds').query();
                    },
                    failure: function () {
                        Leaf.showWarningMessage('', '${l:PRJ509.DATA_NOT_BACK}', null, 200, 100);
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function () {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });
            })

        }

        function submit_success_btn(ds) {
            $('acr516_invoice_result_ds').query();
        }

        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:dataSets>
            <a:dataSet id="acr516_invoice_kind_ds" lookupCode="ACR510_INVOICE_KIND"/>
            <a:dataSet id="acr516_invoice_statu_ds" lookupCode="ACR510_AR_INVOICE_STATUS"/>
            <a:dataSet id="acr516_claim_status_ds" lookupCode="CLAIM_STATUS"/>
            <a:dataSet id="cf_item_options">
                <a:datas dataSource="/model/hls_cashflow_item_list"/>
            </a:dataSet>
            <a:dataSet id="claim_status_ds" loadData="true" lookupCode="CLAIM_STATUS"/>
            <a:dataSet id="csh_transaction_flag_ds">
                <a:datas>
                    <a:record code_value="NOT" code_value_name="未收款"/>
                    <a:record code_value="FULL" code_value_name="完全收款"/>
                    <a:record code_value="PARTIAL" code_value_name="部分收款"/>
                </a:datas>
            </a:dataSet>

            <a:dataSet id="acr516_invoice_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="invoice_apply_num"/>
                    <a:field name="invoice_kind_desc" displayField="code_value_name" options="acr516_invoice_kind_ds"
                             returnField="invoice_kind" valueField="code_value"/>
                    <a:field name="invoice_status_desc" displayField="code_value_name" options="acr516_invoice_statu_ds"
                             returnField="invoice_status" valueField="code_value"/>
                    <a:field name="total_amount"/>
                    <a:field name="csh_transaction_flag"/>
                    <a:field name="csh_transaction_flag_desc" options="csh_transaction_flag_ds"
                             displayField="code_value_name" returnField="code_value" valueField="csh_transaction_flag"/>
                    <a:field name="cf_item"/>
                    <a:field name="cf_item_n" options="cf_item_options" displayField="description" returnField="cf_item"
                             valueField="cf_item"/>
                    <a:field name="claim_status_n" options="claim_status_ds" displayField="code_value_name"
                             valueField="code_value" returnField="claim_status"/>
                    <a:field name="cf_item_desc" autoComplete="true" lovGridHeight="350" lovHeight="500"
                             lovLabelWidth="100" lovService="acr.ACR510.hls_cashflow_item_v_lov" lovWidth="520"
                             title="现金流项目">
                        <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="claim_status" displayField="code_value_name" options="acr516_claim_status_ds"
                             returnField="claim_status" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="acr516_invoice_result_ds" fetchAll="false" autoPageSize="true" autoQuery="true"
                       model="acr.ACR604.acr_invoice_claim_application_new" queryDataSet="acr516_invoice_query_ds"
                       selectable="true">
                <a:events>
                    <a:event name="submitsuccess" handler="submit_success_btn"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:toolbarButton click="acr516_invoice_query" text="HLS.QUERY"/>
                <a:toolbarButton click="acr516_invoice_reset" text="HLS.RESET"/>
                <a:toolbarButton click="acr516_invoice_apply" text="申请"/>
            </a:screenTopToolbar>
            <a:form marginWidth="30" padding="0" title="查询条件" column="4">
                <a:textField name="document_number" bindTarget="acr516_invoice_query_ds" prompt="单据编号" width="120"/>
                <a:textField name="contract_number" bindTarget="acr516_invoice_query_ds" prompt="合同编号" width="120"/>
                <a:textField name="contract_name" bindTarget="acr516_invoice_query_ds" prompt="合同名称" width="120"/>
                <!--                <a:lov name="cf_item_desc" bindTarget="acr516_invoice_query_ds" prompt="现金流项目" width="135"/>-->
                <a:numberField name="total_amount_f" allowFormat="true" bindTarget="acr516_invoice_query_ds"
                               prompt="开票金额含税额从" width="120"/>
                <a:numberField name="total_amount_t" allowFormat="true" bindTarget="acr516_invoice_query_ds"
                               prompt="开票金额含税额到" width="120"/>
                <a:textField name="invoice_title" bindTarget="acr516_invoice_query_ds" prompt="发票抬头" width="120"/>
                <a:comboBox name="invoice_kind_desc" bindTarget="acr516_invoice_query_ds" prompt="ACR.INVOICE_KIND"
                            width="120"/>
                <!--                <a:comboBox name="invoice_status_desc" bindTarget="acr516_invoice_query_ds" prompt="发票状态" width="135"/>-->
                <a:textField name="vat_invoice_code" bindTarget="acr516_invoice_query_ds" prompt="发票代码" width="120"/>
                <a:textField name="invoice_number" bindTarget="acr516_invoice_query_ds" prompt="发票号码" width="120"/>
                <a:comboBox name="claim_status_n" bindTarget="acr516_invoice_query_ds" prompt="认领状态" width="120"/>
                <a:comboBox name="csh_transaction_flag_desc" bindTarget="acr516_invoice_query_ds" prompt="收款标记"
                            width="120"/>
                <a:textField name="invoice_apply_num" bindTarget="acr516_invoice_query_ds" prompt="申请编号" width="120"/>
                <a:datePicker name="invoice_date_from" bindTarget="acr516_invoice_query_ds" prompt="发票日期从" width="120"/>
                <a:datePicker name="invoice_date_to" bindTarget="acr516_invoice_query_ds" prompt="发票日期到" width="120"/>
            </a:form>
            <a:grid id="acr516_invoice_grid_id" bindTarget="acr516_invoice_result_ds" marginHeight="225"
                    marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="document_number" lock="true" prompt="HLS.DOCUMENT_NUMBER" width="120"
                              renderer="document_number_render"/>
                    <a:column name="contract_number" autoAdjust="false" prompt="HLS.CONTRACT_NUMBER" showTitle="true"
                              width="150"/>
                    <!--                    <a:column name="contract_name" width="150" prompt="合同名称"/>-->
                    <a:column name="bp_agent_name" prompt="代理商" width="100"/>
                    <a:column name="invoice_kind_desc" prompt="发票种类" width="100"/>
                    <a:column name="invoice_number" width="120" prompt="发票号码"/>
                    <a:column name="vat_invoice_code" width="120" prompt="发票代码"/>
                    <a:column name="invoice_date" renderer="Leaf.formatDate" prompt="发票日期" width="100"/>
                    <a:column name="invoice_bp_code" prompt="开票客户编号" width="100"/>
                    <!--                    <a:column name="invoice_bp_name" autoAdjust="false" showTitle="true" prompt="开票客户名称" width="150"/>-->
                    <a:column name="invoice_title" autoAdjust="false" showTitle="true" prompt="发票抬头" width="150"/>
                    <a:column name="total_amount" align="right" renderer="Leaf.formatMoney" prompt="发票金额" width="100"/>
                    <a:column name="tax_amount" align="right" renderer="Leaf.formatMoney" prompt="税额" width="100"/>
                    <a:column name="net_amount" align="right" renderer="Leaf.formatMoney" prompt="不含税金额" width="100"/>
<!--                    <a:column name="currency" prompt="币种" width="80"/>-->
                    <a:column name="created_by_name" autoAdjust="false" showTitle="true" prompt="创建人" width="150"/>
                    <!--                    <a:column name="invoice_status_desc" prompt="发票状态" width="100"/>-->
                    <!--                    <a:column name="vat_interface_status_desc"  prompt="金税状态" width="100"/>-->
                    <a:column name="accounting_date" renderer="Leaf.formatDate" prompt="期间序号" width="100"/>
                    <!--                    <a:column name="create_je_flag" prompt="凭证标志" width="60"/>-->
                    <a:column name="bp_tax_registry_num" prompt="纳税人识别号"/>
                    <a:column name="claim_status_n" prompt="认领状态" width="100"/>
                    <a:column name="invoice_apply_num" prompt="申请编号" width="120"/>
                    <a:column name="csh_transaction_flag_desc" prompt="收款标记" width="80"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>