{{ javascript_include("js/jquery.min.js") }}
{{ javascript_include("vendors/jquery-ui-1.12.1.custom/jquery-ui.min.js") }}

<script>
$(document).ready(function() {
  let filename;
  let date = new Date();
  let currDate = ''+date.getFullYear()+(date.getMonth()-1+2)+date.getDate();
  let currTime = ''+date.getHours()+date.getMinutes()+date.getSeconds();
  filename = 'template_'+currDate+'_'+currTime;
  $.ajax({
    type: "POST",
    url: "{{ url('excel/execDownloadXlsTemplateForNewOrder') }}",
    dataType: "json",
    data: {
      cdcata: "{{ cdcata }}",
      cdetic: "{{ cdetic }}",
      tpanag: "{{ tpanag }}",
      cdanag: "{{ cdanag }}",
      cddesm: "{{ cddesm }}",
      dtmcli: "{{ dtmcli }}",
      'filename': filename
    }
  }).done(function(data) {
    // download
    var link = document.createElement('a');
    link.href = "../public/io/template/" + filename + '.xlsx';
    link.download = filename+'.xlsx';
    document.body.appendChild(link);
    link.click();
    setTimeout(function(){
      window.close();
    }, 1000);
  }).error(function(x, t, m) {
    console.log(m.toString());
		printAjaxError(x, t, m);
    var link = document.createElement('a');
    link.href = "../public/io/template/" + filename + '.xlsx';
    link.download = filename+'.xlsx';
    document.body.appendChild(link);
    link.click();
    setTimeout(function(){
      window.close();
    }, 1000);
  });
});
</script>
