<div class="container-md">
  <div class="row">
    <div class="col-6 col-md-6">
      <textarea class='data_qr form-control col-12' style="display:block;height:100px;" Placeholder="Place your Data String"></textarea>
      <br/>
      <button class="btn btn-primary collg-4 m0 g_qr float-right"  >Generate / Validate QR</button>
      <div class="qrcode col-10 float-left" ></div>
    </div>
    <div class=".col-6 col-md-6 float-right" id="form_data" style="display:none" >
      
      <div class="col-md-12 mb-12">
        <label for="SellerGstin">Seller GSTIN</label>
        <input type="text" class="form-control" id="SellerGstin" placeholder="" value="" readonly required>        
      </div>
      <div class="col-md-12 mb-12">
        <label for="BuyerGstin">Buyer GSTIN</label>
        <input type="text" class="form-control" id="BuyerGstin" placeholder="" value="" readonly required>        
      </div>
      <div class="col-md-12 mb-12">
        <label for="DocNo">Invoice No</label>
        <input type="text" class="form-control" id="DocNo" placeholder="" value="" readonly required>        
      </div>
      <div class="col-md-12 mb-12">
        <label for="DocDt">Invoice Date</label>
        <input type="text" class="form-control" id="DocDt" placeholder="" value="" readonly required>        
      </div>
      <div class="col-md-12 mb-12">
        <label for="TotInvVal">Net Value</label>
        <input type="text" class="form-control" id="TotInvVal" placeholder="" value="" readonly required>        
      </div>
      <div class="col-md-12 mb-12">
        <label for="ItemCnt">Items (count)</label>
        <input type="text" class="form-control" id="ItemCnt" placeholder="" value="" readonly required>        
      </div>
      <div class="col-md-12 mb-12">
        <label for="Irn">IRN </label>
        <input type="text" class="form-control" id="Irn" placeholder="" value="" readonly required>        
      </div>
      <div class="col-md-12 mb-12">
        <label for="excel_file">Upload Excel File to Fetch QR Details </label>        
        <input type="file" id="excel_file" name="excel_file" class="form-control" />     
        <br/>
        <br/> 
      </div>
      <div class="col-md-12 mb-12">
        <button class="btn btn-primary form-control submitBtn " id="submitBtn">Upload</button>
      </div>
      <div class="form-group">
        <a id="download_link" style="display:none;" class="btn btn-primary" download="" href='' >Download uploaded File</a>
      </div>

    </div>    
  </div>
  <div class="ListInvoices" id="ListInvoices">

  </div>
</div>
<script>



