<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: 38823
    $Date: 2023-12-21
    $Revision: 1.0
    $purpose: 付款凭证审批明细
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script"
          customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
    </a:init-procedure>
    <a:view>
        <a:link id="save_detail_link" model="inv.inv100.payment_detail_save" modelaction="update"/>
        <a:link id="journal_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="journal_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script type="text/javascript"><![CDATA[
        $L.onReady(function(){
            debugger;
            if("${/parameter/@function_usage}"=='QUERY'){
                if(document.getElementById('${/parameter/@layout_code}_user_button1')){
                    document.getElementById("${/parameter/@layout_code}_user_button1").style.display = "none";
                }
                if(document.getElementById('${/parameter/@layout_code}_exit')){
                    document.getElementById("${/parameter/@layout_code}_exit").style.display = "none";
                }
            }
        });
        //自定义保存
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            debugger;
            var ds_id =get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_journal_header');
            var record = $(ds_id).getCurrentRecord();
            var invoiceSeries = record.get('invoice_series');
            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.SAVING}');
            Leaf.request({
                url: $('save_detail_link').getUrl(),
                para: {
                    payment_journal_id: "${/parameter/@payment_journal_id}",
                    invoice_series: invoiceSeries
                },
                success: function(res) {
                    Leaf.SideBar.show({
                        msg: '${l:HLS.SUBMIT_SUCCESS}',
                        duration: 2000
                    });
                    Leaf.Masker.unmask(Ext.getBody());
                },
                failure: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                error: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                scope: this
            });
        };

          function upload_voucher_file(id,name,record_id,item_code) {
                 var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
                if (item_code=='INVOICE') {
                 var url = $('journal_uploadFile_id').getUrl() + '?table_name=INVOICE&header_id=' + record_id;
                }else if(item_code=='PAYMENT_REQUEST_LETTER'){
                 var url = $('journal_uploadFile_id').getUrl() + '?table_name=PAYMENT_REQUEST_LETTER&header_id=' + record_id;
                }else if(item_code=='OTHERS'){
                 var url = $('journal_uploadFile_id').getUrl() + '?table_name=OTHERS&header_id=' + record_id;
               }else if(item_code=='PAYMENT_APPROVAL_PROCESS'){
                 var url = $('journal_uploadFile_id').getUrl() + '?table_name=PAYMENT_APPROVAL_PROCESS&header_id=' + record_id;
               }else if(item_code=='SBO_JOURNAL_PDF'){
                var url = $('journal_uploadFile_id').getUrl() + '?table_name=SBO_JOURNAL_PDF&header_id=' + record_id;
            }
                 var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'csh_attachment_uploadFile_id',
                    width: 850,
                    height: 400
                    });
                  win.on('close', function () {
                    record.ds.query();
                });

            }

         window['${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record, bp_seq) {
             window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
             if (name == 'attachment'){
               return '<a href=javascript:upload_voucher_file(\''+record.id+'\',\''+ name + '\',\'' +record.get('journal_header_id')+'\',\'' + record.get('item_code')+'\')>附件上传</a>';
             } else if (name == 'attach_file_name') {
              if (value != null) {
             var link = '${/request/@context_path}/atm_download.lsc?attachment_id=';
             var str = value.split(';;');
             var url = '';
             for (var i = 0; i < str.length; i++) {
                 var temp = str[i].split('--');
                 if (!Leaf.isEmpty(temp[0])) {
                     var file_name = temp[0].toUpperCase();
                     var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                    if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                         url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ',';
                     } else {
                         url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                     }
                 }
             }
             return url;

         }

            }
                };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>