<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2018-07-12 下午2:20:47
    $Revision: 1.0
    $Purpose:
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.function_code = ${/parameter/@function_code}"
                       model="acr.ACR519.default_function_name" rootPath="default_function_name"/>
        <a:model-query model="acr.ACR519.acr_delivery_import_batch_id" rootPath="batch_id"/>
    </a:init-procedure>
    <a:view>
        <a:link id="acr_invoice_delivery_save_link" model="acr.ACR519.acr_invoice_delivery_grid"
                modelaction="batch_update"/>
        <a:link id="acr_delivery_upload_link"
                url="${/request/@context_path}/modules/acr/ACR519/acr_delivery_import.lview"/>
        <a:link id="invoice_attachment_uploadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script type="text/javascript"><![CDATA[
        function acr_invoice_delivery_ds_query() {
            $('acr_invoice_delivery_ds').query();
        }

        function acr_invoice_delivery_query_ds_reset() {
            $('acr_invoice_delivery_query_ds').reset();
        }

        function acr_invoice_delivery_ds_submit() {
            var records = $('acr_invoice_delivery_ds').getSelected();
            for (i = 0; i < records.length; i++) {
                records[i].set('express_status', 'TRANSFERRED');
                records[i].set('_status', 'update');
            }
            $('acr_invoice_delivery_ds').submit();
            $('acr_invoice_delivery_ds').query();
        }

        function acr_invoice_delivery_ds_hand() {
            var records = $('acr_invoice_delivery_ds').getSelected();
            for (i = 0; i < records.length; i++) {
                records[i].set('express_status', 'RECEIVED');
                records[i].set('_status', 'update');
            }
            $('acr_invoice_delivery_ds').submit();
            $('acr_invoice_delivery_ds').query();
        }

        function acr_invoice_delivery_ds_send() {
            var records = $('acr_invoice_delivery_ds').getSelected();
            for (i = 0; i < records.length; i++) {
                records[i].set('express_status', 'SEND_OFF');
                records[i].set('_status', 'update');
            }
            $('acr_invoice_delivery_ds').submit();
            $('acr_invoice_delivery_ds').query();
        }

        function acr_invoice_delivery_ds_export() {
            $('acr_invoice_grid')._export('xlsx', '${/model/default_function_name/record/@function_name}');
        }

        function acr_invoice_delivery_ds_save() {

            var records = $('acr_invoice_delivery_ds').getSelected();
            if (records.length == 0) {
                Leaf.showMessage('${l:PROMPT}', '请至少选择一条数据进行保存!');
                return;
            }
            var post_data = [];
            for (var i = 0; i < records.length; i++) {
                post_data.push({
                    'transfer_time': records[i].get('transfer_time'),
                    'recipient': records[i].get('recipient'),
                    'express_date': records[i].get('express_date'),
                    'express_num': records[i].get('express_num'),
                    'express_to': records[i].get('express_to'),
                    'invoice_hd_id': records[i].get('invoice_hd_id'),
                    '_status': 'update'
                });
            }
            Leaf.request({
                url: $('acr_invoice_delivery_save_link').getUrl(),
                para: post_data,
                success: function () {
                    $('acr_invoice_delivery_ds').query();
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    //Leaf.showMessage('${l:PROMPT}', '保存成功!');
                }, failure: function () {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                error: function () {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                scope: this
            });
        }

        /*
         function load_handle_func() {

         var query_ds = $('acr_invoice_delivery_ds');
         var contract_id = '${/parameter/@contract_id}';
         query_ds.setQueryParameter('contract_id', contract_id);
         query_ds.query();
         }
         */


        function acr_invoice_delivery_ds_import() {
            var win = new Leaf.Window({
                id: 'acr_delivery_upload_link_winId',
                url: $('acr_delivery_upload_link').getUrl(),
                params: {
                    batch_id: '${/model/batch_id/record/@batch_id}',
                    group_code:'REPAYMENT',
                    winId: 'acr_delivery_upload_link_winId'
                },
                title: '交接单导入',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $('contract_doc_result_ds').query();
            });
        }
        function acr_invoice_delivery_ds_import_2() {
            var win = new Leaf.Window({
                id: 'acr_delivery_upload_link_winId',
                url: $('acr_delivery_upload_link').getUrl(),
                params: {
                    batch_id: '${/model/batch_id/record/@batch_id}',
                    group_code:'TAX',
                    winId: 'acr_delivery_upload_link_winId'
                },
                title: '交接单导入',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $('contract_doc_result_ds').query();
            });
        }

        //pdf附件
        function downloadPdf(val, rec, name) {
            if (rec.get('ele_invoice_status') == 'DOWNLOAD') {
                return '<a href=javascript:detail_upload_window(' + rec.get('ele_invoice_hd_id') + ')>pdf附件</a>';
            }
        }

        function detail_upload_window(id) {
            var url = $('invoice_attachment_uploadFile_id').getUrl() + '?table_name=ACR_ELE_INVOICE_HD&header_id=' + id;
            var win = new Leaf.Window({
                url: url,
                title: '${l:HLS.SUPPORTING_DOCUMENT}',
                id: 'invoice_attachment_uploadFile_id_win',
                width: 850,
                height: 400
            });
            win.on('close', function () {
            });
        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="express_status_ds" lookupCode="ACR520_EXPESS_STATUS"/>
            <a:dataSet id="division_name_ds" loadData="true" model="basic.hls_division_for_lov"/>
            <a:dataSet id="billing_way_ds" lookupCode="DS_INVOICE_CATEGORY"/>
            <a:dataSet id="acr_invoice_delivery_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="contract_number"/>
                    <a:field name="product_name"/>
                    <a:field name="division_n" displayField="description" options="division_name_ds"
                             returnField="division" valueField="division"/>
                    <a:field name="billing_way_n" displayField="code_value_name" options="billing_way_ds"
                                                 returnField="billing_way" valueField="code_value"/>
                    <a:field name="__async__"  defaultValue="Y" prompt="异步导出"/>
                </a:fields>


            </a:dataSet>
            <a:dataSet id="acr_invoice_delivery_ds" autoPageSize="true" autoQuery="false"
                       model="acr.ACR519.acr_invoice_delivery" queryDataSet="acr_invoice_delivery_query_ds"
                       queryUrl="${/request/@context_path}/autocrud/acr.ACR519.acr_invoice_delivery/query?contract_id=${/parameter/@contract_id}"
                       selectable="true"
                       submitUrl="${/request/@context_path}/autocrud/acr.ACR519.acr_invoice_delivery/batch_update">
                <a:fields>
                    <a:field name="invoice_hd_id"/>
                    <a:field name="description_l"/>
                    <a:field name="express_status"/>
                    <a:field name="express_status_n" displayField="code_value_name" options="express_status_ds"
                             returnField="express_status" valueField="code_value"/>
                    <a:field name="transfer_time"/>
                    <a:field name="recipient"/>
                    <a:field name="express_date"/>
                    <a:field name="express_num"/>
                    <a:field name="express_to"/>
                </a:fields>
                <a:events>
                    <a:event name="submit" handler="acr_invoice_delivery_ds_query"/>
                    <!--<a:event name="load" handler="load_handle_func"/>-->
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="acr_invoice_delivery_ds_query" text="HAP_QUERY"/>
                <a:gridButton click="acr_invoice_delivery_query_ds_reset" text="HLS.RESET"/>
                <a:gridButton click="acr_invoice_delivery_ds_export" text="导出"/>
                <a:gridButton click="acr_invoice_delivery_ds_save" text="保存"/>
                <a:gridButton click="acr_invoice_delivery_ds_submit" text="已转交"/>
                <a:gridButton click="acr_invoice_delivery_ds_hand" text="已接收"/>
                <a:gridButton click="acr_invoice_delivery_ds_send" text="已邮寄"/>
                <a:gridButton click="acr_invoice_delivery_ds_import" text="交接单导入-收款组"/>
                <a:gridButton click="acr_invoice_delivery_ds_import_2" text="交接单导入-税务组"/>
            </a:screenTopToolbar>
            <a:form column="4" marginWidth="130" labelwidth="150" title="销项发票交接">

                <!--  <a:textField name="invoice_number" bindTarget="acr_invoice_delivery_query_ds"
                               prompt="ACR.INVOICE_NUMBER"/>-->

                <a:textField name="invoice_number_from" bindTarget="acr_invoice_delivery_query_ds"
                             prompt="发票号码从"/>
                <a:textField name="invoice_number_to" bindTarget="acr_invoice_delivery_query_ds"
                             prompt="TO"/>
                <a:datePicker name="invoice_date_from" bindTarget="acr_invoice_delivery_query_ds"
                              prompt="ACR519.INVOICE_DATE_FROM"/>
                <a:datePicker name="invoice_date_to" bindTarget="acr_invoice_delivery_query_ds"
                              prompt="TO"/>
                <a:textField name="contract_number" bindTarget="acr_invoice_delivery_query_ds" prompt="合同编号"/>
                <a:textField name="bp_name" bindTarget="acr_invoice_delivery_query_ds" prompt="HLS.CUSTOMER_NAME"/>
                <!-- <a:textField name="product_name" bindTarget="acr_invoice_delivery_query_ds" prompt="货物名称"/>-->
                <!-- <a:numberField name="times" allowDecimals="false" bindTarget="acr_invoice_delivery_query_ds" prompt="HLS.TIMES"/> -->
                <!-- <a:numberField name="total_amount" bindTarget="acr_invoice_delivery_query_ds"
                                prompt="ACR.TOTAL_AMOUNT"/>-->
                <a:comboBox name="division_n" bindTarget="acr_invoice_delivery_query_ds" prompt="产品线"/>
                <a:datePicker name="transfer_time" bindTarget="acr_invoice_delivery_query_ds"
                              prompt="转交时间"/>
                <a:textField name="bp_agent_name"  bindTarget="acr_invoice_delivery_query_ds" prompt="代理商" />

                <a:datePicker name="express_date"  bindTarget="acr_invoice_delivery_query_ds" prompt="邮寄时间" />

                <a:textField name="express_num"  bindTarget="acr_invoice_delivery_query_ds" prompt="快递单号" />

                <a:textField name="pattern"  bindTarget="acr_invoice_delivery_query_ds" prompt="机型" />

                <a:textField name="machine_number"  bindTarget="acr_invoice_delivery_query_ds" prompt="机号" />

                <a:comboBox name="billing_way_n" bindTarget="acr_invoice_delivery_query_ds" prompt="发票类型"/>

            </a:form>
            <a:grid id="acr_invoice_grid" bindTarget="acr_invoice_delivery_ds" marginHeight="215" marginWidth="50"
                    navBar="true">
                <a:columns>
                    <a:column name="contract_number" prompt="合同编号" width="150" align="center"/>
                    <a:column name="bp_agent_name" prompt="代理商" width="100"/>
                    <a:column name="billing_way_n" prompt="发票类型" width="100"/>
                    <a:column name="invoice_number" prompt="ACR.INVOICE_NUMBER" align="center" width="150"/>
                    <a:column name="vat_invoice_code" prompt="发票代码" align="center" width="150"/>
                    <a:column name="cf_item_n" prompt="现金流描述" align="center" width="150"/>
                    <a:column name="division_n" prompt="产品线" width="80" align="center"/>
                    <a:column name="machine_number" prompt="机号" width="100" align="center"/>
                    <a:column name="invoice_date" prompt="ACR521.INVOICE_DATE" align="center" width="100"/>
                    <a:column name="bp_name" align="center" prompt="HLS.CUSTOMER_NAME" width="180"/>
                    <!-- <a:column name="product_name" align="center" prompt="货物名称" width="200"/>-->
                    <!--  <a:column name="times" align="center" prompt="ACR521.TENANCY_TERM" width="60"/>-->
                    <a:column name="total_amount" align="right" prompt="HLS.AMOUNT" renderer="Leaf.formatMoney"
                              width="100"/>
                    <a:column name="invoice_title" prompt="发票抬头"/>
                    <a:column name="invoice_kind_n" align="center" prompt="发票种类" width="120"/>
                    <a:column name="transfer_time" renderer="Leaf.formatDate" editor="datePicker_e" align="center"
                              prompt="已转交时间" width="100"/>
                    <a:column name="recipient" editor="textField_e" align="center" prompt="已签收人" width="100"/>
                    <a:column name="express_date" renderer="Leaf.formatDate" editor="datePicker_e" align="center"
                              prompt="已邮寄时间" width="100"/>
                    <a:column name="express_num" editor="textField_e" align="center" prompt="邮寄快递单号" width="100"/>
                    <a:column name="express_to" editor="textField_e" align="center" prompt="接收人" width="100"/>
                    <!-- <a:column  name="description_l"  editor="textArea_e"  prompt="备注" width="400"    /> -->
                    <a:column name="pattern" align="center" prompt="机型" width="100"/>
                    <a:column name="machine_number" align="center" prompt="机号" width="100"/>
                    <a:column name="express_status_n" align="center" prompt="状态" width="100"/>
                    <a:column name="download" prompt="电子发票下载" renderer="downloadPdf" align="center"/>
                </a:columns>
                <a:editors>
                    <a:textArea id="textArea_e"/>
                    <a:datePicker id="datePicker_e"/>
                    <a:textField id="textField_e"/>
                </a:editors>
            </a:grid>

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

            /*  Leaf.onReady(init);
              function init() {
                  var skip_flag = '${/parameter/@skip_flag}';
                  if (skip_flag = 'Y') {
                      var query_ds = $('acr_invoice_delivery_ds');
                      var contract_id = '${/parameter/@contract_id}';
                      query_ds.setQueryParameter('contract_id', contract_id);
                      query_ds.query();
                  }
              }*/

            ]]></script>
        </a:screenBody>
    </a:view>
</a:screen>