</script>
<script>
        $(document).ready(function(){     

          LoadList();  

          $('#submitBtn').click(function(){
            var extension = $('#excel_file').val().split('.').pop().toLowerCase();
            var validFileExtensions = ['xls', 'xlsb', 'xlsx', 'xlsm', 'xlw', 'xps','xml' ];
            if ($.inArray(extension, validFileExtensions) == -1){
                $(this).replaceWith($(this).val('').clone(true));
                swal("Warning","Please select valid file");
            }
            else{
              var Qr_data = $('.data_qr').val();
              var Inv_no = $('#DocNo').val();
              var Inv_Date = $('#DocDt').val();
              var SellerGstin = $('#SellerGstin').val();
              var BuyerGstin = $('#BuyerGstin').val();
              var TotInvVal = $('#TotInvVal').val();
              var ItemCnt = $('#ItemCnt').val();
              var Irn = $('#Irn').val();
              var Qr_url = $('#ImageUrl').val();

              //var Qr_data = $('#SellerGstin').val();
              //var Qr_data = $('#SellerGstin').val();
              var file_data = $('#excel_file').prop('files')[0];   
              var form_data = new FormData();                  
              form_data.append('Qr_data', Qr_data);
              form_data.append('Inv_no', Inv_no);
              form_data.append('Inv_Date', Inv_Date);
              form_data.append('SellerGstin', SellerGstin);
              form_data.append('BuyerGstin', BuyerGstin);
              form_data.append('TotInvVal', TotInvVal);
              form_data.append('ItemCnt', ItemCnt);
              form_data.append('Irn', Irn);
              form_data.append('Qr_url', Qr_url);
              form_data.append('excel_file', file_data);
              //$(this).hide();
              
              $.ajax({
                url: 'pages/save_invoice.php', 
                //url: 'tools/save_excel.php',
                dataType: 'JSON',  
                cache: false,
                contentType: false,
                processData: false,
                data: form_data,                         
                type: 'post',
                success: function(php_script_response){                
                  $('#download_link').attr("href",php_script_response.download );
                  $('#download_link').attr("download","" );
                  $('#download_link').show();
                  LoadList();
                }
              });
            }

          });   


            $('.g_qr').click(function(){
                var post_data = $('.data_qr').val();
                $.ajax({
                    url : 'qr/index.php?data='+post_data,
                    type : 'GET',
                    // dataType: "JSON",
                    // data : {
                    //     data : post_data
                    // },
                    success : function(response){
                        $('.qrcode').html(response);                        
                    }
                });

                $.ajax({
                    url : 'tools/decrypt_QR.php?data='+post_data,
                    type : 'GET',
                    success : function(response){
                        $('.qrcode_details > textarea').val(response);    
                        $('.qrcode_details > textarea').show();                        
                        var json = $.parseJSON(response);
                        var datas = $.parseJSON(json.data);
                        $('#SellerGstin').val(datas['SellerGstin']);
                        $('#BuyerGstin').val(datas['BuyerGstin']);
                        $('#DocNo').val(datas['DocNo']);
                        $('#DocDt').val(datas['DocDt']);
                        $('#TotInvVal').val(datas['TotInvVal']);
                        $('#ItemCnt').val(datas['ItemCnt']);
                        $('#Irn').val(datas['Irn']);

                        $('.data_qr ').attr('readonly','readonly');
                        $('.g_qr').hide();
                        $('#form_data').show();
                    }
                });

                $('.upload').show();
            });

            $('.sidebar-sticky > ul > li > a').on('click', function(){
                $('.sidebar-sticky > ul > li > a').removeClass('active');
                $(this).addClass('active');        
            });
            
            
            

            
        });

        $('#excel_file').change(function(){
          var extension = $(this).val().split('.').pop().toLowerCase();
          var validFileExtensions = ['xls', 'xlsb', 'xlsx', 'xlsm', 'xlw', 'xps','xml' ];
          if ($.inArray(extension, validFileExtensions) == -1){
              $(this).replaceWith($(this).val('').clone(true));
              swal("Warning","Please select valid file");
          }

        });

        $('#excel_files').change(function(){
          var extension = $(this).val().split('.').pop().toLowerCase();
          var validFileExtensions = ['xls', 'xlsb', 'xlsx', 'xlsm', 'xlw', 'xps','xml' ];
          if ($.inArray(extension, validFileExtensions) == -1){
              $(this).replaceWith($(this).val('').clone(true));
              swal("Warning","Please select valid file");
          }
          else{
              if ($(this).get(0).files[0].size > (2050 * 1024)){
                  swal("Warning","File size above the limit");
              }
              else{
                var file_data = $('#excel_file').prop('files')[0];   
                var form_data = new FormData();                  
                form_data.append('excel_file', file_data);               
                form_data.append('irn_value',$('#Irn').val());
                $.ajax({
                    url: 'tools/save_excel.php', // point to server-side PHP script 
                    dataType: 'text',  // what to expect back from the PHP script, if anything
                    cache: false,
                    contentType: false,
                    processData: false,
                    data: form_data,                         
                    type: 'post',
                    success: function(php_script_response){
                        //alert(php_script_response); // display response from the PHP script, if any
                        $('#download_link').show();
                    }
                });
              }        
          }
        });




    </script>

<link rel="stylesheet" href="wait/waitMe.css"/>
<link rel="stylesheet" href="wait/waitMe.min.css"/>
<script src="wait/waitMe.js" type="text/javascript"></script>
<script src="wait/waitMe.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.22/datatables.min.css"/> 
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.22/datatables.min.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> -->




