<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">function getAjaxUrl() {

    var notasupto_ajaxUrl = '/wp-admin/admin-ajax.php';

    if (typeof ajaxurl === 'undefined') {

        return notasupto_ajaxUrl;

    } else {
        return ajaxurl;
    }
}

jQuery(document).ready(function( $ ) {

  if($('input[type=checkbox][name=billing_is_invoice]').is(':checked')){
     $('.invoice').show(500);
  }else{
     $('.invoice').hide(500);
  }
  $('input[type=checkbox][name=billing_is_invoice]').on('change', function () {

   if($('input[type=checkbox][name=billing_is_invoice]').is(':checked')){
          $('.invoice').show(500);
   }else{
          $('.invoice').hide(500);
   }
  });
  
  if(notasupto_php_vars.isCheckout){

    var vat_num = $("#billing_invoice_vatnum").val();
    //var length = $("#billing_invoice_vatnum").val().length;
    var length = ($('#billing_invoice_vatnum').length) ? $("#billing_invoice_vatnum").val().length : 2;
    eu_vat_ajax(vat_num, length);  

      $.fn.extend({
        donetyping: function(callback,timeout){
        timeout = timeout || 2e3;
        var timeoutReference,
        doneTyping = function(el){
          if (!timeoutReference) return;
            timeoutReference = null;
            callback.call(el);
          };
          return this.each(function(i,el){
          var $el = $(el);

          $el.is(':input') &amp;&amp; $el.on('keyup keypress paste',function(e){

            if (e.type=='keyup' &amp;&amp; e.keyCode!=8) return;

            if (timeoutReference) clearTimeout(timeoutReference);
              timeoutReference = setTimeout(function(){

                doneTyping(el);
              }, timeout);
            }).on('blur',function(){

              doneTyping(el);
            });
        });
      }
    });

    if($('input[type=checkbox][name=billing_is_invoice]').is(':checked')){
      $('.invoice').show(500);
    }else{
      $('.invoice').hide(500);
    }

    $('#billing_invoice_vatnum').donetyping(function(){
      var vat_num = $("#billing_invoice_vatnum").val();
      var length = ($('#billing_invoice_vatnum').length) ? $("#billing_invoice_vatnum").val().length : 2;
      eu_vat_ajax(vat_num, length);
    });


    function eu_vat_ajax(vat_num, length){
      if( length &gt; 9 || length == 0 ){
        $.ajax({
          type: 'POST',
          url: ajaxurl,
          data: {
            action: 'notasuptoinvoice_handle_ajax',
            action2: 'eu_vat_exempt',
            vat_num: vat_num,
            length: length
          },
          success: function( response ) {
            jQuery( 'body' ).trigger( 'update_checkout' );
          },
        });
      }
    }

  }


  function update_documents_customer_details(order_id){
        jQuery('#notasuptoLoader').show();
        jQuery.ajax({

                url: ajaxurl,
                dataType: "json",
                
                data: {
                action: 'notasuptoinvoice_handle_ajax',
                action2: 'update_documents_customer_details',
                order_id: order_id,
                },

                success: function(data){
                  jQuery('#notasuptoLoader').hide();
                    //location.reload();
                  
                },


         });

      }
  
      jQuery(".notasupto-update-documents-customer-details-btn").click(function(e){
        var order_id = jQuery(this).data('order-id');
        update_documents_customer_details(order_id);

      });

      function create_manual_invoice(order_id){
        jQuery('#notasuptoLoader').show();
        jQuery.ajax({

                url: ajaxurl,
                dataType: "json",
                
                data: {
                action: 'notasuptoinvoice_handle_ajax',
                action2: 'create_manual_invoice',
                order_id: order_id,
                },

                success: function(data){
                  console.log('data', data);
                  jQuery('#notasuptoLoader').hide();
                  //location.reload();

                  if (data.pdf_button &amp;&amp; data.order_id) {
                      // Find the button with the matching data-order-id
                      var $button = $('.notasupto-create-manual-invoice-btn[data-order-id="' + data.order_id + '"]');
                      
                      if ($button.length) {
                          // Replace the button with the content of 'pdf_button'
                          $button.replaceWith(data.pdf_button);
                      }
                  }

                },


         });

      }

      jQuery(".notasupto-create-manual-invoice-btn").click(function(e){
        var order_id = jQuery(this).data('order-id');
        create_manual_invoice(order_id);

      });



});
</pre></body></html>