	var invoice_id;
  $("#piprintoption").css("width","500px");

  $('.invoice_printbtn').on('click',function(){
		invoice_id=$(this).data('id');
		var optionappend=0;appendoption="";
		
		
	if(invoice_id.slice(0,1) == 'v'){
		
			invoice_id = invoice_id.substring(1);
		   printInvoice(optionappend ,invoice_id,1);
	}else{
			invoice_id = invoice_id.substring(1);
		appendoption=appendoption+'<label class="control-label"> Select Print Option </label>'+'<select class="form-control printoption_select" id="printoption_selectinvoice" style="width: 100%;">'+'<option value="0" disabled selected value >- Select Invoice Print Option -</option>'+'<option value="1">Print with logo</option>'+'<option value="2">Print without logo</option>'+'</select>';
		$('#selectappend_invoice').html(appendoption);
		$("#invoice_printoption").modal('show');
	}
  });
     
  $('.printoption_submitinvoice').on('click',function(){
         $("#invoice_printoption").modal('hide');
         optionappend=$('#printoption_selectinvoice').find(':selected').val();
         printInvoice(optionappend ,invoice_id,0);
  });
     
	 $('#close_printoption').on('click',function(){
         $('#selectappend_invoice').empty();
      });
    


function printInvoice(optionappend,invoice_id,isViewOnly){
	var result="";var invoice="";var billaddress_line3="";var shipaddress_line3="";var header = "";
    var mysty='<style> .invoice { border: 2px solid black; height: 1318px; width: 1050px; }.invoice-header{border-bottom: 2px solid black;  height: 150px;width: 100%;}.invoice-address{border-bottom: 2px solid black;height: 250px;width: 100%;padding-left:13px;}.invoice-table{border-bottom: 2px solid black;height: 600px;width: 100%;}.invoice-total{border-bottom: 2px solid black;}.address-col{border-right: 2px solid black;height: 220px;}#product_table{max-height: 650px;margin-left: 13px;table-layout:fixed;}#product_table thead{border-bottom: 2px solid black;}.total-row{border-bottom: 2px solid black;}.gst-info{border-right: 2px solid black;}.bank-payment{border-bottom: 2px solid black;}.gst-total{border-bottom: 2px solid black;}.empty-head{height: 200px;}.empty-foot{height: 135px;}</style>';
	var serialNoData= "";
	
  $.ajaxSetup({
    headers: {
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
  });  
    
  $.ajax({
    url:url_getinvoicedetail,
    method:"POST",
    data:
    {invoice_id:invoice_id},
    success:function(data){
		result=productrowcalculaton(data);
        var title = data.data['invoice_no'];
		if(optionappend == 1  || isViewOnly){
		    mysty='<style> .invoice { border: 2px solid black; height: 1490px; width: 1050px; } .invoice-header {  height: 143px; width: 100%; } .invoice-address { border-bottom: 2px solid black; height: 250px; width: 100%;padding-left:13px; } .invoice-table { border-bottom: 2px solid black; height: 600px; width: 100%; padding-left:13px } .invoice-total { border-bottom: 2px solid black; } .address-col { border-right: 2px solid black; height: 220px; } .total-row { border-bottom: 2px solid black; } .gst-info { border-right: 2px solid black; } .bank-payment { border-bottom: 2px solid black; } .gst-total { border-bottom: 2px solid black; } #product_table { max-height: 750px; table-layout:fixed; } </style>';
			header = printHeader();
		}
		else{
			invoice ='<div class="empty-head"></div>';
			serialNoData = '<div class="empty-head"></div>';
		}
		
		  invoice= invoice+
          '<div class="invoice">'
		  + header 
		  + getBillingShippingAddress(data,'Invoice') 
		  + productData(result)
			+
            getFootData(result , data,'Invoice')
			+printFooter('Invoice');
            
          $("#printdivision").html(invoice);
       
		  if(data.isSerialNo){
			  serialNoData = serialNoData 
			  + '<div class="invoice">' 
			  +header 
			  + getBillingShippingAddress(data,'Invoice')
			  +productSerialNoData(data);
			  +'</div>'
			  $("#printdivSerialNo").html(serialNoData);
		  }
		 if(!isViewOnly){
				printCustom(mysty,title);
				
		  }else{
			  var mystyle1 ="<style> .invoice { border: 2px solid black; height: 1250px; width: 1050px; }.invoice-header{border-bottom: 2px solid black;  height: 150px;width: 100%;}.invoice-address{border-bottom: 2px solid black;height: 250px;width: 100%;padding-left:13px;}.invoice-table{border-bottom: 2px solid black;height: 650px;width: 100%;}.invoice-total{border-bottom: 2px solid black;}.address-col{border-right: 2px solid black;height: 220px;}#product_table{max-height: 650px;margin-left: 13px;table-layout:fixed;}#product_table thead{border-bottom: 2px solid black;}.total-row{border-bottom: 2px solid black;}.gst-info{border-right: 2px solid black;}.bank-payment{border-bottom: 2px solid black;}.gst-total{border-bottom: 2px solid black;}.empty-head{height: 200px;}.empty-foot{height: 135px;}</style>";
				$("#printdivisionqv").html(invoice);
				$('.custom-modal-title').html('Tax Invoice');
				$("#quotation_view").modal('show');
		  }

	}	

  });
}
