
 

 $(document).ready(function(){

  $('.invoice_shippdf').on('click',function(){

    var id=[];
    

    $('input:checkbox[name=invoice_shipcheck]:checked').each(function(i){
      id[i]=$(this).data('id');
    });
    
    if(id=="")
    {
      alert("Please Select any invoice !!!");
    }
    else
    {
      getdetailsforlable(id);
    }


  });

});

function getdetailsforlable(id)
{
  
  

  $.ajaxSetup({

    headers: {
   
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  
    } 
  
  });
   
    
  $.ajax({ 
    
    url:url_getdetailsforlabel,
  
    method:"POST",
   
    data:{
      id:id,
      "type":"pdf",
    },
  
    success:function(result)
  
    {
      // console.log(result);
      
        printlabel(result);
        
    }
  });
}


function printlabel(data)
{ 
  
// console.log(data);
var label="";
var count=0;

  for(var i=0;i<((data.invoice).length);i++)
  {
	  
      label=label+
  
      '<div class="main-box">'+
      
        '<div class="box">'+

           '<div name="row 1" style="font-size: 24px; border-top: 3px solid black; border-left: 3px solid black; border-right: 3px solid black; border-bottom:5px solid black; height:25;" >'+

            'SHIP TO:'+

          '</div>'+

          '<div class="row2" style="border-left: 3px solid black; font-size:20px; padding:5px; border-right: 3px solid black;">'+

              data.ship[i][0].person_name+'<br/>'+  
              data.invoice[i][0].name+'<br/>'+
              data.ship[i][0].address_line1+'<br/>'+
              data.ship[i][0].address_line2+'<br/>'+
              data.ship[i][0].address_line3+'<br/>'+
              data.ship[i][0].name+' , '+data.ship[i][0].state_title+' -'+data.ship[i][0].pincode+

          '</div>'+

          '<div style="font-size: 20px; border-left: 3px solid black; border-right: 3px solid black; height:25px; border-bottom: 5px solid black;"> '+
            'PH.NO:'+data.ship[i][0].mobile+''+
          '</div>'+
        
          
          '<div style="font-size: 24px; border-bottom: 3px solid black; border-left: 3px solid black; border-right: 3px solid black;"> '+
            'FROM:'+
          '</div>'+

          '<div style="border-left: 3px solid black; border-right: 3px solid black; border-bottom: 3px solid black;height: 115px;">'+
            '<img src="'+ttb_logo+'"  width="180" height="105">'+
          '</div>'+
      
        '</div>'+

        '<div style="padding: 11px; margin: 20px 0px 0px 0px; font-size: 15px; ">'+
          'Invoice No:'+data.invoice[i][0].invoice_no+''+
        '</div>'+

      '</div>'+
	  '</td></td>';
		
		if(count%2){
			label =label+'<div class="pagebreak"></div>'; 
		}

   
    count++;
  }
  
 
  $("#printdivisionlabel").append(label);
  
  convertprint();

  }

function convertprint()
{
  var mystyle='<style> .main-box { height: 453.54330709px !important ; width: 340.15748031px !important ; margin: 10px !important; } .box { height: 377.95275591px !important; } .row2 { border-bottom: 5px solid black !important; height: 178px !important; } .row3 { border-bottom: 5px solid black !important; height: 30.236220472px !important; } .center { display: block !important; margin-left: auto !important; margin-right: auto !important; width: 50% !important; }  @media print { .pagebreak { page-break-before: always; } }  </style>';
  var divContents = document.getElementById("printdivisionlabel").innerHTML;
  var a = window.open('', '', 'height=3508, width=2480'); 
  a.document.write('<html><body>');
  a.document.write(mystyle);
  a.document.write(divContents);
  a.document.write('</body></html>');
  a.document.close();
  

  setTimeout(function(){
    a.print();
  }, 400);
   
  $('#printdivisionlabel').empty();

}





